HTClient
-
class
HTClient HTClientis 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 theTick()function to receive the calls directly.Most of the configuration work for an
HTClientis handled by manipulating its member variables. Some of these variables are initialized to usable values, whereas others are not. For anHTClientderivative to do anything useful, three operations are required. First, mt_style must be set to anHTCStyleother 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 toHTManager::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
HOpCameraWalkoperator, where anHTClientis 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 theHOpCameraWalk.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 callSetPriorityLowest()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_styleis 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.
Methods
-
HTClient::HTClient(float interval = 0.1f, HTCStyle style = HTCS_Invalid, HTClientTickFunction tick_function = 0, void *user_data = 0) Constructs an
HTClientobject.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
HTCStyleenumerations.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.
-
virtual bool
HTClient::Tick(float request_time, float actual_time) virtual
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_functionargument of the constructor or later on withSetTickFunction().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.
-
void
HTClient::SetInterval(float interval) This method sets the interval in which the
HTClientwould like to receive timer events.Parameters
interval: Pass a float that defines that period of time in between receiving timer events.
-
float
HTClient::GetInterval() const const
Returns
The timer interval in which theHTClientwould like to receive timer events.
-
void
HTClient::SetStyle(HTCStyle style) This method sets how the client would like to receive tick calls.
Parameters
style: Pass one the defined styles:HTCS_Invalid,HTCS_Once,HTCS_PeriodicorHTCS_PeriodicSkip. Note that you must select a style other thanHTCS_Invalidto receive timer events.
-
HTCStyle
HTClient::GetStyle() const const
Returns
The timer style which describes how the client would like to receive timer events.
-
void
HTClient::SetNextRequest(float nr) 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.
-
int
HTClient::GetPriority() const const
Returns
The priority level for this client to receive timer event. Within a single time slice, theHTManagerdelivers 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.
-
void
HTClient::SetPriorityLowest() 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.
-
void
HTClient::SetUserData(void *user_data) 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.
-
void
HTClient::SetTickFunction(HTClientTickFunction tick_function) 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.
-
HTClientTickFunction
HTClient::GetTickFunction() const const
Returns
A pointer to the Tick function callback.
Variables
-
HTCStyle
HTClient::mt_style protected
The client style which describes how this object would like to receive timer events.
-
float
HTClient::mt_interval protected
floatThe interval, in seconds, at which tick events occur. The first event will occur mt_interval seconds after the call to
HTManager::RegisterClient(). ForHTCS_Onceclients, mt_interval specifies the delay until the one and only timer event is received.
-
int
HTClient::mt_priority protected
intThe priority determines the order in which to sort timer events within a single
HTManagerbucket. In other words, it is a tie breaker for two timer events that are supposed to occur at the same time.
-
void *
HTClient::mt_user_data protected
voidA pointer passed back to the Tick function callback, if one is set.
-
HTClientTickFunction
HTClient::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.