OpenClonk
C4ApplicationGameTimer Class Reference

#include <C4Application.h>

Inheritance diagram for C4ApplicationGameTimer:
[legend]
Collaboration diagram for C4ApplicationGameTimer:
[legend]

Public Member Functions

 C4ApplicationGameTimer ()
 
void SetGameTickDelay (uint32_t iDelay)
 
bool Execute (int iTimeout, pollfd *) override
 
bool IsLowPriority () override
 

Detailed Description

Definition at line 109 of file C4Application.h.

Constructor & Destructor Documentation

◆ C4ApplicationGameTimer()

C4ApplicationGameTimer::C4ApplicationGameTimer ( )

Definition at line 886 of file C4Application.cpp.

889 {
890 }
#define CStdMultimediaTimerProc
Definition: StdScheduler.h:216

Member Function Documentation

◆ Execute()

bool C4ApplicationGameTimer::Execute ( int  iTimeout,
pollfd *   
)
override

Definition at line 913 of file C4Application.cpp.

914 {
915  // Check timer and reset
916  if (!CheckAndReset()) return true;
918  // Execute
919  if (tNow >= tLastGameTick + iExtraGameTickDelay || Game.GameGo)
920  {
921  if (iGameTickDelay)
922  tLastGameTick += iGameTickDelay;
923  else
924  tLastGameTick = tNow;
925 
926  // Compensate if things get too slow
927  if (tNow > tLastGameTick + iGameTickDelay)
928  tLastGameTick += (tNow - tLastGameTick) / 2;
929 
931  }
932  // Draw
933  if (!Game.DoSkipFrame)
934  {
936 
937  Application.Draw();
938 
939  // Automatic frame skip if graphics are slowing down the game (skip max. every 2nd frame)
940  Game.DoSkipFrame = Game.Parameters.AutoFrameSkip && (tPreGfxTime + iGameTickDelay < C4TimeMilliseconds::Now());
941  } else {
942  Game.DoSkipFrame=false;
943  }
944  return true;
945 }
C4Game Game
Definition: C4Globals.cpp:52
C4Application Application
Definition: C4Globals.cpp:44
bool DoSkipFrame
Definition: C4Game.h:138
C4GameParameters & Parameters
Definition: C4Game.h:67
bool GameGo
Definition: C4Game.h:136
static C4TimeMilliseconds Now()

References Application, C4GameParameters::AutoFrameSkip, C4Game::DoSkipFrame, C4Application::Draw(), Game, C4Game::GameGo, C4Application::GameTick(), C4TimeMilliseconds::Now(), and C4Game::Parameters.

Here is the call graph for this function:

◆ IsLowPriority()

bool C4ApplicationGameTimer::IsLowPriority ( )
override

Definition at line 947 of file C4Application.cpp.

947 { return true; }

◆ SetGameTickDelay()

void C4ApplicationGameTimer::SetGameTickDelay ( uint32_t  iDelay)

Definition at line 892 of file C4Application.cpp.

893 {
894  // Remember delay
895  iGameTickDelay = iDelay;
896  // Smaller than minimum refresh delay?
897  if (iDelay < uint32_t(Config.Graphics.MaxRefreshDelay))
898  {
899  // Set critical timer
900  SetDelay(iDelay);
901  // No additional breaking needed
902  iExtraGameTickDelay = 0;
903  }
904  else
905  {
906  // Set critical timer
907  SetDelay(Config.Graphics.MaxRefreshDelay);
908  // Slow down game tick
909  iExtraGameTickDelay = iDelay;
910  }
911 }
C4Config Config
Definition: C4Config.cpp:930
int32_t MaxRefreshDelay
Definition: C4Config.h:113
C4ConfigGraphics Graphics
Definition: C4Config.h:257

References Config, C4Config::Graphics, and C4ConfigGraphics::MaxRefreshDelay.

Referenced by C4Application::SetGameTickDelay().

Here is the caller graph for this function:

The documentation for this class was generated from the following files: