Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: pause and play function

File size: 4.0 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
30   this->animationList = new tList<Anim>();
[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*/
[3812]74void AnimationPlayer::addAnimation(Anim* animation)
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*/
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/**
[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.
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;
[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
144
[3816]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");
[3812]167}
Note: See TracBrowser for help on using the repository browser.