HTManager

class HTManager

HTManager provides a centralized timing service for MVO. It is intended to allow animation or other ongoing actions to proceed without completely usurping control of the application.

The timer service is completely platform and GUI independent and therefore requires timer ticks to be delivered from whatever GUI or system calls are appropriate from the environment. It is recommended (though not required) that such ticks be delivered at the highest available frequency from the system. See CTDriver.cpp in hoops_mfc for an example.

Once such ticks are set up, clients can register themselves to request notification at any frequency. Such clients must derive from HTClient. A reference implementation is provided by HTCObjectRotate.[cpp,h]

The HTManager‘s sense of time is achieved by repeated calls to HOOPS/3dGS’ HC_Show_Time. Refer to the 3dGS reference manual.

This platform-independent class keeps an array of linked lists to store all of the events for one second, then has a spillover list to handle anything that needs to be scheduled further out. Its main job is to dispatch timer messages from the OS to whatever clients would like to request them. With this service in place, clients can safely release control during an animation, knowing that control will be returned when it is needed.

Methods

HTManager::HTManager(int output_hz = 100)

Constructs an HTManager object.

Parameters

output_hz: The number of buckets into which the timer manager splits a single second.
virtual HTManager::~HTManager()

virtual

virtual void HTManager::Tick(float time)

virtual

The mechanism for receiving timer events from the OS is platform dependent, so here we only provide a function call for the external “timer driver” to deliver timer events. It is recommended that such events be delivered at the highest available frequency.

void HTManager::RegisterClient(HTClient *c)

This method informs the timer manager of a client that would like to start receiving timer events.

Parameters

c: A pointer to the HTClient that would like to receiver timer events.
void HTManager::UnRegisterClient(HTClient *c)

This method stops the timer service for the given client.

Parameters

c: A pointer the HTClient that no longer wants to receive timer events.
static HTManager *HTManager::GetCurrentHTManager()

static

Returns

A pointer to the timer manager currently associated with hoops_mvo’s central HDB object.
void HTManager::Init(float start_time)

protected

This method must be called before any dispatching can be done. Note it is automatically performed on the first call to RegisterClient. It allocates all required memory for member data.

Parameters

start_time: The time, as reported by #HC_Show_Time, at which this class was initialized.
void HTManager::ScheduleNextTick(HTClient *c, float time)

protected

This method finds the appropriate list to which the given client should be added so that an event is scheduled at the right time.

Parameters

c: The client that is requesting a timer event.

time: Pass the ideal time at which this timer event should be delivered.

Variables

double HTManager::m_interval

protected

double

1.0 / m_output_hz

double HTManager::m_request_time

protected

double

The time that the current bucket’s events had requested.

double HTManager::m_actual_time

protected

double

The actual time which may be different from m_request_time if control is lost for a while.

int HTManager::m_output_hz

protected

int

The granularity of the timer, i.e. the number of buckets into which the timer manager splits a single second. Timer events scheduled in the same bucket may be delivered sorted only by priority.

struct vlist_s **HTManager::m_buckets

protected

struct vlist_s

The array of buckets of size m_output_hz. This array holds precisely 1 sec of events.

int HTManager::m_current_bucket

protected

int

The bucket of events currently being dispatched.

struct vlist_s *HTManager::m_spillover

protected

struct vlist_s

An array of things that need to be scheduled for more than 1s away.

struct vhash_s *HTManager::m_active_clients

protected

struct vhash_s

A hash table of all the currently registered clients. Only currently registered clients can receive ticks, or even accessed in any way to make sure we don’t access any memory after free. */

struct vlist_s *HTManager::m_recently_deleted_expirations

protected

struct vlist_s

A vlist parallel to m_recently_deleted_clients to indicate how long things need to stay on the list.

struct vlist_s *HTManager::m_recently_deleted_clients

protected

struct vlist_s

A list of recently deleted clients. Only if an item is unregistered and then re-registered very quickly.