Panda3D
|
00001 // Filename: animControlCollection.h 00002 // Created by: drose (22Feb00) 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 ANIMCONTROLCOLLECTION_H 00016 #define ANIMCONTROLCOLLECTION_H 00017 00018 #include "pandabase.h" 00019 00020 #include "animControl.h" 00021 00022 #include "event.h" 00023 #include "pt_Event.h" 00024 00025 #include "pmap.h" 00026 00027 //////////////////////////////////////////////////////////////////// 00028 // Class : AnimControlCollection 00029 // Description : This is a named collection of AnimControl pointers. 00030 // An AnimControl may be added to the collection by 00031 // name. While an AnimControl is associated, its 00032 // reference count is maintained; associating a new 00033 // AnimControl with the same name will decrement the 00034 // previous control's reference count (and possibly 00035 // delete it, unbinding its animation). 00036 //////////////////////////////////////////////////////////////////// 00037 class EXPCL_PANDA_CHAN AnimControlCollection { 00038 PUBLISHED: 00039 AnimControlCollection(); 00040 ~AnimControlCollection(); 00041 00042 void store_anim(AnimControl *control, const string &name); 00043 AnimControl *find_anim(const string &name) const; 00044 bool unbind_anim(const string &name); 00045 00046 int get_num_anims() const; 00047 AnimControl *get_anim(int n) const; 00048 string get_anim_name(int n) const; 00049 MAKE_SEQ(get_anims, get_num_anims, get_anim); 00050 MAKE_SEQ(get_anim_names, get_num_anims, get_anim_name); 00051 00052 void clear_anims(); 00053 00054 // The following functions are convenience functions that vector 00055 // directly into the AnimControl's functionality by anim name. 00056 00057 INLINE bool play(const string &anim_name); 00058 INLINE bool play(const string &anim_name, int from, int to); 00059 INLINE bool loop(const string &anim_name, bool restart); 00060 INLINE bool loop(const string &anim_name, bool restart, int from, int to); 00061 INLINE bool stop(const string &anim_name); 00062 INLINE bool pose(const string &anim_name, int frame); 00063 00064 // These functions operate on all anims at once. 00065 void play_all(); 00066 void play_all(int from, int to); 00067 void loop_all(bool restart); 00068 void loop_all(bool restart, int from, int to); 00069 bool stop_all(); 00070 void pose_all(int frame); 00071 00072 INLINE int get_frame(const string &anim_name) const; 00073 INLINE int get_frame() const; 00074 00075 INLINE int get_num_frames(const string &anim_name) const; 00076 INLINE int get_num_frames() const; 00077 00078 INLINE bool is_playing(const string &anim_name) const; 00079 INLINE bool is_playing() const; 00080 00081 string which_anim_playing() const; 00082 00083 void output(ostream &out) const; 00084 void write(ostream &out) const; 00085 00086 private: 00087 class ControlDef { 00088 public: 00089 string _name; 00090 PT(AnimControl) _control; 00091 }; 00092 typedef pvector<ControlDef> Controls; 00093 Controls _controls; 00094 00095 typedef pmap<string, size_t> ControlsByName; 00096 ControlsByName _controls_by_name; 00097 00098 AnimControl *_last_started_control; 00099 }; 00100 00101 INLINE ostream &operator << (ostream &out, const AnimControlCollection &collection); 00102 00103 #include "animControlCollection.I" 00104 00105 #endif