From 648edc92c888c6ab2f26003758164418b4c5eee6 Mon Sep 17 00:00:00 2001 From: casey langen Date: Thu, 23 Mar 2017 17:09:09 -0700 Subject: [PATCH] Updated PDCurses's message pump to use way fewer CPU cycles. --- src/3rdparty/win32_src/pdcurses/pdcutil.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/3rdparty/win32_src/pdcurses/pdcutil.c b/src/3rdparty/win32_src/pdcurses/pdcutil.c index 3bcba15ef..5a7a718ed 100644 --- a/src/3rdparty/win32_src/pdcurses/pdcutil.c +++ b/src/3rdparty/win32_src/pdcurses/pdcutil.c @@ -16,23 +16,24 @@ void PDC_napms(int ms) /* 'ms' = milli, _not_ microseconds! */ { /* RR: keep GUI window responsive while PDCurses sleeps */ MSG msg; - DWORD milliseconds_sleep_limit = ms + GetTickCount(); + int start, end, sleepMs; extern bool PDC_bDone; - PDC_LOG(("PDC_napms() - called: ms=%d\n", ms)); + start = (int) GetTickCount(); + + //PDC_LOG(("PDC_napms() - called: ms=%d\n", ms)); /* Pump all pending messages from WIN32 to the window handler */ - while( !PDC_bDone && GetTickCount() < milliseconds_sleep_limit ) + while( !PDC_bDone && PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) ) { - while( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) ) - { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - Sleep(1); + TranslateMessage(&msg); + DispatchMessage(&msg); } - /* Sleep(ms); */ + end = (int) GetTickCount(); + sleepMs = ms - (end - start); + sleepMs = (sleepMs < 0) ? 0 : sleepMs; + Sleep((DWORD) sleepMs); } const char *PDC_sysname(void)