16 #include "animControlCollection.h"
35 AnimControlCollection::
36 ~AnimControlCollection() {
50 ControlsByName::iterator ci = _controls_by_name.find(name);
52 if (ci == _controls_by_name.end()) {
54 size_t index = _controls.size();
56 cdef._control = control;
58 _controls.push_back(cdef);
59 _controls_by_name.insert(ControlsByName::value_type(name, index));
63 size_t index = (*ci).second;
64 nassertv(index < _controls.size());
65 nassertv(_controls[index]._name == name);
66 if (_last_started_control == _controls[index]._control) {
69 _controls[index]._control = control;
81 ControlsByName::const_iterator ci = _controls_by_name.find(name);
82 if (ci == _controls_by_name.end()) {
85 size_t index = (*ci).second;
86 nassertr(index < _controls.size(), NULL);
87 nassertr(_controls[index]._name == name, NULL);
88 return _controls[index]._control;
101 ControlsByName::iterator ci = _controls_by_name.find(name);
102 if (ci == _controls_by_name.end()) {
105 size_t index = (*ci).second;
106 nassertr(index < _controls.size(),
false);
107 nassertr(_controls[index]._name == name,
false);
109 if (_last_started_control == _controls[index]._control) {
112 _controls_by_name.erase(ci);
114 _controls.erase(_controls.begin() + index);
117 for (ci = _controls_by_name.begin();
118 ci != _controls_by_name.end();
120 if ((*ci).second > index) {
136 return _controls.size();
147 nassertr(n >= 0 && n < (
int)_controls.size(), NULL);
148 return _controls[n]._control;
159 nassertr(n >= 0 && n < (
int)_controls.size(), string());
160 return _controls[n]._name;
171 _controls_by_name.clear();
181 Controls::const_iterator ci;
182 for (ci = _controls.begin(); ci != _controls.end(); ++ci) {
183 (*ci)._control->play();
184 _last_started_control = (*ci)._control;
195 Controls::const_iterator ci;
196 for (ci = _controls.begin(); ci != _controls.end(); ++ci) {
197 (*ci)._control->play(from, to);
198 _last_started_control = (*ci)._control;
209 Controls::const_iterator ci;
210 for (ci = _controls.begin(); ci != _controls.end(); ++ci) {
211 (*ci)._control->loop(restart);
212 _last_started_control = (*ci)._control;
223 Controls::const_iterator ci;
224 for (ci = _controls.begin(); ci != _controls.end(); ++ci) {
225 (*ci)._control->loop(restart, from, to);
226 _last_started_control = (*ci)._control;
240 Controls::const_iterator ci;
241 for (ci = _controls.begin(); ci != _controls.end(); ++ci) {
242 if ((*ci)._control->is_playing()) {
244 (*ci)._control->stop();
258 Controls::const_iterator ci;
259 for (ci = _controls.begin(); ci != _controls.end(); ++ci) {
260 (*ci)._control->pose(frame);
261 _last_started_control = (*ci)._control;
277 Controls::const_iterator ci;
278 for (ci = _controls.begin();
279 ci != _controls.end();
281 if ((*ci)._control->is_playing()) {
282 if (!result.empty()) {
285 result += (*ci)._name;
297 void AnimControlCollection::
298 output(ostream &out)
const {
299 out << _controls.size() <<
" anims.";
307 void AnimControlCollection::
308 write(ostream &out)
const {
309 ControlsByName::const_iterator ci;
310 for (ci = _controls_by_name.begin();
311 ci != _controls_by_name.end();
313 out << (*ci).first <<
": " << *_controls[(*ci).second]._control <<
"\n";
string which_anim_playing() const
Returns the name of the bound AnimControl currently playing, if any.
AnimControl * find_anim(const string &name) const
Returns the AnimControl associated with the given name, or NULL if no such control has been associate...
void pose_all(int frame)
Sets all animations to the indicated frame.
void loop_all(bool restart)
Starts all animations looping.
void play_all()
Starts all animations playing.
AnimControlCollection()
Returns the AnimControl associated with the given name, or NULL if no such control has been associate...
void store_anim(AnimControl *control, const string &name)
Associates the given AnimControl with this collection under the given name.
void clear_anims()
Disassociates all anims from this collection.
AnimControl * get_anim(int n) const
Returns the nth AnimControl associated with this collection.
bool unbind_anim(const string &name)
Removes the AnimControl associated with the given name, if any.
bool stop_all()
Stops all currently playing animations.
Controls the timing of a character animation.
int get_num_anims() const
Returns the number of AnimControls associated with this collection.
string get_anim_name(int n) const
Returns the name of the nth AnimControl associated with this collection.