Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 15, 2009, 11:45:29 PM (15 years ago)
Author:
rgrieder
Message:

Converted SoundManager into a more suitable singleton.

Location:
code/branches/pch/src/orxonox/sound
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/pch/src/orxonox/sound/SoundBase.cc

    r3157 r3184  
    4141namespace orxonox
    4242{
    43     SoundManager* SoundBase::soundmanager_s = NULL;
    44 
    4543    SoundBase::SoundBase(WorldEntity* entity)
    4644    {
    47         if(SoundBase::soundmanager_s == NULL)
    48         {
    49             SoundBase::soundmanager_s = new SoundManager();
    50         }
    51 
    5245        this->source_ = 0;
    5346        this->buffer_ = 0;
    5447        this->entity_ = entity;
    5548
    56         SoundBase::soundmanager_s->addSound(this);
     49        SoundManager::getInstance().addSound(this);
    5750    }
    5851
     
    144137        filename = Core::getMediaPathString() + "/audio/" + filename;
    145138
    146         if(!SoundBase::soundmanager_s->isSoundAvailable())
     139        if(!SoundManager::getInstance().isSoundAvailable())
    147140        {
    148141            COUT(3) << "Sound: not available, skipping " << filename << std::endl;
  • code/branches/pch/src/orxonox/sound/SoundBase.h

    r3167 r3184  
    6464
    6565        ALint getSourceState();
    66 
    67         static SoundManager* soundmanager_s;
    6866    }; // class SoundBase
    6967} // namepsace orxonox
  • code/branches/pch/src/orxonox/sound/SoundManager.cc

    r3133 r3184  
    3838namespace orxonox
    3939{
     40    SoundManager* SoundManager::singletonRef_s = NULL;
    4041    ALCdevice* SoundManager::device_s = NULL;
    4142
     
    4546    SoundManager::SoundManager()
    4647    {
     48        assert(singletonRef_s == NULL);
     49        singletonRef_s = this;
     50
    4751        this->soundavailable_ = true;
    4852        if(!alutInitWithoutContext(NULL,NULL))
     
    9195    SoundManager::~SoundManager()
    9296    {
     97        assert(singletonRef_s != NULL);
     98        singletonRef_s = NULL;
     99
    93100        alcDestroyContext(this->context_);
    94101        alcCloseDevice(SoundManager::device_s);
  • code/branches/pch/src/orxonox/sound/SoundManager.h

    r3177 r3184  
    3030#include "OrxonoxPrereqs.h"
    3131
     32#include <cassert>
    3233#include <list>
    3334#include "interfaces/Tickable.h"
     
    5152        bool isSoundAvailable();
    5253
     54        static SoundManager& getInstance() { assert(singletonRef_s); return *singletonRef_s; }
     55
    5356    private:
    5457        static ALCdevice* device_s;
     
    5760        bool soundavailable_;
    5861
     62        static SoundManager* singletonRef_s;
    5963    }; // class SoundManager
    6064} // namespace orxonox
Note: See TracChangeset for help on using the changeset viewer.