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 15:11:09 -0500
committerItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com>2026-11-22 15:11:09 -0500
commitcda0da18b8a3bd7882ff18e54c077018e2531ad7 (patch)
treec584d489b111a1268fd3cc6cfc2e8cb16c7e6789 /runtime/test/gameinput_test.cpp
parent796486fb47497fabacbf9416d78360a12b4970de (diff)
parentf5907ef65ab326d92db9d4035b2899e4fe57b688 (diff)
Merge pull request #2567 from marquezini
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 99e74a082..0a739e781 100644
--- a/runtime/test/gameinput_test.cpp
+++ b/runtime/test/gameinput_test.cpp
@@ -131,10 +131,17 @@ void CALLBACK on_device(GameInputCallbackToken token, void*, IGameInputDevice* d
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 133DWORD g_reading_sleep_ms = 0; // makes on_reading slow, for the Dispatch quota checks
134SDL_Joystick* g_requeue_pad = nullptr; // set: on_reading queues one more reading from inside the callback
135bool g_requeue_down = false;
134 136
135void CALLBACK on_reading(GameInputCallbackToken, void*, IGameInputReading* reading, bool) { 137void CALLBACK on_reading(GameInputCallbackToken, void*, IGameInputReading* reading, bool) {
136 if (reading) ++g_reading_events; 138 if (reading) ++g_reading_events;
137 if (g_reading_sleep_ms) Sleep(g_reading_sleep_ms); 139 if (g_reading_sleep_ms) Sleep(g_reading_sleep_ms);
140 if (g_requeue_pad) {
141 g_requeue_down = !g_requeue_down;
142 SDL_SetJoystickVirtualButton(g_requeue_pad, SDL_GAMEPAD_BUTTON_WEST, g_requeue_down);
143 rt::gameinput::poll();
144 }
138} 145}
139void CALLBACK on_guide(GameInputCallbackToken, void*, IGameInputDevice*, uint64_t, bool pressed) { 146void CALLBACK on_guide(GameInputCallbackToken, void*, IGameInputDevice*, uint64_t, bool pressed) {
140 g_guide_events.push_back(pressed); 147 g_guide_events.push_back(pressed);
@@ -1361,6 +1368,8 @@ int main() {
1361 if (wait) WaitForSingleObject(wait, 0); // consume the signal from queueing 1368 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"); 1369 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"); 1370 check(wait && WaitForSingleObject(wait, 0) == WAIT_OBJECT_0, "the wait handle is signalled again while events remain");
1371 // The callback sleeps 5 ms, so at least 5 ms have passed after the first event however loaded the machine
1372 // is; a slower run only makes the 1 ms quota more clearly spent.
1364 g_reading_sleep_ms = 5; 1373 g_reading_sleep_ms = 5;
1365 before_quota = g_reading_events; 1374 before_quota = g_reading_events;
1366 check(dispatcher->Dispatch(1000) && g_reading_events == before_quota + 1, 1375 check(dispatcher->Dispatch(1000) && g_reading_events == before_quota + 1,
@@ -1370,6 +1379,26 @@ int main() {
1370 check(!dispatcher->Dispatch(1'000'000) && g_reading_events >= before_quota + 2, 1379 check(!dispatcher->Dispatch(1'000'000) && g_reading_events >= before_quota + 2,
1371 "a large quota drains the queue and returns false"); 1380 "a large quota drains the queue and returns false");
1372 check(!dispatcher->Dispatch(0), "Dispatch on an empty queue returns false"); 1381 check(!dispatcher->Dispatch(0), "Dispatch on an empty queue returns false");
1382
1383 // Events queued during a call wait for the next one: each callback here queues another reading, so a
1384 // Dispatch that kept draining would never return. With two events queued, each call runs exactly the batch
1385 // it started with and reports the readings queued meanwhile.
1386 queue_changes(2);
1387 g_requeue_pad = xbox.js;
1388 before_quota = g_reading_events;
1389 check(dispatcher->Dispatch(UINT64_MAX) && g_reading_events == before_quota + 2,
1390 "Dispatch runs only the events queued when it started");
1391 before_quota = g_reading_events;
1392 check(dispatcher->Dispatch(UINT64_MAX) && g_reading_events == before_quota + 2,
1393 "the events queued during the call run on the next one");
1394 g_requeue_pad = nullptr;
1395 while (dispatcher->Dispatch(UINT64_MAX)) {}
1396 if (g_requeue_down) {
1397 g_requeue_down = false;
1398 SDL_SetJoystickVirtualButton(xbox.js, SDL_GAMEPAD_BUTTON_WEST, false);
1399 rt::gameinput::poll();
1400 while (dispatcher->Dispatch(UINT64_MAX)) {}
1401 }
1373 } 1402 }
1374 if (wait) CloseHandle(wait); 1403 if (wait) CloseHandle(wait);
1375 if (dispatcher) dispatcher->Release(); 1404 if (dispatcher) dispatcher->Release();