Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5777 in orxonox.OLD


Ignore:
Timestamp:
Nov 25, 2005, 3:37:11 AM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: stl::list in AnimationPlayer

Location:
trunk/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/physics/physics_engine.h

    r5776 r5777  
    1414#include "field.h"
    1515#include <list>
    16 
    1716
    1817// Forward Declaration
  • trunk/src/util/animation/animation.cc

    r4836 r5777  
    3131  // initialize a beginning KeyFrame, that will be deleted afterwards
    3232  this->keyFrameCount = 0;
    33   this->bHandled = true;
    3433  this->bDelete = false;
    3534  this->baseObject = NULL;
     
    5049Animation::~Animation()
    5150{
    52   this->doNotHandle();
     51  AnimationPlayer::getInstance()->removeAnimation(this);
    5352}
    5453
    55 /**
    56  *  tells the AnimationPlayer, that we do not wish to  handle this animation
    57    automatically.
    58 
    59    This means that it will not be ticked, and not be deleted with the AnimationPlayer
    60 */
    61 void Animation::doNotHandle()
    62 {
    63   if (this->bHandled)
    64     AnimationPlayer::getInstance()->removeAnimation(this);
    65 }
    6654
    6755/**
  • trunk/src/util/animation/animation.h

    r5405 r5777  
    7676 public:
    7777  virtual ~Animation();
    78   void doNotHandle();
    7978
    8079  void setInfinity(ANIM_INFINITY postInfinity = ANIM_INF_CONSTANT);
     
    110109  unsigned int          keyFrameCount;          //!< The Count of KeyFrames.
    111110  int                   keyFramesToPlay;        //!< How many more Keyframes to play. if negative it will be ignored if 0 stop.
    112   bool                  bHandled;               //!< If this Animation is handled by the AnimationPlayer.
    113111  bool                  bRunning;               //!< If the animation is running
    114112  bool                  bDelete;                //!< If true, the animation will be deleted through the AnimationPlayer.
  • trunk/src/util/animation/animation_player.cc

    r5115 r5777  
    3131  this->setName("AnimationPlayer");
    3232
    33   this->animationList = new tList<Animation>();
    3433  this->play();
    3534}
     
    5251  // deleting the Animation List AND all the elements of the List
    5352  this->flush();
    54   delete this->animationList;
    5553
    5654  AnimationPlayer::singletonRef = NULL;
     
    6765void AnimationPlayer::addAnimation(Animation* animation)
    6866{
    69   this->animationList->add(animation);
     67  this->animationList.push_back(animation);
    7068}
    7169
     
    7674void AnimationPlayer::removeAnimation(Animation* animation)
    7775{
    78   this->animationList->remove(animation);
     76  this->animationList.remove(animation);
    7977}
    8078
     
    8583{
    8684  // 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>();
     85  while(this->animationList.size() > 0)
     86  {
     87    Animation* anim = this->animationList.front();
     88    this->animationList.pop_front();
     89    delete anim;
     90  }
    9991}
    10092
     
    10294 *  Ticks all the animations in animationList
    10395 * @param timePassed the time passed since the last tick.
    104 */
     96 */
    10597void AnimationPlayer::tick(float timePassed)
    10698{
    10799  if (this->bRunning)
     100  {
     101      // iterate through all the animations and tick them.
     102    list<Animation*>::iterator anim;
     103    for (anim = this->animationList.begin(); anim != this->animationList.end(); anim++)
    108104    {
    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;
     105      (*anim)->tick(timePassed);
     106      if(unlikely((*anim)->ifDelete()))
     107      {
     108        this->animationList.remove(*anim);
     109        delete *anim;
     110      }
    123111    }
     112  }
    124113}
    125114/**
    126115 *  starts playing the AnimationPlayer
    127 */
     116 */
    128117void AnimationPlayer::play()
    129118{
     
    133122/**
    134123 *  pauses playing of the AnimationPlayer
    135 */
     124 */
    136125void AnimationPlayer::pause()
    137126{
     
    146135Animation* AnimationPlayer::getAnimationFromBaseObject(const BaseObject* baseObject) const
    147136{
    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;
     137  list<Animation*>::const_iterator anim;
     138  for (anim = this->animationList.begin(); anim != this->animationList.end(); anim++)
     139    if((*anim)->getBaseObject() == baseObject)
     140      return *anim;
    160141  return NULL;
    161142}
     
    172153  PRINT(0)("+------------------------------------+\n");
    173154  PRINT(0)("| Reference: %p\n", this);
    174   PRINT(0)("| CountOfAnims %d\n", this->animationList->getSize());
     155  PRINT(0)("| CountOfAnims %d\n", this->animationList.size());
    175156  PRINT(0)("-Animation Information---------------+\n");
    176157  // Per ANIMATION DEBUG
    177   tIterator<Animation>* animIt = this->animationList->getIterator();
    178   Animation* anim = animIt->firstElement();
    179   while( anim != NULL)
     158  list<Animation*>::iterator anim;
     159  for (anim = this->animationList.begin(); anim != this->animationList.end(); anim++)
    180160    {
    181161      //      anim->debug();
    182       anim = animIt->nextElement();
    183162    }
    184   delete animIt;
    185 
    186163  PRINT(0)("+--------------------------------AP--+\n");
    187164}
  • trunk/src/util/animation/animation_player.h

    r5405 r5777  
    88#include "base_object.h"
    99#include "animation.h"
     10
     11#include <list>
    1012
    1113/* FORWARD DECLARATION */
     
    5456
    5557  /* class specific */
    56   tList<Animation>*            animationList;         //!< A List of Animations to be handled.
     58  std::list<Animation*>        animationList;         //!< A List of Animations to be handled.
    5759  bool                         bRunning;              //!< If the AnimationPlayer is running.
    5860};
Note: See TracChangeset for help on using the changeset viewer.