Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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