Panda3D
animControlCollection.h
1 // Filename: animControlCollection.h
2 // Created by: drose (22Feb00)
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 ANIMCONTROLCOLLECTION_H
16 #define ANIMCONTROLCOLLECTION_H
17 
18 #include "pandabase.h"
19 
20 #include "animControl.h"
21 
22 #include "event.h"
23 #include "pt_Event.h"
24 
25 #include "pmap.h"
26 
27 ////////////////////////////////////////////////////////////////////
28 // Class : AnimControlCollection
29 // Description : This is a named collection of AnimControl pointers.
30 // An AnimControl may be added to the collection by
31 // name. While an AnimControl is associated, its
32 // reference count is maintained; associating a new
33 // AnimControl with the same name will decrement the
34 // previous control's reference count (and possibly
35 // delete it, unbinding its animation).
36 ////////////////////////////////////////////////////////////////////
37 class EXPCL_PANDA_CHAN AnimControlCollection {
38 PUBLISHED:
41 
42  void store_anim(AnimControl *control, const string &name);
43  AnimControl *find_anim(const string &name) const;
44  bool unbind_anim(const string &name);
45 
46  int get_num_anims() const;
47  AnimControl *get_anim(int n) const;
48  string get_anim_name(int n) const;
49  MAKE_SEQ(get_anims, get_num_anims, get_anim);
50  MAKE_SEQ(get_anim_names, get_num_anims, get_anim_name);
51 
52  void clear_anims();
53 
54  // The following functions are convenience functions that vector
55  // directly into the AnimControl's functionality by anim name.
56 
57  INLINE bool play(const string &anim_name);
58  INLINE bool play(const string &anim_name, int from, int to);
59  INLINE bool loop(const string &anim_name, bool restart);
60  INLINE bool loop(const string &anim_name, bool restart, int from, int to);
61  INLINE bool stop(const string &anim_name);
62  INLINE bool pose(const string &anim_name, int frame);
63 
64  // These functions operate on all anims at once.
65  void play_all();
66  void play_all(int from, int to);
67  void loop_all(bool restart);
68  void loop_all(bool restart, int from, int to);
69  bool stop_all();
70  void pose_all(int frame);
71 
72  INLINE int get_frame(const string &anim_name) const;
73  INLINE int get_frame() const;
74 
75  INLINE int get_num_frames(const string &anim_name) const;
76  INLINE int get_num_frames() const;
77 
78  INLINE bool is_playing(const string &anim_name) const;
79  INLINE bool is_playing() const;
80 
81  string which_anim_playing() const;
82 
83  void output(ostream &out) const;
84  void write(ostream &out) const;
85 
86 private:
87  class ControlDef {
88  public:
89  string _name;
90  PT(AnimControl) _control;
91  };
93  Controls _controls;
94 
96  ControlsByName _controls_by_name;
97 
98  AnimControl *_last_started_control;
99 };
100 
101 INLINE ostream &operator << (ostream &out, const AnimControlCollection &collection);
102 
103 #include "animControlCollection.I"
104 
105 #endif
This is a named collection of AnimControl pointers.
Controls the timing of a character animation.
Definition: animControl.h:41