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

AnimControl Class Reference

Controls the timing of a character animation. More...

#include <animControl.h>

Inheritance diagram for AnimControl:

ReferenceCount List of all members.

Public Member Functions

 AnimControl (PartBundle *part, AnimBundle *anim, int channel_index)
 ~AnimControl ()
void play (const CPT_Event &stop_event=NULL)
 Runs the entire animation from beginning to end and stops, throwing the stop event (if it is non-NULL).

void play (int from, int to, const CPT_Event &stop_event=NULL)
 Runs the animation from the frame "from" to and including the frame "to", at which point the animation is stopped and the indicated stop event is thrown (if it is non-NULL).

void loop (bool restart)
 Starts the entire animation looping.

void loop (bool restart, int from, int to)
 Loops the animation from the frame "from" to and including the frame "to", indefinitely.

void pingpong (bool restart, int from, int to)
 Loops the animation from the frame "from" to and including the frame "to", and then back in the opposite direction, indefinitely.

void stop ()
 Stops a currently playing or looping animation right where it is.

void pose (int frame)
 Sets the animation to the indicated frame and holds it there.

void add_event (int frame, const CPT_Event &event)
 Adds the indicated event to the list of events that will be called whenever the animation reaches the indicated frame number.

int remove_event (const string &event_name)
 Removes all events found that match the indicated event name, and returns the number of events removed.

void remove_all_events ()
 Removes all user-defined event messages.

void set_play_rate (double play_rate)
 Sets the speed of the animation, relative to its "normal" speed.

double get_play_rate () const
 Returns the current speed of the animation.

double get_frame_rate () const
 Returns the actual frame rate of the animation, based on the play_rate (see set_play_rate()) and the animation's base frame rate (see AnimBundle::get_base_frame_rate()).

int get_frame () const
 Returns the current frame number of the animation.

int get_num_frames () const
 Returns the number of frames of animation.

bool is_playing () const
 Returns true if the AnimControl is currently playing, false otherwise.

PartBundleget_part () const
 Returns the PartBundle bound in with this AnimControl.

AnimBundleget_anim () const
 Returns the AnimBundle bound in with this AnimControl.

void advance_time (double time)
 Tells the AnimControl what time it is.

bool channel_has_changed (AnimChannelBase *channel) const
 Returns true if the indicated channel value has changed since the last call to mark_channels().

void mark_channels ()
 Marks this point as the point of reference for the next call to channel_has_changed().

int get_channel_index () const
void output (ostream &out) const
int get_ref_count () const
 Returns the current reference count.

int ref () const
 Explicitly increments the reference count.

int unref () const
 Explicitly decrements the reference count.

void test_ref_count_integrity () const
 Does some easy checks to make sure that the reference count isn't completely bogus.


Static Public Member Functions

TypeHandle get_class_type ()
void init_type ()

Private Types

typedef pmultimap< int, ActionActions
enum  ActionType {
  AT_event, AT_stop, AT_jump, AT_forward,
  AT_backward
}

Private Member Functions

void set_frame (double frame)
 Sets the current frame number to the indicated frame, and performs any actions on that frame.

bool do_actions_forward (int from, int to)
 Calls each of the actions, in turn, on the timeline between the indicated "from" frame and the indicated "to" frame, inclusive.

bool do_actions_backward (int from, int to)
 Calls each of the actions, in turn, on the timeline between the indicated "from" frame and the indicated "to" frame, in reverse order.

void do_action (int frame, const Action &action, int &sequence_frame, const Action *&sequence_action)
 Performs a single action.

void do_sequence_action (int frame, const Action &action)
 Performs an action that was saved from do_action(), above.


Static Private Member Functions

void insert_event_action (Actions &actions, int frame, const CPT_Event &event)
 Inserts an "event" action at the indicated frame number.

void insert_stop_action (Actions &actions, int frame)
 Inserts a "stop" action at the indicated frame number.

void insert_jump_action (Actions &actions, int frame, int jump_to)
 Inserts a "jump" action at the indicated frame number.

void insert_forward_action (Actions &actions, int frame)
 Inserts a "forward" action at the indicated frame number.

