  Platform eXtended Library (PXL)Units Class Hierarchy Classes, Interfaces, Objects and Records Types Variables Constants Functions and Procedures Identifiers |
Class TMultimediaTimer
Unit
PXL.Timing
Declaration
type TMultimediaTimer = class(TObject)
Description
A special-purpose timer implementation that can provide fixed frame-based processing independently of rendering frame rate. This class provides OnProcess event, which occurs exactly Speed times per second, and Latency property, which can be used from within OnTimer event as a scaling coefficient for moving things. In order to function properly, NotifyTick method should be called as fast as possible (for example, before rendering each frame), whereas Process event should be called right before flipping rendering buffers, to take advantage of parallel processing between CPU and GPU. FrameRate will indicate how many frames per second NotifyTick is called. See accompanying examples on how this component can be used.
Hierarchy
Overview
Internal Types
 |
TTimerEvent = procedure(const Sender: TObject) of object; |
Methods
Properties
 |
property Delta: Double read FDelta; |
 |
property Enabled: Boolean read FEnabled write FEnabled; |
 |
property FrameRate: Integer read FFrameRate; |
 |
property Latency: Double read FLatency; |
 |
property MaxFPS: Integer read FMaxFPS write SetMaxFPS; |
 |
property OnProcess: TTimerEvent read FOnProcess write FOnProcess; |
 |
property OnTimer: TTimerEvent read FOnTimer write FOnTimer; |
 |
property SingleCallOnly: Boolean read FSingleCallOnly write FSingleCallOnly; |
 |
property Speed: Double read FSpeed write SetSpeed; |
Description
Internal Types
 |
TTimerEvent = procedure(const Sender: TObject) of object; |
|
Event handler description that is used for timer events.
|
Methods
 |
procedure NotifyTick(AllowSleep: Boolean = True); |
|
This method should be called as fast as possible from within the main application for the timer to work. It can be either called when idle event occurs or from within system timer event.
|
 |
procedure Process; |
|
This method should only be called from within OnTimer event to do constant object movement and animation control. Each time this method is called, OnProcess event may (or may not) occur depending on the current rendering frame rate (see FrameRate) and the desired processing speed (see Speed). The only thing that is assured is that OnProcess event will occur exactly Speed times per second no matter how fast OnTimer occurs (that is, the value of FrameRate).
|
 |
procedure Reset; |
|
Resets internal structures of the timer and starts over the timing calculations. This can be useful when a very time-consuming task was executed inside OnTimer event that only occurs once. Normally, it would stall the timer making it think that the processing takes too long or the rendering is too slow; calling this method will tell the timer that it should ignore the situation and prevent the stall.
|
Properties
 |
property Delta: Double read FDelta; |
|
Movement differential between the current frame rate and the requested Speed. Object movement and animation control can be made inside OnTimer event if all displacements are multiplied by this coefficient. For instance, if frame rate is 30 FPS and speed is set to 60, this coefficient will equal to 2.0, so objects moving at 30 FPS will have double displacement to match 60 FPS speed; on the other hand, if frame rate is 120 FPS with speed set to 60, this coefficient will equal to 0.5, to move objects two times slower. An easier and more straight-forward approach can be used with OnProcess event, where using this coefficient is not necessary.
|
 |
property Enabled: Boolean read FEnabled write FEnabled; |
|
Determines whether the timer is enabled or not. The internal processing may still be occurring independently of this value, but it controls whether OnTimer event occurs or not.
|
 |
property FrameRate: Integer read FFrameRate; |
|
The current frame rate in frames per second. This value is calculated approximately two times per second and can only be used for informative purposes (e.g. displaying frame rate in the application). For precise real-time indications it is recommended to use Latency property instead.
|
 |
property Latency: Double read FLatency; |
|
The time (in milliseconds) calculated between previous frame and the current one. This can be a direct indicator of rendering performance as it indicates how much time it took to render (and possibly process) the frame.
|
 |
property MaxFPS: Integer read FMaxFPS write SetMaxFPS; |
|
The maximum allowed frame rate at which OnTimer should be executed. This value is an approximate and the resulting frame rate may be quite different (the resolution can be as low as 10 ms). It should be used with reasonable values to prevent the application from using 100% of CPU and GPU with unnecessarily high frame rates such as 1000 FPS. A reasonable and default value for this property is 200.
|
 |
property OnProcess: TTimerEvent read FOnProcess write FOnProcess; |
|
This event occurs when calling Process method inside OnTimer event. In this event all constant object movement and animation control should be made. This event can occur more than once for each call to Process or may not occur, depending on the current FrameRate and Speed. For instance, when frame rate is 120 FPS and speed set to 60, this event will occur for each second call to Process; on the other hand, if frame rate is 30 FPS with speed set to 60, this event will occur twice for each call to Process to maintain constant processing. An alternative to this is doing processing inside OnTimer event using Delta as coefficient for object movement. If the processing takes too much time inside this event so that the target speed cannot be achieved, the timer may stall (that is, reduce number of occurrences of this event until the balance is restored).
|
 |
property OnTimer: TTimerEvent read FOnTimer write FOnTimer; |
|
This event occurs when Enabled is set to True and as fast as possible (only limited approximately by MaxFPS). In this event, all rendering should be made. Inside this event, at some location it is recommended to call Process method, which will invoke OnProcess event for constant object movement and animation control. The idea is to render graphics as fast as possible while moving objects and controlling animation at constant speed. Note that for this event to occur, it is necessary to call NotifyIdle at some point in the application for this timer to do the required calculations.
|
 |
property SingleCallOnly: Boolean read FSingleCallOnly write FSingleCallOnly; |
|
If this property is set to True, it will prevent the timer from trying to fix situations where the rendering speed is slower than the processing speed (that is, FrameRate is lower than Speed). Therefore, faster rendering produces constant speed, while slower rendering slows the processing down. This is particularly useful for dedicated servers that do no rendering but only processing; in this case, the processing cannot be technically any faster than it already is.
|
 |
property Speed: Double read FSpeed write SetSpeed; |
|
The speed of constant processing and animation control in frames per second. This affects both Delta property and occurrence of OnProcess event.
|
Copyright © 2000 - 2017 Yuriy Kotsarenko. Help files generated by PasDoc.
|