00001 // Filename: animControlCollection.I 00002 // Created by: drose (22Feb00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 00020 //////////////////////////////////////////////////////////////////// 00021 // Function: AnimControlCollection::set_stop_event 00022 // Access: Public 00023 // Description: Sets the event that will be thrown when the next 00024 // animation that is played eventually comes to a stop. 00025 // Setting this does not affect any stop event that is 00026 // pending from a previously-started animation. 00027 //////////////////////////////////////////////////////////////////// 00028 INLINE void AnimControlCollection:: 00029 set_stop_event(const CPT_Event &stop_event) { 00030 _stop_event = stop_event; 00031 } 00032 00033 //////////////////////////////////////////////////////////////////// 00034 // Function: AnimControlCollection::clear_stop_event 00035 // Access: Public 00036 // Description: Indicates that the next-started animation will not 00037 // throw a stop event when it comes to a stop. This 00038 // does not affect any already-started animations. 00039 //////////////////////////////////////////////////////////////////// 00040 INLINE void AnimControlCollection:: 00041 clear_stop_event() { 00042 _stop_event = (const Event *)NULL; 00043 } 00044 00045 //////////////////////////////////////////////////////////////////// 00046 // Function: AnimControlCollection::has_stop_event 00047 // Access: Public 00048 // Description: Returns true if a stop event has been established via 00049 // set_stop_event(). If true, this means that 00050 // animations that are to be started in the future will 00051 // throw this event when they stop. However, it does 00052 // not necessarily mean that the currently-playing 00053 // animation will throw this event. 00054 //////////////////////////////////////////////////////////////////// 00055 INLINE bool AnimControlCollection:: 00056 has_stop_event() const { 00057 return (_stop_event != (const Event *)NULL); 00058 } 00059 00060 //////////////////////////////////////////////////////////////////// 00061 // Function: AnimControlCollection::get_stop_event 00062 // Access: Public 00063 // Description: Returns the event that has been established via 00064 // set_stop_event(). This is the event that will be 00065 // thrown by animations that are started in the future 00066 // when they stop. However, this may or may not be 00067 // associated with any currently-playing animations. 00068 //////////////////////////////////////////////////////////////////// 00069 INLINE CPT_Event AnimControlCollection:: 00070 get_stop_event() const { 00071 return _stop_event; 00072 } 00073 00074 //////////////////////////////////////////////////////////////////// 00075 // Function: AnimControlCollection::play 00076 // Access: Public 00077 // Description: Starts the named animation playing. 00078 //////////////////////////////////////////////////////////////////// 00079 INLINE bool AnimControlCollection:: 00080 play(const string &anim_name) { 00081 AnimControl *control = find_anim(anim_name); 00082 if (control == (AnimControl *)NULL) { 00083 return false; 00084 } 00085 _last_started_control = control; 00086 control->play(_stop_event); 00087 return true; 00088 } 00089 00090 //////////////////////////////////////////////////////////////////// 00091 // Function: AnimControlCollection::play 00092 // Access: Public 00093 // Description: Starts the named animation playing. 00094 //////////////////////////////////////////////////////////////////// 00095 INLINE bool AnimControlCollection:: 00096 play(const string &anim_name, int from, int to) { 00097 AnimControl *control = find_anim(anim_name); 00098 if (control == (AnimControl *)NULL) { 00099 return false; 00100 } 00101 _last_started_control = control; 00102 control->play(from, to, _stop_event); 00103 return true; 00104 } 00105 00106 //////////////////////////////////////////////////////////////////// 00107 // Function: AnimControlCollection::loop 00108 // Access: Public 00109 // Description: Starts the named animation looping. 00110 //////////////////////////////////////////////////////////////////// 00111 INLINE bool AnimControlCollection:: 00112 loop(const string &anim_name, bool restart) { 00113 AnimControl *control = find_anim(anim_name); 00114 if (control == (AnimControl *)NULL) { 00115 return false; 00116 } 00117 _last_started_control = control; 00118 control->loop(restart); 00119 return true; 00120 } 00121 00122 //////////////////////////////////////////////////////////////////// 00123 // Function: AnimControlCollection::loop 00124 // Access: Public 00125 // Description: Starts the named animation looping. 00126 //////////////////////////////////////////////////////////////////// 00127 INLINE bool AnimControlCollection:: 00128 loop(const string &anim_name, bool restart, int from, int to) { 00129 AnimControl *control = find_anim(anim_name); 00130 if (control == (AnimControl *)NULL) { 00131 return false; 00132 } 00133 _last_started_control = control; 00134 control->loop(restart, from, to); 00135 return true; 00136 } 00137 00138 //////////////////////////////////////////////////////////////////// 00139 // Function: AnimControlCollection::stop 00140 // Access: Public 00141 // Description: Stops the named animation. 00142 //////////////////////////////////////////////////////////////////// 00143 INLINE bool AnimControlCollection:: 00144 stop(const string &anim_name) { 00145 AnimControl *control = find_anim(anim_name); 00146 if (control == (AnimControl *)NULL) { 00147 return false; 00148 } 00149 control->stop(); 00150 return true; 00151 } 00152 00153 00154 //////////////////////////////////////////////////////////////////// 00155 // Function: AnimControlCollection::pose 00156 // Access: Public 00157 // Description: Sets to a particular frame in the named animation. 00158 //////////////////////////////////////////////////////////////////// 00159 INLINE bool AnimControlCollection:: 00160 pose(const string &anim_name, int frame) { 00161 AnimControl *control = find_anim(anim_name); 00162 if (control == (AnimControl *)NULL) { 00163 return false; 00164 } 00165 _last_started_control = control; 00166 control->pose(frame); 00167 return true; 00168 } 00169 00170 //////////////////////////////////////////////////////////////////// 00171 // Function: AnimControlCollection::get_frame 00172 // Access: Public 00173 // Description: Returns the current frame in the named animation, or 00174 // 0 if the animation is not found. 00175 //////////////////////////////////////////////////////////////////// 00176 INLINE int AnimControlCollection:: 00177 get_frame(const string &anim_name) const { 00178 AnimControl *control = find_anim(anim_name); 00179 if (control == (AnimControl *)NULL) { 00180 return 0; 00181 } 00182 return control->get_frame(); 00183 } 00184 00185 //////////////////////////////////////////////////////////////////// 00186 // Function: AnimControlCollection::get_frame 00187 // Access: Public 00188 // Description: Returns the current frame in the last-started 00189 // animation. 00190 //////////////////////////////////////////////////////////////////// 00191 INLINE int AnimControlCollection:: 00192 get_frame() const { 00193 if (_last_started_control == (AnimControl *)NULL) { 00194 return 0; 00195 } 00196 return _last_started_control->get_frame(); 00197 } 00198 00199 //////////////////////////////////////////////////////////////////// 00200 // Function: AnimControlCollection::is_playing 00201 // Access: Public 00202 // Description: Returns true if the named animation is currently 00203 // playing, false otherwise. 00204 //////////////////////////////////////////////////////////////////// 00205 INLINE bool AnimControlCollection:: 00206 is_playing(const string &anim_name) const { 00207 AnimControl *control = find_anim(anim_name); 00208 if (control == (AnimControl *)NULL) { 00209 return false; 00210 } 00211 return control->is_playing(); 00212 } 00213 00214 //////////////////////////////////////////////////////////////////// 00215 // Function: AnimControlCollection::is_playing 00216 // Access: Public 00217 // Description: Returns true if the last-started animation is 00218 // currently playing, false otherwise. 00219 //////////////////////////////////////////////////////////////////// 00220 INLINE bool AnimControlCollection:: 00221 is_playing() const { 00222 if (_last_started_control == (AnimControl *)NULL) { 00223 return false; 00224 } 00225 return _last_started_control->is_playing(); 00226 } 00227 00228 //////////////////////////////////////////////////////////////////// 00229 // Function: AnimControlCollection::get_num_frames 00230 // Access: Public 00231 // Description: Returns the total number of frames in the named 00232 // animation, or 0 if the animation is not found. 00233 //////////////////////////////////////////////////////////////////// 00234 INLINE int AnimControlCollection:: 00235 get_num_frames(const string &anim_name) const { 00236 AnimControl *control = find_anim(anim_name); 00237 if (control == (AnimControl *)NULL) { 00238 return 0; 00239 } 00240 return control->get_num_frames(); 00241 }