void insert_backward_action (Actions &actions, int frame)
 Inserts a "backward" action at the indicated frame number.


Private Attributes

Actions _actions
Actions _user_actions
PointerTo< PartGroup_part
PointerTo< AnimBundle_anim
int _channel_index
double _play_rate
double _frame
double _as_of_time
bool _playing
int _marked_frame

Static Private Attributes

TypeHandle _type_handle

Friends

class AnimControl::Action
ostream & operator<< (ostream &, const AnimControl::Action &)

Detailed Description

Controls the timing of a character animation.

An AnimControl object is created for each character/bundle binding and manages the state of the animation: whether started, stopped, or looping, and the current frame number and play rate.

Definition at line 57 of file animControl.h.


Member Typedef Documentation

typedef pmultimap<int, Action> AnimControl::Actions [private]
 

Definition at line 125 of file animControl.h.


Member Enumeration Documentation

enum AnimControl::ActionType [private]
 

Enumeration values:
AT_event 
AT_stop 
AT_jump 
AT_forward 
AT_backward 

Definition at line 103 of file animControl.h.


Constructor & Destructor Documentation

AnimControl::AnimControl PartBundle part,
AnimBundle anim,
int  channel_index
 

Definition at line 42 of file animControl.cxx.

References _anim, _as_of_time, _channel_index, _frame, _marked_frame, _part, _play_rate, and _playing.

AnimControl::~AnimControl  ) 
 

Definition at line 67 of file animControl.cxx.

References get_num_frames(), get_play_rate(), nassertv, and play().


Member Function Documentation

void AnimControl::add_event int  frame,
const CPT_Event event
 

Adds the indicated event to the list of events that will be called whenever the animation reaches the indicated frame number.

Once added, the event will persist until it is removed via remove_event() or remove_all_events().

Definition at line 336 of file animControl.cxx.

void AnimControl::advance_time double  time  ) 
 

Tells the AnimControl what time it is.

This recomputes the frame number according to the amount of time elapsed since last time. Until this function is called, the frame number will not increment. The time passed to this function must be nondecreasing; it is an error to call it with a value less than a previously-passed value.

Definition at line 455 of file animControl.cxx.

References _marked_frame, and get_frame().

bool AnimControl::channel_has_changed AnimChannelBase channel  )  const
 

Returns true if the indicated channel value has changed since the last call to mark_channels().

Definition at line 520 of file animControl.cxx.

References AT_jump.

Referenced by MovingPartBase::write_with_value().

void AnimControl::do_action int  frame,
const Action action,
int &  sequence_frame,
const Action *&  sequence_action
[private]
 

Performs a single action.

If the action involves some resequencing behavior--stopping, or jumping around to a new frame or something--does nothing immediately, but instead sets sequence_frame and sequence_action to the current frame number and action, so they may be executed later (after all the other actions this frame have been executed).

Definition at line 827 of file animControl.cxx.

bool AnimControl::do_actions_backward int  from,
int  to
[private]
 

Calls each of the actions, in turn, on the timeline between the indicated "from" frame and the indicated "to" frame, in reverse order.

If any of the actions specifies to stop the animation, the animation is stopped, the current frame number is set to the point of stopping, no further actions are called, and false is returned. Otherwise, true is returned.

Definition at line 767 of file animControl.cxx.

References AT_backward, and AT_forward.

bool AnimControl::do_actions_forward int  from,
int  to
[private]
 

Calls each of the actions, in turn, on the timeline between the indicated "from" frame and the indicated "to" frame, inclusive.

If any of the actions specifies to stop the animation, the animation is stopped, the current frame number is set to the point of stopping, no further actions are called, and false is returned. Otherwise, true is returned.

Definition at line 712 of file animControl.cxx.

Referenced by output().

void AnimControl::do_sequence_action int  frame,
const Action action
[private]
 

Performs an action that was saved from do_action(), above.

This action presumably does some mucking around with the frame number or something, so we needed to do all the other actions associated with that frame first.

Definition at line 881 of file animControl.cxx.

Referenced by insert_forward_action().

AnimBundle * AnimControl::get_anim  )  const [inline]
 

