Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9869 in orxonox.OLD for trunk/src/lib/sound/sound_engine.cc


Ignore:
Timestamp:
Oct 3, 2006, 12:19:30 AM (18 years ago)
Author:
bensch
Message:

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:
1 edited

Legend:

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

    r9235 r9869  
    2121#include "sound_engine.h"
    2222
    23 #include "class_list.h"
    24 
    2523#include "p_node.h"
    26 #include "util/loading/resource_manager.h"
    2724#include "debug.h"
    28 #include "util/preferences.h"
     25#include "parser/preferences/preferences.h"
    2926#include "globals.h"
     27#include "resource_sound_buffer.h"
    3028
    3129namespace OrxSound
    3230{
    33 
     31  ObjectListDefinition(SoundEngine);
    3432  //////////////////
    3533  /* SOUND-ENGINE */
     
    4038  SoundEngine::SoundEngine ()
    4139  {
    42     this->setClassID(CL_SOUND_ENGINE, "SoundEngine");
     40    this->registerObject(this, SoundEngine::_objectList);
    4341    this->setName("SoundEngine");
    4442
    4543    this->listener = NULL;
    46     this->bufferList = NULL;
    47     this->sourceList = NULL;
    4844
    4945    this->device = NULL;
     
    6965  {
    7066    // deleting all the SoundSources
    71     if(this->sourceList != NULL)
    72     {
    73       while (this->sourceList->size() > 0)
    74         delete static_cast<SoundSource*>(this->sourceList->front());
    75     }
     67    while (!SoundSource::objectList().empty())
     68      delete (SoundSource::objectList().front());
    7669
    7770    while(!this->ALSources.empty())
     
    8982
    9083    // deleting all the SoundBuffers
    91     if (this->bufferList != NULL)
    92     {
    93       while(this->bufferList->size() > 0)
    94         ResourceManager::getInstance()->unload(static_cast<SoundBuffer*>(this->bufferList->front()));
    95     }
     84    //    while(!SoundBuffer::objectList().empty())
     85    //ResourceManager::getInstance()->unload(SoundBuffer::objectList().front());
    9686
    9787    // removing openAL from AudioResource
     
    129119  SoundSource* SoundEngine::createSource(const std::string& fileName, PNode* sourceNode)
    130120  {
    131     SoundBuffer* buffer = NULL;
     121    SoundBuffer buffer;
    132122    if (!fileName.empty())
    133123    {
    134       buffer= (SoundBuffer*)ResourceManager::getInstance()->load(fileName, WAV, RP_LEVEL);
    135       if (buffer == NULL)
     124      buffer = ResourceSoundBuffer(fileName);
     125      if (!buffer.loaded())
    136126        PRINTF(2)("Wav-Sound %s could not be loaded onto new Source\n", fileName.c_str());
    137127    }
     
    212202
    213203    // updating all the Sources positions
    214     if (likely(this->sourceList != NULL || (this->sourceList = ClassList::getList(CL_SOUND_SOURCE)) != NULL))
    215     {
    216       std::list<BaseObject*>::const_iterator sourceIT;
    217       SoundSource* source;
    218       for (sourceIT = this->sourceList->begin(); sourceIT != this->sourceList->end(); sourceIT++)
     204    ObjectList<SoundSource>::const_iterator sourceIT;
     205    for (sourceIT = SoundSource::objectList().begin();
     206         sourceIT != SoundSource::objectList().end();
     207         sourceIT++)
     208    {
     209      if ((*sourceIT)->isPlaying())
    219210      {
    220         source = static_cast<SoundSource*>(*sourceIT);
    221         if (source->isPlaying())
     211        int play = 0x000;
     212        alGetSourcei((*sourceIT)->getID(), AL_SOURCE_STATE, &play);
     213        if (DEBUG_LEVEL > 2)
     214          SoundEngine::checkError("SoundEngine::update() Play", __LINE__);
     215        if(play == AL_PLAYING)
    222216        {
    223           int play = 0x000;
    224           alGetSourcei(source->getID(), AL_SOURCE_STATE, &play);
    225           if (DEBUG_LEVEL > 2)
    226             SoundEngine::checkError("SoundEngine::update() Play", __LINE__);
    227           if(play == AL_PLAYING)
     217          if (likely((*sourceIT)->getNode() != NULL))
    228218          {
    229             if (likely(source->getNode() != NULL))
    230             {
    231               alSource3f(source->getID(), AL_POSITION,
    232                          source->getNode()->getAbsCoor().x,
    233                          source->getNode()->getAbsCoor().y,
    234                          source->getNode()->getAbsCoor().z);
    235               if (DEBUG_LEVEL > 2)
    236                 SoundEngine::checkError("SoundEngine::update() Set Source Position", __LINE__);
    237               alSource3f(source->getID(), AL_VELOCITY,
    238                          source->getNode()->getVelocity().x,
    239                          source->getNode()->getVelocity().y,
    240                          source->getNode()->getVelocity().z);
    241               if (DEBUG_LEVEL > 2)
    242                 SoundEngine::checkError("SoundEngine::update() Set Source Velocity", __LINE__);
    243             }
     219            alSource3f((*sourceIT)->getID(), AL_POSITION,
     220                       (*sourceIT)->getNode()->getAbsCoor().x,
     221                       (*sourceIT)->getNode()->getAbsCoor().y,
     222                       (*sourceIT)->getNode()->getAbsCoor().z);
     223            if (DEBUG_LEVEL > 2)
     224              SoundEngine::checkError("SoundEngine::update() Set Source Position", __LINE__);
     225            alSource3f((*sourceIT)->getID(), AL_VELOCITY,
     226                       (*sourceIT)->getNode()->getVelocity().x,
     227                       (*sourceIT)->getNode()->getVelocity().y,
     228                       (*sourceIT)->getNode()->getVelocity().z);
     229            if (DEBUG_LEVEL > 2)
     230              SoundEngine::checkError("SoundEngine::update() Set Source Velocity", __LINE__);
    244231          }
    245           else
    246           {
    247             source->stop();
    248           }
     232        }
     233        else
     234        {
     235          (*sourceIT)->stop();
    249236        }
    250237      }
     
    393380      default:
    394381      case AL_NO_ERROR:
    395         return ("AL_NO_ERROR");
     382      return ("AL_NO_ERROR");
    396383      case AL_INVALID_NAME:
    397         return ("AL_INVALID_NAME");
     384      return ("AL_INVALID_NAME");
    398385      case AL_INVALID_ENUM:
    399         return ("AL_INVALID_ENUM");
     386      return ("AL_INVALID_ENUM");
    400387      case AL_INVALID_VALUE:
    401         return ("AL_INVALID_VALUE");
     388      return ("AL_INVALID_VALUE");
    402389      case AL_INVALID_OPERATION:
    403         return ("AL_INVALID_OPERATION");
     390      return ("AL_INVALID_OPERATION");
    404391      case AL_OUT_OF_MEMORY:
    405         return ("AL_OUT_OF_MEMORY");
     392      return ("AL_OUT_OF_MEMORY");
    406393    };
    407394  }
     
    414401      default:
    415402      case ALC_NO_ERROR:
    416         return ("AL_NO_ERROR");
     403      return ("AL_NO_ERROR");
    417404      case ALC_INVALID_DEVICE:
    418         return ("ALC_INVALID_DEVICE");
     405      return ("ALC_INVALID_DEVICE");
    419406      case ALC_INVALID_CONTEXT:
    420         return("ALC_INVALID_CONTEXT");
     407      return("ALC_INVALID_CONTEXT");
    421408      case ALC_INVALID_ENUM:
    422         return("ALC_INVALID_ENUM");
     409      return("ALC_INVALID_ENUM");
    423410      case ALC_INVALID_VALUE:
    424         return ("ALC_INVALID_VALUE");
     411      return ("ALC_INVALID_VALUE");
    425412      case ALC_OUT_OF_MEMORY:
    426         return("ALC_OUT_OF_MEMORY");
     413      return("ALC_OUT_OF_MEMORY");
    427414    };
    428415  }
Note: See TracChangeset for help on using the changeset viewer.