#include <HTManager.h>
Public Member Functions | |
float | GetInterval () const |
float | GetNextRequest () const |
int | GetPriority () const |
HTCStyle | GetStyle () const |
HTClientTickFunction | GetTickFunction () const |
void * | GetUserData () const |
HTClient (float interval=0.1f, HTCStyle style=HTCS_Invalid, HTClientTickFunction tick_function=0, void *user_data=0) | |
void | SetInterval (float interval) |
void | SetNextRequest (float nr) |
void | SetPriorityLowest () |
void | SetStyle (HTCStyle style) |
void | SetTickFunction (HTClientTickFunction tick_function) |
void | SetUserData (void *user_data) |
virtual bool | Tick (float request_time, float actual_time) |
Protected Attributes | |
float | mt_interval |
float | mt_next_request |
int | mt_priority |
HTCStyle | mt_style |
HTClientTickFunction | mt_tick_function |
void * | mt_user_data |
Detailed Description
HTClient is a class from which any object that wishes to begin receiving timer events should derive.
It can work in one of two ways. Clients can either register a C-style callback with the "tick_function" argument of the constructor, or they can override the Tick() function to receive the calls directly.
Most of the configuration work for an HTClient is handled by manipulating its member variables. Some of these variables are initialized to usable values, whereas others are not. For an HTClient derivative to do anything useful, three operations are required. First, mt_style must be set to an HTCStyle other than the default value of HTCS_Invalid. Second, there must be some interface provided to receive timer events, either a callback or a function override. Finally, a pointer to the client must be passed to HTManager::RegisterClient()
If the callback mechanism is used to deliver timer events, there is a void pointer attached to the events that come back to the caller. This interface should be used for situations where multiple timers are to be associated with a single object. A good example of such usage is in hoops_mvo's HOpCameraWalk operator, where an HTClient is instantiated directly and assigned to a member variable:
m_pWalkTimer = new HTClient( 0.01f, HTCS_PeriodicSkip, WalkTimerClbk, this );
WalkTimerClbk is a static function that simply uses the user_data pointer at the end to dispatch to one of the member functions of the HOpCameraWalk.
Priority is used for sorting the list of timer events that happen within the span of one of the HTManager's bucket. One example of where this might be appropriate is a timer client that polls a flag to call HC_Update_Display at the appropriate times. Such a client should call SetPriorityLowest() on itself to request that it be processed last.
Troubleshooting:
If no timer events are received, check the following:
- There is a timer driver passing OS timer events into the timer manager correctly.
- Any overrides of Tick() exactly match this base class. Double check capitalization and the argument list.
- The memeber mt_style is set to something other than the default.
- The client was registered via HTManager::RegisterClient().
- The timer events can be delivered to a callback or a Tick() override, but not both. If there is an attempt to use both, the override wins.
Constructor & Destructor Documentation
◆ HTClient()
|
inline |
Constructs an HTClient object.
- Parameters
-
interval Pass the requested time between timer events. style This parameter defaults to HTCS_Invalid but before the client can be registered, it must be set to one of the HTCStyle enumerations.
tick_function The callback function pointer which is generally a static function associated with the class. user_data A pointer passed back to the tick_function callback. Generally set to "this" so that the tick callback can find its way to the class.
Member Function Documentation
◆ GetInterval()
|
inline |
- Returns
- The timer interval in which the HTClient would like to receive timer events.
◆ GetNextRequest()
|
inline |
- Returns
- The time of the next scheduled event.
◆ GetPriority()
|
inline |
- Returns
- The priority level for this client to receive timer event. Within a single time slice, the HTManager delivers timer events according to priority values of the given HTClients. Note that clients with higher priorities will receive timer events before those with lower priority levels.
◆ GetStyle()
|
inline |
- Returns
- The timer style which describes how the client would like to receive timer events.
◆ GetTickFunction()
|
inline |
- Returns
- A pointer to the Tick function callback.
◆ GetUserData()
|
inline |
- Returns
- The user data that is specific to this client.
◆ SetInterval()
|
inline |
This method sets the interval in which the HTClient would like to receive timer events.
- Parameters
-
interval Pass a float that defines that period of time in between receiving timer events.
◆ SetNextRequest()
|
inline |
This method sets the next timer request. Generally this is only called from the timer manager after a timer event has been delivered to a Periodic-style client.
- Parameters
-
nr The time at which we would like to receive the next timer event.
◆ SetPriorityLowest()
|
inline |
This method sets the priority to the lowest supported value. This client will subsequently be placed at the list tail of any bucket it is scheduled into, as opposed to the head, as usual. It has the effect of postponing timer events very slightly.
◆ SetStyle()
|
inline |
This method sets how the client would like to receive tick calls.
- Parameters
-
style Pass one the defined styles: HTCS_Invalid, HTCS_Once, HTCS_Periodic or HTCS_PeriodicSkip. Note that you must select a style other than HTCS_Invalid to receive timer events.
◆ SetTickFunction()
|
inline |
Use this method to set the callback function that will handle the timer events.
- Parameters
-
tick_function A pointer to the function that will handle this client's timer events.
◆ SetUserData()
|
inline |
Use this method to pass data via the timer callback. When the timer manager calls the Tick() function, it will pass the user data.
- Parameters
-
user_data User defined data that may be specifically used for this client's Tick function.
◆ Tick()
|
inlinevirtual |
Timer events are delivered here first. If this function is not overridden, the events will be delivered to whatever was set with the mt_tick_function argument of the constructor or later on with SetTickFunction().
- Parameters
-
request_time The time for which the timer event was originally scheduled. actual_time The time at which the tick was actually delivered which is greater than or equal to request_time.
- Returns
- True if no errors were encountered.
Reimplemented in HBhvBehaviorManager, and HTCObjectRotate.
Member Data Documentation
◆ mt_interval
|
protected |
The interval, in seconds, at which tick events occur. The first event will occur mt_interval seconds after the call to HTManager::RegisterClient(). For HTCS_Once clients, mt_interval specifies the delay until the one and only timer event is received.
◆ mt_next_request
|
protected |
The time at which the next event is scheduled.
◆ mt_priority
|
protected |
The priority determines the order in which to sort timer events within a single HTManager bucket.
In other words, it is a tie breaker for two timer events that are supposed to occur at the same time.
◆ mt_style
|
protected |
The client style which describes how this object would like to receive timer events.
◆ mt_tick_function
|
protected |
A function to call whenever timer events are received.
This is called automatically if and only if Tick() is not overridden.
◆ mt_user_data
|
protected |
A pointer passed back to the Tick function callback, if one is set.
The documentation for this class was generated from the following file: