Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4960 in orxonox.OLD for orxonox/trunk/src/lib/sound


Ignore:
Timestamp:
Jul 27, 2005, 6:27:03 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: the SoundEngine now gets the SoundBuffer- and SoundSource - Lists directly from the ClassList, and therefor we have much less overhead in the process of alocating deleting them (/2)

Location:
orxonox/trunk/src/lib/sound
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/lib/sound/sound_engine.cc

    r4959 r4960  
    2222
    2323//#include <AL/alc.h> // maybe later
     24#include "class_list.h"
    2425
    2526#include "p_node.h"
     
    8182SoundBuffer::~SoundBuffer()
    8283{
    83   SoundEngine::getInstance()->removeBuffer(this);
     84//  SoundEngine::getInstance()->removeBuffer(this);
    8485  alDeleteBuffers(1, &this->bufferID);
    8586}
     
    118119SoundSource::~SoundSource()
    119120{
    120   SoundEngine::getInstance()->removeSource(this);
     121  //SoundEngine::getInstance()->removeSource(this);
    121122  alDeleteSources(1, &this->sourceID);
    122123}
     
    192193
    193194  this->listener = NULL;
    194   this->bufferList = new tList<SoundBuffer>;
    195   this->sourceList = new tList<SoundSource>;
     195  this->bufferList = NULL;
     196  this->sourceList = NULL;
    196197}
    197198
     
    210211
    211212  // deleting all the SoundSources
    212   tIterator<SoundSource>* sourceIterator = this->sourceList->getIterator();
    213   SoundSource* enumSource = sourceIterator->nextElement();
    214   while (enumSource)
    215     {
    216       delete enumSource;
    217       enumSource = sourceIterator->nextElement();
    218     }
    219   delete sourceIterator;
     213  if(this->sourceList != NULL)
     214  {
     215    tIterator<BaseObject>* sourceIterator = this->sourceList->getIterator();
     216    SoundSource* enumSource = (SoundSource*)sourceIterator->nextElement();
     217    while (enumSource)
     218    {
     219        delete enumSource;
     220        enumSource = (SoundSource*)sourceIterator->nextElement();
     221    }
     222    delete sourceIterator;
     223  }
    220224
    221225  // deleting all the SoundBuffers
    222   tIterator<SoundBuffer>* bufferIterator = this->bufferList->getIterator();
    223   SoundBuffer* enumBuffer = bufferIterator->nextElement();
    224   while (enumBuffer)
     226  if (this->bufferList != NULL)
     227  {
     228    tIterator<BaseObject>* bufferIterator = this->bufferList->getIterator();
     229    SoundBuffer* enumBuffer = (SoundBuffer*)bufferIterator->nextElement();
     230    while (enumBuffer)
    225231    {
    226232      ResourceManager::getInstance()->unload(enumBuffer);
    227       enumBuffer = bufferIterator->nextElement();
    228     }
    229   delete bufferIterator;
    230 
     233      enumBuffer = (SoundBuffer*)bufferIterator->nextElement();
     234    }
     235    delete bufferIterator;
     236  }
    231237  // removing openAL from AudioResource
    232238  alutExit();
     
    273279void SoundEngine::addBuffer(SoundBuffer* buffer)
    274280{
    275   this->bufferList->add(buffer);
     281  if (unlikely(this->bufferList == NULL))
     282    this->bufferList = ClassList::getList(CL_SOUND_BUFFER);
    276283}
    277284
     
    283290{
    284291  // look if there are any sources that have the buffer still loaded
    285   tIterator<SoundSource>* sourceIterator = this->sourceList->getIterator();
    286   SoundSource* enumSource = sourceIterator->nextElement();
     292  tIterator<BaseObject>* sourceIterator = this->sourceList->getIterator();
     293  SoundSource* enumSource = (SoundSource*)sourceIterator->nextElement();
    287294  while (enumSource)
    288295    {
    289296      if (buffer == enumSource->getBuffer())
    290297        delete enumSource;
    291       enumSource = sourceIterator->nextElement();
     298      enumSource = (SoundSource*)sourceIterator->nextElement();
    292299    }
    293300  delete sourceIterator;
    294 
    295   // remove the Buffer
    296   this->bufferList->remove(buffer);
    297301}
    298302
     
    303307void SoundEngine::addSource(SoundSource* source)
    304308{
    305   this->sourceList->add(source);
    306 }
    307 
    308 /**
    309  *  removes a SoundSource from the sourceList of the SoundEngine
    310  * @param source The source to delete from the SoundEngine
    311 */
    312 void SoundEngine::removeSource(SoundSource* source)
    313 {
    314   this->sourceList->remove(source);
    315 }
    316 
     309  this->sourceList = ClassList::getList(CL_SOUND_SOURCE);
     310}
    317311
    318312/**
     
    341335
    342336  // updating all the Sources positions
    343   tIterator<SoundSource>* iterator = this->sourceList->getIterator();
    344   SoundSource* enumSource = iterator->nextElement();
    345   while (enumSource)
     337  if (likely(this->sourceList != NULL))
     338  {
     339    tIterator<BaseObject>* iterator = this->sourceList->getIterator();
     340    SoundSource* enumSource = (SoundSource*)iterator->nextElement();
     341    while (enumSource)
    346342    {
    347343      if (likely(enumSource->getNode()!=NULL))
     
    356352                   enumSource->getNode()->getVelocity().z);
    357353      }
    358       enumSource = iterator->nextElement();
    359     }
    360   delete iterator;
     354      enumSource = (SoundSource*)iterator->nextElement();
     355    }
     356    delete iterator;
     357  }
    361358}
    362359
     
    366363void SoundEngine::flushUnusedBuffers()
    367364{
    368   tIterator<SoundBuffer>* bufferIterator = this->bufferList->getIterator();
    369   SoundBuffer* enumBuffer = bufferIterator->nextElement();
    370   while (enumBuffer)
    371     {
    372       tIterator<SoundSource>* sourceIterator = this->sourceList->getIterator();
    373       SoundSource* enumSource = sourceIterator->nextElement();
     365  if(this->sourceList && this->bufferList)
     366  {
     367    tIterator<BaseObject>* bufferIterator = this->bufferList->getIterator();
     368    SoundBuffer* enumBuffer = (SoundBuffer*)bufferIterator->nextElement();
     369    while (enumBuffer)
     370    {
     371      tIterator<BaseObject>* sourceIterator = this->sourceList->getIterator();
     372      SoundSource* enumSource = (SoundSource*)sourceIterator->nextElement();
    374373      while (enumSource)
    375         {
    376           if (enumBuffer == enumSource->getBuffer())
    377             break;
    378           enumSource = sourceIterator->nextElement();
    379         }
     374      {
     375        if (enumBuffer == enumSource->getBuffer())
     376          break;
     377        enumSource = (SoundSource*)sourceIterator->nextElement();
     378      }
    380379      delete sourceIterator;
    381380      if (enumSource == NULL)
    382381        ResourceManager::getInstance()->unload(enumBuffer);
    383       enumBuffer = bufferIterator->nextElement();
    384     }
    385   delete bufferIterator;
     382      enumBuffer = (SoundBuffer*)bufferIterator->nextElement();
     383    }
     384    delete bufferIterator;
     385  }
    386386}
    387387
     
    391391void SoundEngine::flushAllBuffers()
    392392{
    393   tIterator<SoundBuffer>* bufferIterator = this->bufferList->getIterator();
    394   SoundBuffer* enumBuffer = bufferIterator->nextElement();
    395   while (enumBuffer)
     393  if (this->bufferList)
     394  {
     395    tIterator<BaseObject>* bufferIterator = this->bufferList->getIterator();
     396    SoundBuffer* enumBuffer = (SoundBuffer*)bufferIterator->nextElement();
     397    while (enumBuffer)
    396398    {
    397399      ResourceManager::getInstance()->unload(enumBuffer, RP_LEVEL);
    398       enumBuffer = bufferIterator->nextElement();
    399     }
    400   delete bufferIterator;
     400      enumBuffer = (SoundBuffer*)bufferIterator->nextElement();
     401    }
     402    delete bufferIterator;
     403  }
    401404}
    402405
     
    406409void SoundEngine::flushAllSources()
    407410{
    408   tIterator<SoundSource>* Iterator = this->sourceList->getIterator();
    409   SoundSource* enumSource = Iterator->nextElement();
    410   while (enumSource)
     411  if (this->sourceList)
    411412  {
    412     delete enumSource;
    413     enumSource = Iterator->nextElement();
     413    tIterator<BaseObject>* Iterator = this->sourceList->getIterator();
     414    SoundSource* enumSource = (SoundSource*)Iterator->nextElement();
     415    while (enumSource)
     416    {
     417      delete enumSource;
     418      enumSource = (SoundSource*)Iterator->nextElement();
     419    }
     420    delete Iterator;
    414421  }
    415   delete Iterator;
    416 }
    417 
     422}
    418423
    419424/**
  • orxonox/trunk/src/lib/sound/sound_engine.h

    r4959 r4960  
    99#include "base_object.h"
    1010#include "alincl.h"
    11 
    1211
    1312#define SOUND_DOPPLER_FACTOR       0.001          //!< A factor for the audible doppler effect
     
    8584    void removeBuffer(SoundBuffer* buffer);
    8685    void addSource(SoundSource* source);
    87     void removeSource(SoundSource* source);
    8886
    8987    void update();
     
    109107
    110108    PNode*                   listener;                 //!< The listener of the Scene
    111     tList<SoundBuffer>*      bufferList;               //!< A list of buffers
    112     tList<SoundSource>*      sourceList;               //!< A list for all the sources in the scene.
     109    tList<BaseObject>*       bufferList;               //!< A list of buffers
     110    tList<BaseObject>*       sourceList;               //!< A list for all the sources in the scene.
    113111
    114112};
Note: See TracChangeset for help on using the changeset viewer.