Panda3D
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
CMetaInterval Class Reference

This interval contains a list of nested intervals, each of which has its own begin and end times. More...

#include "cMetaInterval.h"

Inheritance diagram for CMetaInterval:
CInterval TypedReferenceCount TypedObject ReferenceCount MemoryBase MemoryBase

Public Types

enum  DefType { DT_c_interval, DT_ext_index, DT_push_level, DT_pop_level }
 
enum  RelativeStart { RS_previous_end, RS_previous_begin, RS_level_begin }
 
- Public Types inherited from CInterval
enum  EventType {
  ET_initialize, ET_instant, ET_step, ET_finalize,
  ET_reverse_initialize, ET_reverse_instant, ET_reverse_finalize, ET_interrupt
}
 
enum  State { S_initial, S_started, S_paused, S_final }
 

Public Member Functions

 CMetaInterval (const string &name)
 
int add_c_interval (CInterval *c_interval, double rel_time=0.0f, RelativeStart rel_to=RS_previous_end)
 Adds a new CInterval to the list. More...
 
int add_ext_index (int ext_index, const string &name, double duration, bool open_ended, double rel_time, RelativeStart rel_to)
 Adds a new external interval to the list. More...
 
void clear_intervals ()
 Resets the list of intervals and prepares for receiving a new list. More...
 
virtual TypeHandle force_init_type ()
 
CIntervalget_c_interval (int n) const
 Return the CInterval pointer associated with the nth interval definition. More...
 
DefType get_def_type (int n) const
 Returns the type of the nth interval definition that has been added. More...
 
int get_event_index () const
 If a previous call to is_event_ready() returned true, this returns the index number (added via add_event_index()) of the external interval that needs to be played. More...
 
double get_event_t () const
 If a previous call to is_event_ready() returned true, this returns the t value that should be fed to the given interval. More...
 
EventType get_event_type () const
 If a previous call to is_event_ready() returned true, this returns the type of the event (initialize, step, finalize, etc.) for the given interval. More...
 
int get_ext_index (int n) const
 Return the external interval index number associated with the nth interval definition. More...
 
double get_interval_end_time (const string &name) const
 Returns the actual end time, relative to the beginning of the interval, of the child interval with the given name, if found, or -1 if the interval is not found. More...
 
double get_interval_start_time (const string &name) const
 Returns the actual start time, relative to the beginning of the interval, of the child interval with the given name, if found, or -1 if the interval is not found. More...
 
int get_num_defs () const
 Returns the number of interval and push/pop definitions that have been added to the meta interval. More...
 
double get_precision () const
 Returns the precision with which time measurements are compared. More...
 
virtual TypeHandle get_type () const
 
bool is_event_ready ()
 Returns true if a recent call to priv_initialize(), priv_step(), or priv_finalize() has left some external intervals ready to play. More...
 
void pop_event ()
 Acknowledges that the external interval on the top of the queue has been extracted, and is about to be serviced by the scripting language. More...
 
int pop_level (double duration=-1.0)
 Finishes a level marked by a previous call to push_level(), and returns to the previous level. More...
 
virtual void priv_finalize ()
 This is called when an interval is interrupted. More...
 
virtual void priv_initialize (double t)
 This replaces the first call to priv_step(), and indicates that the interval has just begun. More...
 
virtual void priv_instant ()
 This is called in lieu of priv_initialize() . More...
 
virtual void priv_interrupt ()
 This is called while the interval is playing to indicate that it is about to be interrupted; that is, priv_step() will not be called for a length of time. More...
 
virtual void priv_reverse_finalize ()
 Called generally following a priv_reverse_initialize(), this indicates the interval should set itself to the initial state. More...
 
virtual void priv_reverse_initialize (double t)
 Similar to priv_initialize(), but this is called when the interval is being played backwards; it indicates that the interval should start at the finishing state and undo any intervening intervals. More...
 
virtual void priv_reverse_instant ()
 This is called in lieu of priv_reverse_initialize() More...
 
virtual void priv_step (double t)
 Advances the time on the interval. More...
 
int push_level (const string &name, double rel_time, RelativeStart rel_to)
 Marks the beginning of a nested level of child intervals. More...
 
bool set_interval_start_time (const string &name, double rel_time, RelativeStart rel_to=RS_level_begin)
 Adjusts the start time of the child interval with the given name, if found. More...
 
void set_precision (double precision)
 Indicates the precision with which time measurements are compared. More...
 
void timeline (ostream &out) const
 Outputs a list of all events in the order in which they occur. More...
 
virtual void write (ostream &out, int indent_level) const
 
