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:
authorItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com>2026-11-22 13:16:16 -0500
committerItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com>2026-11-22 13:16:16 -0500
commit8599c9e64c40219a9e60e567102ea4a2252bc7dd (patch)
tree7c6e8f8a0e30e0b60ee81b61c654159fdd6f0f41 /runtime/test/gameinput_test.cpp
parentcd7bcc34a33163f9a082e0864415112ec6181e53 (diff)
parent2aed56c6e50c4fa577c50e5b10976ba9f9a7379f (diff)
Merge pull request #2567 from marquezini
# Conflicts: # docs/gameinput.md
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 93eda4085..99e74a082 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);
@@ -1342,6 +1345,32 @@ int main() {
1342 check(wait && WaitForSingleObject(wait, 0) == WAIT_OBJECT_0, "the wait handle is signalled"); 1345 check(wait && WaitForSingleObject(wait, 0) == WAIT_OBJECT_0, "the wait handle is signalled");
1343 if (dispatcher) dispatcher->Dispatch(1000); 1346 if (dispatcher) dispatcher->Dispatch(1000);
1344 check(g_reading_events > before_dispatch, "Dispatch runs them"); 1347 check(g_reading_events > before_dispatch, "Dispatch runs them");
1348
1349 // The quota: Dispatch runs at least one queued event, takes no more once the quota has passed, and returns whether
1350 // events remain (re-signalling the wait handle). Four button changes queue four reading events.
1351 auto queue_changes = [&](int n) {
1352 for (int i = 0; i < n; ++i) {
1353 SDL_SetJoystickVirtualButton(xbox.js, SDL_GAMEPAD_BUTTON_NORTH, i % 2 == 1); // NORTH is down now: up, down, up, down
1354 rt::gameinput::poll();
1355 }
1356 };
1357 if (dispatcher) {
1358 while (dispatcher->Dispatch(UINT64_MAX)) {}
1359 queue_changes(4);
1360 int before_quota = g_reading_events;
1361 if (wait) WaitForSingleObject(wait, 0); // consume the signal from queueing
1362 check(dispatcher->Dispatch(0) && g_reading_events == before_quota + 1, "Dispatch(0) runs exactly one event and reports more");
1363 check(wait && WaitForSingleObject(wait, 0) == WAIT_OBJECT_0, "the wait handle is signalled again while events remain");
1364 g_reading_sleep_ms = 5;
1365 before_quota = g_reading_events;
1366 check(dispatcher->Dispatch(1000) && g_reading_events == before_quota + 1,
1367 "a 1 ms quota stops after a 5 ms callback and reports more");
1368 g_reading_sleep_ms = 0;
1369 before_quota = g_reading_events;
1370 check(!dispatcher->Dispatch(1'000'000) && g_reading_events >= before_quota + 2,
1371 "a large quota drains the queue and returns false");
1372 check(!dispatcher->Dispatch(0), "Dispatch on an empty queue returns false");
1373 }
1345 if (wait) CloseHandle(wait); 1374 if (wait) CloseHandle(wait);
1346 if (dispatcher) dispatcher->Release(); 1375 if (dispatcher) dispatcher->Release();
1347 1376