From 3cdf53732b52ae9e55162bf4b079f9e917176183 Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Sun, 29 Jun 2014 13:11:06 +0200 Subject: [PATCH] Make the emuthread idle when minimized on Windows. --- Core/Core.cpp | 20 +++++++++++++++----- Core/Core.h | 4 ++++ Windows/WndMainWindow.cpp | 16 ++++++++++++++-- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/Core/Core.cpp b/Core/Core.cpp index 63894d4d0..ecc13619c 100644 --- a/Core/Core.cpp +++ b/Core/Core.cpp @@ -47,6 +47,7 @@ static event m_hInactiveEvent; static recursive_mutex m_hInactiveMutex; static bool singleStepPending = false; static std::set shutdownFuncs; +static bool windowHidden = false; #ifdef _WIN32 InputState input_state; @@ -54,6 +55,11 @@ InputState input_state; extern InputState input_state; #endif +void Core_NotifyWindowHidden(bool hidden) { + windowHidden = hidden; + // TODO: Wait until we can react? +} + void Core_ListenShutdown(Core_ShutdownFunc func) { shutdownFuncs.insert(func); } @@ -143,20 +149,24 @@ static inline void UpdateRunLoop() { void Core_RunLoop() { while ((GetUIState() != UISTATE_INGAME || !PSP_IsInited()) && GetUIState() != UISTATE_EXIT) { - time_update(); - #if defined(USING_WIN_UI) + time_update(); double startTime = time_now_d(); - UpdateRunLoop(); + if (!windowHidden) { + UpdateRunLoop(); + } // Simple throttling to not burn the GPU in the menu. time_update(); double diffTime = time_now_d() - startTime; - int sleepTime = (int) (1000000.0 / 60.0) - (int) (diffTime * 1000000.0); + int sleepTime = (int)(1000000.0 / 60.0) - (int)(diffTime * 1000000.0); if (sleepTime > 0) Sleep(sleepTime / 1000); - GL_SwapBuffers(); + if (!windowHidden) { + GL_SwapBuffers(); + } #else + time_update(); UpdateRunLoop(); #endif } diff --git a/Core/Core.h b/Core/Core.h index d96601e98..2b10254d6 100644 --- a/Core/Core.h +++ b/Core/Core.h @@ -42,3 +42,7 @@ void Core_WaitInactive(); void Core_WaitInactive(int milliseconds); void UpdateScreenScale(int width, int height); + +// Don't run the core when minimized etc. +void Core_NotifyWindowHidden(bool hidden); + diff --git a/Windows/WndMainWindow.cpp b/Windows/WndMainWindow.cpp index 78979f1a9..6e52816b3 100644 --- a/Windows/WndMainWindow.cpp +++ b/Windows/WndMainWindow.cpp @@ -244,6 +244,7 @@ namespace MainWindow { } void SetWindowSize(int zoom) { + AssertCurrentThreadName("Main"); RECT rc, rcOuter; GetWindowRectAtResolution(480 * (int)zoom, 272 * (int)zoom, rc, rcOuter); MoveWindow(hwndMain, rcOuter.left, rcOuter.top, rcOuter.right - rcOuter.left, rcOuter.bottom - rcOuter.top, TRUE); @@ -913,8 +914,19 @@ namespace MainWindow { switch (message) { case WM_SIZE: - SavePosition(); - ResizeDisplay(); + switch (wParam) { + case SIZE_MAXIMIZED: + case SIZE_RESTORED: + Core_NotifyWindowHidden(false); + SavePosition(); + ResizeDisplay(); + break; + case SIZE_MINIMIZED: + Core_NotifyWindowHidden(true); + break; + default: + break; + } break; case WM_GETMINMAXINFO: