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>
|
#include <StdPNG.h>
|
||||||
|
|
||||||
|
static const int MAX_BACKGROUND_FPS = 5;
|
||||||
|
|
||||||
C4GraphicsSystem::C4GraphicsSystem()
|
C4GraphicsSystem::C4GraphicsSystem()
|
||||||
{
|
{
|
||||||
Default();
|
Default();
|
||||||
|
@ -68,8 +70,9 @@ bool C4GraphicsSystem::StartDrawing()
|
||||||
if (!pDraw) return false;
|
if (!pDraw) return false;
|
||||||
if (!pDraw->Active) return false;
|
if (!pDraw->Active) return false;
|
||||||
|
|
||||||
// only if application is active or windowed (if config allows)
|
// if the window is not focused, draw no more than MAX_BACKGROUND_FPS frames per second
|
||||||
if (!Application.Active && (!Application.isEditor || !Config.Graphics.RenderInactiveEM)) return false;
|
if (!Application.Active && (C4TimeMilliseconds::Now() - lastFrame) < 1000 / MAX_BACKGROUND_FPS)
|
||||||
|
return false;
|
||||||
|
|
||||||
// drawing OK
|
// drawing OK
|
||||||
return true;
|
return true;
|
||||||
|
@ -78,6 +81,7 @@ bool C4GraphicsSystem::StartDrawing()
|
||||||
void C4GraphicsSystem::FinishDrawing()
|
void C4GraphicsSystem::FinishDrawing()
|
||||||
{
|
{
|
||||||
if (!Application.isEditor) FullScreen.pSurface->PageFlip();
|
if (!Application.isEditor) FullScreen.pSurface->PageFlip();
|
||||||
|
lastFrame = C4TimeMilliseconds::Now();
|
||||||
}
|
}
|
||||||
|
|
||||||
void C4GraphicsSystem::Execute()
|
void C4GraphicsSystem::Execute()
|
||||||
|
|
|
@ -60,7 +60,8 @@ public:
|
||||||
bool DoSaveScreenshot(bool fSaveAll, const char *szFilename, float fSaveAllZoom);
|
bool DoSaveScreenshot(bool fSaveAll, const char *szFilename, float fSaveAllZoom);
|
||||||
inline void InvalidateBg() { iRedrawBackground=2; }
|
inline void InvalidateBg() { iRedrawBackground=2; }
|
||||||
inline void OverwriteBg() { InvalidateBg(); }
|
inline void OverwriteBg() { InvalidateBg(); }
|
||||||
protected:
|
|
||||||
|
private:
|
||||||
char FlashMessageText[C4MaxTitle+1];
|
char FlashMessageText[C4MaxTitle+1];
|
||||||
int32_t FlashMessageTime,FlashMessageX,FlashMessageY;
|
int32_t FlashMessageTime,FlashMessageX,FlashMessageY;
|
||||||
void DrawHelp();
|
void DrawHelp();
|
||||||
|
@ -68,6 +69,8 @@ protected:
|
||||||
void DrawHoldMessages();
|
void DrawHoldMessages();
|
||||||
void ClearFullscreenBackground();
|
void ClearFullscreenBackground();
|
||||||
|
|
||||||
|
C4TimeMilliseconds lastFrame;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool ToggleShow8BitSurface();
|
bool ToggleShow8BitSurface();
|
||||||
bool ToggleShowNetStatus();
|
bool ToggleShowNetStatus();
|
||||||
|
|
Loading…
Reference in New Issue