diff --git a/Core/Core.cpp b/Core/Core.cpp index 2032b53606..cfa25cf1df 100644 --- a/Core/Core.cpp +++ b/Core/Core.cpp @@ -42,6 +42,10 @@ #include "Core/Debugger/Breakpoints.h" +// Time until we stop considering the core active without user input. +// Should this be configurable? 2 hours currently. +static const double ACTIVITY_IDLE_TIMEOUT = 2.0 * 3600.0; + static event m_hStepEvent; static recursive_mutex m_hStepMutex; static event m_hInactiveEvent; @@ -49,6 +53,8 @@ static recursive_mutex m_hInactiveMutex; static bool singleStepPending = false; static std::set shutdownFuncs; static bool windowHidden = false; +static double lastActivity = 0.0; +static double lastKeepAwake = 0.0; #ifdef _WIN32 InputState input_state; @@ -61,6 +67,10 @@ void Core_NotifyWindowHidden(bool hidden) { // TODO: Wait until we can react? } +void Core_NotifyActivity() { + lastActivity = time_now_d(); +} + void Core_ListenShutdown(Core_ShutdownFunc func) { shutdownFuncs.insert(func); } @@ -200,6 +210,17 @@ void Core_RunLoop() { #if defined(USING_WIN_UI) if (!windowHidden && !Core_IsStepping()) { GPU_SwapBuffers(); + + // Keep the system awake for longer than normal for cutscenes and the like. + const double now = time_now_d(); + if (now < lastActivity + ACTIVITY_IDLE_TIMEOUT) { + // Only resetting it ever prime number seconds in case the call is expensive. + // Using a prime number to ensure there's no interaction with other periodic events. + if (now - lastKeepAwake > 89.0 || now < lastKeepAwake) { + SetThreadExecutionState(ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED); + lastKeepAwake = now; + } + } } #endif } diff --git a/Core/Core.h b/Core/Core.h index abe844e538..301cd3e8c7 100644 --- a/Core/Core.h +++ b/Core/Core.h @@ -46,4 +46,4 @@ bool UpdateScreenScale(int width, int height); // Don't run the core when minimized etc. void Core_NotifyWindowHidden(bool hidden); - +void Core_NotifyActivity(); diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index b44c41d20b..06e7fa02bb 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -285,6 +285,8 @@ inline float clamp1(float x) { } bool EmuScreen::touch(const TouchInput &touch) { + Core_NotifyActivity(); + if (root_) { root_->Touch(touch); return true; @@ -427,6 +429,8 @@ inline void EmuScreen::setVKeyAnalogY(int stick, int virtualKeyMin, int virtualK } bool EmuScreen::key(const KeyInput &key) { + Core_NotifyActivity(); + std::vector pspKeys; KeyMap::KeyToPspButton(key.deviceId, key.keyCode, &pspKeys); @@ -470,6 +474,8 @@ void EmuScreen::pspKey(int pspKeyCode, int flags) { } bool EmuScreen::axis(const AxisInput &axis) { + Core_NotifyActivity(); + if (axis.value > 0) { processAxis(axis, 1); return true;