OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
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)
 
virtual bool Execute (int iTimeout, pollfd *)
 
virtual bool IsLowPriority ()
 

Detailed Description

Definition at line 108 of file C4Application.h.

Constructor & Destructor Documentation

C4ApplicationGameTimer::C4ApplicationGameTimer ( )

Definition at line 871 of file C4Application.cpp.

873  tLastGameTick(C4TimeMilliseconds::NegativeInfinity), iGameTickDelay(28), iExtraGameTickDelay(0)
874 {
875 }
#define CStdMultimediaTimerProc
Definition: StdScheduler.h:220

Member Function Documentation

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

Definition at line 898 of file C4Application.cpp.

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

899 {
900  // Check timer and reset
901  if (!CheckAndReset()) return true;
903  // Execute
904  if (tNow >= tLastGameTick + iExtraGameTickDelay || Game.GameGo)
905  {
906  if (iGameTickDelay)
907  tLastGameTick += iGameTickDelay;
908  else
909  tLastGameTick = tNow;
910 
911  // Compensate if things get too slow
912  if (tNow > tLastGameTick + iGameTickDelay)
913  tLastGameTick += (tNow - tLastGameTick) / 2;
914 
916  }
917  // Draw
918  if (!Game.DoSkipFrame)
919  {
921 
922  Application.Draw();
923 
924  // Automatic frame skip if graphics are slowing down the game (skip max. every 2nd frame)
925  Game.DoSkipFrame = Game.Parameters.AutoFrameSkip && (tPreGfxTime + iGameTickDelay < C4TimeMilliseconds::Now());
926  } else {
927  Game.DoSkipFrame=false;
928  }
929  return true;
930 }
C4Game Game
Definition: C4Globals.cpp:52
bool DoSkipFrame
Definition: C4Game.h:139
C4GameParameters & Parameters
Definition: C4Game.h:69
bool GameGo
Definition: C4Game.h:137
C4Application Application
Definition: C4Globals.cpp:44
static C4TimeMilliseconds Now()

Here is the call graph for this function:

bool C4ApplicationGameTimer::IsLowPriority ( )
virtual

Definition at line 932 of file C4Application.cpp.

932 { return true; }
void C4ApplicationGameTimer::SetGameTickDelay ( uint32_t  iDelay)

Definition at line 877 of file C4Application.cpp.

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

Referenced by C4Application::SetGameTickDelay().

878 {
879  // Remember delay
880  iGameTickDelay = iDelay;
881  // Smaller than minimum refresh delay?
882  if (iDelay < uint32_t(Config.Graphics.MaxRefreshDelay))
883  {
884  // Set critical timer
885  SetDelay(iDelay);
886  // No additional breaking needed
887  iExtraGameTickDelay = 0;
888  }
889  else
890  {
891  // Set critical timer
892  SetDelay(Config.Graphics.MaxRefreshDelay);
893  // Slow down game tick
894  iExtraGameTickDelay = iDelay;
895  }
896 }
C4Config Config
Definition: C4Config.cpp:837
C4ConfigGraphics Graphics
Definition: C4Config.h:254
int32_t MaxRefreshDelay
Definition: C4Config.h:114

Here is the caller graph for this function:


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