From 21aa1bef68c3590c1898a539da4c38e3854a5a9d Mon Sep 17 00:00:00 2001 From: Martin Fouilleul Date: Mon, 26 Jun 2023 19:59:34 +0200 Subject: [PATCH] [win32] honor timeout value in mp_pump_events --- src/mp_app.h | 6 ++++++ src/win32_app.c | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/mp_app.h b/src/mp_app.h index e2cd6b1..468b06c 100644 --- a/src/mp_app.h +++ b/src/mp_app.h @@ -268,7 +268,13 @@ MP_API void mp_set_cursor(mp_mouse_cursor cursor); //-------------------------------------------------------------------- // Main loop and events handling //-------------------------------------------------------------------- +/*NOTE: + mp_pump_events() pumps system events into the event queue. A timeout of 0 polls for events, + while a timeout of -1 blocks for events. A timeout > 0 blocks until new events are available + or the timeout elapses. + mp_next_event() get the next event from the event queue, allocating from the passed arena +*/ MP_API void mp_pump_events(f64 timeout); MP_API mp_event* mp_next_event(mem_arena* arena); diff --git a/src/win32_app.c b/src/win32_app.c index 14e11d9..af99453 100644 --- a/src/win32_app.c +++ b/src/win32_app.c @@ -553,6 +553,16 @@ void mp_request_quit() void mp_pump_events(f64 timeout) { MSG message; + + if(timeout < 0) + { + WaitMessage(); + } + else if(timeout > 0) + { + MsgWaitForMultipleObjects(0, NULL, FALSE, (DWORD) (timeout * 1e3), QS_ALLEVENTS); + } + while(PeekMessage(&message, 0, 0, 0, PM_REMOVE)) { TranslateMessage(&message);