Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

CIntervalManager Class Reference

This object holds a number of currently-playing intervals and is responsible for advancing them each frame as needed. More...

#include <cIntervalManager.h>

List of all members.

Public Member Functions

 CIntervalManager ()
 ~CIntervalManager ()
void set_event_queue (EventQueue *event_queue)
 Specifies a custom event queue to be used for throwing done events from intervals as they finish.

EventQueueget_event_queue () const
 Returns the custom event queue to be used for throwing done events from intervals as they finish.

int add_c_interval (CInterval *interval, bool external)
 Adds the interval to the manager, and returns a unique index for the interval.

int find_c_interval (const string &name) const
 Returns the index associated with the named interval, if there is such an interval, or -1 if there is not.

CIntervalget_c_interval (int index) const
 Returns the interval associated with the given index.

void remove_c_interval (int index)
 Removes the indicated interval from the queue immediately.

int interrupt ()
 Pauses or finishes (removes from the active queue) all intervals tagged with auto_pause or auto_finish set to true.

int get_num_intervals () const
 Returns the number of currently active intervals.

void step ()
 This should be called every frame to do the processing for all the active intervals.

int get_next_event ()
 This should be called by the scripting language after each call to step().

int get_next_removal ()
 This should be called by the scripting language after each call to step().

void output (ostream &out) const
void write (ostream &out) const

Static Public Member Functions

CIntervalManager * get_global_ptr ()
 Returns the pointer to the one global CIntervalManager object.


Private Types

typedef pvector< IntervalDefIntervals
typedef pmap< string, intNameIndex
typedef vector_int Removed
enum  Flags { F_external = 0x0001, F_meta_interval = 0x0002 }

Private Member Functions

void finish_interval (CInterval *interval)
 Explicitly finishes the indicated interval in preparation for moving it to the removed queue.

void remove_index (int index)
 Removes the indicated index number from the active list, either by moving it to the removed queue if it is flagged external, or by simply making the slot available again if it is not.


Private Attributes

Intervals _intervals
NameIndex _name_index
Removed _removed
EventQueue_event_queue
int _first_slot
int _next_event_index

Static Private Attributes

CIntervalManager * _global_ptr


Detailed Description

This object holds a number of currently-playing intervals and is responsible for advancing them each frame as needed.

There is normally only one IntervalManager object in the world, and it is the responsibility of the scripting language to call step() on this object once each frame, and to then process the events indicated by get_next_event().

It is also possible to create multiple IntervalManager objects for special needs.

Definition at line 63 of file cIntervalManager.h.


Member Typedef Documentation

typedef pvector<IntervalDef> CIntervalManager::Intervals [private]
 

Definition at line 103 of file cIntervalManager.h.

typedef pmap<string, int> CIntervalManager::NameIndex [private]
 

Definition at line 105 of file cIntervalManager.h.

typedef vector_int CIntervalManager::Removed [private]
 

Definition at line 107 of file cIntervalManager.h.


Member Enumeration Documentation

enum CIntervalManager::Flags [private]
 

Enumeration values:
F_external 
F_meta_interval 

Definition at line 93 of file cIntervalManager.h.


Constructor & Destructor Documentation

CIntervalManager::CIntervalManager  ) 
 

Definition at line 38 of file cIntervalManager.cxx.

References _name_index, and nassertv.

CIntervalManager::~CIntervalManager  ) 
 

Definition at line 53 of file cIntervalManager.cxx.

References _first_slot, _intervals, _name_index, finish_interval(), CInterval::get_name(), nassertr, and remove_index().


Member Function Documentation

int CIntervalManager::add_c_interval CInterval interval,
bool  external
 

Adds the interval to the manager, and returns a unique index for the interval.

This index will be unique among all the currently added intervals, but not unique across all intervals ever added to the manager. The maximum index value will never exceed the maximum number of intervals added at any given time.

If the external flag is true, the interval is understood to also be stored in the scripting language data structures. In this case, it will be available for information returned by get_next_event() and get_next_removal(). If external is false, the interval's index will never be returned by these two functions.

Definition at line 94 of file cIntervalManager.cxx.

Referenced by CInterval::loop().

int CIntervalManager::find_c_interval const string &  name  )  const
 

Returns the index associated with the named interval, if there is such an interval, or -1 if there is not.

Definition at line 155 of file cIntervalManager.cxx.

References _first_slot, _name_index, and NULL.

Referenced by CInterval::pause().

void CIntervalManager::finish_interval CInterval interval  )  [private]
 

Explicitly finishes the indicated interval in preparation for moving it to the removed queue.

Definition at line 525 of file cIntervalManager.cxx.

Referenced by ~CIntervalManager().

CInterval * CIntervalManager::get_c_interval int  index  )  const
 

Returns the interval associated with the given index.

Definition at line 172 of file cIntervalManager.cxx.

References CIntervalManager::IntervalDef::_interval, _name_index, nassertr, and NULL.

