[win32] honor timeout value in mp_pump_events

This commit is contained in:
Martin Fouilleul 2023-06-26 19:59:34 +02:00
parent 0d65d19436
commit 21aa1bef68
2 changed files with 16 additions and 0 deletions

View File

@ -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);

View File

@ -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);