Panda3D
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Friends | List of all members
CInterval Class Reference

The base class for timeline components. More...

#include "cInterval.h"

Inheritance diagram for CInterval:
TypedReferenceCount TypedObject ReferenceCount MemoryBase MemoryBase CConstraintInterval CLerpInterval CMetaInterval HideInterval ShowInterval WaitInterval CConstrainHprInterval CConstrainPosHprInterval CConstrainPosInterval CConstrainTransformInterval CLerpAnimEffectInterval CLerpNodePathInterval

Public Types

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

 CInterval (const std::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...
 
virtual TypeHandle force_init_type ()
 
bool get_auto_finish () const
 
bool get_auto_pause () const
 
const std::string & get_done_event () const
 
double get_duration () const
 
CIntervalManagerget_manager () const
 
const std::string & get_name () const
 
bool get_open_ended () const
 
double get_play_rate () const
 
State get_state () const
 
double get_t () const
 
virtual TypeHandle get_type () const
 
bool get_wants_t_callback () const
 Returns the state of the 'wants_t_callback' flag. More...
 
bool is_playing () const
 
bool is_stopped () const
 
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 (std::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...
 
virtual void priv_finalize ()
 This is called to stop an interval, forcing it to whatever state it would be after it played all the way through. 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...
 
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)
 
void set_auto_pause (bool auto_pause)
 
void set_done_event (const std::string &event)
 
void set_manager (CIntervalManager *manager)
 
void set_play_rate (double play_rate)
 
void set_t (double t)
 
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...
 
virtual void write (std::ostream &out, int indent_level) const
 
- 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)=default
 
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...
 
TypedObjectoperator= (const TypedObject &copy)=default
 
- Public Member Functions inherited from ReferenceCount
int get_ref_count () const
 
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 ref_if_nonzero () const
 Atomically increases the reference count of this object if it is not zero. 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...
 
WeakReferenceListweak_ref ()
 Adds the indicated PointerToVoid as a weak reference to this object. More...
 
void weak_unref ()
 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 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 ()
 

Public Attributes

 get_auto_finish
 Returns the state of the 'auto_finish' flag. More...
 
 get_auto_pause
 Returns the state of the 'auto_pause' flag. More...
 
 get_done_event
 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...
 
 get_duration
 Returns the duration of the interval in seconds. More...
 
 get_manager
 Returns the CIntervalManager object which will be responsible for playing this interval. More...
 
 get_name
 Returns the interval's name. More...
 
 get_open_ended
 Returns the state of the "open_ended" flag. More...
 
 get_play_rate
 Returns the play rate as set by the last call to start(), loop(), or set_play_rate(). More...
 
 get_state
 Indicates the state the interval believes it is in: whether it has been started, is currently in the middle, or has been finalized. More...
 
 get_t
 Returns the current time of the interval: the last value of t passed to priv_initialize(), priv_step(), or priv_finalize(). More...
 
 is_playing
 Returns true if the interval is currently playing, false otherwise. More...
 
 is_stopped
 Returns true if the interval is in either its initial or final states (but not in a running or paused state). More...
 
 set_auto_finish
 Changes the state of the 'auto_finish' flag. More...
 
 set_auto_pause
 Changes the state of the 'auto_pause' flag. More...
 
 set_done_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...
 
 set_manager
 Indicates the CIntervalManager object which will be responsible for playing this interval. More...
 
 set_play_rate
 Changes the play rate of the interval. More...
 
 set_t
 Explicitly sets the time within the interval. More...
 
- Public Attributes inherited from TypedObject
 get_type
 
- Public Attributes inherited from ReferenceCount
 get_ref_count
 Returns the current reference count. More...
 

Friends

class CMetaInterval
 

Detailed Description

The base class for timeline components.

A CInterval represents a single action, event, or collection of nested intervals that will be performed at some specific time or over a period of time.

This is essentially similar to the Python "Interval" class, but it is implemented in C++ (hence the name). Intervals that may be implemented in C++ will inherit from this class; Intervals that must be implemented in Python will inherit from the similar Python class.

Definition at line 35 of file cInterval.h.

Member Function Documentation

◆ check_t_callback()

bool CInterval::check_t_callback ( )
inline

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.

Definition at line 178 of file cInterval.I.

References get_t, and get_wants_t_callback().

◆ clear_to_initial()

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

Calling this is like pausing the interval and discarding it, creating a new one in its place.

Definition at line 237 of file cInterval.cxx.

References pause().

◆ finish()

void CInterval::finish ( )

Stops the interval from playing and sets it to its final state.

Definition at line 211 of file cInterval.cxx.

References CIntervalManager::find_c_interval(), get_name, get_state, priv_finalize(), priv_instant(), and CIntervalManager::remove_c_interval().

◆ get_wants_t_callback()

bool CInterval::get_wants_t_callback ( ) const
inline

Returns the state of the 'wants_t_callback' flag.

See set_wants_t_callback().

Definition at line 145 of file cInterval.I.

Referenced by check_t_callback().

◆ loop()

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

The interval will play until it is interrupted with finish() or pause(), looping back to start_t when it reaches end_t.

