Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/util/animation/animation_player.cc @ 4488

Last change on this file since 4488 was 4485, checked in by bensch, 19 years ago

orxonox/trunk: more documentation in util

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