[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 | |
---|
[1856] | 20 | using namespace std; |
---|
[1853] | 21 | |
---|
[1856] | 22 | |
---|
[3245] | 23 | /** |
---|
| 24 | \brief standard constructor |
---|
| 25 | */ |
---|
[3812] | 26 | AnimationPlayer::AnimationPlayer () |
---|
[3365] | 27 | { |
---|
[3812] | 28 | this->setClassName ("AnimationPlayer"); |
---|
| 29 | |
---|
| 30 | this->animationList = new tList<Anim>(); |
---|
[3365] | 31 | } |
---|
[1853] | 32 | |
---|
[3812] | 33 | /** |
---|
| 34 | \brief the singleton reference to this class |
---|
| 35 | */ |
---|
| 36 | AnimationPlayer* AnimationPlayer::singletonRef = NULL; |
---|
[1853] | 37 | |
---|
[3245] | 38 | /** |
---|
[3812] | 39 | \returns a Pointer to this Class |
---|
| 40 | */ |
---|
| 41 | AnimationPlayer* AnimationPlayer::getInstance(void) |
---|
| 42 | { |
---|
| 43 | if (!AnimationPlayer::singletonRef) |
---|
| 44 | AnimationPlayer::singletonRef = new AnimationPlayer(); |
---|
| 45 | return AnimationPlayer::singletonRef; |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | /** |
---|
[3245] | 49 | \brief standard deconstructor |
---|
[1853] | 50 | |
---|
[3812] | 51 | !! DANGER !! when unloading the AnimationPlayer no other Function |
---|
| 52 | should reference any Animations, because it automatically deletes |
---|
| 53 | them. This usually happens when unloading a World. |
---|
[3245] | 54 | */ |
---|
[3812] | 55 | AnimationPlayer::~AnimationPlayer () |
---|
[3543] | 56 | { |
---|
[3812] | 57 | // deleting the Animation List AND all the elements of the List |
---|
| 58 | tIterator<Anim>* animIt = animationList->getIterator(); |
---|
| 59 | Anim* anim = animIt->nextElement(); |
---|
| 60 | while( anim != NULL) |
---|
| 61 | { |
---|
| 62 | delete anim; |
---|
| 63 | anim = animIt->nextElement(); |
---|
| 64 | } |
---|
| 65 | delete animIt; |
---|
| 66 | delete this->animationList; |
---|
| 67 | |
---|
| 68 | AnimationPlayer::singletonRef = NULL; |
---|
[3543] | 69 | } |
---|
[1853] | 70 | |
---|
[3245] | 71 | /** |
---|
[3812] | 72 | \brief adds an Animation to the AnimationList. |
---|
| 73 | \param animation the Animation to handle |
---|
[3245] | 74 | |
---|
[3812] | 75 | when adding a Animation the Animation will too be deleted when |
---|
| 76 | the AnimationPlayer gets deleted. Consider not adding it, or |
---|
| 77 | unadding it with animation->notHandled(); |
---|
[3245] | 78 | */ |
---|
[3812] | 79 | void AnimationPlayer::addAnimation(Anim* animation) |
---|
| 80 | { |
---|
| 81 | this->animationList->add(animation); |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | /** |
---|
| 85 | \brief Ticks all the animations in animationList |
---|
| 86 | \param timePassed the time passed since the last tick. |
---|
| 87 | */ |
---|
| 88 | void AnimationPlayer::tick(float timePassed) |
---|
| 89 | { |
---|
| 90 | tIterator<Anim>* animIt = animationList->getIterator(); |
---|
| 91 | Anim* anim = animIt->nextElement(); |
---|
| 92 | while( anim != NULL) |
---|
| 93 | { |
---|
| 94 | anim->tick(timePassed); |
---|
| 95 | anim = animIt->nextElement(); |
---|
| 96 | } |
---|
| 97 | delete animIt; |
---|
| 98 | |
---|
| 99 | } |
---|