If end_t is less than zero, it indicates the end of the interval.

Definition at line 154 of file cInterval.cxx.

References CIntervalManager::add_c_interval(), and setup_play().

◆ mark_dirty()

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

Definition at line 654 of file cInterval.cxx.

Referenced by CMetaInterval::set_precision().

◆ pause()

double CInterval::pause ( )

Stops the interval from playing but leaves it in its current state.

It may later be resumed from this point by calling resume().

Definition at line 164 of file cInterval.cxx.

References CIntervalManager::find_c_interval(), get_name, get_state, get_t, priv_interrupt(), and CIntervalManager::remove_c_interval().

Referenced by clear_to_initial().

◆ priv_do_event()

void CInterval::priv_do_event ( double  t,
EventType  event 
)

Calls the appropriate event function indicated by the EventType.

Definition at line 283 of file cInterval.cxx.

References priv_finalize(), priv_initialize(), priv_instant(), priv_interrupt(), priv_reverse_finalize(), priv_reverse_initialize(), priv_reverse_instant(), and priv_step().

◆ priv_finalize()

void CInterval::priv_finalize ( )
virtual

This is called to stop an interval, forcing it to whatever state it would be after it played all the way through.

It's generally invoked by set_final_t().

Reimplemented in CMetaInterval.

Definition at line 369 of file cInterval.cxx.

References get_duration, and priv_step().

Referenced by finish(), priv_do_event(), and step_play().

◆ priv_initialize()

void CInterval::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 in CMetaInterval, and CLerpNodePathInterval.

Definition at line 329 of file cInterval.cxx.

References priv_step().

Referenced by priv_do_event(), and step_play().

◆ priv_instant()

void CInterval::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 in CMetaInterval, CLerpNodePathInterval, HideInterval, and ShowInterval.

Definition at line 342 of file cInterval.cxx.

References get_duration, and priv_step().

Referenced by finish(), priv_do_event(), and step_play().

◆ priv_interrupt()

void CInterval::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 in CMetaInterval.

Definition at line 427 of file cInterval.cxx.

Referenced by pause(), priv_do_event(), and step_play().

◆ priv_reverse_finalize()

void CInterval::priv_reverse_finalize ( )
virtual

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

Reimplemented in CMetaInterval.

Definition at line 410 of file cInterval.cxx.

References priv_step().

Referenced by priv_do_event(), and step_play().

◆ priv_reverse_initialize()

void CInterval::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 in CMetaInterval, and CLerpNodePathInterval.

Definition at line 383 of file cInterval.cxx.

References priv_step().

Referenced by priv_do_event(), and step_play().

◆ priv_reverse_instant()

void CInterval::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 in CMetaInterval, CLerpNodePathInterval, HideInterval, and ShowInterval.

Definition at line 397 of file cInterval.cxx.

References priv_step().

Referenced by priv_do_event(), and step_play().

◆ priv_step()

void CInterval::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 in CMetaInterval, CLerpNodePathInterval, CLerpAnimEffectInterval, CConstrainPosHprInterval, CConstrainHprInterval, CConstrainPosInterval, CConstrainTransformInterval, and WaitInterval.

Definition at line 357 of file cInterval.cxx.

Referenced by priv_do_event(), priv_finalize(), priv_initialize(), priv_instant(), priv_reverse_finalize(), priv_reverse_initialize(), priv_reverse_instant(), and step_play().

◆ resume() [1/2]

void CInterval::resume ( )

Restarts the interval from its current point after a previous call to pause().

Definition at line 180 of file cInterval.cxx.

References CIntervalManager::add_c_interval(), and setup_resume().

◆ resume() [2/2]

void CInterval::resume ( double  start_t)

Restarts the interval from the indicated point after a previous call to pause().

Definition at line 190 of file cInterval.cxx.

References CIntervalManager::add_c_interval(), set_t, and setup_resume().

◆ resume_until()

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

Definition at line 202 of file cInterval.cxx.

References CIntervalManager::add_c_interval(), and setup_resume_until().

◆ set_wants_t_callback()

void CInterval::set_wants_t_callback ( bool  wants_t_callback)
inline

Changes the state of the 'wants_t_callback' flag.

If this is true, the interval will be returned by CIntervalManager::get_event() each time the interval's time value has been changed, regardless of whether it has any external events.

Definition at line 135 of file cInterval.I.

◆ setup_play()

void CInterval::setup_play ( double  start_t,
double  end_t,
double  play_rate,
bool  do_loop 
)

Called to prepare the interval for automatic timed playback, e.g.

via a Python task. The interval will be played from start_t to end_t, at a time factor specified by play_rate. start_t must always be less than end_t (except for the exception for end_t == -1, below), but if play_rate is negative the interval will be played backwards.

Specify end_t of -1 to play the entire interval from start_t.

Call step_play() repeatedly to execute the interval.

Definition at line 463 of file cInterval.cxx.

Referenced by loop(), and start().

◆ setup_resume()

void CInterval::setup_resume ( )

Called to prepare the interval for restarting at the current point within the interval after an interruption.

Definition at line 499 of file cInterval.cxx.

References ClockObject::get_frame_time, ClockObject::get_global_clock(), and get_t.

Referenced by resume(), and setup_resume_until().

◆ setup_resume_until()

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

Definition at line 516 of file cInterval.cxx.

References get_duration, and setup_resume().

Referenced by resume_until().

◆ start()

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

The interval will play to the end and stop.

If end_t is less than zero, it indicates the end of the interval.

Definition at line 141 of file cInterval.cxx.

References CIntervalManager::add_c_interval(), and setup_play().

◆ step_play()

bool CInterval::step_play ( )

Should be called once per frame to execute the automatic timed playback begun with setup_play().

Returns true if the interval should continue, false if it is done and should stop.

Definition at line 538 of file cInterval.cxx.

References get_duration, ClockObject::get_frame_time, ClockObject::get_global_clock(), get_open_ended, is_stopped, priv_finalize(), priv_initialize(), priv_instant(), priv_interrupt(), priv_reverse_finalize(), priv_reverse_initialize(), priv_reverse_instant(), and priv_step().

Member Data Documentation

◆ get_auto_finish

bool CInterval::get_auto_finish
inline

Returns the state of the 'auto_finish' flag.

See set_auto_finish().

Definition at line 131 of file cInterval.h.

◆ get_auto_pause

bool CInterval::get_auto_pause
inline

Returns the state of the 'auto_pause' flag.

See set_auto_pause().

Definition at line 130 of file cInterval.h.

◆ get_done_event

const std::string & CInterval::get_done_event
inline

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.

Definition at line 128 of file cInterval.h.

◆ get_duration

double CInterval::get_duration
inline

◆ get_manager

CIntervalManager * CInterval::get_manager
inline

Returns the CIntervalManager object which will be responsible for playing this interval.

Note that this can only return a C++ object; if the particular CIntervalManager object has been extended in the scripting language, this will return the encapsulated C++ object, not the full extended object.

Definition at line 132 of file cInterval.h.

◆ get_name

const std::string & CInterval::get_name
inline

Returns the interval's name.

Definition at line 123 of file cInterval.h.

Referenced by CIntervalManager::add_c_interval(), finish(), and pause().

◆ get_open_ended

bool CInterval::get_open_ended
inline

Returns the state of the "open_ended" flag.

This is primarily intended for instantaneous intervals like FunctionIntervals; it indicates true if the interval has some lasting effect that should be applied even if the interval doesn't get started until after its finish time, or false if the interval is a transitive thing that doesn't need to be called late.

Definition at line 125 of file cInterval.h.

Referenced by step_play().

◆ get_play_rate

double CInterval::get_play_rate

Returns the play rate as set by the last call to start(), loop(), or set_play_rate().

Definition at line 133 of file cInterval.h.

◆ get_state

CInterval::State CInterval::get_state
inline

Indicates the state the interval believes it is in: whether it has been started, is currently in the middle, or has been finalized.

Definition at line 126 of file cInterval.h.

Referenced by finish(), and pause().

◆ get_t

double CInterval::get_t
inline

Returns the current time of the interval: the last value of t passed to priv_initialize(), priv_step(), or priv_finalize().

Definition at line 129 of file cInterval.h.

Referenced by check_t_callback(), pause(), and setup_resume().

◆ is_playing

bool CInterval::is_playing

Returns true if the interval is currently playing, false otherwise.

Definition at line 134 of file cInterval.h.

◆ is_stopped

bool CInterval::is_stopped
inline

Returns true if the interval is in either its initial or final states (but not in a running or paused state).

Definition at line 127 of file cInterval.h.

Referenced by step_play().

◆ set_auto_finish

void CInterval::set_auto_finish
inline

Changes the state of the 'auto_finish' flag.

If this is true, the interval may be arbitrarily finished when the system needs to reset due to some external event by calling CIntervalManager::interrupt(). If this is false (the default), the interval must always be explicitly finished or paused.

Definition at line 131 of file cInterval.h.

◆ set_auto_pause

void CInterval::set_auto_pause
inline

Changes the state of the 'auto_pause' flag.

If this is true, the interval may be arbitrarily interrupted when the system needs to reset due to some external event by calling CIntervalManager::interrupt(). If this is false (the default), the interval must always be explicitly finished or paused.

Definition at line 130 of file cInterval.h.

◆ set_done_event

void CInterval::set_done_event
inline

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.

Definition at line 128 of file cInterval.h.

◆ set_manager

void CInterval::set_manager
inline

Indicates the CIntervalManager object which will be responsible for playing this interval.

This defaults to the global CIntervalManager; you should need to change this only if you have special requirements for playing this interval.

Definition at line 132 of file cInterval.h.

◆ set_play_rate

void CInterval::set_play_rate

Changes the play rate of the interval.

If the interval is already started, this changes its speed on-the-fly. Note that since play_rate is a parameter to start() and loop(), the next call to start() or loop() will reset this parameter.

Definition at line 133 of file cInterval.h.

◆ set_t

void CInterval::set_t

Explicitly sets the time within the interval.

Normally, you would use start() .. finish() to let the time play normally, but this may be used to set the time to some particular value.

Definition at line 129 of file cInterval.h.

Referenced by resume().


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