IGameClock Interface |
Namespace: DigitalRune.Game.Timing
The IGameClock type exposes the following members.
Name | Description | |
---|---|---|
Reset |
Stops the clock and resets all times to 0.
| |
ResetDeltaTime |
Resets the time measurement for the current DeltaTime. The next
DeltaTime will be the time since ResetDeltaTime was called.
| |
Start |
Starts/resumes the clock.
| |
Stop |
Pauses the clock.
|
Name | Description | |
---|---|---|
DeltaTime |
Gets the amount of time that has elapsed since the last TimeChanged
event.
| |
GameTime |
Gets the game time, which is the sum of all DeltaTime values.
| |
IsRunning |
Gets a value indicating whether the clock is running.
| |
MaxDeltaTime |
Gets the max limit for DeltaTime.
| |
TotalTime |
Gets the duration (wall clock time) for which the clock is running.
|
Name | Description | |
---|---|---|
TimeChanged |
Occurs when the time changed.
|
A game clock measures elapsed time. Call Start to start or resume the time measurement. Call Stop to pause the time measurement. Reset stops the time measurement and sets the measured time to 0. The flag IsRunning indicates whether the clock is currently measuring time.
When time changes, the event TimeChanged is raised. This event is usually raised at variable (or fixed) intervals to indicate the beginning of a new frame. Between TimeChanged events, the time is treated as constant.
TotalTime indicates the total duration for which the clock is running. DeltaTime indicates the time since the last TimeChanged event or the time since the last ResetDeltaTime call, whichever is more recent. GameTime is the sum of all DeltaTime values. If ResetDeltaTime is never executed, TotalTime and GameTime are equal. If ResetDeltaTime was called, TotalTime is greater than GameTime. After long-running operations (e.g. file access) ResetDeltaTime can be called to reset the measurement of DeltaTime. This avoids large jumps of the GameTime.
A game usually has one IGameClock that is running permanently and acts as the central time source. Each game module can further have its own IGameTimer. The IGameTimer controls the timing of the game module. For example: A FixedStepTimer ensures that a game module is updated with a constant frame rate. All IGameTimers are updated by the central IGameClock.
The IGameClock is not running by default - Start needs to be called explicitly. The clock should be suspended (Stop method) when the application becomes inactive or the application windows is minimized. Call Start to resume the clock when the application becomes active again.