00001 // Filename: animControlCollection.cxx 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 #include "animControlCollection.h" 00021 00022 00023 //////////////////////////////////////////////////////////////////// 00024 // Function: AnimControlCollection::Constructor 00025 // Access: Published 00026 // Description: Returns the AnimControl associated with the given 00027 // name, or NULL if no such control has been associated. 00028 //////////////////////////////////////////////////////////////////// 00029 AnimControlCollection:: 00030 AnimControlCollection() { 00031 _last_started_control = (AnimControl *)NULL; 00032 } 00033 00034 //////////////////////////////////////////////////////////////////// 00035 // Function: AnimControlCollection::Destructor 00036 // Access: Published 00037 // Description: 00038 //////////////////////////////////////////////////////////////////// 00039 AnimControlCollection:: 00040 ~AnimControlCollection() { 00041 } 00042 00043 //////////////////////////////////////////////////////////////////// 00044 // Function: AnimControlCollection::store_anim 00045 // Access: Published 00046 // Description: Associates the given AnimControl with this collection 00047 // under the given name. The AnimControl will remain 00048 // associated until a new AnimControl is associated with 00049 // the same name later, or until unbind_anim() is called 00050 // with this name. 00051 //////////////////////////////////////////////////////////////////// 00052 void AnimControlCollection:: 00053 store_anim(AnimControl *control, const string &name) { 00054 Controls::iterator ci = _controls.find(name); 00055 if (ci == _controls.end()) { 00056 _controls.insert(Controls::value_type(name, control)); 00057 } else { 00058 if (_last_started_control == (*ci).second) { 00059 _last_started_control = (AnimControl *)NULL; 00060 } 00061 (*ci).second = control; 00062 } 00063 } 00064 00065 //////////////////////////////////////////////////////////////////// 00066 // Function: AnimControlCollection::find_anim 00067 // Access: Published 00068 // Description: Returns the AnimControl associated with the given 00069 // name, or NULL if no such control has been associated. 00070 //////////////////////////////////////////////////////////////////// 00071 AnimControl *AnimControlCollection:: 00072 find_anim(const string &name) const { 00073 Controls::const_iterator ci = _controls.find(name); 00074 if (ci == _controls.end()) { 00075 return (AnimControl *)NULL; 00076 } 00077 return (*ci).second; 00078 } 00079 00080 //////////////////////////////////////////////////////////////////// 00081 // Function: AnimControlCollection::unbind_anim 00082 // Access: Published 00083 // Description: Removes the AnimControl associated with the given 00084 // name, if any. Returns true if an AnimControl was 00085 // removed, false if there was no AnimControl with the 00086 // indicated name. 00087 //////////////////////////////////////////////////////////////////// 00088 bool AnimControlCollection:: 00089 unbind_anim(const string &name) { 00090 Controls::iterator ci = _controls.find(name); 00091 if (ci == _controls.end()) { 00092 return false; 00093 } 00094 if (_last_started_control == (*ci).second) { 00095 _last_started_control = (AnimControl *)NULL; 00096 } 00097 _controls.erase(ci); 00098 return true; 00099 } 00100 00101 //////////////////////////////////////////////////////////////////// 00102 // Function: AnimControlCollection::get_num_anims 00103 // Access: Published 00104 // Description: Returns the number of AnimControls associated with 00105 // this collection. 00106 //////////////////////////////////////////////////////////////////// 00107 int AnimControlCollection:: 00108 get_num_anims() const { 00109 return _controls.size(); 00110 } 00111 00112 //////////////////////////////////////////////////////////////////// 00113 // Function: AnimControlCollection::clear_anims 00114 // Access: Published 00115 // Description: Disassociates all anims from this collection. 00116 //////////////////////////////////////////////////////////////////// 00117 void AnimControlCollection:: 00118 clear_anims() { 00119 _controls.clear(); 00120 } 00121 00122 //////////////////////////////////////////////////////////////////// 00123 // Function: AnimControlCollection::play_all 00124 // Access: Published 00125 // Description: Starts all animations playing. 00126 //////////////////////////////////////////////////////////////////// 00127 void AnimControlCollection:: 00128 play_all() { 00129 Controls::const_iterator ci; 00130 for (ci = _controls.begin(); ci != _controls.end(); ++ci) { 00131 (*ci).second->play(); 00132 } 00133 } 00134 00135 //////////////////////////////////////////////////////////////////// 00136 // Function: AnimControlCollection::play_all 00137 // Access: Published 00138 // Description: Starts all animations playing. 00139 //////////////////////////////////////////////////////////////////// 00140 void AnimControlCollection:: 00141 play_all(int from, int to) { 00142 Controls::const_iterator ci; 00143 for (ci = _controls.begin(); ci != _controls.end(); ++ci) { 00144 (*ci).second->play(from, to); 00145 } 00146 } 00147 00148 //////////////////////////////////////////////////////////////////// 00149 // Function: AnimControlCollection::loop_all 00150 // Access: Published 00151 // Description: Starts all animations looping. 00152 //////////////////////////////////////////////////////////////////// 00153 void AnimControlCollection:: 00154 loop_all(bool restart) { 00155 Controls::const_iterator ci; 00156 for (ci = _controls.begin(); ci != _controls.end(); ++ci) { 00157 (*ci).second->loop(restart); 00158 } 00159 } 00160 00161 //////////////////////////////////////////////////////////////////// 00162 // Function: AnimControlCollection::loop_all 00163 // Access: Published 00164 // Description: Starts all animations looping. 00165 //////////////////////////////////////////////////////////////////// 00166 void AnimControlCollection:: 00167 loop_all(bool restart, int from, int to) { 00168 Controls::const_iterator ci; 00169 for (ci = _controls.begin(); ci != _controls.end(); ++ci) { 00170 (*ci).second->loop(restart, from, to); 00171 } 00172 } 00173 00174 //////////////////////////////////////////////////////////////////// 00175 // Function: AnimControlCollection::stop_all 00176 // Access: Published 00177 // Description: Stops all currently playing animations. Returns true 00178 // if any animations were stopped, false if none were 00179 // playing. 00180 //////////////////////////////////////////////////////////////////// 00181 bool AnimControlCollection:: 00182 stop_all() { 00183 bool any = false; 00184 Controls::const_iterator ci; 00185 for (ci = _controls.begin(); ci != _controls.end(); ++ci) { 00186 if ((*ci).second->is_playing()) { 00187 any = true; 00188 (*ci).second->stop(); 00189 } 00190 } 00191 00192 return any; 00193 } 00194 00195 //////////////////////////////////////////////////////////////////// 00196 // Function: AnimControlCollection::pose_all 00197 // Access: Published 00198 // Description: Sets all animations to the indicated frame. 00199 //////////////////////////////////////////////////////////////////// 00200 void AnimControlCollection:: 00201 pose_all(int frame) { 00202 Controls::const_iterator ci; 00203 for (ci = _controls.begin(); ci != _controls.end(); ++ci) { 00204 (*ci).second->pose(frame); 00205 } 00206 } 00207 00208 //////////////////////////////////////////////////////////////////// 00209 // Function: AnimControlCollection::which_anim_playing 00210 // Access: Published 00211 // Description: Returns the name of the bound AnimControl currently 00212 // playing, if any. If more than one AnimControl is 00213 // currently playing, returns all of the names separated 00214 // by spaces. 00215 //////////////////////////////////////////////////////////////////// 00216 string AnimControlCollection:: 00217 which_anim_playing() const { 00218 string result; 00219 00220 Controls::const_iterator ci; 00221 for (ci = _controls.begin(); ci != _controls.end(); ++ci) { 00222 if ((*ci).second->is_playing()) { 00223 if (!result.empty()) { 00224 result += " "; 00225 } 00226 result += (*ci).first; 00227 } 00228 } 00229 00230 return result; 00231 }