Returns the AnimBundle bound in with this AnimControl.

Definition at line 159 of file animControl.I.

Referenced by set_play_rate().

int AnimControl::get_channel_index  )  const [inline]
 

Definition at line 171 of file animControl.I.

Referenced by MovingPartBase::write_with_value().

TypeHandle AnimControl::get_class_type void   )  [inline, static]
 

Reimplemented from ReferenceCount.

Definition at line 167 of file animControl.h.

int AnimControl::get_frame  )  const [inline]
 

Returns the current frame number of the animation.

Definition at line 105 of file animControl.I.

References _anim, and INLINE.

Referenced by advance_time(), AnimControlCollection::loop(), output(), and AnimControlCollection::stop().

double AnimControl::get_frame_rate  )  const [inline]
 

Returns the actual frame rate of the animation, based on the play_rate (see set_play_rate()) and the animation's base frame rate (see AnimBundle::get_base_frame_rate()).

This is in frames per second.

Definition at line 92 of file animControl.I.

int AnimControl::get_num_frames  )  const [inline]
 

Returns the number of frames of animation.

This is actually just extracted directly from the AnimBundle; the function is duplicated here for convenience. The frame number will never be outside the range 0 <= frame < get_num_frames().

Definition at line 129 of file animControl.I.

Referenced by AnimControlCollection::get_frame(), loop(), pingpong(), play(), and ~AnimControl().

PartBundle * AnimControl::get_part  )  const
 

Returns the PartBundle bound in with this AnimControl.

Definition at line 429 of file animControl.cxx.

Referenced by pingpong(), and play().

double AnimControl::get_play_rate  )  const [inline]
 

Returns the current speed of the animation.

See set_play_rate().

Definition at line 71 of file animControl.I.

References _frame, cfloor(), and INLINE.

Referenced by loop(), play(), set_play_rate(), and ~AnimControl().

int ReferenceCount::get_ref_count  )  const [inline, inherited]
 

Returns the current reference count.

Definition at line 183 of file referenceCount.I.

Referenced by RenderState::determine_bin_index(), RenderEffects::determine_show_bounds(), FontPool::ns_garbage_collect(), TexturePool::ns_garbage_collect(), MaterialPool::ns_get_material(), and TexturePool::ns_release_texture().

void AnimControl::init_type void   )  [inline, static]
 

Reimplemented from ReferenceCount.

Definition at line 170 of file animControl.h.

void AnimControl::insert_backward_action Actions actions,
int  frame
[static, private]
 

Inserts a "backward" action at the indicated frame number.

When the animation hits this action while playing in a forward direction, it will stop and play in a backward direction instead.

Definition at line 667 of file animControl.cxx.

References AnimControl::Action::_type, AT_jump, and AT_stop.

void AnimControl::insert_event_action Actions actions,
int  frame,
const CPT_Event event
[static, private]
 

Inserts an "event" action at the indicated frame number.

The event will be thrown as the animation reaches the indicated frame number.

Definition at line 578 of file animControl.cxx.

References _actions.

Referenced by play().

void AnimControl::insert_forward_action Actions actions,
int  frame
[static, private]
 

Inserts a "forward" action at the indicated frame number.

When the animation hits this action while playing in a backward direction, it will stop and play in a forward direction instead.

Definition at line 646 of file animControl.cxx.

References do_sequence_action().

void AnimControl::insert_jump_action Actions actions,
int  frame,
int  jump_to
[static, private]
 

Inserts a "jump" action at the indicated frame number.

When the animation reaches the indicated frame number, it will jump to the indicated jump_to frame. It will not seem to spend any time at the reached frame number.

Definition at line 624 of file animControl.cxx.

References _actions.

Referenced by loop().

void AnimControl::insert_stop_action Actions actions,
int  frame
[static, private]
 

Inserts a "stop" action at the indicated frame number.

The animation will stop as soon as it reaches the indicated frame number, traveling from either direction.

Definition at line 600 of file animControl.cxx.

Referenced by play().

bool AnimControl::is_playing  )  const [inline]
 

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

Definition at line 144 of file animControl.I.

void AnimControl::loop bool  restart,
int  from,
int  to
 

Loops the animation from the frame "from" to and including the frame "to", indefinitely.

If restart is true, the animation is restarted from the beginning; otherwise, it continues from the current frame.

Definition at line 180 of file animControl.cxx.

void AnimControl::loop bool  restart  ) 
 

Starts the entire animation looping.

If restart is true, the animation is restarted from the beginning; otherwise, it continues from the current frame.

Definition at line 145 of file animControl.cxx.

References _actions, _as_of_time, _playing, _user_actions, ClockObject::get_frame_time(), ClockObject::get_global_clock(), get_num_frames(), get_play_rate(), insert_jump_action(), and nassertv.

Referenced by AnimControlCollection::play().

void AnimControl::mark_channels  ) 
 

Marks this point as the point of reference for the next call to channel_has_changed().

Definition at line 546 of file animControl.cxx.

References AnimControl::Action::_type, and AT_backward.

Referenced by PartBundle::bind_anim().

void AnimControl::output ostream &  out  )  const
 

Definition at line 558 of file animControl.cxx.

References _frame, do_actions_forward(), and get_frame().

void AnimControl::pingpong bool  restart,
int  from,
int  to
 

Loops the animation from the frame "from" to and including the frame "to", and then back in the opposite direction, indefinitely.

Definition at line 250 of file animControl.cxx.

References _actions, _as_of_time, _playing, cfloor(), PartBundle::control_activated(), ClockObject::get_frame_time(), ClockObject::get_global_clock(), get_num_frames(), get_part(), nassertv, num_frames, and set_frame().

void AnimControl::play int  from,
int  to,
const CPT_Event stop_event = NULL
 

Runs the animation from the frame "from" to and including the frame "to", at which point the animation is stopped and the indicated stop event is thrown (if it is non-NULL).

If the to frame is less than the from frame (unless play_rate is negative), the animation will wrap around the end and begins again at the beginning before the animation stops.

Definition at line 114 of file animControl.cxx.

References _actions, _as_of_time, _playing, _user_actions, PartBundle::control_activated(), ClockObject::get_frame_time(), ClockObject::get_global_clock(), get_num_frames(), get_part(), get_play_rate(), nassertv, and set_frame().

void AnimControl::play const CPT_Event stop_event = NULL  ) 
 

Runs the entire animation from beginning to end and stops, throwing the stop event (if it is non-NULL).

Definition at line 83 of file animControl.cxx.

References _actions, _as_of_time, _playing, _user_actions, PartBundle::control_activated(), ClockObject::get_frame_time(), ClockObject::get_global_clock(), get_num_frames(), get_part(), insert_event_action(), insert_stop_action(), nassertv, and set_frame().

Referenced by AnimControlCollection::has_stop_event(), and ~AnimControl().

void AnimControl::pose int  frame  ) 
 

Sets the animation to the indicated frame and holds it there.

Definition at line 302 of file animControl.cxx.

References AT_event.

int ReferenceCount::ref  )  const [inline, inherited]
 

Explicitly increments the reference count.

User code should avoid using ref() and unref() directly, which can result in missed reference counts. Instead, let a PointerTo object manage the reference counting automatically.

This function is const, even though it changes the object, because generally fiddling with an object's reference count isn't considered part of fiddling with the object. An object might be const in other ways, but we still need to accurately count the number of references to it.

The return value is the new reference count.

Definition at line 225 of file referenceCount.I.

Referenced by ClientDevice::ClientDevice(), EggGroupNode::find_textures(), EggGroupNode::r_apply_texmats(), EggGroupNode::r_flatten_transforms(), and EggGroupNode::reverse_vertex_ordering().

void AnimControl::remove_all_events  ) 
 

Removes all user-defined event messages.

However, if called while an animation is running, this will not take effect until the animation is stopped and restarted.

Definition at line 414 of file animControl.cxx.

int AnimControl::remove_event const string &  event_name  ) 
 

Removes all events found that match the indicated event name, and returns the number of events removed.

Definition at line 356 of file animControl.cxx.

References _part, and DCAST.

void AnimControl::set_frame double  frame  )  [private]
 

Sets the current frame number to the indicated frame, and performs any actions on that frame.

Definition at line 685 of file animControl.cxx.

References _play_rate, and AT_forward.

Referenced by pingpong(), and play().

void AnimControl::set_play_rate double  play_rate  )  [inline]
 

Sets the speed of the animation, relative to its "normal" speed.

Setting this number to 2.0 plays it twice as fast, 0.5 half as fast. -1.0 plays it backwards, and 0.0 stops it. The change is actually retroactive to the last frame.

If you are going to change the play_rate from a positive number to a negative number, or vice-versa, you should do this before starting the animation. The various flavors of play() and loop() do slightly different behavior based on whether play_rate is positive or negative.

Definition at line 56 of file animControl.I.

References get_anim(), AnimBundle::get_base_frame_rate(), get_play_rate(), and INLINE.

void AnimControl::stop  ) 
 

Stops a currently playing or looping animation right where it is.

The animation remains posed at the current frame, and no event is thrown.

Definition at line 287 of file animControl.cxx.

void ReferenceCount::test_ref_count_integrity  )  const [inline, inherited]
 

Does some easy checks to make sure that the reference count isn't completely bogus.

Definition at line 328 of file referenceCount.I.

References INLINE.

Referenced by EggNode::determine_bin(), and ReferenceCount::~ReferenceCount().

int ReferenceCount::unref  )  const [inline, inherited]
 

Explicitly decrements the reference count.

Note that the object will not be implicitly deleted by unref() simply because the reference count drops to zero. (Having a member function delete itself is problematic; plus, we don't have a virtual destructor anyway.) However, see the helper function unref_delete().

User code should avoid using ref() and unref() directly, which can result in missed reference counts. Instead, let a PointerTo object manage the reference counting automatically.

This function is const, even though it changes the object, because generally fiddling with an object's reference count isn't considered part of fiddling with the object. An object might be const in other ways, but we still need to accurately count the number of references to it.

The return value is the new reference count.

Definition at line 293 of file referenceCount.I.

References INLINE.

Referenced by RenderState::determine_bin_index(), and RenderEffects::determine_show_bounds().


Friends And Related Function Documentation

friend class AnimControl::Action [friend]
 

Definition at line 180 of file animControl.h.

ostream& operator<< ostream &  out,
const AnimControl::Action action
[friend]
 

Definition at line 188 of file animControl.h.


Member Data Documentation

Actions AnimControl::_actions [private]
 

Definition at line 142 of file animControl.h.

Referenced by insert_event_action(), insert_jump_action(), loop(), pingpong(), and play().

PointerTo< AnimBundle > AnimControl::_anim [private]
 

Definition at line 149 of file animControl.h.

Referenced by AnimControl(), and get_frame().

double AnimControl::_as_of_time [private]
 

Definition at line 159 of file animControl.h.

Referenced by AnimControl(), loop(), pingpong(), and play().

int AnimControl::_channel_index [private]
 

Definition at line 150 of file animControl.h.

Referenced by AnimControl().

double AnimControl::_frame [private]
 

Definition at line 158 of file animControl.h.

Referenced by AnimControl(), get_play_rate(), and output().

int AnimControl::_marked_frame [private]
 

Definition at line 164 of file animControl.h.

Referenced by advance_time(), and AnimControl().

PointerTo< PartGroup > AnimControl::_part [private]
 

Definition at line 148 of file animControl.h.

Referenced by AnimControl(), and remove_event().

double AnimControl::_play_rate [private]
 

Definition at line 152 of file animControl.h.

Referenced by AnimControl(), and set_frame().

bool AnimControl::_playing [private]
 

Definition at line 161 of file animControl.h.

Referenced by AnimControl(), loop(), pingpong(), and play().

TypeHandle AnimControl::_type_handle [static, private]
 

Reimplemented from ReferenceCount.

Definition at line 32 of file animControl.cxx.

Actions AnimControl::_user_actions [private]
 

Definition at line 143 of file animControl.h.

Referenced by loop(), and play().


The documentation for this class was generated from the following files:
Generated on Fri May 2 00:47:26 2003 for Panda by doxygen1.3