diff options
| author | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-22 15:11:09 -0500 |
|---|---|---|
| committer | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-22 15:11:09 -0500 |
| commit | cda0da18b8a3bd7882ff18e54c077018e2531ad7 (patch) | |
| tree | c584d489b111a1268fd3cc6cfc2e8cb16c7e6789 /runtime/shims/gameinput.cpp | |
| parent | 796486fb47497fabacbf9416d78360a12b4970de (diff) | |
| parent | f5907ef65ab326d92db9d4035b2899e4fe57b688 (diff) | |
Merge pull request #2567 from marquezini
Diffstat (limited to 'runtime/shims/gameinput.cpp')
| -rw-r--r-- | runtime/shims/gameinput.cpp | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/runtime/shims/gameinput.cpp b/runtime/shims/gameinput.cpp index 89b66364d..a6940f6ad 100644 --- a/runtime/shims/gameinput.cpp +++ b/runtime/shims/gameinput.cpp | |||
| @@ -700,31 +700,32 @@ bool deliver() { | |||
| 700 | return !s.queue.empty(); | 700 | return !s.queue.empty(); |
| 701 | } | 701 | } |
| 702 | 702 | ||
| 703 | // IGameInputDispatcher::Dispatch: runs queued events oldest first, at least one even with a quota of 0, and takes no | 703 | // IGameInputDispatcher::Dispatch: runs the events queued when the call starts, oldest first: at least one even with a |
| 704 | // further event once quota_us microseconds have passed (an event already started runs to the end, so the quota is a | 704 | // quota of 0, and no further event once quota_us microseconds have passed (an event already started runs to the end, |
| 705 | // target, as on Windows). While events remain the wait handle is signalled again, so a title that waits on it before | 705 | // so the quota is a target, as on Windows). Events queued during the call wait for the next one, so a busy poll thread |
| 706 | // each call comes back for the rest. Returns whether events remain. | 706 | // cannot keep the title inside Dispatch even with an unlimited quota. Events left over go back to the front of the |
| 707 | // queue, ahead of newer ones, and the wait handle is signalled again while any remain. Returns whether events remain. | ||
| 707 | bool deliver_within(uint64_t quota_us) { | 708 | bool deliver_within(uint64_t quota_us) { |
| 708 | State& s = g(); | 709 | State& s = g(); |
| 709 | std::lock_guard dl(s.deliver_mu); | 710 | std::lock_guard dl(s.deliver_mu); |
| 710 | const auto start = std::chrono::steady_clock::now(); | 711 | const auto start = std::chrono::steady_clock::now(); |
| 712 | std::vector<Event> batch; | ||
| 713 | { | ||
| 714 | std::lock_guard lock(s.mu); | ||
| 715 | batch.swap(s.queue); | ||
| 716 | } | ||
| 711 | s.delivering_thread = GetCurrentThreadId(); | 717 | s.delivering_thread = GetCurrentThreadId(); |
| 712 | for (bool first = true;; first = false) { | 718 | size_t next = 0; |
| 713 | if (!first) { | 719 | while (next < batch.size()) { |
| 720 | if (next > 0) { | ||
| 714 | const auto spent = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - start); | 721 | const auto spent = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - start); |
| 715 | if (static_cast<uint64_t>(spent.count()) >= quota_us) break; | 722 | if (static_cast<uint64_t>(spent.count()) >= quota_us) break; |
| 716 | } | 723 | } |
| 717 | Event e; | 724 | deliver_event(batch[next++]); |
| 718 | { | ||
| 719 | std::lock_guard lock(s.mu); | ||
| 720 | if (s.queue.empty()) break; | ||
| 721 | e = s.queue.front(); | ||
| 722 | s.queue.erase(s.queue.begin()); | ||
| 723 | } | ||
| 724 | deliver_event(e); | ||
| 725 | } | 725 | } |
| 726 | s.delivering_thread = 0; | 726 | s.delivering_thread = 0; |
| 727 | std::lock_guard lock(s.mu); | 727 | std::lock_guard lock(s.mu); |
| 728 | if (next < batch.size()) s.queue.insert(s.queue.begin(), batch.begin() + static_cast<std::ptrdiff_t>(next), batch.end()); | ||
| 728 | const bool remaining = !s.queue.empty(); | 729 | const bool remaining = !s.queue.empty(); |
| 729 | if (remaining && s.wait_event) SetEvent(s.wait_event); | 730 | if (remaining && s.wait_event) SetEvent(s.wait_event); |
| 730 | return remaining; | 731 | return remaining; |