forked from Mirrors/openclonk
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
parent
98c966c7d1
commit
0c3811fe66
|
@ -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()
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue