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