perf(window): block message loop while paused on Win32 (#134) #152

Merged
catbot merged 1 commit from claude/issue-134 into master 2026-06-18 16:01:28 +02:00

View file

@ -698,7 +698,20 @@ void Window::StartSync() {
} }
#endif #endif
#ifdef CRAFTER_GRAPHICS_WINDOW_WIN32 #ifdef CRAFTER_GRAPHICS_WINDOW_WIN32
// While updating, the FIFO present inside Update() paces this loop to the
// vblank, so the PeekMessage poll is vsync-gated. While NOT updating
// (paused / minimized / stopped) nothing throttles the loop, and a bare
// PeekMessage(PM_REMOVE) spin pins a core at 100% while uselessly re-running
// Gamepad::Tick() (mutex + per-pad COM reads) and onBeforeUpdate every
// iteration. Block on the message queue instead, waking on input or after a
// short timeout so gamepad polling / onBeforeUpdate still tick at a sane
// rate (e.g. to detect a controller button asking to resume).
constexpr DWORD kPausedPollIntervalMs = 16;
while(open) { while(open) {
if (!updating) {
MsgWaitForMultipleObjectsEx(0, nullptr, kPausedPollIntervalMs,
QS_ALLINPUT, MWMO_INPUTAVAILABLE);
}
MSG msg; MSG msg;
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
TranslateMessage(&msg); TranslateMessage(&msg);