- Public Member Functions inherited from CInterval
 CInterval (const string &name, double duration, bool open_ended)
 
bool check_t_callback ()
 Returns true if the wants_t_callback() flag is true and the interval's t value has changed since the last call to check_t_callback(), false otherwise. More...
 
void clear_to_initial ()
 Pauses the interval, if it is playing, and resets its state to its initial state, abandoning any state changes already in progress in the middle of the interval. More...
 
void finish ()
 Stops the interval from playing and sets it to its final state. More...
 
bool get_auto_finish () const
 Returns the state of the 'auto_finish' flag. More...
 
bool get_auto_pause () const
 Returns the state of the 'auto_pause' flag. More...
 
const string & get_done_event () const
 Returns the event that is generated whenever the interval reaches its final state, whether it is explicitly finished or whether it gets there on its own. More...
 
double get_duration () const
 Returns the duration of the interval in seconds. More...
 
CIntervalManagerget_manager () const
 Returns the CIntervalManager object which will be responsible for playing this interval. More...
 
const string & get_name () const
 Returns the interval's name. More...
 
bool get_open_ended () const
 Returns the state of the "open_ended" flag. More...
 
double get_play_rate () const
 Returns the play rate as set by the last call to start(), loop(), or set_play_rate(). More...
 
State get_state () const
 Indicates the state the interval believes it is in: whether it has been started, is currently in the middle, or has been finalized. More...
 
double get_t () const
 Returns the current time of the interval: the last value of t passed to priv_initialize(), priv_step(), or priv_finalize(). More...
 
bool get_wants_t_callback () const
 Returns the state of the 'wants_t_callback' flag. More...
 
bool is_playing () const
 Returns true if the interval is currently playing, false otherwise. More...
 
bool is_stopped () const
 Returns true if the interval is in either its initial or final states (but not in a running or paused state). More...
 
void loop (double start_t=0.0, double end_t=-1.0, double play_rate=1.0)
 Starts the interval playing by registering it with the current CIntervalManager. More...
 
void mark_dirty ()
 Called by a derived class to indicate the interval has been changed internally and must be recomputed before its duration may be returned. More...
 
virtual void output (ostream &out) const
 
double pause ()
 Stops the interval from playing but leaves it in its current state. More...
 
void priv_do_event (double t, EventType event)
 Calls the appropriate event function indicated by the EventType. More...
 
void resume ()
 Restarts the interval from its current point after a previous call to pause(). More...
 
void resume (double start_t)
 Restarts the interval from the indicated point after a previous call to pause(). More...
 
void resume_until (double end_t)
 Restarts the interval from the current point after a previous call to pause() (or a previous play-to-point-and-stop), to play until the indicated point and then stop. More...
 
void set_auto_finish (bool auto_finish)
 Changes the state of the 'auto_finish' flag. More...
 
void set_auto_pause (bool auto_pause)
 Changes the state of the 'auto_pause' flag. More...
 
void set_done_event (const string &event)
 Sets the event that is generated whenever the interval reaches its final state, whether it is explicitly finished or whether it gets there on its own. More...
 
void set_manager (CIntervalManager *manager)
 Indicates the CIntervalManager object which will be responsible for playing this interval. More...
 
void set_play_rate (double play_rate)
 Changes the play rate of the interval. More...
 
void set_t (double t)
 Explicitly sets the time within the interval. More...
 
void set_wants_t_callback (bool wants_t_callback)
 Changes the state of the 'wants_t_callback' flag. More...
 
void setup_play (double start_time, double end_time, double play_rate, bool do_loop)
 Called to prepare the interval for automatic timed playback, e.g. More...
 
void setup_resume ()
 Called to prepare the interval for restarting at the current point within the interval after an interruption. More...
 
void setup_resume_until (double end_t)
 Called to prepare the interval for restarting from the current point after a previous call to pause() (or a previous play-to-point-and-stop), to play until the indicated point and then stop. More...
 
void start (double start_t=0.0, double end_t=-1.0, double play_rate=1.0)
 Starts the interval playing by registering it with the current CIntervalManager. More...
 
bool step_play ()
 Should be called once per frame to execute the automatic timed playback begun with setup_play(). More...
 
- Public Member Functions inherited from TypedReferenceCount
 TypedReferenceCount (const TypedReferenceCount &copy)
 
void operator= (const TypedReferenceCount &copy)
 
- Public Member Functions inherited from TypedObject
 TypedObject (const TypedObject &copy)
 
TypedObjectas_typed_object ()
 Returns the object, upcast (if necessary) to a TypedObject pointer. More...
 
