Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4654 in orxonox.OLD for orxonox/trunk/src/lib/particles


Ignore:
Timestamp:
Jun 18, 2005, 6:56:00 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: speeded up the QuickAnimation-getValue-function.

Location:
orxonox/trunk/src/lib/particles
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/lib/particles/particle_system.cc

    r4649 r4654  
    9595  this->setType(PARTICLE_DEFAULT_TYPE, 1);
    9696  ParticleEngine::getInstance()->addSystem(this);
     97
     98  colorAnim[0].setName("test"); //!< \todo delete this line
    9799}
    98100
  • orxonox/trunk/src/lib/particles/quick_animation.cc

    r4649 r4654  
    3434   this->setClassID(CL_QUICK_ANIMATION, "QuickAnimation");
    3535
    36    this->first = this->current = NULL;
    37 }
    38 
    39 /**
    40    \brief standard deconstructor
    41 
     36   // initialize the First KeyFrame (will be deleted if a new one gets created)
     37   this->count = 0;
     38   this->first = this->current = new QuickKeyFrame;
     39   this->first->next = this->first->prev = this->first;
     40   this->first->position = 0.0;
     41   this->first->value = 0.0;
     42}
     43
     44/**
     45   \brief deletes all the deconstructor stuff
    4246*/
    4347QuickAnimation::~QuickAnimation (void)
    4448{
    4549  this->current = this->first;
    46   QuickKeyFrame delKF;
    47 
    48   while (this->current != NULL)
    49     {
    50       this->first = this->current->next;
    51       delete this->current;
    52       this->current = this->first;
    53     }
     50  QuickKeyFrame* delKF = this->first;
     51
     52  do
     53  {
     54    delKF = this->current;
     55    this->current = this->current->next;
     56    delete delKF;
     57  }  while (this->current != this->first);
     58
    5459}
    5560
     
    6065   \returns false if the key existed already for a given position
    6166*/
    62 bool QuickAnimation::addEntry(float position, float value)
    63 {
    64   this->current = this->first;
    65   while (this->current != NULL)
     67void QuickAnimation::addEntry(float position, float value)
     68{
     69  if (this->getName())
     70  {
     71    printf("ADDED KEYFRAME %d\n", this->count);
     72  }
     73
     74  // create the new KeyFrame
     75  QuickKeyFrame* newKey = new QuickKeyFrame;
     76  newKey->position = position;
     77  newKey->value = value;
     78
     79  // if we add a KeyFrame for the first Time:
     80  if (unlikely (this->count == 0))
     81  {
     82    delete this->first;
     83
     84    newKey->next  = newKey;
     85    newKey->prev  = newKey;
     86    this->first   = newKey;
     87    this->current = newKey;
     88  }
     89  // if the KeyFrame is in front of the FIRST keyFrame
     90  else if (this->first->position > position)
     91  {
     92    newKey->next = this->first;
     93    newKey->prev = this->first->prev;
     94    newKey->prev->next = newKey;
     95    newKey->next->prev = newKey;
     96
     97    this->first = newKey; // the new Key becomes the FIRST.
     98  }
     99  // if the KeyFrame is at the End of the Animation
     100  else if (this->first->prev->position < position)
     101  {
     102    newKey->next = this->first;
     103    newKey->prev = this->first->prev;
     104    newKey->prev->next = newKey;
     105    newKey->next->prev = newKey;
     106  }
     107  // if the Key is between two frames.
     108  else
     109  {
     110    this->current = this->first;
     111    do
    66112    {
    67       // if it is between some keyframes
    68       if ((!this->current->next && this->current->position < position)
    69           || (this->current->position < position && this->current->next->position > position))
     113      if (this->current->position < position && this->current->next->position > position)
    70114        break;
    71115      // if it is the same as an already existing keyframe
    72116      else if (this->current->position == position)
    73         return false;
     117      {
     118        this->current->value = value;
     119        delete newKey;
     120        return;
     121      }
    74122      this->current = this->current->next;
    75     }
    76 
    77   QuickKeyFrame* newKey = new QuickKeyFrame;
    78   if (this->first == NULL)
    79     {
    80       this->first = newKey;
    81       this->current = newKey;
    82       newKey->next = NULL;
    83     }
    84   else
    85     {
    86       newKey->next = this->current->next;
    87       this->current->next = newKey;
    88     }
    89   newKey->value = value;
    90   newKey->position = position;
    91 
    92   this->current = this->first;
    93 
    94   return true;
     123    } while (this->current != this->first);
     124
     125    newKey->next = this->current->next;
     126    newKey->prev = this->current;
     127    newKey->next->prev = newKey;
     128    newKey->prev->next = newKey;
     129  }
     130  this->current = this->first;
     131  ++this->count;
    95132}
    96133
     
    100137   \param region a deviation of the existing keyframe (like a delta in witch to search for
    101138   \param value the new Value
    102 */
    103 bool QuickAnimation::changeEntry(float position, float value, float region)
    104 {
    105   this->current = this->first;
    106   while (this->current)
    107     {
    108       if (this->current->position < position+region && this->current->position > position-region)
    109         {
    110           this->current->value = value;
    111           return true;
    112         }
    113       this->current = this->current->next;
    114     }
    115   this->current = this->first;
     139
     140   \todo rimplement
     141*/
     142void QuickAnimation::changeEntry(float position, float value, float region)
     143{
     144//   this->current = this->first;
     145//   do
     146//   {
     147//     if (this->current->position < position+region && this->current->position > position-region)
     148//     {
     149//       this->current->value = value;
     150//       return;
     151//     }
     152//     this->current = this->current->next;
     153//   }  while (this->current != this->first);
     154//
     155//   this->current = this->first;
    116156
    117157  this->addEntry(position, value);
     
    145185float QuickAnimation::getValue(float position)
    146186{
    147   if (unlikely(this->first == NULL))
    148     return 0.0;
    149   else if (unlikely (this->first->next == NULL))
    150     return this->first->value;
    151   else
     187  int counter = 0;
     188  while (true)
     189  {
     190    counter++;
     191    if (counter >= 10)
    152192    {
    153       if (unlikely(position < this->current->position))
    154         {
    155           if (position <= this->first->position)
    156             return this->first->value;
    157           this->current = this->first;
    158         }
    159       while (likely(this->current->next != NULL && position > this->current->next->position))
    160         this->current = this->current->next;
    161       if (this->current->next == NULL)
    162         return this->current->value;
    163 
     193      printf("FUCK!!! %f\n", position);
     194      this->debug();
     195      break;
     196
     197    }
     198    // if we have a match
     199    if (likely(this->current->position <= position && this->current->next->position >= position))
    164200      return this->current->value + (this->current->next->value - this->current->value)
    165         * ((position-this->current->position) / (this->current->next->position -this->current->position));
    166     }
     201          * ((position-this->current->position) / (this->current->next->position -this->current->position));
     202
     203    else if (unlikely(this->first->prev->position < position))
     204      return this->first->prev->value;
     205    else if (unlikely(this->first->position > position))
     206      return this->first->value;
     207    else if(likely(this->current->next->position < position))
     208      this->current = this->current->next;
     209    else if (likely(this->current->position > position))
     210      this->current = this->current->prev;
     211  }
    167212}
    168213
     
    174219  this->current = this->first;
    175220
    176   PRINT(0)("QuickAnim:: (position, value)");
    177   while(this->current)
     221  PRINT(0)("QuickAnim(entries:%d)::(position, value)", this->count);
     222  do
    178223    {
    179224      PRINT(0)("->(%f, %f)", this->current->position, this->current->value);
    180225      this->current = this->current->next;
    181     }
     226    } while(this->current != this->first);
    182227
    183228  PRINT(0)("\n");
  • orxonox/trunk/src/lib/particles/quick_animation.h

    r4597 r4654  
    2121   this class is optimized for a raising value. eg. 100 particles sorted
    2222   by age.
    23   \todo speedUP this stuff (especially getValue)
    2423*/
    2524class QuickAnimation : public BaseObject {
     
    3433
    3534    QuickKeyFrame*   next;              //!< The next Animation
     35    QuickKeyFrame*   prev;              //!< The previous QuickKeyFrame
    3636  };
    3737
     
    3939  virtual ~QuickAnimation();
    4040
    41   bool addEntry(float position, float value);
    42   bool changeEntry(float position, float value, float region = .04);
     41  void addEntry(float position, float value);
     42  void changeEntry(float position, float value, float region = .04);
    4343
    4444  /** \todo implemente thos functions
     
    5252
    5353 private:
    54   QuickKeyFrame*       first;          //!< The first KeyFrame in a Sequence of Keyframes
    55   QuickKeyFrame*       current;        //!< The currently selected KeyFrame
     54  QuickKeyFrame*       first;          //!< The first KeyFrame in a Sequence of Keyframes.
     55  QuickKeyFrame*       current;        //!< The currently selected KeyFrame.
     56  unsigned int         count;          //!< How many Keyframes the QuickAnimation has.
    5657};
    5758
Note: See TracChangeset for help on using the changeset viewer.