# HTClient

## Functions

| `HTClient`
| `~HTClient`
bool | `Tick`
void | `SetInterval`
float | `GetInterval`
void | `SetStyle`
`HTCStyle` | `GetStyle`
void | `SetNextRequest`
float | `GetNextRequest`
int | `GetPriority`
void | `SetPriorityLowest`
void | `SetUserData`
void * | `GetUserData`
void | `SetTickFunction`
`HTClientTickFunction` | `GetTickFunction`

## Detailed Description

class HTClient

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

  Subclassed by HBhvBehaviorManager, HSelectionSetOOC< SelectionSet >, HTCObjectRotate

  Public Functions

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

    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.

  virtual ~HTClient()
  inline virtual bool Tick(float request_time, float actual_time)

    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.

  inline void SetInterval(float interval)

    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.

  inline float GetInterval() const
    Returns

      The timer interval in which the HTClient would like to receive timer events.

  inline void 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_Periodic or HTCS_PeriodicSkip. Note that you must select a style other than HTCS_Invalid to receive timer events.

  inline HTCStyle GetStyle() const
    Returns

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

  inline void 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.

  inline float GetNextRequest() const
    Returns

      The time of the next scheduled event.

  inline int GetPriority() const
    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.

  inline void 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.

  inline void 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.

  inline void *GetUserData() const
    Returns

      The user data that is specific to this client.

  inline void 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.

  inline HTClientTickFunction GetTickFunction() const
    Returns

      A pointer to the Tick function callback.