Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: reimplemented the list functions, as i did before in revision 5110.
This time, i looked out for the bugs, and i think i found one

@patrick: i know, that you do not want to code at the moment… :/ → see mail

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 *  standard constructor
27*/
28AnimationPlayer::AnimationPlayer ()
29{
30  this->setClassID(CL_ANIMATION_PLAYER, "AnimationPlayer");
31  this->setName("AnimationPlayer");
32
33  this->animationList = new tList<Animation>();
34  this->play();
35}
36
37/**
38 *  the singleton reference to this class
39*/
40AnimationPlayer* AnimationPlayer::singletonRef = NULL;
41
42/**
43 *  standard deconstructor
44
45   !! DANGER !! when unloading the AnimationPlayer no other Function
46   should reference any Animations, from the animationList because it
47   automatically deletes them.
48   This usually happens when unloading a World.
49*/
50AnimationPlayer::~AnimationPlayer ()
51{
52  // deleting the Animation List AND all the elements of the List
53  this->flush();
54  delete this->animationList;
55
56  AnimationPlayer::singletonRef = NULL;
57}
58
59/**
60 *  adds an Animation to the AnimationList.
61 * @param animation the Animation to handle
62
63   when adding a Animation the Animation will too be deleted when
64   the AnimationPlayer gets deleted. Consider not adding it, or
65   unadding it with animation->notHandled();
66*/
67void AnimationPlayer::addAnimation(Animation* animation)
68{
69  this->animationList->add(animation);
70}
71
72/**
73 *  removes an Animation from the Animation List, WITHOUT deleting it.
74 * @param animation the Anmination to remove from the List
75*/
76void AnimationPlayer::removeAnimation(Animation* animation)
77{
78  this->animationList->remove(animation);
79}
80
81/**
82 *  empties the list AND deletes all the Animations
83*/
84void AnimationPlayer::flush()
85{
86  // deleting the Animation List AND all the elements of the List
87  tIterator<Animation>* animIt = this->animationList->getIterator();
88  Animation* anim = animIt->firstElement();
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;
98  this->animationList = new tList<Animation>();
99}
100
101/**
102 *  Ticks all the animations in animationList
103 * @param timePassed the time passed since the last tick.
104*/
105void AnimationPlayer::tick(float timePassed)
106{
107  if (this->bRunning)
108    {
109      // iterate through all the animations and tick them.
110      tIterator<Animation>* animIt = this->animationList->getIterator();
111      Animation* anim = animIt->firstElement();
112      while( anim != NULL)
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        }
122      delete animIt;
123    }
124}
125/**
126 *  starts playing the AnimationPlayer
127*/
128void AnimationPlayer::play()
129{
130  this->bRunning = true;
131}
132
133/**
134 *  pauses playing of the AnimationPlayer
135*/
136void AnimationPlayer::pause()
137{
138  this->bRunning = false;
139}
140
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
147{
148  tIterator<Animation>* animIt = this->animationList->getIterator();
149  Animation* anim = animIt->firstElement();
150  while( anim != NULL)
151    {
152      if(anim->getBaseObject() == baseObject)
153        {
154          delete animIt;
155          return anim;
156        }
157      anim = animIt->nextElement();
158    }
159  delete animIt;
160  return NULL;
161}
162
163
164
165/**
166 *  Outputs some nice debug-information
167*/
168void AnimationPlayer::debug()
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
177  tIterator<Animation>* animIt = this->animationList->getIterator();
178  Animation* anim = animIt->firstElement();
179  while( anim != NULL)
180    {
181      //      anim->debug();
182      anim = animIt->nextElement();
183    }
184  delete animIt;
185
186  PRINT(0)("+--------------------------------AP--+\n");
187}
Note: See TracBrowser for help on using the repository browser.