const TypedObjectas_typed_object () const
 Returns the object, upcast (if necessary) to a TypedObject pointer. More...
 
int get_best_parent_from_Set (const std::set< int > &) const
 
int get_type_index () const
 Returns the internal index number associated with this object's TypeHandle, a unique number for each different type. More...
 
bool is_exact_type (TypeHandle handle) const
 Returns true if the current object is the indicated type exactly. More...
 
bool is_of_type (TypeHandle handle) const
 Returns true if the current object is or derives from the indicated type. More...
 
void operator= (const TypedObject &copy)
 
- Public Member Functions inherited from ReferenceCount
int get_ref_count () const
 Returns the current reference count. More...
 
WeakReferenceListget_weak_list () const
 Returns the WeakReferenceList associated with this ReferenceCount object. More...
 
bool has_weak_list () const
 Returns true if this particular ReferenceCount object has a WeakReferenceList created, false otherwise. More...
 
void local_object ()
 This function should be called, once, immediately after creating a new instance of some ReferenceCount-derived object on the stack. More...
 
void ref () const
 Explicitly increments the reference count. More...
 
bool test_ref_count_integrity () const
 Does some easy checks to make sure that the reference count isn't completely bogus. More...
 
bool test_ref_count_nonzero () const
 Does some easy checks to make sure that the reference count isn't zero, or completely bogus. More...
 
virtual bool unref () const
 Explicitly decrements the reference count. More...
 
void weak_ref (WeakPointerToVoid *ptv)
 Adds the indicated PointerToVoid as a weak reference to this object. More...
 
void weak_unref (WeakPointerToVoid *ptv)
 Removes the indicated PointerToVoid as a weak reference to this object. More...
 

Static Public Member Functions

static TypeHandle get_class_type ()
 
static void init_type ()
 
- Static Public Member Functions inherited from CInterval
static TypeHandle get_class_type ()
 
static void init_type ()
 
- Static Public Member Functions inherited from TypedReferenceCount
static TypeHandle get_class_type ()
 
static void init_type ()
 
- Static Public Member Functions inherited from TypedObject
static TypeHandle get_class_type ()
 
static void init_type ()
 This function is declared non-inline to work around a compiler bug in g++ 2.96. More...
 
- Static Public Member Functions inherited from ReferenceCount
static TypeHandle get_class_type ()
 
static void init_type ()
 

Detailed Description

This interval contains a list of nested intervals, each of which has its own begin and end times.

Some of them may overlap and some of them may not.

Definition at line 34 of file cMetaInterval.h.

Member Function Documentation

◆ add_c_interval()

int CMetaInterval::add_c_interval ( CInterval c_interval,
double  rel_time = 0.0f,
RelativeStart  rel_to = RS_previous_end 
)

Adds a new CInterval to the list.

The interval will be played when the indicated time (relative to the given point) has been reached.

The return value is the index of the def entry representing the new interval.

Definition at line 137 of file cMetaInterval.cxx.

References add_ext_index(), and CInterval::mark_dirty().

Referenced by push_level().

◆ add_ext_index()

int CMetaInterval::add_ext_index ( int  ext_index,
const string &  name,
double  duration,
bool  open_ended,
double  rel_time,
RelativeStart  rel_to 
)

Adds a new external interval to the list.

This represents some object in the external scripting language that has properties similar to a CInterval (for instance, a Python Interval object).

The CMetaInterval object cannot play this external interval directly, but it records a placeholder for it and will ask the scripting language to play it when it is time, via is_event_ready() and related methods.

The ext_index number itself is simply a handle that the scripting language makes up and associates with its interval object somehow. The CMetaInterval object does not attempt to interpret this value.

The return value is the index of the def entry representing the new interval.

Definition at line 178 of file cMetaInterval.cxx.

References CInterval::mark_dirty(), and pop_level().

Referenced by add_c_interval().

◆ clear_intervals()

void CMetaInterval::clear_intervals ( )

Resets the list of intervals and prepares for receiving a new list.

Definition at line 59 of file cMetaInterval.cxx.

References push_level().

◆ get_c_interval()

CInterval * CMetaInterval::get_c_interval ( int  n) const
inline

Return the CInterval pointer associated with the nth interval definition.

It is only valid to call this if get_def_type(n) returns DT_c_interval.

Definition at line 77 of file cMetaInterval.I.

References get_ext_index().

Referenced by get_def_type().

◆ get_def_type()

CMetaInterval::DefType CMetaInterval::get_def_type ( int  n) const
inline

