Click or drag to resize
DigitalRuneIGameClock Interface
Measures time and raises an event when time changes.

Namespace: DigitalRune.Game.Timing
Assembly: DigitalRune.Game (in DigitalRune.Game.dll) Version: 1.4.0.0 (1.4.0.14427)
Syntax
public interface IGameClock

The IGameClock type exposes the following members.

Methods
  NameDescription
Public methodReset
Stops the clock and resets all times to 0.
Public methodResetDeltaTime
Resets the time measurement for the current DeltaTime. The next DeltaTime will be the time since ResetDeltaTime was called.
Public methodStart
Starts/resumes the clock.
Public methodStop
Pauses the clock.
Top
Properties
  NameDescription
Public propertyDeltaTime
Gets the amount of time that has elapsed since the last TimeChanged event.
Public propertyGameTime
Gets the game time, which is the sum of all DeltaTime values.
Public propertyIsRunning
Gets a value indicating whether the clock is running.
Public propertyMaxDeltaTime
Gets the max limit for DeltaTime.
Public propertyTotalTime
Gets the duration (wall clock time) for which the clock is running.
Top
Events
  NameDescription
Public eventTimeChanged
Occurs when the time changed.
Top
Remarks

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.

See Also