[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 |
---|
[3816] | 52 | should reference any Animations, from the animationList because it |
---|
| 53 | automatically deletes them. |
---|
| 54 | This usually happens when unloading a World. |
---|
[3245] | 55 | */ |
---|
[3812] | 56 | AnimationPlayer::~AnimationPlayer () |
---|
[3543] | 57 | { |
---|
[3812] | 58 | // deleting the Animation List AND all the elements of the List |
---|
[3816] | 59 | this->flush(); |
---|
[3812] | 60 | delete this->animationList; |
---|
| 61 | |
---|
| 62 | AnimationPlayer::singletonRef = NULL; |
---|
[3543] | 63 | } |
---|
[1853] | 64 | |
---|
[3245] | 65 | /** |
---|
[3812] | 66 | \brief adds an Animation to the AnimationList. |
---|
| 67 | \param animation the Animation to handle |
---|
[3245] | 68 | |
---|
[3812] | 69 | when adding a Animation the Animation will too be deleted when |
---|
| 70 | the AnimationPlayer gets deleted. Consider not adding it, or |
---|
| 71 | unadding it with animation->notHandled(); |
---|
[3245] | 72 | */ |
---|
[3812] | 73 | void AnimationPlayer::addAnimation(Anim* animation) |
---|
| 74 | { |
---|
| 75 | this->animationList->add(animation); |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | /** |
---|
[3816] | 79 | \brief removes an Animation from the Animation List, WITHOUT deleting it. |
---|
| 80 | \param animation the Anmination to remove from the List |
---|
| 81 | */ |
---|
| 82 | void AnimationPlayer::removeAnimation(Anim* animation) |
---|
| 83 | { |
---|
| 84 | this->animationList->remove(animation); |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | /** |
---|
| 88 | \brief empties the list AND deletes all the Animations |
---|
| 89 | */ |
---|
| 90 | void AnimationPlayer::flush(void) |
---|
| 91 | { |
---|
| 92 | // deleting the Animation List AND all the elements of the List |
---|
| 93 | tIterator<Anim>* animIt = this->animationList->getIterator(); |
---|
| 94 | Anim* anim = animIt->nextElement(); |
---|
| 95 | while( anim != NULL) |
---|
| 96 | { |
---|
| 97 | delete anim; |
---|
| 98 | this->animationList->remove(anim); |
---|
| 99 | anim = animIt->nextElement(); |
---|
| 100 | } |
---|
| 101 | delete animIt; |
---|
| 102 | |
---|
| 103 | delete this->animationList; |
---|
| 104 | this->animationList = new tList<Anim>(); |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | /** |
---|
[3812] | 108 | \brief Ticks all the animations in animationList |
---|
| 109 | \param timePassed the time passed since the last tick. |
---|
| 110 | */ |
---|
| 111 | void AnimationPlayer::tick(float timePassed) |
---|
| 112 | { |
---|
[3816] | 113 | tIterator<Anim>* animIt = this->animationList->getIterator(); |
---|
[3812] | 114 | Anim* anim = animIt->nextElement(); |
---|
| 115 | while( anim != NULL) |
---|
| 116 | { |
---|
| 117 | anim->tick(timePassed); |
---|
| 118 | anim = animIt->nextElement(); |
---|
| 119 | } |
---|
| 120 | delete animIt; |
---|
[3816] | 121 | } |
---|
[3812] | 122 | |
---|
[3816] | 123 | |
---|
| 124 | /** |
---|
| 125 | \brief Outputs some nice debug-information |
---|
| 126 | */ |
---|
| 127 | void AnimationPlayer::debug(void) |
---|
| 128 | { |
---|
| 129 | PRINT(0)("+------------------------------------+\n"); |
---|
| 130 | PRINT(0)("+ ANIMATION PLAYER DEBUG INFORMATION +\n"); |
---|
| 131 | PRINT(0)("+------------------------------------+\n"); |
---|
| 132 | PRINT(0)("| Reference: %p\n", this); |
---|
| 133 | PRINT(0)("| CountOfAnims %d\n", this->animationList->getSize()); |
---|
| 134 | PRINT(0)("-Animation Information---------------+\n"); |
---|
| 135 | // Per ANIMATION DEBUG |
---|
| 136 | tIterator<Anim>* animIt = this->animationList->getIterator(); |
---|
| 137 | Anim* anim = animIt->nextElement(); |
---|
| 138 | while( anim != NULL) |
---|
| 139 | { |
---|
| 140 | // anim->debug(); |
---|
| 141 | anim = animIt->nextElement(); |
---|
| 142 | } |
---|
| 143 | delete animIt; |
---|
| 144 | |
---|
| 145 | PRINT(0)("+--------------------------------AP--+\n"); |
---|
[3812] | 146 | } |
---|