Returns the type of the nth interval definition that has been added.

Definition at line 64 of file cMetaInterval.I.

References get_c_interval().

Referenced by get_num_defs().

◆ get_event_index()

int CMetaInterval::get_event_index ( ) const
inline

If a previous call to is_event_ready() returned true, this returns the index number (added via add_event_index()) of the external interval that needs to be played.

Definition at line 120 of file cMetaInterval.I.

References get_event_t().

Referenced by is_event_ready().

◆ get_event_t()

double CMetaInterval::get_event_t ( ) const
inline

If a previous call to is_event_ready() returned true, this returns the t value that should be fed to the given interval.

Definition at line 136 of file cMetaInterval.I.

References get_event_type().

Referenced by get_event_index().

◆ get_event_type()

CInterval::EventType CMetaInterval::get_event_type ( ) const
inline

If a previous call to is_event_ready() returned true, this returns the type of the event (initialize, step, finalize, etc.) for the given interval.

Definition at line 149 of file cMetaInterval.I.

Referenced by get_event_t().

◆ get_ext_index()

int CMetaInterval::get_ext_index ( int  n) const
inline

Return the external interval index number associated with the nth interval definition.

It is only valid to call this if get_def_type(n) returns DT_ext_index.

Definition at line 91 of file cMetaInterval.I.

References is_event_ready().

Referenced by get_c_interval().

◆ get_interval_end_time()

double CMetaInterval::get_interval_end_time ( const string &  name) const

Returns the actual end time, relative to the beginning of the interval, of the child interval with the given name, if found, or -1 if the interval is not found.

Definition at line 318 of file cMetaInterval.cxx.

References priv_initialize().

Referenced by get_interval_start_time().

◆ get_interval_start_time()

double CMetaInterval::get_interval_start_time ( const string &  name) const

Returns the actual start time, relative to the beginning of the interval, of the child interval with the given name, if found, or -1 if the interval is not found.

Definition at line 281 of file cMetaInterval.cxx.

References get_interval_end_time().

Referenced by set_interval_start_time().

◆ get_num_defs()

int CMetaInterval::get_num_defs ( ) const
inline

Returns the number of interval and push/pop definitions that have been added to the meta interval.

Definition at line 53 of file cMetaInterval.I.

References get_def_type().

Referenced by get_precision().

◆ get_precision()

double CMetaInterval::get_precision ( ) const
inline

Returns the precision with which time measurements are compared.

See set_precision().

Definition at line 41 of file cMetaInterval.I.

References get_num_defs().

Referenced by set_precision().

◆ is_event_ready()

bool CMetaInterval::is_event_ready ( )
inline

Returns true if a recent call to priv_initialize(), priv_step(), or priv_finalize() has left some external intervals ready to play.

If this returns true, call get_event_index(), get_event_t(), and pop_event() to retrieve the relevant information.

Definition at line 107 of file cMetaInterval.I.

References get_event_index().

Referenced by get_ext_index(), and CIntervalManager::get_next_event().

◆ pop_event()

void CMetaInterval::pop_event ( )

Acknowledges that the external interval on the top of the queue has been extracted, and is about to be serviced by the scripting language.

This prepares the interval so the next call to is_event_ready() will return information about the next external interval on the queue, if any.

Definition at line 725 of file cMetaInterval.cxx.

References CInterval::get_name(), and timeline().

Referenced by priv_interrupt().

◆ pop_level()

int CMetaInterval::pop_level ( double  duration = -1.0)

Finishes a level marked by a previous call to push_level(), and returns to the previous level.

If the duration is not negative, it represents a phony duration to assign to the level, for the purposes of sequencing later intervals. Otherwise, the level's duration is computed based on the intervals within the level.

Definition at line 210 of file cMetaInterval.cxx.

References CInterval::mark_dirty(), and set_interval_start_time().

Referenced by add_ext_index().

◆ priv_finalize()

void CMetaInterval::priv_finalize ( )
virtual

This is called when an interval is interrupted.

It should advance the time as if priv_step() were called, and also perform whatever cleanup might be required.

Reimplemented from CInterval.

Definition at line 519 of file cMetaInterval.cxx.

References CInterval::get_duration(), CLerpNodePathInterval::priv_initialize(), and priv_reverse_initialize().

Referenced by priv_step().

◆ priv_initialize()

void CMetaInterval::priv_initialize ( double  t)
virtual

This replaces the first call to priv_step(), and indicates that the interval has just begun.

This may be overridden by derived classes that need to do some explicit initialization on the first call.

Reimplemented from CInterval.

