1 | /* |
---|
2 | orxonox - the future of 3D-vertical-scrollers |
---|
3 | |
---|
4 | Copyright (C) 2004 orx |
---|
5 | |
---|
6 | This program is free software; you can redistribute it and/or modify |
---|
7 | it under the terms of the GNU General Public License as published by |
---|
8 | the Free Software Foundation; either version 2, or (at your option) |
---|
9 | any later version. |
---|
10 | |
---|
11 | ### File Specific: |
---|
12 | main-programmer: Benjamin Grauer |
---|
13 | co-programmer: ... |
---|
14 | */ |
---|
15 | |
---|
16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_ANIM |
---|
17 | |
---|
18 | #include "animation_player.h" |
---|
19 | |
---|
20 | using namespace std; |
---|
21 | |
---|
22 | |
---|
23 | /** |
---|
24 | \brief standard constructor |
---|
25 | */ |
---|
26 | AnimationPlayer::AnimationPlayer () |
---|
27 | { |
---|
28 | this->setClassName ("AnimationPlayer"); |
---|
29 | |
---|
30 | this->animationList = new tList<Animation>(); |
---|
31 | this->play(); |
---|
32 | } |
---|
33 | |
---|
34 | /** |
---|
35 | \brief the singleton reference to this class |
---|
36 | */ |
---|
37 | AnimationPlayer* AnimationPlayer::singletonRef = NULL; |
---|
38 | |
---|
39 | /** |
---|
40 | \returns a Pointer to this Class |
---|
41 | */ |
---|
42 | AnimationPlayer* AnimationPlayer::getInstance(void) |
---|
43 | { |
---|
44 | if (!AnimationPlayer::singletonRef) |
---|
45 | AnimationPlayer::singletonRef = new AnimationPlayer(); |
---|
46 | return AnimationPlayer::singletonRef; |
---|
47 | } |
---|
48 | |
---|
49 | /** |
---|
50 | \brief standard deconstructor |
---|
51 | |
---|
52 | !! DANGER !! when unloading the AnimationPlayer no other Function |
---|
53 | should reference any Animations, from the animationList because it |
---|
54 | automatically deletes them. |
---|
55 | This usually happens when unloading a World. |
---|
56 | */ |
---|
57 | AnimationPlayer::~AnimationPlayer () |
---|
58 | { |
---|
59 | // deleting the Animation List AND all the elements of the List |
---|
60 | this->flush(); |
---|
61 | delete this->animationList; |
---|
62 | |
---|
63 | AnimationPlayer::singletonRef = NULL; |
---|
64 | } |
---|
65 | |
---|
66 | /** |
---|
67 | \brief adds an Animation to the AnimationList. |
---|
68 | \param animation the Animation to handle |
---|
69 | |
---|
70 | when adding a Animation the Animation will too be deleted when |
---|
71 | the AnimationPlayer gets deleted. Consider not adding it, or |
---|
72 | unadding it with animation->notHandled(); |
---|
73 | */ |
---|
74 | void AnimationPlayer::addAnimation(Animation* animation) |
---|
75 | { |
---|
76 | this->animationList->add(animation); |
---|
77 | } |
---|
78 | |
---|
79 | /** |
---|
80 | \brief removes an Animation from the Animation List, WITHOUT deleting it. |
---|
81 | \param animation the Anmination to remove from the List |
---|
82 | */ |
---|
83 | void AnimationPlayer::removeAnimation(Animation* animation) |
---|
84 | { |
---|
85 | this->animationList->remove(animation); |
---|
86 | } |
---|
87 | |
---|
88 | /** |
---|
89 | \brief empties the list AND deletes all the Animations |
---|
90 | */ |
---|
91 | void AnimationPlayer::flush(void) |
---|
92 | { |
---|
93 | // deleting the Animation List AND all the elements of the List |
---|
94 | tIterator<Animation>* animIt = this->animationList->getIterator(); |
---|
95 | Animation* anim = animIt->nextElement(); |
---|
96 | while( anim != NULL) |
---|
97 | { |
---|
98 | delete anim; |
---|
99 | this->animationList->remove(anim); |
---|
100 | anim = animIt->nextElement(); |
---|
101 | } |
---|
102 | delete animIt; |
---|
103 | |
---|
104 | delete this->animationList; |
---|
105 | this->animationList = new tList<Animation>(); |
---|
106 | } |
---|
107 | |
---|
108 | /** |
---|
109 | \brief Ticks all the animations in animationList |
---|
110 | \param timePassed the time passed since the last tick. |
---|
111 | */ |
---|
112 | void AnimationPlayer::tick(float timePassed) |
---|
113 | { |
---|
114 | if (this->bRunning) |
---|
115 | { |
---|
116 | // iterate through all the animations and tick them. |
---|
117 | tIterator<Animation>* animIt = this->animationList->getIterator(); |
---|
118 | Animation* anim = animIt->nextElement(); |
---|
119 | while( anim != NULL) |
---|
120 | { |
---|
121 | anim->tick(timePassed); |
---|
122 | anim = animIt->nextElement(); |
---|
123 | } |
---|
124 | delete animIt; |
---|
125 | } |
---|
126 | } |
---|
127 | /** |
---|
128 | \brief starts playing the AnimationPlayer |
---|
129 | */ |
---|
130 | void AnimationPlayer::play(void) |
---|
131 | { |
---|
132 | this->bRunning = true; |
---|
133 | } |
---|
134 | |
---|
135 | /** |
---|
136 | \brief pauses playing of the AnimationPlayer |
---|
137 | */ |
---|
138 | void AnimationPlayer::pause(void) |
---|
139 | { |
---|
140 | this->bRunning = false; |
---|
141 | } |
---|
142 | |
---|
143 | |
---|
144 | Animation* AnimationPlayer::getObjectFromBaseObject(const BaseObject* baseObject) const |
---|
145 | { |
---|
146 | tIterator<Animation>* animIt = this->animationList->getIterator(); |
---|
147 | Animation* anim = animIt->nextElement(); |
---|
148 | while( anim != NULL) |
---|
149 | { |
---|
150 | if(anim->getBaseObject() == baseObject) |
---|
151 | { |
---|
152 | delete animIt; |
---|
153 | return anim; |
---|
154 | } |
---|
155 | anim = animIt->nextElement(); |
---|
156 | } |
---|
157 | delete animIt; |
---|
158 | |
---|
159 | } |
---|
160 | |
---|
161 | |
---|
162 | |
---|
163 | /** |
---|
164 | \brief Outputs some nice debug-information |
---|
165 | */ |
---|
166 | void AnimationPlayer::debug(void) |
---|
167 | { |
---|
168 | PRINT(0)("+------------------------------------+\n"); |
---|
169 | PRINT(0)("+ ANIMATION PLAYER DEBUG INFORMATION +\n"); |
---|
170 | PRINT(0)("+------------------------------------+\n"); |
---|
171 | PRINT(0)("| Reference: %p\n", this); |
---|
172 | PRINT(0)("| CountOfAnims %d\n", this->animationList->getSize()); |
---|
173 | PRINT(0)("-Animation Information---------------+\n"); |
---|
174 | // Per ANIMATION DEBUG |
---|
175 | tIterator<Animation>* animIt = this->animationList->getIterator(); |
---|
176 | Animation* anim = animIt->nextElement(); |
---|
177 | while( anim != NULL) |
---|
178 | { |
---|
179 | // anim->debug(); |
---|
180 | anim = animIt->nextElement(); |
---|
181 | } |
---|
182 | delete animIt; |
---|
183 | |
---|
184 | PRINT(0)("+--------------------------------AP--+\n"); |
---|
185 | } |
---|