Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 12, 2009, 8:20:07 PM (15 years ago)
Author:
rgrieder
Message:

Merged core5 branch back to the trunk.
Key features include clean level unloading and an extended XML event system.

Two important notes:
Delete your keybindings.ini files! * or you will still get parser errors when loading the key bindings.
Delete build_dir/lib/modules/libgamestates.module! * or orxonox won't start.
Best thing to do is to delete the build folder ;)

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/orxonox/sound/SoundManager.cc

    r5781 r5929  
    3131#include <AL/alut.h>
    3232
     33#include "util/Exception.h"
    3334#include "util/Math.h"
    34 #include "CameraManager.h"
    35 #include "graphics/Camera.h"
    36 #include "SoundBase.h"
     35#include "util/ScopeGuard.h"
     36#include "core/GameMode.h"
     37#include "core/ScopedSingletonManager.h"
    3738
    3839namespace orxonox
    3940{
    4041    SoundManager* SoundManager::singletonPtr_s = NULL;
     42    ManageScopedSingleton(SoundManager, ScopeID::Graphics, true);
    4143
    42     /**
    43      * Default constructor
    44      */
    4544    SoundManager::SoundManager()
    4645    {
    47         this->device_ = NULL;
    48         this->soundavailable_ = true;
    49         if(!alutInitWithoutContext(NULL,NULL))
     46        if (!alutInitWithoutContext(NULL,NULL))
     47            ThrowException(InitialisationFailed, "OpenAL ALUT error: " << alutGetErrorString(alutGetError()));
     48        Loki::ScopeGuard alutExitGuard = Loki::MakeGuard(&alutExit);
     49
     50        COUT(3) << "OpenAL: Opening sound device..." << std::endl;
     51        this->device_ = alcOpenDevice(NULL);
     52        if (this->device_ == NULL)
    5053        {
    51             COUT(2) << "Sound: OpenAL ALUT: " << alutGetErrorString(alutGetError()) << std::endl;
    52             this->soundavailable_ = false;
     54            COUT(0) << "OpenaAL: Could not open sound device. Have you installed OpenAL?" << std::endl;
     55#ifdef ORXONOX_PLATFORM_WINDOWS
     56            COUT(0) << "Just getting the DLL with the dependencies is not enough for Windows (esp. Windows 7)!" << std::endl;
     57#endif
     58            ThrowException(InitialisationFailed, "OpenAL error: Could not open sound device.");
    5359        }
     60        Loki::ScopeGuard closeDeviceGuard = Loki::MakeGuard(&alcCloseDevice, this->device_);
     61
     62        COUT(3) << "OpenAL: Sound device opened" << std::endl;
     63        this->context_ = alcCreateContext(this->device_, NULL);
     64        if (this->context_ == NULL)
     65            ThrowException(InitialisationFailed, "OpenAL error: Could not create sound context");
     66        Loki::ScopeGuard desroyContextGuard = Loki::MakeGuard(&alcDestroyContext, this->context_);
     67
     68        if (alcMakeContextCurrent(this->context_) == AL_TRUE)
     69            COUT(3) << "OpenAL: Context " << this->context_ << " loaded" << std::endl;
     70
     71        COUT(4) << "Sound: OpenAL ALUT version: " << alutGetMajorVersion() << "." << alutGetMinorVersion() << std::endl;
     72
     73        const char* str = alutGetMIMETypes(ALUT_LOADER_BUFFER);
     74        if (str == NULL)
     75            COUT(2) << "OpenAL ALUT error: " << alutGetErrorString(alutGetError()) << std::endl;
    5476        else
    55         {
    56             assert(this->device_ == NULL);
    57             COUT(3) << "Sound: OpenAL: Open sound device..." << std::endl;
    58             this->device_ = alcOpenDevice(NULL);
     77            COUT(4) << "OpenAL ALUT supported MIME types: " << str << std::endl;
    5978
    60             if(this->device_ == NULL)
    61             {
    62                 COUT(2) << "Sound: OpenAL: Could not open sound device" << std::endl;
    63                 this->soundavailable_ = false;
    64             }
    65             else
    66             {
    67                 COUT(3) << "Sound: OpenAL: Sound device opened" << std::endl;
    68                 this->context_ = alcCreateContext(this->device_, NULL);
    69                 if(this->context_ == NULL)
    70                 {
    71                     COUT(2) << "Sound: OpenAL: Could not create sound context" << std::endl;
    72                     this->soundavailable_ = false;
    73                 }
    74                 else
    75                 {
    76                     if(alcMakeContextCurrent(this->context_) == AL_TRUE)
    77                         COUT(3) << "Sound: OpenAL: Context " << this->context_ << " loaded" << std::endl;
    78 
    79                     COUT(4) << "Sound: OpenAL ALUT version: " << alutGetMajorVersion() << "." << alutGetMinorVersion() << std::endl;
    80                     const char* str = alutGetMIMETypes(ALUT_LOADER_BUFFER);
    81                     if (str == NULL)
    82                         COUT(2) << "Sound: OpenAL ALUT: " << alutGetErrorString(alutGetError()) << std::endl;
    83                     else
    84                         COUT(4) << "Sound: OpenAL ALUT supported MIME types: " << str << std::endl;
    85                 }
    86             }
    87         }
     79        GameMode::setPlaysSound(true);
     80        // Disarm guards
     81        alutExitGuard.Dismiss();
     82        closeDeviceGuard.Dismiss();
     83        desroyContextGuard.Dismiss();
    8884    }
    8985
    9086    SoundManager::~SoundManager()
    9187    {
     88        GameMode::setPlaysSound(false);
    9289        alcDestroyContext(this->context_);
    9390        alcCloseDevice(this->device_);
     
    9592    }
    9693
    97     /**
    98      * Add a SoundBase object to the list. Every SoundBase object should be in
    99      * this list.
    100      *
    101      * @param sound Pointer to the SoundBase object to add
    102      */
    103     void SoundManager::addSound(SoundBase* sound)
     94    void SoundManager::setListenerPosition(const Vector3& position)
    10495    {
    105         this->soundlist_.push_back(sound);
     96        alListener3f(AL_POSITION, position.x, position.y, position.z);
     97        ALenum error = alGetError();
     98        if (error == AL_INVALID_VALUE)
     99            COUT(2) << "Sound: OpenAL: Invalid listener position" << std::endl;
    106100    }
    107101
    108     /**
    109      * Remove a SoundBase object from the list and destroy it.
    110      */
    111     void SoundManager::removeSound(SoundBase* sound)
     102    void SoundManager::setListenerOrientation(const Quaternion& orientation)
    112103    {
    113         std::list<SoundBase*>::iterator pos = this->soundlist_.end();
    114         for(std::list<SoundBase*>::iterator i = this->soundlist_.begin(); i != this->soundlist_.end(); i++)
    115         {
    116             if((*i) == sound)
    117                 pos = i;
    118         }
     104        // update listener orientation
     105        Vector3 up = orientation.xAxis(); // just a wild guess
     106        Vector3 at = orientation.zAxis();
    119107
    120         delete (*pos);
    121         this->soundlist_.erase(pos);
    122     }
     108        ALfloat orient[6] = { at.x, at.y, at.z,
     109                              up.x, up.y, up.z };
    123110
    124     /**
    125      * Tick function, updates listener and registred SoundBase objects
    126      *
    127      * @param dt @see Orxonox::Tickable
    128      */
    129     void SoundManager::tick(float dt)
    130     {
    131         if (!CameraManager::getInstancePtr())
    132             return;
    133 
    134         // update listener position
    135         Camera* camera = CameraManager::getInstance().getActiveCamera();
    136         if(camera == NULL) return;
    137         Vector3 pos = camera->getPosition();
    138         alListener3f(AL_POSITION, pos.x, pos.y, pos.z);
     111        alListenerfv(AL_POSITION, orient);
    139112        ALenum error = alGetError();
    140         if(error == AL_INVALID_VALUE)
    141             COUT(2) << "Sound: OpenAL: Invalid listener position" << std::endl;
    142 
    143         // update listener orientation
    144         const Quaternion& orient = camera->getOrientation();
    145         Vector3 up = orient.xAxis(); // just a wild guess
    146         Vector3 at = orient.zAxis();
    147 
    148         ALfloat orientation[6] = { at.x, at.y, at.z,
    149                                  up.x, up.y, up.z };
    150 
    151         alListenerfv(AL_POSITION, orientation);
    152         error = alGetError();
    153         if(error == AL_INVALID_VALUE)
     113        if (error == AL_INVALID_VALUE)
    154114            COUT(2) << "Sound: OpenAL: Invalid listener orientation" << std::endl;
    155 
    156         // update sounds
    157         for(std::list<SoundBase*>::iterator i = this->soundlist_.begin(); i != this->soundlist_.end(); i++)
    158             (*i)->update();
    159     }
    160 
    161     /**
    162     * Check if sound is available
    163     */
    164     bool SoundManager::isSoundAvailable()
    165     {
    166         return this->soundavailable_;
    167115    }
    168116}
Note: See TracChangeset for help on using the changeset viewer.