Definition at line 358 of file cMetaInterval.cxx.

References priv_instant().

Referenced by get_interval_end_time().

◆ priv_instant()

void CMetaInterval::priv_instant ( )
virtual

This is called in lieu of priv_initialize() .

. priv_step() .. priv_finalize(), when everything is to happen within one frame. The interval should initialize itself, then leave itself in the final state.

Reimplemented from CInterval.

Definition at line 413 of file cMetaInterval.cxx.

References CInterval::get_duration(), and priv_step().

Referenced by priv_initialize().

◆ priv_interrupt()

void CMetaInterval::priv_interrupt ( )
virtual

This is called while the interval is playing to indicate that it is about to be interrupted; that is, priv_step() will not be called for a length of time.

But the interval should remain in its current state in anticipation of being eventually restarted when the calls to priv_step() eventually resume.

The purpose of this function is to allow self-running intervals like sound intervals to stop the actual sound playback during the pause.

Reimplemented from CInterval.

Definition at line 695 of file cMetaInterval.cxx.

References pop_event().

Referenced by priv_reverse_finalize().

◆ priv_reverse_finalize()

void CMetaInterval::priv_reverse_finalize ( )
virtual

Called generally following a priv_reverse_initialize(), this indicates the interval should set itself to the initial state.

Reimplemented from CInterval.

Definition at line 653 of file cMetaInterval.cxx.

References CLerpNodePathInterval::priv_initialize(), and priv_interrupt().

Referenced by priv_reverse_instant().

◆ priv_reverse_initialize()

void CMetaInterval::priv_reverse_initialize ( double  t)
virtual

Similar to priv_initialize(), but this is called when the interval is being played backwards; it indicates that the interval should start at the finishing state and undo any intervening intervals.

Reimplemented from CInterval.

Definition at line 562 of file cMetaInterval.cxx.

References priv_reverse_instant().

Referenced by priv_finalize().

◆ priv_reverse_instant()

void CMetaInterval::priv_reverse_instant ( )
virtual

This is called in lieu of priv_reverse_initialize()

. priv_step() .. priv_reverse_finalize(), when everything is to happen within one frame. The interval should initialize itself, then leave itself in the initial state.

Reimplemented from CInterval.

Definition at line 618 of file cMetaInterval.cxx.

References priv_reverse_finalize().

Referenced by priv_reverse_initialize().

◆ priv_step()

void CMetaInterval::priv_step ( double  t)
virtual

Advances the time on the interval.

The time may either increase (the normal case) or decrease (e.g. if the interval is being played by a slider).

Reimplemented from CInterval.

Definition at line 454 of file cMetaInterval.cxx.

References priv_finalize().

Referenced by priv_instant().

◆ push_level()

int CMetaInterval::push_level ( const string &  name,
double  rel_time,
RelativeStart  rel_to 
)

Marks the beginning of a nested level of child intervals.

Within the nested level, a RelativeStart time of RS_level_begin refers to the start of the level, and the first interval added within the level is always relative to the start of the level.

The return value is the index of the def entry created by this push.

Definition at line 111 of file cMetaInterval.cxx.

References add_c_interval(), and CInterval::mark_dirty().

Referenced by clear_intervals().

◆ set_interval_start_time()

bool CMetaInterval::set_interval_start_time ( const string &  name,
double  rel_time,
CMetaInterval::RelativeStart  rel_to = RS_level_begin 
)

Adjusts the start time of the child interval with the given name, if found.

This may be either a C++ interval added via add_c_interval(), or an external interval added via add_ext_index(); the name must match exactly.

If the interval is found, its start time is adjusted, and all subsequent intervals are adjusting accordingly, and true is returned. If a matching interval is not found, nothing is changed and false is returned.

Definition at line 240 of file cMetaInterval.cxx.

References get_interval_start_time(), and CInterval::mark_dirty().

Referenced by pop_level().

◆ set_precision()

void CMetaInterval::set_precision ( double  precision)
inline

Indicates the precision with which time measurements are compared.

For numerical accuracy, all floating-point time values are converted to integer values internally by scaling by the precision factor. The larger the number given here, the smaller the delta of time that can be differentiated; the limit is the maximum integer that can be represented in the system.

Definition at line 29 of file cMetaInterval.I.

References get_precision(), and CInterval::mark_dirty().

◆ timeline()

void CMetaInterval::timeline ( ostream &  out) const

Outputs a list of all events in the order in which they occur.

Definition at line 773 of file cMetaInterval.cxx.

References CInterval::priv_do_event().

Referenced by pop_event().


The documentation for this class was generated from the following files: