Panda3D
animControl.h
1 // Filename: animControl.h
2 // Created by: drose (19Feb99)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef ANIMCONTROL_H
16 #define ANIMCONTROL_H
17 
18 #include "pandabase.h"
19 
20 #include "animInterface.h"
21 #include "animBundle.h"
22 #include "partGroup.h"
23 #include "bitArray.h"
24 #include "pandaNode.h"
25 #include "typedReferenceCount.h"
26 #include "namable.h"
27 #include "pmutex.h"
28 #include "conditionVarFull.h"
29 
30 class PartBundle;
31 class AnimChannelBase;
32 
33 ////////////////////////////////////////////////////////////////////
34 // Class : AnimControl
35 // Description : Controls the timing of a character animation. An
36 // AnimControl object is created for each
37 // character/bundle binding and manages the state of the
38 // animation: whether started, stopped, or looping, and
39 // the current frame number and play rate.
40 ////////////////////////////////////////////////////////////////////
41 class EXPCL_PANDA_CHAN AnimControl : public TypedReferenceCount, public AnimInterface, public Namable {
42 public:
43  AnimControl(const string &name, PartBundle *part,
44  double frame_rate, int num_frames);
45  void setup_anim(PartBundle *part, AnimBundle *anim, int channel_index,
46  const BitArray &bound_joints);
47  void set_bound_joints(const BitArray &bound_joints);
48  void fail_anim(PartBundle *part);
49 
50 PUBLISHED:
51  virtual ~AnimControl();
52 
53  INLINE bool is_pending() const;
54  void wait_pending();
55  INLINE bool has_anim() const;
56  void set_pending_done_event(const string &done_event);
57  string get_pending_done_event() const;
58 
59  PartBundle *get_part() const;
60  INLINE AnimBundle *get_anim() const;
61  INLINE int get_channel_index() const;
62  INLINE const BitArray &get_bound_joints() const;
63 
64  INLINE void set_anim_model(PandaNode *model);
65  INLINE PandaNode *get_anim_model() const;
66 
67  virtual void output(ostream &out) const;
68 
69 public:
70  // The following functions aren't really part of the public
71  // interface; they're just public so we don't have to declare a
72  // bunch of friends.
73 
74  bool channel_has_changed(AnimChannelBase *channel, bool frame_blend_flag) const;
75  void mark_channels(bool frame_blend_flag);
76 
77 protected:
78  virtual void animation_activated();
79 
80 private:
81  bool _pending;
82  string _pending_done_event;
83  Mutex _pending_lock; // protects the above two.
84  ConditionVarFull _pending_cvar; // signals when _pending goes true.
85 
86  // This is a PT(PartGroup) instead of a PT(PartBundle), just because
87  // we can't include partBundle.h for circular reasons. But it
88  // actually keeps a pointer to a PartBundle.
89  PT(PartGroup) _part;
90  PT(AnimBundle) _anim;
91  int _channel_index;
92 
93  // This is the frame number as of the last call to mark_channels().
94  // In frame_blend mode, we also record the fractional part of the
95  // frame number.
96  int _marked_frame;
97  double _marked_frac;
98 
99  // This is the bitmask of joints and/or sliders from the animation
100  // that we have actually bound into this AnimControl. See
101  // get_bound_joints().
102  BitArray _bound_joints;
103 
104  PT(PandaNode) _anim_model;
105 
106 public:
107  virtual TypeHandle get_type() const {
108  return get_class_type();
109  }
110  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
111 
112  static TypeHandle get_class_type() {
113  return _type_handle;
114  }
115  static void init_type() {
116  TypedReferenceCount::init_type();
117  AnimInterface::init_type();
118  register_type(_type_handle, "AnimControl",
119  TypedReferenceCount::get_class_type(),
120  AnimInterface::get_class_type());
121  }
122 
123 private:
124  static TypeHandle _type_handle;
125 };
126 
127 INLINE ostream &operator << (ostream &out, const AnimControl &control);
128 
129 #include "animControl.I"
130 
131 #endif
A basic node of the scene graph or data graph.
Definition: pandaNode.h:72
void output(ostream &out) const
Outputs the Namable.
Definition: namable.I:97
This is the root of an AnimChannel hierarchy.
Definition: animBundle.h:31
A base class for things which need to inherit from both TypedObject and from ReferenceCount.
A standard mutex, or mutual exclusion lock.
Definition: pmutex.h:44
This is the fundamental interface for things that have a play/loop/stop type interface for frame-base...
Definition: animInterface.h:39
A dynamic array with an unlimited number of bits.
Definition: bitArray.h:42
Parent class for all animation channels.
A base class for all things which can have a name.
Definition: namable.h:29
This class implements a condition variable; see ConditionVar for a brief introduction to this class...
This is the root of a MovingPart hierarchy.
Definition: partBundle.h:49
Controls the timing of a character animation.
Definition: animControl.h:41
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
This is the base class for PartRoot and MovingPart.
Definition: partGroup.h:45