EventQueue * CIntervalManager::get_event_queue  )  const [inline]
 

Returns the custom event queue to be used for throwing done events from intervals as they finish.

Definition at line 63 of file cIntervalManager.I.

CIntervalManager * CIntervalManager::get_global_ptr  )  [static]
 

Returns the pointer to the one global CIntervalManager object.

Definition at line 507 of file cIntervalManager.cxx.

Referenced by CInterval::CInterval().

int CIntervalManager::get_next_event  ) 
 

This should be called by the scripting language after each call to step().

It returns the index number of the next interval that has events requiring servicing by the scripting language, or -1 if no more intervals have any events pending.

If this function returns something other than -1, it is the scripting language's responsibility to query the indicated interval for its next event via get_event_index(), and eventually pop_event().

Then get_next_event() should be called again until it returns -1.

Definition at line 383 of file cIntervalManager.cxx.

int CIntervalManager::get_next_removal  ) 
 

This should be called by the scripting language after each call to step().

It returns the index number of an interval that was recently removed, or -1 if no intervals were removed.

If this returns something other than -1, the scripting language should clean up its own data structures accordingly, and then call get_next_removal() again.

Definition at line 431 of file cIntervalManager.cxx.

int CIntervalManager::get_num_intervals  )  const
 

Returns the number of currently active intervals.

Definition at line 294 of file cIntervalManager.cxx.

References CIntervalManager::IntervalDef::_flags, CIntervalManager::IntervalDef::_interval, _next_event_index, DCAST_INTO_R, F_external, F_meta_interval, CMetaInterval::is_event_ready(), nassertr, and NULL.

int CIntervalManager::interrupt  ) 
 

Pauses or finishes (removes from the active queue) all intervals tagged with auto_pause or auto_finish set to true.

These are intervals that someone fired up but won't necessarily expect to clean up; they can be interrupted at will when necessary.

Returns the number of intervals affected.

Definition at line 228 of file cIntervalManager.cxx.

void CIntervalManager::output ostream &  out  )  const
 

Definition at line 456 of file cIntervalManager.cxx.

Referenced by set_event_queue().

void CIntervalManager::remove_c_interval int  index  ) 
 

Removes the indicated interval from the queue immediately.

It will not be returned from get_next_removal(), and none of its pending events, if any, will be returned by get_next_event().

Definition at line 192 of file cIntervalManager.cxx.

References CIntervalManager::IntervalDef::_interval.

Referenced by CInterval::resume().

void CIntervalManager::remove_index int  index  )  [private]
 

Removes the indicated index number from the active list, either by moving it to the removed queue if it is flagged external, or by simply making the slot available again if it is not.

Definition at line 554 of file cIntervalManager.cxx.

Referenced by ~CIntervalManager().

void CIntervalManager::set_event_queue EventQueue event_queue  )  [inline]
 

Specifies a custom event queue to be used for throwing done events from intervals as they finish.

If this is not specified, the global event queue is used.

The caller maintains ownership of the EventQueue object; it is the caller's responsibility to ensure that the supplied EventQueue does not destruct during the lifetime of the CIntervalManager.

Definition at line 48 of file cIntervalManager.I.

References INLINE, and output().

void CIntervalManager::step void   ) 
 

This should be called every frame to do the processing for all the active intervals.

It will call step_play() for each interval that has been added and that has not yet been removed.

After each call to step(), the scripting language should call get_next_event() and get_next_removal() repeatedly to process all the high-level (e.g. Python-interval-based) events and to manage the high-level list of intervals.

Definition at line 325 of file cIntervalManager.cxx.

void CIntervalManager::write ostream &  out  )  const
 

Definition at line 469 of file cIntervalManager.cxx.


Member Data Documentation

EventQueue* CIntervalManager::_event_queue [private]
 

Definition at line 109 of file cIntervalManager.h.

int CIntervalManager::_first_slot [private]
 

Definition at line 111 of file cIntervalManager.h.

Referenced by find_c_interval(), and ~CIntervalManager().

CIntervalManager * CIntervalManager::_global_ptr [static, private]
 

Definition at line 27 of file cIntervalManager.cxx.

Intervals CIntervalManager::_intervals [private]
 

Definition at line 104 of file cIntervalManager.h.

Referenced by ~CIntervalManager().

NameIndex CIntervalManager::_name_index [private]
 

Definition at line 106 of file cIntervalManager.h.

Referenced by CIntervalManager(), find_c_interval(), get_c_interval(), and ~CIntervalManager().

int CIntervalManager::_next_event_index [private]
 

Definition at line 112 of file cIntervalManager.h.

Referenced by get_num_intervals().

Removed CIntervalManager::_removed [private]
 

Definition at line 108 of file cIntervalManager.h.


The documentation for this class was generated from the following files:
Generated on Fri May 2 01:40:51 2003 for Direct by doxygen1.3