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