[Orxonox-commit 1157] r5878 - in code/branches/core5/src: libraries/core orxonox/gamestates orxonox/sound
rgrieder at orxonox.net
rgrieder at orxonox.net
Mon Oct 5 01:36:34 CEST 2009
Author: rgrieder
Date: 2009-10-05 01:36:33 +0200 (Mon, 05 Oct 2009)
New Revision: 5878
Modified:
code/branches/core5/src/libraries/core/GameMode.cc
code/branches/core5/src/libraries/core/GameMode.h
code/branches/core5/src/orxonox/gamestates/GSMainMenu.cc
code/branches/core5/src/orxonox/sound/SoundManager.cc
Log:
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.
Modified: code/branches/core5/src/libraries/core/GameMode.cc
===================================================================
--- code/branches/core5/src/libraries/core/GameMode.cc 2009-10-04 23:34:10 UTC (rev 5877)
+++ code/branches/core5/src/libraries/core/GameMode.cc 2009-10-04 23:36:33 UTC (rev 5878)
@@ -26,16 +26,12 @@
*
*/
-/**
- @file
- @brief Implementation of the GameMode class.
-*/
-
#include "GameMode.h"
namespace orxonox
{
bool GameMode::bShowsGraphics_s = false;
+ bool GameMode::bPlaysSound_s = false;
bool GameMode::bHasServer_s = false;
bool GameMode::bIsClient_s = false;
bool GameMode::bIsStandalone_s = false;
Modified: code/branches/core5/src/libraries/core/GameMode.h
===================================================================
--- code/branches/core5/src/libraries/core/GameMode.h 2009-10-04 23:34:10 UTC (rev 5877)
+++ code/branches/core5/src/libraries/core/GameMode.h 2009-10-04 23:36:33 UTC (rev 5878)
@@ -44,11 +44,13 @@
public:
static bool showsGraphics() { return bShowsGraphics_s; }
+ static bool playsSound() { return bPlaysSound_s; }
static bool hasServer() { return bHasServer_s; }
static bool isClient() { return bIsClient_s; }
static bool isStandalone() { return bIsStandalone_s; }
static bool isMaster() { return bIsMaster_s; }
+ static void setPlaysSound (bool val) { bPlaysSound_s = val; }
static void setHasServer (bool val) { bHasServer_s = val; updateIsMaster(); }
static void setIsClient (bool val) { bIsClient_s = val; updateIsMaster(); }
static void setIsStandalone (bool val) { bIsStandalone_s = val; updateIsMaster(); }
@@ -64,6 +66,7 @@
}
static bool bShowsGraphics_s; //!< global variable that tells whether to show graphics
+ static bool bPlaysSound_s; //!< global variable that tells whether to sound works
static bool bHasServer_s; //!< global variable that tells whether this is a server
static bool bIsClient_s;
static bool bIsStandalone_s;
Modified: code/branches/core5/src/orxonox/gamestates/GSMainMenu.cc
===================================================================
--- code/branches/core5/src/orxonox/gamestates/GSMainMenu.cc 2009-10-04 23:34:10 UTC (rev 5877)
+++ code/branches/core5/src/orxonox/gamestates/GSMainMenu.cc 2009-10-04 23:36:33 UTC (rev 5878)
@@ -58,12 +58,20 @@
this->scene_ = new Scene(NULL);
// and a Camera
this->camera_ = this->scene_->getSceneManager()->createCamera("mainMenu/Camera");
- // Load sound
- this->ambient_ = new SoundMainMenu();
+ if (GameMode::playsSound())
+ {
+ // Load sound
+ this->ambient_ = new SoundMainMenu();
+ }
}
GSMainMenu::~GSMainMenu()
{
+ if (GameMode::playsSound())
+ {
+ this->ambient_->destroy();
+ }
+
InputManager::getInstance().destroyState("mainMenu");
this->scene_->getSceneManager()->destroyCamera(this->camera_);
@@ -86,12 +94,18 @@
KeyBinderManager::getInstance().setToDefault();
InputManager::getInstance().enterState("mainMenu");
- this->ambient_->play(true);
+ if (GameMode::playsSound())
+ {
+ this->ambient_->play(true);
+ }
}
void GSMainMenu::deactivate()
{
- this->ambient_->stop();
+ if (GameMode::playsSound())
+ {
+ this->ambient_->stop();
+ }
InputManager::getInstance().leaveState("mainMenu");
Modified: code/branches/core5/src/orxonox/sound/SoundManager.cc
===================================================================
--- code/branches/core5/src/orxonox/sound/SoundManager.cc 2009-10-04 23:34:10 UTC (rev 5877)
+++ code/branches/core5/src/orxonox/sound/SoundManager.cc 2009-10-04 23:36:33 UTC (rev 5878)
@@ -30,7 +30,10 @@
#include <AL/alut.h>
+#include "util/Exception.h"
#include "util/Math.h"
+#include "util/ScopeGuard.h"
+#include "core/GameMode.h"
#include "core/ScopedSingletonManager.h"
#include "CameraManager.h"
#include "graphics/Camera.h"
@@ -41,56 +44,46 @@
SoundManager* SoundManager::singletonPtr_s = NULL;
ManageScopedSingleton(SoundManager, ScopeID::Graphics, true);
- /**
- * Default constructor
- */
SoundManager::SoundManager()
{
- this->device_ = NULL;
- this->soundavailable_ = true;
- if(!alutInitWithoutContext(NULL,NULL))
- {
- COUT(2) << "Sound: OpenAL ALUT: " << alutGetErrorString(alutGetError()) << std::endl;
- this->soundavailable_ = false;
- }
- else
- {
- assert(this->device_ == NULL);
- COUT(3) << "Sound: OpenAL: Open sound device..." << std::endl;
- this->device_ = alcOpenDevice(NULL);
+ if (!alutInitWithoutContext(NULL,NULL))
+ ThrowException(InitialisationFailed, "OpenAL ALUT error: " << alutGetErrorString(alutGetError()));
+ Loki::ScopeGuard alutExitGuard = Loki::MakeGuard(&alutExit);
- if(this->device_ == NULL)
- {
- COUT(2) << "Sound: OpenAL: Could not open sound device" << std::endl;
- this->soundavailable_ = false;
- }
- else
- {
- COUT(3) << "Sound: OpenAL: Sound device opened" << std::endl;
- this->context_ = alcCreateContext(this->device_, NULL);
- if(this->context_ == NULL)
- {
- COUT(2) << "Sound: OpenAL: Could not create sound context" << std::endl;
- this->soundavailable_ = false;
- }
- else
- {
- if(alcMakeContextCurrent(this->context_) == AL_TRUE)
- COUT(3) << "Sound: OpenAL: Context " << this->context_ << " loaded" << std::endl;
+ COUT(3) << "OpenAL: Opening sound device..." << std::endl;
+ this->device_ = alcOpenDevice(NULL);
+ if (this->device_ == NULL)
+ ThrowException(InitialisationFailed, "OpenAL error: Could not open sound device.");
+ Loki::ScopeGuard closeDeviceGuard = Loki::MakeGuard(&alcCloseDevice, this->device_);
- COUT(4) << "Sound: OpenAL ALUT version: " << alutGetMajorVersion() << "." << alutGetMinorVersion() << std::endl;
- const char* str = alutGetMIMETypes(ALUT_LOADER_BUFFER);
- if (str == NULL)
- COUT(2) << "Sound: OpenAL ALUT: " << alutGetErrorString(alutGetError()) << std::endl;
- else
- COUT(4) << "Sound: OpenAL ALUT supported MIME types: " << str << std::endl;
- }
- }
- }
+ COUT(3) << "OpenAL: Sound device opened" << std::endl;
+ this->context_ = alcCreateContext(this->device_, NULL);
+ if (this->context_ == NULL)
+ ThrowException(InitialisationFailed, "OpenAL error: Could not create sound context");
+ Loki::ScopeGuard desroyContextGuard = Loki::MakeGuard(&alcDestroyContext, this->context_);
+
+ if (alcMakeContextCurrent(this->context_) == AL_TRUE)
+ COUT(3) << "OpenAL: Context " << this->context_ << " loaded" << std::endl;
+
+ COUT(4) << "Sound: OpenAL ALUT version: " << alutGetMajorVersion() << "." << alutGetMinorVersion() << std::endl;
+
+ const char* str = alutGetMIMETypes(ALUT_LOADER_BUFFER);
+ if (str == NULL)
+ COUT(2) << "OpenAL ALUT error: " << alutGetErrorString(alutGetError()) << std::endl;
+ else
+ COUT(4) << "OpenAL ALUT supported MIME types: " << str << std::endl;
+ ThrowException(InitialisationFailed, "Just testing");
+
+ GameMode::setPlaysSound(true);
+ // Disarm guards
+ alutExitGuard.Dismiss();
+ closeDeviceGuard.Dismiss();
+ desroyContextGuard.Dismiss();
}
SoundManager::~SoundManager()
{
+ GameMode::setPlaysSound(false);
alcDestroyContext(this->context_);
alcCloseDevice(this->device_);
alutExit();
More information about the Orxonox-commit
mailing list