From 90b9b63b2001c4595c08f7da5aa4403611327678 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 22 Jan 2025 10:44:34 -0500 Subject: Windows: Avoid waiting less than a millisecond There is API to access the minimum timer resolution, but it seems to always be 1 millisecond, which is also the unit of the MsgWaitForMultipleObjects parameter, so just avoid the fuss and hardcode this as the minimum. This should slightly reduce overhead when the main loop is running without much of a margin until the frame needs to be drawn. --- src/win.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/win.c b/src/win.c index d06e257..bc13a0f 100644 --- a/src/win.c +++ b/src/win.c @@ -1137,16 +1137,18 @@ puglDispatchWinEvents(PuglWorld* world) PuglStatus puglUpdate(PuglWorld* world, double timeout) { + static const double minWaitSeconds = 0.002; + const double startTime = puglGetTime(world); PuglStatus st = PUGL_SUCCESS; if (timeout < 0.0) { st = puglPollWinEvents(world, timeout); st = st ? st : puglDispatchWinEvents(world); - } else if (timeout <= 0.001) { + } else if (timeout < minWaitSeconds) { st = puglDispatchWinEvents(world); } else { - const double endTime = startTime + timeout - 0.001; + const double endTime = startTime + timeout - minWaitSeconds; for (double t = startTime; t < endTime; t = puglGetTime(world)) { if ((st = puglPollWinEvents(world, endTime - t)) || (st = puglDispatchWinEvents(world))) { -- cgit v1.2.1