[Orxonox-commit 652] r3184 - in branches/pch/src/orxonox: gamestates sound

rgrieder at orxonox.net rgrieder at orxonox.net
Mon Jun 15 23:45:29 CEST 2009


Author: rgrieder
Date: 2009-06-15 23:45:29 +0200 (Mon, 15 Jun 2009)
New Revision: 3184

Modified:
   branches/pch/src/orxonox/gamestates/GSGraphics.cc
   branches/pch/src/orxonox/gamestates/GSGraphics.h
   branches/pch/src/orxonox/sound/SoundBase.cc
   branches/pch/src/orxonox/sound/SoundBase.h
   branches/pch/src/orxonox/sound/SoundManager.cc
   branches/pch/src/orxonox/sound/SoundManager.h
Log:
Converted SoundManager into a more suitable singleton.

Modified: branches/pch/src/orxonox/gamestates/GSGraphics.cc
===================================================================
--- branches/pch/src/orxonox/gamestates/GSGraphics.cc	2009-06-15 20:48:12 UTC (rev 3183)
+++ branches/pch/src/orxonox/gamestates/GSGraphics.cc	2009-06-15 21:45:29 UTC (rev 3184)
@@ -51,6 +51,7 @@
 #include "core/XMLFile.h"
 #include "overlays/console/InGameConsole.h"
 #include "gui/GUIManager.h"
+#include "sound/SoundManager.h"
 #include "GraphicsManager.h"
 
 namespace orxonox
@@ -63,6 +64,7 @@
         , console_(0)
         , guiManager_(0)
         , graphicsManager_(0)
+        , soundManager_(0)
         , masterKeyBinder_(0)
         , masterInputState_(0)
         , debugOverlay_(0)
@@ -94,6 +96,7 @@
         \li manages render window
         \li creates input manager
         \li loads master key bindings
+        \li loads the SoundManager
         \li loads ingame console
         \li loads GUI interface (GUIManager)
         \li creates console command to toggle GUI
@@ -128,6 +131,9 @@
         masterKeyBinder_->loadBindings("masterKeybindings.ini");
         masterInputState_->setKeyHandler(masterKeyBinder_);
 
+        // Load the SoundManager
+        soundManager_ = new SoundManager();
+
         // Load the InGameConsole
         console_ = new InGameConsole();
         console_->initialise(renderWindow->getWidth(), renderWindow->getHeight());
@@ -172,6 +178,8 @@
         Loader::unload(this->debugOverlay_);
         delete this->debugOverlay_;
 
+        delete this->soundManager_;
+
         delete this->inputManager_;
         this->inputManager_ = 0;
 

Modified: branches/pch/src/orxonox/gamestates/GSGraphics.h
===================================================================
--- branches/pch/src/orxonox/gamestates/GSGraphics.h	2009-06-15 20:48:12 UTC (rev 3183)
+++ branches/pch/src/orxonox/gamestates/GSGraphics.h	2009-06-15 21:45:29 UTC (rev 3184)
@@ -71,6 +71,7 @@
         InGameConsole*        console_;
         GUIManager*           guiManager_;          //!< Interface to GUI
         GraphicsManager*      graphicsManager_;     //!< Interface to Ogre
+        SoundManager*         soundManager_;        //!< Keeps track of SoundBase objects
 
         KeyBinder*            masterKeyBinder_;     //!< Key binder for master key bindings
         SimpleInputState*     masterInputState_;    //!< Special input state for master input

Modified: branches/pch/src/orxonox/sound/SoundBase.cc
===================================================================
--- branches/pch/src/orxonox/sound/SoundBase.cc	2009-06-15 20:48:12 UTC (rev 3183)
+++ branches/pch/src/orxonox/sound/SoundBase.cc	2009-06-15 21:45:29 UTC (rev 3184)
@@ -40,20 +40,13 @@
 
 namespace orxonox 
 {
-    SoundManager* SoundBase::soundmanager_s = NULL;
-
     SoundBase::SoundBase(WorldEntity* entity)
     {
-        if(SoundBase::soundmanager_s == NULL)
-        {
-            SoundBase::soundmanager_s = new SoundManager();
-        }
-
         this->source_ = 0;
         this->buffer_ = 0;
         this->entity_ = entity;
 
-        SoundBase::soundmanager_s->addSound(this);
+        SoundManager::getInstance().addSound(this);
     }
 
     SoundBase::~SoundBase()
@@ -143,7 +136,7 @@
     bool SoundBase::loadFile(std::string filename) {
         filename = Core::getMediaPathString() + "/audio/" + filename;
 
-        if(!SoundBase::soundmanager_s->isSoundAvailable())
+        if(!SoundManager::getInstance().isSoundAvailable())
         {
             COUT(3) << "Sound: not available, skipping " << filename << std::endl;
             return false;

Modified: branches/pch/src/orxonox/sound/SoundBase.h
===================================================================
--- branches/pch/src/orxonox/sound/SoundBase.h	2009-06-15 20:48:12 UTC (rev 3183)
+++ branches/pch/src/orxonox/sound/SoundBase.h	2009-06-15 21:45:29 UTC (rev 3184)
@@ -63,8 +63,6 @@
         WorldEntity* entity_;
 
         ALint getSourceState();
-
-        static SoundManager* soundmanager_s;
     }; // class SoundBase
 } // namepsace orxonox
 

Modified: branches/pch/src/orxonox/sound/SoundManager.cc
===================================================================
--- branches/pch/src/orxonox/sound/SoundManager.cc	2009-06-15 20:48:12 UTC (rev 3183)
+++ branches/pch/src/orxonox/sound/SoundManager.cc	2009-06-15 21:45:29 UTC (rev 3184)
@@ -37,6 +37,7 @@
 
 namespace orxonox
 {
+    SoundManager* SoundManager::singletonRef_s = NULL;
     ALCdevice* SoundManager::device_s = NULL;
 
     /**
@@ -44,6 +45,9 @@
      */
     SoundManager::SoundManager()
     {
+        assert(singletonRef_s == NULL);
+        singletonRef_s = this;
+
         this->soundavailable_ = true;
         if(!alutInitWithoutContext(NULL,NULL))
         {
@@ -90,6 +94,9 @@
 
     SoundManager::~SoundManager()
     {
+        assert(singletonRef_s != NULL);
+        singletonRef_s = NULL;
+
         alcDestroyContext(this->context_);
         alcCloseDevice(SoundManager::device_s);
         alutExit();

Modified: branches/pch/src/orxonox/sound/SoundManager.h
===================================================================
--- branches/pch/src/orxonox/sound/SoundManager.h	2009-06-15 20:48:12 UTC (rev 3183)
+++ branches/pch/src/orxonox/sound/SoundManager.h	2009-06-15 21:45:29 UTC (rev 3184)
@@ -29,6 +29,7 @@
 
 #include "OrxonoxPrereqs.h"
 
+#include <cassert>
 #include <list>
 #include "interfaces/Tickable.h"
 
@@ -50,12 +51,15 @@
         void tick(float dt);
         bool isSoundAvailable();
 
+        static SoundManager& getInstance() { assert(singletonRef_s); return *singletonRef_s; }
+
     private:
         static ALCdevice* device_s;
         ALCcontext* context_;
         std::list<SoundBase*> soundlist_;
         bool soundavailable_;
 
+        static SoundManager* singletonRef_s;
     }; // class SoundManager
 } // namespace orxonox
 




More information about the Orxonox-commit mailing list