upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/test/gameinput_test.cpp
diff options
context:
space:
mode:
authormarquezini <felipemarquesini10@gmail.com>2026-11-22 14:31:09 -0300
committermarquezini <felipemarquesini10@gmail.com>2026-11-22 14:31:09 -0300
commit2aed56c6e50c4fa577c50e5b10976ba9f9a7379f (patch)
tree17d97c52f6d32794c0a98f9fb75edd66beba3713 /runtime/test/gameinput_test.cpp
parent49475796c226c8511b9470bf97a4daf57b8af323 (diff)
RT-176: IGameInputDispatcher::Dispatch honours its quota
Dispatch ran the whole queue whatever quota it was given. It now runs queued events oldest first, at least one per call (a quota of 0 runs exactly one, as the GDK documents), takes no further event once the quota has passed, and returns whether events remain. While events remain the wait handle is signalled again, so a title that waits on it before each call comes back for the rest. The automatic path (no dispatcher, poll thread) still delivers the whole queue. gameinput_test checks Dispatch(0), a 1 ms quota against a 5 ms callback, a large quota draining the queue, and an empty queue.
Diffstat (limited to 'runtime/test/gameinput_test.cpp')
-rw-r--r--runtime/test/gameinput_test.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/runtime/test/gameinput_test.cpp b/runtime/test/gameinput_test.cpp
index f525d1cb9..d9b5d57e2 100644
--- a/runtime/test/gameinput_test.cpp
+++ b/runtime/test/gameinput_test.cpp
@@ -130,8 +130,11 @@ void CALLBACK on_device(GameInputCallbackToken token, void*, IGameInputDevice* d
130 uint32_t previous) { 130 uint32_t previous) {
131 g_device_events.push_back({device, current, previous, token}); 131 g_device_events.push_back({device, current, previous, token});
132} 132}
133DWORD g_reading_sleep_ms = 0; // makes on_reading slow, for the Dispatch quota checks
134
133void CALLBACK on_reading(GameInputCallbackToken, void*, IGameInputReading* reading, bool) { 135void CALLBACK on_reading(GameInputCallbackToken, void*, IGameInputReading* reading, bool) {
134 if (reading) ++g_reading_events; 136 if (reading) ++g_reading_events;
137 if (g_reading_sleep_ms) Sleep(g_reading_sleep_ms);
135} 138}
136void CALLBACK on_guide(GameInputCallbackToken, void*, IGameInputDevice*, uint64_t, bool pressed) { 139void CALLBACK on_guide(GameInputCallbackToken, void*, IGameInputDevice*, uint64_t, bool pressed) {
137 g_guide_events.push_back(pressed); 140 g_guide_events.push_back(pressed);
@@ -979,6 +982,32 @@ int main() {
979 check(wait && WaitForSingleObject(wait, 0) == WAIT_OBJECT_0, "the wait handle is signalled"); 982 check(wait && WaitForSingleObject(wait, 0) == WAIT_OBJECT_0, "the wait handle is signalled");
980 if (dispatcher) dispatcher->Dispatch(1000); 983 if (dispatcher) dispatcher->Dispatch(1000);
981 check(g_reading_events > before_dispatch, "Dispatch runs them"); 984 check(g_reading_events > before_dispatch, "Dispatch runs them");
985
986 // The quota: Dispatch runs at least one queued event, takes no more once the quota has passed, and returns whether
987 // events remain (re-signalling the wait handle). Four button changes queue four reading events.
988 auto queue_changes = [&](int n) {
989 for (int i = 0; i < n; ++i) {
990 SDL_SetJoystickVirtualButton(xbox.js, SDL_GAMEPAD_BUTTON_NORTH, i % 2 == 1); // NORTH is down now: up, down, up, down
991 rt::gameinput::poll();
992 }
993 };
994 if (dispatcher) {
995 while (dispatcher->Dispatch(UINT64_MAX)) {}
996 queue_changes(4);
997 int before_quota = g_reading_events;
998 if (wait) WaitForSingleObject(wait, 0); // consume the signal from queueing
999 check(dispatcher->Dispatch(0) && g_reading_events == before_quota + 1, "Dispatch(0) runs exactly one event and reports more");
1000 check(wait && WaitForSingleObject(wait, 0) == WAIT_OBJECT_0, "the wait handle is signalled again while events remain");
1001 g_reading_sleep_ms = 5;
1002 before_quota = g_reading_events;
1003 check(dispatcher->Dispatch(1000) && g_reading_events == before_quota + 1,
1004 "a 1 ms quota stops after a 5 ms callback and reports more");
1005 g_reading_sleep_ms = 0;
1006 before_quota = g_reading_events;
1007 check(!dispatcher->Dispatch(1'000'000) && g_reading_events >= before_quota + 2,
1008 "a large quota drains the queue and returns false");
1009 check(!dispatcher->Dispatch(0), "Dispatch on an empty queue returns false");
1010 }
982 if (wait) CloseHandle(wait); 1011 if (wait) CloseHandle(wait);
983 if (dispatcher) dispatcher->Release(); 1012 if (dispatcher) dispatcher->Release();
984 1013