26 namespace SiliconStudio.
Paradox.Games
33 private TimeSpan accumulatedElapsedTime;
34 private int accumulatedFrameCountPerSecond;
36 #region Constructors and Destructors
43 accumulatedElapsedTime = TimeSpan.Zero;
51 public GameTime(TimeSpan totalTime, TimeSpan elapsedTime)
54 Elapsed = elapsedTime;
55 accumulatedElapsedTime = TimeSpan.Zero;
64 public GameTime(TimeSpan totalTime, TimeSpan elapsedTime,
bool isRunningSlowly)
67 Elapsed = elapsedTime;
68 IsRunningSlowly = isRunningSlowly;
69 accumulatedElapsedTime = TimeSpan.Zero;
74 #region Public Properties
80 public TimeSpan Elapsed {
get;
private set; }
86 public bool IsRunningSlowly {
get;
private set; }
92 public TimeSpan Total {
get;
private set; }
97 public int FrameCount {
get;
private set; }
103 public float FramePerSecond {
get;
private set; }
109 public TimeSpan TimePerFrame {
get;
private set; }
115 public bool FramePerSecondUpdated {
get;
private set; }
117 internal void Update(TimeSpan totalGameTime, TimeSpan elapsedGameTime, TimeSpan elapsedUpdateTime,
bool isRunningSlowly,
bool incrementFrameCount)
119 Total = totalGameTime;
120 Elapsed = elapsedGameTime;
121 IsRunningSlowly = isRunningSlowly;
122 FramePerSecondUpdated =
false;
124 if (incrementFrameCount)
126 accumulatedElapsedTime += elapsedGameTime;
127 var accumulatedElapsedGameTimeInSecond = accumulatedElapsedTime.TotalSeconds;
128 if (accumulatedFrameCountPerSecond > 0 && accumulatedElapsedGameTimeInSecond > 1.0)
130 TimePerFrame = TimeSpan.FromTicks(accumulatedElapsedTime.Ticks / accumulatedFrameCountPerSecond);
131 FramePerSecond = (float)(accumulatedFrameCountPerSecond / accumulatedElapsedGameTimeInSecond);
132 accumulatedFrameCountPerSecond = 0;
133 accumulatedElapsedTime = TimeSpan.Zero;
134 FramePerSecondUpdated =
true;
137 accumulatedFrameCountPerSecond++;
142 internal void Reset(TimeSpan totalGameTime)
144 Update(totalGameTime, TimeSpan.Zero, TimeSpan.Zero,
false,
false);
145 accumulatedElapsedTime = TimeSpan.Zero;
146 accumulatedFrameCountPerSecond = 0;
GameTime(TimeSpan totalTime, TimeSpan elapsedTime)
Initializes a new instance of the GameTime class.
GameTime(TimeSpan totalTime, TimeSpan elapsedTime, bool isRunningSlowly)
Initializes a new instance of the GameTime class.
Current timing used for variable-step (real time) or fixed-step (game time) games.
GameTime()
Initializes a new instance of the GameTime class.