Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10406 was 9869, checked in by bensch, 18 years ago

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

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