Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: setClassID implemented in all files

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