Pause rendering when the window is minimized

This commit is contained in:
abcdefg30
2020-10-03 15:14:18 +02:00
committed by Paul Chote
parent 5667081764
commit 3276373745
5 changed files with 30 additions and 2 deletions

View File

@@ -828,8 +828,7 @@ namespace OpenRA
var haveSomeTimeUntilNextLogic = now < nextLogic; var haveSomeTimeUntilNextLogic = now < nextLogic;
var isTimeToRender = now >= nextRender; var isTimeToRender = now >= nextRender;
if (!Renderer.WindowIsSuspended && ((isTimeToRender && haveSomeTimeUntilNextLogic) || forceRender))
if ((isTimeToRender && haveSomeTimeUntilNextLogic) || forceRender)
{ {
nextRender = now + renderInterval; nextRender = now + renderInterval;
@@ -844,6 +843,19 @@ namespace OpenRA
RenderTick(); RenderTick();
renderBeforeNextTick = false; renderBeforeNextTick = false;
} }
// Simulate a render tick if it was time to render but we skip actually rendering
if (Renderer.WindowIsSuspended && isTimeToRender)
{
// Make sure that nextUpdate is set to a proper minimum interval
nextRender = now + renderInterval;
// Still process SDL events to allow a restore to come through
Renderer.Window.PumpInput(new NullInputHandler());
// Ensure that we still logic tick despite not rendering
renderBeforeNextTick = false;
}
} }
else else
Thread.Sleep((int)(nextUpdate - now)); Thread.Sleep((int)(nextUpdate - now));

View File

@@ -59,6 +59,7 @@ namespace OpenRA
int DisplayCount { get; } int DisplayCount { get; }
int CurrentDisplay { get; } int CurrentDisplay { get; }
bool HasInputFocus { get; } bool HasInputFocus { get; }
bool IsSuspended { get; }
event Action<float, float, float, float> OnWindowScaleChanged; event Action<float, float, float, float> OnWindowScaleChanged;

View File

@@ -33,6 +33,7 @@ namespace OpenRA
public RgbaSpriteRenderer RgbaSpriteRenderer { get; private set; } public RgbaSpriteRenderer RgbaSpriteRenderer { get; private set; }
public bool WindowHasInputFocus => Window.HasInputFocus; public bool WindowHasInputFocus => Window.HasInputFocus;
public bool WindowIsSuspended => Window.IsSuspended;
public IReadOnlyDictionary<string, SpriteFont> Fonts; public IReadOnlyDictionary<string, SpriteFont> Fonts;

View File

@@ -94,6 +94,18 @@ namespace OpenRA.Platforms.Default
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_SIZE_CHANGED: case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_SIZE_CHANGED:
device.WindowSizeChanged(); device.WindowSizeChanged();
break; break;
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_HIDDEN:
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_MINIMIZED:
device.IsSuspended = true;
break;
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_EXPOSED:
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_SHOWN:
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_MAXIMIZED:
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_RESTORED:
device.IsSuspended = false;
break;
} }
break; break;

View File

@@ -99,6 +99,8 @@ namespace OpenRA.Platforms.Default
public bool HasInputFocus { get; internal set; } public bool HasInputFocus { get; internal set; }
public bool IsSuspended { get; internal set; }
public GLProfile GLProfile public GLProfile GLProfile
{ {
get get