Panda3D

animControl.h

00001 // Filename: animControl.h
00002 // Created by:  drose (19Feb99)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef ANIMCONTROL_H
00016 #define ANIMCONTROL_H
00017 
00018 #include "pandabase.h"
00019 
00020 #include "animInterface.h"
00021 #include "animBundle.h"
00022 #include "partGroup.h"
00023 #include "bitArray.h"
00024 #include "pandaNode.h"
00025 #include "typedReferenceCount.h"
00026 #include "namable.h"
00027 #include "pmutex.h"
00028 #include "conditionVarFull.h"
00029 
00030 class PartBundle;
00031 class AnimChannelBase;
00032 
00033 ////////////////////////////////////////////////////////////////////
00034 //       Class : AnimControl
00035 // Description : Controls the timing of a character animation.  An
00036 //               AnimControl object is created for each
00037 //               character/bundle binding and manages the state of the
00038 //               animation: whether started, stopped, or looping, and
00039 //               the current frame number and play rate.
00040 ////////////////////////////////////////////////////////////////////
00041 class EXPCL_PANDA_CHAN AnimControl : public TypedReferenceCount, public AnimInterface, public Namable {
00042 public:
00043   AnimControl(const string &name, PartBundle *part, 
00044               double frame_rate, int num_frames);
00045   void setup_anim(PartBundle *part, AnimBundle *anim, int channel_index,
00046                   const BitArray &bound_joints);
00047   void set_bound_joints(const BitArray &bound_joints);
00048   void fail_anim(PartBundle *part);
00049 
00050 PUBLISHED:
00051   virtual ~AnimControl();
00052 
00053   INLINE bool is_pending() const;
00054   void wait_pending();
00055   INLINE bool has_anim() const;
00056   void set_pending_done_event(const string &done_event);
00057   string get_pending_done_event() const;
00058 
00059   PartBundle *get_part() const;
00060   INLINE AnimBundle *get_anim() const;
00061   INLINE int get_channel_index() const;
00062   INLINE const BitArray &get_bound_joints() const;
00063 
00064   INLINE void set_anim_model(PandaNode *model);
00065   INLINE PandaNode *get_anim_model() const;
00066 
00067   virtual void output(ostream &out) const;
00068 
00069 public:
00070   // The following functions aren't really part of the public
00071   // interface; they're just public so we don't have to declare a
00072   // bunch of friends.
00073 
00074   bool channel_has_changed(AnimChannelBase *channel, bool frame_blend_flag) const;
00075   void mark_channels(bool frame_blend_flag);
00076 
00077 protected:
00078   virtual void animation_activated();
00079 
00080 private:
00081   bool _pending;
00082   string _pending_done_event;
00083   Mutex _pending_lock;  // protects the above two.
00084   ConditionVarFull _pending_cvar; // signals when _pending goes true.
00085 
00086   // This is a PT(PartGroup) instead of a PT(PartBundle), just because
00087   // we can't include partBundle.h for circular reasons.  But it
00088   // actually keeps a pointer to a PartBundle.
00089   PT(PartGroup) _part;
00090   PT(AnimBundle) _anim;
00091   int _channel_index;
00092 
00093   // This is the frame number as of the last call to mark_channels().
00094   // In frame_blend mode, we also record the fractional part of the
00095   // frame number.
00096   int _marked_frame;
00097   double _marked_frac;
00098 
00099   // This is the bitmask of joints and/or sliders from the animation
00100   // that we have actually bound into this AnimControl.  See
00101   // get_bound_joints().
00102   BitArray _bound_joints;
00103 
00104   PT(PandaNode) _anim_model;
00105 
00106 public:
00107   virtual TypeHandle get_type() const {
00108     return get_class_type();
00109   }
00110   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00111 
00112   static TypeHandle get_class_type() {
00113     return _type_handle;
00114   }
00115   static void init_type() {
00116     TypedReferenceCount::init_type();
00117     AnimInterface::init_type();
00118     register_type(_type_handle, "AnimControl",
00119                   TypedReferenceCount::get_class_type(),
00120                   AnimInterface::get_class_type());
00121   }
00122 
00123 private:
00124   static TypeHandle _type_handle;
00125 };
00126 
00127 INLINE ostream &operator << (ostream &out, const AnimControl &control);
00128 
00129 #include "animControl.I"
00130 
00131 #endif
 All Classes Functions Variables Enumerations