Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 3858 was 3847, checked in by bensch, 20 years ago

orxonox/trunk: naming of animation changed
Anim → Animation
tAnim → tAnimation
Animation → Animation3D

@paede: i hope you like it.

File size: 4.4 KB
RevLine 
[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]20using namespace std;
[1853]21
[1856]22
[3245]23/**
24   \brief standard constructor
25*/
[3812]26AnimationPlayer::AnimationPlayer () 
[3365]27{
[3812]28   this->setClassName ("AnimationPlayer");
29
[3847]30   this->animationList = new tList<Animation>();
[3821]31   this->play();
[3365]32}
[1853]33
[3812]34/**
35   \brief the singleton reference to this class
36*/
37AnimationPlayer* AnimationPlayer::singletonRef = NULL;
[1853]38
[3245]39/**
[3812]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/**
[3245]50   \brief standard deconstructor
[1853]51
[3812]52   !! DANGER !! when unloading the AnimationPlayer no other Function
[3816]53   should reference any Animations, from the animationList because it
54   automatically deletes them.
55   This usually happens when unloading a World.
[3245]56*/
[3812]57AnimationPlayer::~AnimationPlayer () 
[3543]58{
[3812]59  // deleting the Animation List AND all the elements of the List
[3816]60  this->flush();
[3812]61  delete this->animationList;
62
63  AnimationPlayer::singletonRef = NULL;
[3543]64}
[1853]65
[3245]66/**
[3812]67   \brief adds an Animation to the AnimationList.
68   \param animation the Animation to handle
[3245]69
[3812]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();
[3245]73*/
[3847]74void AnimationPlayer::addAnimation(Animation* animation)
[3812]75{
76  this->animationList->add(animation);
77}
78
79/**
[3816]80   \brief removes an Animation from the Animation List, WITHOUT deleting it.
81   \param animation the Anmination to remove from the List
82*/
[3847]83void AnimationPlayer::removeAnimation(Animation* animation)
[3816]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
[3847]94  tIterator<Animation>* animIt = this->animationList->getIterator();
95  Animation* anim = animIt->nextElement();
[3816]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;
[3847]105  this->animationList = new tList<Animation>();
[3816]106}
107
108/**
[3812]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{
[3821]114  if (this->bRunning)
[3812]115    {
[3821]116      // iterate through all the animations and tick them.
[3847]117      tIterator<Animation>* animIt = this->animationList->getIterator();
118      Animation* anim = animIt->nextElement();
[3821]119      while( anim != NULL)
120        {
121          anim->tick(timePassed);
122          anim = animIt->nextElement();
123        }
124      delete animIt;
[3812]125    }
[3816]126}
[3821]127/**
128   \brief starts playing the AnimationPlayer
129*/
130void AnimationPlayer::play(void)
131{
132  this->bRunning = true;
133}
[3812]134
[3821]135/**
136   \brief pauses playing of the AnimationPlayer
137*/
138void AnimationPlayer::pause(void)
139{
140  this->bRunning = false;
141}
[3816]142
[3821]143
[3847]144Animation* AnimationPlayer::getObjectFromBaseObject(const BaseObject* baseObject) const
[3833]145{
[3847]146  tIterator<Animation>* animIt = this->animationList->getIterator();
147  Animation* anim = animIt->nextElement();
[3833]148  while( anim != NULL)
149    {
150      if(anim->getBaseObject() == baseObject)
151        {
152          delete animIt;
153          return anim;
154        }
155      anim = animIt->nextElement();
156    }
157  delete animIt;
[3821]158
[3833]159}
160
161
162
[3816]163/**
164   \brief Outputs some nice debug-information
165*/
166void AnimationPlayer::debug(void)
167{
168  PRINT(0)("+------------------------------------+\n");
169  PRINT(0)("+ ANIMATION PLAYER DEBUG INFORMATION +\n");
170  PRINT(0)("+------------------------------------+\n");
171  PRINT(0)("| Reference: %p\n", this);
172  PRINT(0)("| CountOfAnims %d\n", this->animationList->getSize());
173  PRINT(0)("-Animation Information---------------+\n");
174  // Per ANIMATION DEBUG
[3847]175  tIterator<Animation>* animIt = this->animationList->getIterator();
176  Animation* anim = animIt->nextElement();
[3816]177  while( anim != NULL)
178    {
179      //      anim->debug();
180      anim = animIt->nextElement();
181    }
182  delete animIt;
183
184  PRINT(0)("+--------------------------------AP--+\n");
[3812]185}
Note: See TracBrowser for help on using the repository browser.