Panda3D
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Friends

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

List of all members.

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 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.
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.
void finish ()
 Stops the interval from playing and sets it to its final state.
virtual TypeHandle force_init_type ()
bool get_auto_finish () const
 Returns the state of the 'auto_finish' flag.
bool get_auto_pause () const
 Returns the state of the 'auto_pause' flag.
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.
double get_duration () const
 Returns the duration of the interval in seconds.
CIntervalManagerget_manager () const
 Returns the CIntervalManager object which will be responsible for playing this interval.
const string & get_name () const
 Returns the interval's name.
bool get_open_ended () const
 Returns the state of the "open_ended" flag.
double get_play_rate () const
 Returns the play rate as set by the last call to start(), loop(), or set_play_rate().
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.
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().
virtual TypeHandle get_type () const
bool get_wants_t_callback () const
 Returns the state of the 'wants_t_callback' flag.
bool is_playing () const
 Returns true if the interval is currently playing, false otherwise.
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).
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.
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.
virtual void output (ostream &out) const
double pause ()
 Stops the interval from playing but leaves it in its current state.
void priv_do_event (double t, EventType event)
 Calls the appropriate event function indicated by the EventType.
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.
virtual void priv_initialize (double t)
 This replaces the first call to priv_step(), and indicates that the interval has just begun.
virtual void priv_instant ()
 This is called in lieu of priv_initialize() .
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.
virtual void priv_reverse_finalize ()
 Called generally following a priv_reverse_initialize(), this indicates the interval should set itself to the initial state.
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.
virtual void priv_reverse_instant ()
 This is called in lieu of priv_reverse_initialize()
virtual void priv_step (double t)
 Advances the time on the interval.
void resume (double start_t)
 Restarts the interval from the indicated point after a previous call to pause().
void resume ()
 Restarts the interval from its current point after a previous call to pause().
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.
void set_auto_finish (bool auto_finish)
 Changes the state of the 'auto_finish' flag.
void set_auto_pause (bool auto_pause)
 Changes the state of the 'auto_pause' flag.
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.
void set_manager (CIntervalManager *manager)
 Indicates the CIntervalManager object which will be responsible for playing this interval.
void set_play_rate (double play_rate)
 Changes the play rate of the interval.
void set_t (double t)
 Explicitly sets the time within the interval.
void set_wants_t_callback (bool wants_t_callback)
 Changes the state of the 'wants_t_callback' flag.
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.
void setup_resume ()
 Called to prepare the interval for restarting at the current point within the interval after an interruption.
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.
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.
bool step_play ()
 Should be called once per frame to execute the automatic timed playback begun with setup_play().
virtual void write (ostream &out, int indent_level) const

Static Public Member Functions

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.

Protected Member Functions

void check_started (TypeHandle type, const char *method_name) const
 Issues a warning if our internal state is not in one of the started states.
void check_stopped (TypeHandle type, const char *method_name) const
 Issues a warning if our internal state is not in one of the stopped states.
virtual void do_recompute ()
 Does whatever processing is necessary to recompute the interval after a call to mark_dirty() has indicated a recomputation is necessary.
void interval_done ()
 Called internally whenever the interval reaches its final state.
void recompute () const
 Calls do_recompute() if the dirty flag has been set.

Protected Attributes

bool _auto_finish
bool _auto_pause
double _clock_start
double _curr_t
bool _do_loop
string _done_event
double _duration
double _end_t
bool _end_t_at_end
double _last_t_callback
int _loop_count
CIntervalManager_manager
string _name
double _play_rate
string _pname
double _start_t
bool _start_t_at_start
State _state
bool _wants_t_callback

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 39 of file cInterval.h.


Member Function Documentation

void CInterval::check_started ( TypeHandle  type,
const char *  method_name 
) const [inline, protected]
void CInterval::check_stopped ( TypeHandle  type,
const char *  method_name 
) const [inline, protected]
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 232 of file cInterval.I.

References get_t(), and get_wants_t_callback().

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 268 of file cInterval.cxx.

References pause().

void CInterval::do_recompute ( ) [protected, virtual]

Does whatever processing is necessary to recompute the interval after a call to mark_dirty() has indicated a recomputation is necessary.

Reimplemented in CMetaInterval.

Definition at line 777 of file cInterval.cxx.

void CInterval::finish ( )

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

Definition at line 239 of file cInterval.cxx.

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

bool CInterval::get_auto_finish ( ) const [inline]

Returns the state of the 'auto_finish' flag.

See set_auto_finish().

Definition at line 165 of file cInterval.I.

bool CInterval::get_auto_pause ( ) const [inline]

Returns the state of the 'auto_pause' flag.

See set_auto_pause().

Definition at line 138 of file cInterval.I.

const string & CInterval::get_done_event ( ) const [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 99 of file cInterval.I.

double CInterval::get_duration ( ) const [inline]
CIntervalManager * CInterval::get_manager ( ) const [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 220 of file cInterval.I.

const string & CInterval::get_name ( ) const [inline]

Returns the interval's name.

Definition at line 22 of file cInterval.I.

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

bool CInterval::get_open_ended ( ) const [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 49 of file cInterval.I.

Referenced by step_play().

double CInterval::get_play_rate ( ) const

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

Definition at line 294 of file cInterval.cxx.

CInterval::State CInterval::get_state ( ) const [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 61 of file cInterval.I.

Referenced by finish(), pause(), and set_t().

double CInterval::get_t ( ) const [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 111 of file cInterval.I.

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

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 191 of file cInterval.I.

Referenced by check_t_callback().

static void CInterval::init_type ( ) [inline, static]
void CInterval::interval_done ( ) [protected]

Called internally whenever the interval reaches its final state.

Definition at line 763 of file cInterval.cxx.

References CIntervalManager::get_event_queue().

Referenced by priv_finalize(), CMetaInterval::priv_finalize(), priv_instant(), and CMetaInterval::priv_instant().

bool CInterval::is_playing ( ) const

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

Definition at line 282 of file cInterval.cxx.

References CIntervalManager::find_c_interval(), and get_name().

Referenced by set_play_rate(), and set_t().

bool CInterval::is_stopped ( ) const [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 73 of file cInterval.I.

Referenced by step_play().

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 169 of file cInterval.cxx.

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

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 746 of file cInterval.cxx.

Referenced by CMetaInterval::add_c_interval(), CMetaInterval::add_ext_index(), CMetaInterval::pop_level(), CMetaInterval::push_level(), CMetaInterval::set_interval_start_time(), and CMetaInterval::set_precision().

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 182 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(), and set_play_rate().

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

Calls the appropriate event function indicated by the EventType.

Definition at line 325 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().

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 422 of file cInterval.cxx.

References check_started(), get_duration(), interval_done(), and priv_step().

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

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 CLerpNodePathInterval, and CMetaInterval.

Definition at line 374 of file cInterval.cxx.

References check_stopped(), priv_step(), and recompute().

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

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 CLerpNodePathInterval, CMetaInterval, HideInterval, and ShowInterval.

Definition at line 390 of file cInterval.cxx.

References check_stopped(), get_duration(), interval_done(), priv_step(), and recompute().

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

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 493 of file cInterval.cxx.

References check_started().

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

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 472 of file cInterval.cxx.

References check_started(), and priv_step().

Referenced by priv_do_event(), and step_play().

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 CLerpNodePathInterval, and CMetaInterval.

Definition at line 439 of file cInterval.cxx.

References check_stopped(), priv_step(), and recompute().

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

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 CLerpNodePathInterval, CMetaInterval, HideInterval, and ShowInterval.

Definition at line 456 of file cInterval.cxx.

References check_stopped(), priv_step(), and recompute().

Referenced by priv_do_event(), and step_play().

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

Definition at line 407 of file cInterval.cxx.

References check_started().

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

void CInterval::recompute ( ) const [inline, protected]
void CInterval::resume ( double  start_t)

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

Definition at line 212 of file cInterval.cxx.

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

void CInterval::resume ( )

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

Definition at line 200 of file cInterval.cxx.

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

Referenced by set_play_rate().

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 227 of file cInterval.cxx.

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

void CInterval::set_auto_finish ( bool  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 154 of file cInterval.I.

void CInterval::set_auto_pause ( bool  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 127 of file cInterval.I.

void CInterval::set_done_event ( const string &  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 86 of file cInterval.I.

void CInterval::set_manager ( CIntervalManager 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 205 of file cInterval.I.

void CInterval::set_play_rate ( double  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 308 of file cInterval.cxx.

References is_playing(), pause(), and resume().

void CInterval::set_t ( double  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 95 of file cInterval.cxx.

References get_state(), is_playing(), priv_initialize(), priv_interrupt(), priv_reverse_initialize(), priv_step(), and setup_resume().

Referenced by resume().

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 179 of file cInterval.I.

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 538 of file cInterval.cxx.

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

Referenced by loop(), and start().

void CInterval::setup_resume ( )

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

Definition at line 577 of file cInterval.cxx.

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

Referenced by resume(), set_t(), and 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 597 of file cInterval.cxx.

References get_duration(), and setup_resume().

Referenced by resume_until().

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 151 of file cInterval.cxx.

References CIntervalManager::add_c_interval(), and setup_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 621 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().


The documentation for this class was generated from the following files:
 All Classes Functions Variables Enumerations