#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:

  1. There is a timer driver passing OS timer events into the timer manager correctly.
  2. Any overrides of Tick() exactly match this base class. Double check capitalization and the argument list.
  3. The memeber mt_style is set to something other than the default.
  4. The client was registered via HTManager::RegisterClient().
  5. 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()

HTClient::HTClient ( float  interval = 0.1f,
HTCStyle  style = HTCS_Invalid,
HTClientTickFunction  tick_function = 0,
void *  user_data = 0 
)
inline

Constructs an HTClient object.

Parameters
intervalPass the requested time between timer events.
styleThis parameter defaults to HTCS_Invalid but before the client can be registered, it must be set to one of the HTCStyle enumerations.
tick_functionThe callback function pointer which is generally a static function associated with the class.
user_dataA 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()

float HTClient::GetInterval ( ) const
inline
Returns
The timer interval in which the HTClient would like to receive timer events.

◆ GetNextRequest()

float HTClient::GetNextRequest ( ) const
inline
Returns
The time of the next scheduled event.

◆ GetPriority()

int HTClient::GetPriority ( ) const
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()

HTCStyle HTClient::GetStyle ( ) const
inline
Returns
The timer style which describes how the client would like to receive timer events.

◆ GetTickFunction()

HTClientTickFunction HTClient::GetTickFunction ( ) const
inline
Returns
A pointer to the Tick function callback.

◆ GetUserData()

void* HTClient::GetUserData ( ) const
inline
Returns
The user data that is specific to this client.

◆ SetInterval()

void HTClient::SetInterval ( float  interval)
inline

This method sets the interval in which the HTClient would like to receive timer events.

Parameters
intervalPass a float that defines that period of time in between receiving timer events.

◆ SetNextRequest()

void HTClient::SetNextRequest ( float  nr)
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
nrThe time at which we would like to receive the next timer event.

◆ SetPriorityLowest()

void HTClient::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()

void HTClient::SetStyle ( HTCStyle  style)
inline

This method sets how the client would like to receive tick calls.

Parameters
stylePass 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()

void HTClient::SetTickFunction ( HTClientTickFunction  tick_function)
inline

Use this method to set the callback function that will handle the timer events.

Parameters
tick_functionA pointer to the function that will handle this client's timer events.

◆ SetUserData()

void HTClient::SetUserData ( void *  user_data)
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_dataUser defined data that may be specifically used for this client's Tick function.

◆ Tick()

virtual bool HTClient::Tick ( float  request_time,
float  actual_time 
)
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_timeThe time for which the timer event was originally scheduled.
actual_timeThe 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

float HTClient::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

float HTClient::mt_next_request
protected

The time at which the next event is scheduled.

◆ mt_priority

int HTClient::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

HTCStyle HTClient::mt_style
protected

The client style which describes how this object would like to receive timer events.

◆ mt_tick_function

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.

◆ mt_user_data

void* HTClient::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: