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