Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/animation_player.cc @ 3829

Last change on this file since 3829 was 3821, checked in by bensch, 20 years ago

orxonox/trunk: pause and play function

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