From 549dff8339c9e4b1f68ac7506713e1d29a7d078f Mon Sep 17 00:00:00 2001 From: Wouter van Oortmerssen Date: Sat, 6 May 2023 11:33:56 -0700 Subject: [PATCH] Minimized/hidden runs at 10fps to save CPU/GPU --- dev/src/sdlsystem.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/dev/src/sdlsystem.cpp b/dev/src/sdlsystem.cpp index 9859eb82c..645c105d1 100644 --- a/dev/src/sdlsystem.cpp +++ b/dev/src/sdlsystem.cpp @@ -494,7 +494,7 @@ vector &SDLGetFrameTimeLog() { return frametimelog; } bool SDLFrame() { if (minimized) { - SDL_Delay(10); // save CPU/battery + SDL_Delay(100); // save CPU/battery } else { #ifndef __EMSCRIPTEN__ SDL_GL_SwapWindow(_sdl_window); @@ -648,6 +648,16 @@ bool SDLFrame() { // reload and bind shaders/textures here break; } + case SDL_WINDOWEVENT_MINIMIZED: + case SDL_WINDOWEVENT_HIDDEN: + minimized = true; + break; + case SDL_WINDOWEVENT_MAXIMIZED: + case SDL_WINDOWEVENT_RESTORED: + case SDL_WINDOWEVENT_SHOWN: + case SDL_WINDOWEVENT_EXPOSED: + minimized = false; + break; case SDL_WINDOWEVENT_LEAVE: // never gets hit? /*