#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 |
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:
|
inline |
Constructs an HTClient object.
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. |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
This method sets the interval in which the HTClient would like to receive timer events.
interval | Pass a float that defines that period of time in between receiving timer events. |
|
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.
nr | The time at which we would like to receive the next timer event. |
|
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.
|
inline |
This method sets how the client would like to receive tick calls.
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. |
|
inline |
Use this method to set the callback function that will handle the timer events.
tick_function | A pointer to the function that will handle this client's timer events. |
|
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.
user_data | User defined data that may be specifically used for this client's Tick function. |
|
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().
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. |
Reimplemented in HBhvBehaviorManager, and HTCObjectRotate.
|
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.
|
protected |
The time at which the next event is scheduled.
|
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.
|
protected |
The client style which describes how this object would like to receive timer events.
|
protected |
A function to call whenever timer events are received. This is called automatically if and only if Tick() is not overridden.
|
protected |
A pointer passed back to the Tick function callback, if one is set.