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.
epoxy
Nicolas Hake 2016-02-01 20:47:37 +01:00
parent 98c966c7d1
commit 0c3811fe66
2 changed files with 11 additions and 4 deletions

View File

@ -34,6 +34,8 @@
#include <StdPNG.h>
static const int MAX_BACKGROUND_FPS = 5;
C4GraphicsSystem::C4GraphicsSystem()
{
Default();
@ -68,9 +70,10 @@ 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;
}
@ -78,6 +81,7 @@ bool C4GraphicsSystem::StartDrawing()
void C4GraphicsSystem::FinishDrawing()
{
if (!Application.isEditor) FullScreen.pSurface->PageFlip();
lastFrame = C4TimeMilliseconds::Now();
}
void C4GraphicsSystem::Execute()

View File

@ -60,7 +60,8 @@ public:
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();
@ -68,6 +69,8 @@ protected:
void DrawHoldMessages();
void ClearFullscreenBackground();
C4TimeMilliseconds lastFrame;
public:
bool ToggleShow8BitSurface();
bool ToggleShowNetStatus();