Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5878


Ignore:
Timestamp:
Oct 5, 2009, 1:36:33 AM (15 years ago)
Author:
rgrieder
Message:

Added GameMode::playsSound(). This function checks whether sound is available. You MUST NEVER assume that the SoundManager exists and ALWAYS check it (even if graphics is all loaded).
Also cleaned SoundManager c'tor to use Exceptions.

Location:
code/branches/core5/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core5/src/libraries/core/GameMode.cc

    r5738 r5878  
    2727 */
    2828
    29 /**
    30     @file
    31     @brief Implementation of the GameMode class.
    32 */
    33 
    3429#include "GameMode.h"
    3530
     
    3732{
    3833    bool GameMode::bShowsGraphics_s = false;
     34    bool GameMode::bPlaysSound_s    = false;
    3935    bool GameMode::bHasServer_s     = false;
    4036    bool GameMode::bIsClient_s      = false;
  • code/branches/core5/src/libraries/core/GameMode.h

    r5875 r5878  
    4545        public:
    4646            static bool showsGraphics() { return bShowsGraphics_s; }
     47            static bool playsSound()    { return bPlaysSound_s; }
    4748            static bool hasServer()     { return bHasServer_s; }
    4849            static bool isClient()      { return bIsClient_s; }
     
    5051            static bool isMaster()      { return bIsMaster_s; }
    5152
     53            static void setPlaysSound   (bool val) { bPlaysSound_s    = val; }
    5254            static void setHasServer    (bool val) { bHasServer_s     = val; updateIsMaster(); }
    5355            static void setIsClient     (bool val) { bIsClient_s      = val; updateIsMaster(); }
     
    6567
    6668            static bool bShowsGraphics_s;                   //!< global variable that tells whether to show graphics
     69            static bool bPlaysSound_s;                      //!< global variable that tells whether to sound works
    6770            static bool bHasServer_s;                       //!< global variable that tells whether this is a server
    6871            static bool bIsClient_s;
  • code/branches/core5/src/orxonox/gamestates/GSMainMenu.cc

    r5876 r5878  
    5959        // and a Camera
    6060        this->camera_ = this->scene_->getSceneManager()->createCamera("mainMenu/Camera");
    61         // Load sound
    62         this->ambient_ = new SoundMainMenu();
     61        if (GameMode::playsSound())
     62        {
     63            // Load sound
     64            this->ambient_ = new SoundMainMenu();
     65        }
    6366    }
    6467
    6568    GSMainMenu::~GSMainMenu()
    6669    {
     70        if (GameMode::playsSound())
     71        {
     72            this->ambient_->destroy();
     73        }
     74
    6775        InputManager::getInstance().destroyState("mainMenu");
    6876
     
    8795        InputManager::getInstance().enterState("mainMenu");
    8896
    89         this->ambient_->play(true);
     97        if (GameMode::playsSound())
     98        {
     99            this->ambient_->play(true);
     100        }
    90101    }
    91102
    92103    void GSMainMenu::deactivate()
    93104    {
    94         this->ambient_->stop();
     105        if (GameMode::playsSound())
     106        {
     107            this->ambient_->stop();
     108        }
    95109
    96110        InputManager::getInstance().leaveState("mainMenu");
  • code/branches/core5/src/orxonox/sound/SoundManager.cc

    r5877 r5878  
    3131#include <AL/alut.h>
    3232
     33#include "util/Exception.h"
    3334#include "util/Math.h"
     35#include "util/ScopeGuard.h"
     36#include "core/GameMode.h"
    3437#include "core/ScopedSingletonManager.h"
    3538#include "CameraManager.h"
     
    4245    ManageScopedSingleton(SoundManager, ScopeID::Graphics, true);
    4346
    44     /**
    45      * Default constructor
    46      */
    4747    SoundManager::SoundManager()
    4848    {
    49         this->device_ = NULL;
    50         this->soundavailable_ = true;
    51         if(!alutInitWithoutContext(NULL,NULL))
    52         {
    53             COUT(2) << "Sound: OpenAL ALUT: " << alutGetErrorString(alutGetError()) << std::endl;
    54             this->soundavailable_ = false;
    55         }
     49        if (!alutInitWithoutContext(NULL,NULL))
     50            ThrowException(InitialisationFailed, "OpenAL ALUT error: " << alutGetErrorString(alutGetError()));
     51        Loki::ScopeGuard alutExitGuard = Loki::MakeGuard(&alutExit);
     52
     53        COUT(3) << "OpenAL: Opening sound device..." << std::endl;
     54        this->device_ = alcOpenDevice(NULL);
     55        if (this->device_ == NULL)
     56            ThrowException(InitialisationFailed, "OpenAL error: Could not open sound device.");
     57        Loki::ScopeGuard closeDeviceGuard = Loki::MakeGuard(&alcCloseDevice, this->device_);
     58
     59        COUT(3) << "OpenAL: Sound device opened" << std::endl;
     60        this->context_ = alcCreateContext(this->device_, NULL);
     61        if (this->context_ == NULL)
     62            ThrowException(InitialisationFailed, "OpenAL error: Could not create sound context");
     63        Loki::ScopeGuard desroyContextGuard = Loki::MakeGuard(&alcDestroyContext, this->context_);
     64
     65        if (alcMakeContextCurrent(this->context_) == AL_TRUE)
     66            COUT(3) << "OpenAL: Context " << this->context_ << " loaded" << std::endl;
     67
     68        COUT(4) << "Sound: OpenAL ALUT version: " << alutGetMajorVersion() << "." << alutGetMinorVersion() << std::endl;
     69
     70        const char* str = alutGetMIMETypes(ALUT_LOADER_BUFFER);
     71        if (str == NULL)
     72            COUT(2) << "OpenAL ALUT error: " << alutGetErrorString(alutGetError()) << std::endl;
    5673        else
    57         {
    58             assert(this->device_ == NULL);
    59             COUT(3) << "Sound: OpenAL: Open sound device..." << std::endl;
    60             this->device_ = alcOpenDevice(NULL);
     74            COUT(4) << "OpenAL ALUT supported MIME types: " << str << std::endl;
     75        ThrowException(InitialisationFailed, "Just testing");
    6176
    62             if(this->device_ == NULL)
    63             {
    64                 COUT(2) << "Sound: OpenAL: Could not open sound device" << std::endl;
    65                 this->soundavailable_ = false;
    66             }
    67             else
    68             {
    69                 COUT(3) << "Sound: OpenAL: Sound device opened" << std::endl;
    70                 this->context_ = alcCreateContext(this->device_, NULL);
    71                 if(this->context_ == NULL)
    72                 {
    73                     COUT(2) << "Sound: OpenAL: Could not create sound context" << std::endl;
    74                     this->soundavailable_ = false;
    75                 }
    76                 else
    77                 {
    78                     if(alcMakeContextCurrent(this->context_) == AL_TRUE)
    79                         COUT(3) << "Sound: OpenAL: Context " << this->context_ << " loaded" << std::endl;
    80 
    81                     COUT(4) << "Sound: OpenAL ALUT version: " << alutGetMajorVersion() << "." << alutGetMinorVersion() << std::endl;
    82                     const char* str = alutGetMIMETypes(ALUT_LOADER_BUFFER);
    83                     if (str == NULL)
    84                         COUT(2) << "Sound: OpenAL ALUT: " << alutGetErrorString(alutGetError()) << std::endl;
    85                     else
    86                         COUT(4) << "Sound: OpenAL ALUT supported MIME types: " << str << std::endl;
    87                 }
    88             }
    89         }
     77        GameMode::setPlaysSound(true);
     78        // Disarm guards
     79        alutExitGuard.Dismiss();
     80        closeDeviceGuard.Dismiss();
     81        desroyContextGuard.Dismiss();
    9082    }
    9183
    9284    SoundManager::~SoundManager()
    9385    {
     86        GameMode::setPlaysSound(false);
    9487        alcDestroyContext(this->context_);
    9588        alcCloseDevice(this->device_);
Note: See TracChangeset for help on using the changeset viewer.