Skip to content
Permalink
Browse files

Keep rendering while unfocused (#1638)

In windowed mode, we shouldn't stop rendering just because we have lost
focus. However, we don't need to render at full framerate; throttling to
5 fps should be sufficient. Note though that we still have to calculate
game ticks at full speed so network games don't slow down when a player
tabs out of the game.
  • Loading branch information...
isilkor committed Feb 1, 2016
1 parent 98c966c commit 0c3811fe66fc023c84882260776cae7cc6f5e22c
Showing with 11 additions and 4 deletions.
  1. +7 −3 src/game/C4GraphicsSystem.cpp
  2. +4 −1 src/game/C4GraphicsSystem.h
@@ -34,6 +34,8 @@

#include <StdPNG.h>

static const int MAX_BACKGROUND_FPS = 5;

C4GraphicsSystem::C4GraphicsSystem()
{
Default();
@@ -68,16 +70,18 @@ bool C4GraphicsSystem::StartDrawing()
if (!pDraw) return false;
if (!pDraw->Active) return false;

// only if application is active or windowed (if config allows)
if (!Application.Active && (!Application.isEditor || !Config.Graphics.RenderInactiveEM)) return false;

// if the window is not focused, draw no more than MAX_BACKGROUND_FPS frames per second
if (!Application.Active && (C4TimeMilliseconds::Now() - lastFrame) < 1000 / MAX_BACKGROUND_FPS)
return false;

// drawing OK
return true;
}

void C4GraphicsSystem::FinishDrawing()
{
if (!Application.isEditor) FullScreen.pSurface->PageFlip();
lastFrame = C4TimeMilliseconds::Now();
}

void C4GraphicsSystem::Execute()
@@ -60,14 +60,17 @@ class C4GraphicsSystem
bool DoSaveScreenshot(bool fSaveAll, const char *szFilename, float fSaveAllZoom);
inline void InvalidateBg() { iRedrawBackground=2; }
inline void OverwriteBg() { InvalidateBg(); }
protected:

private:
char FlashMessageText[C4MaxTitle+1];
int32_t FlashMessageTime,FlashMessageX,FlashMessageY;
void DrawHelp();
void DrawFlashMessage();
void DrawHoldMessages();
void ClearFullscreenBackground();

C4TimeMilliseconds lastFrame;

public:
bool ToggleShow8BitSurface();
bool ToggleShowNetStatus();

0 comments on commit 0c3811f

Please sign in to comment.
You can’t perform that action at this time.