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