FixedStepTimer Class |
Namespace: DigitalRune.Game.Timing
The FixedStepTimer type exposes the following members.
Name | Description | |
---|---|---|
FixedStepTimer |
Initializes a new instance of the FixedStepTimer class.
|
Name | Description | |
---|---|---|
Equals | (Inherited from Object.) | |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) | |
GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
OnIdle |
Raises the Idle event.
| |
OnTimeChanged |
Raises the TimeChanged event.
| |
Reset |
Stops the timer and resets the time to zero.
| |
Start |
Starts/resumes the timer.
| |
Stop |
Pauses the timer.
| |
ToString | Returns a string that represents the current object. (Inherited from Object.) |
Name | Description | |
---|---|---|
AccumulatedSteps |
Gets the number of accumulated steps.
| |
AccumulatedTime |
Gets the accumulated time.
| |
AccumulateTimeSteps |
Gets or sets a value indicating whether the time steps are accumulated.
| |
Clock |
Gets or sets the clock.
| |
DeltaTime |
Gets the elapsed game time since the last time step.
| |
FrameCount |
Gets the number of frames since the start of the timer (= the number of
TimeChanged events).
| |
IdleTime |
Gets the idle time.
| |
IsRunning |
Gets a value indicating whether the timer is running.
| |
LostTime |
Gets the amount of time dropped in the current time step.
| |
MaxNumberOfSteps |
Gets or sets the maximal number of sub-steps for one time step.
| |
PendingSteps |
Gets the number of pending steps.
| |
Speed |
Gets or sets the speed ratio at which the game time progresses.
| |
StepSize |
Gets or sets the minimal size of a time step.
| |
StepSizeTolerance |
Gets or sets the allowed step size deviation.
| |
Time |
Gets the game time.
|
Name | Description | |
---|---|---|
Idle |
Occurs when application is idle.
| |
TimeChanged |
Occurs when the game time has advanced.
|
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 MaxNumberOfSteps ∙ StepSize. 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: MaxNumberOfSteps ∙ StepSize 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.