Click or drag to resize
DigitalRuneFixedStepTimer Class
Controls the timing of a game or game component using fixed-sized time steps.
Inheritance Hierarchy
SystemObject
  DigitalRune.Game.TimingFixedStepTimer

Namespace: DigitalRune.Game.Timing
Assembly: DigitalRune.Game (in DigitalRune.Game.dll) Version: 1.4.0.0 (1.4.0.14427)
Syntax
public class FixedStepTimer : IGameTimer

The FixedStepTimer type exposes the following members.

Constructors
  NameDescription
Public methodFixedStepTimer
Initializes a new instance of the FixedStepTimer class.
Top
Methods
  NameDescription
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Protected methodOnIdle
Raises the Idle event.
Protected methodOnTimeChanged
Raises the TimeChanged event.
Public methodReset
Stops the timer and resets the time to zero.
Public methodStart
Starts/resumes the timer.
Public methodStop
Pauses the timer.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Properties
  NameDescription
Public propertyAccumulatedSteps
Gets the number of accumulated steps.
Public propertyAccumulatedTime
Gets the accumulated time.
Public propertyAccumulateTimeSteps
Gets or sets a value indicating whether the time steps are accumulated.
Public propertyClock
Gets or sets the clock.
Public propertyDeltaTime
Gets the elapsed game time since the last time step.
Public propertyFrameCount
Gets the number of frames since the start of the timer (= the number of TimeChanged events).
Public propertyIdleTime
Gets the idle time.
Public propertyIsRunning
Gets a value indicating whether the timer is running.
Public propertyLostTime
Gets the amount of time dropped in the current time step.
Public propertyMaxNumberOfSteps
Gets or sets the maximal number of sub-steps for one time step.
Public propertyPendingSteps
Gets the number of pending steps.
Public propertySpeed
Gets or sets the speed ratio at which the game time progresses.
Public propertyStepSize
Gets or sets the minimal size of a time step.
Public propertyStepSizeTolerance
Gets or sets the allowed step size deviation.
Public propertyTime
Gets the game time.
Top
Events
  NameDescription
Public eventIdle
Occurs when application is idle.
Public eventTimeChanged
Occurs when the game time has advanced.
Top
Remarks

See IGameTimer for basic information about game timers.

The FixedStepTimer triggers new time steps (TimeChanged event) in fixed-sized intervals. The size of each time step is StepSize or an integer multiple of StepSize. MaxNumberOfSteps determines the maximal size of time step: The upper limit of a time step is MaxNumberOfStepsStepSize. The time beyond this limit will be ignored. (LostTime indicates the amount of time that is dropped in the current time step.)

The timer waits until at least StepSize seconds have passed since the last time step. During the waiting time the Idle event is raised. IdleTime indicates the time to wait until the next time step.

If the time that has passed is not exactly an integer multiple of StepSize then the remainder will be considered in the next time step (see also AccumulatedTime ). (Exception: MaxNumberOfStepsStepSize is the upper limit. The time beyond this value will be dropped.)

If the elapsed time since the last last time step is equal to or larger than two times the StepSize, the timer will either raise one TimeChanged event with a DeltaTime that is an integer multiple of StepSize, or it will raise several TimeChanged events immediately after each other where each DeltaTime is equal to StepSize. This behavior is controlled by the property AccumulateTimeSteps. If AccumulateTimeSteps is , the timer will raise one TimeChanged event with the accumulated DeltaTime.

To check if the game is running slowly, the properties AccumulatedSteps and PendingSteps can be checked. During a time step, AccumulatedSteps should be equal to 1 and PendingSteps should be equal to 0, otherwise the game is running slowly - the workload of one time step exceeds the desired StepSize. To improve the frame rate of the game, it should reduce its workload and probably skip the rendering until AccumulatedSteps and PendingSteps are back to their normal values. When the game is running slowly and starts to omit work, the game can also call ResetDeltaTime of the Clock to reset the elapsed time of the clock and avoid large jumps of the game time.

Memory Leaks: If a Clock is set and the timer is running, the game timer handles the TimeChanged event of the clock. This means, the clock stores a strong reference to the timer and might prevent the timer from being garbage collected. If the timer is not needed anymore, call Stop or set the property Clock tp to allow the timer to be garbage collected.

See Also