[Orxonox-commit 389] r2980 - in branches/sound/src/orxonox: . objects objects/items sound

erwin at orxonox.net erwin at orxonox.net
Mon May 18 14:24:35 CEST 2009


Author: erwin
Date: 2009-05-18 14:24:34 +0200 (Mon, 18 May 2009)
New Revision: 2980

Modified:
   branches/sound/src/orxonox/OrxonoxPrereqs.h
   branches/sound/src/orxonox/objects/Level.cc
   branches/sound/src/orxonox/objects/Level.h
   branches/sound/src/orxonox/objects/items/Engine.cc
   branches/sound/src/orxonox/objects/items/Engine.h
   branches/sound/src/orxonox/sound/SoundBase.cc
   branches/sound/src/orxonox/sound/SoundBase.h
   branches/sound/src/orxonox/sound/SoundManager.cc
Log:
added config ability to sound, few other changes

Modified: branches/sound/src/orxonox/OrxonoxPrereqs.h
===================================================================
--- branches/sound/src/orxonox/OrxonoxPrereqs.h	2009-05-18 12:06:04 UTC (rev 2979)
+++ branches/sound/src/orxonox/OrxonoxPrereqs.h	2009-05-18 12:24:34 UTC (rev 2980)
@@ -256,7 +256,11 @@
     class GSStandalone;
     class GSServer;
     class GSClient;
-    class GSGUI;
+    class GSGUI; 
+
+    //sound
+    class SoundBase;
+    class SoundManger;
 }
 
 namespace Ogre

Modified: branches/sound/src/orxonox/objects/Level.cc
===================================================================
--- branches/sound/src/orxonox/objects/Level.cc	2009-05-18 12:06:04 UTC (rev 2979)
+++ branches/sound/src/orxonox/objects/Level.cc	2009-05-18 12:24:34 UTC (rev 2980)
@@ -40,6 +40,7 @@
 #include "objects/infos/PlayerInfo.h"
 #include "objects/gametypes/Gametype.h"
 #include "overlays/OverlayGroup.h"
+#include "sound/SoundBase.h"
 
 #include "util/Math.h"
 
@@ -56,8 +57,6 @@
 
         if (this->xmlfilename_.length() >= Core::getMediaPathString().length())
             this->xmlfilename_ = this->xmlfilename_.substr(Core::getMediaPathString().length());
-            
-        this->sndmgr_ = new SoundManager();
     }
 
     Level::~Level()
@@ -69,11 +68,9 @@
 
             if (this->xmlfile_)
                 Loader::unload(this->xmlfile_);
-            
+
             if(this->ambientsound_ != NULL)
                 delete this->ambientsound_;
-            
-            delete this->sndmgr_;
         }
     }
 
@@ -83,7 +80,7 @@
 
         XMLPortParam(Level, "description", setDescription, getDescription, xmlelement, mode);
         XMLPortParam(Level, "gametype", setGametypeString, getGametypeString, xmlelement, mode).defaultValues("Gametype");
-        
+
         XMLPortParamLoadOnly(Level, "ambientsound", loadAmbientSound, xmlelement, mode);
 
         XMLPortObjectExtended(Level, BaseObject, "", addObject, getObject, xmlelement, mode, true, false);
@@ -164,7 +161,6 @@
             if(this->ambientsound_ == NULL)
             {
                 this->ambientsound_ = new SoundBase();
-                this->sndmgr_->addSound(this->ambientsound_);
             }
 
             this->ambientsound_->loadFile(filename);

Modified: branches/sound/src/orxonox/objects/Level.h
===================================================================
--- branches/sound/src/orxonox/objects/Level.h	2009-05-18 12:06:04 UTC (rev 2979)
+++ branches/sound/src/orxonox/objects/Level.h	2009-05-18 12:24:34 UTC (rev 2980)
@@ -32,8 +32,6 @@
 #include "OrxonoxPrereqs.h"
 
 #include "network/synchronisable/Synchronisable.h"
-#include "sound/SoundBase.h"
-#include "sound/SoundManager.h"
 #include "core/BaseObject.h"
 
 namespace orxonox
@@ -72,7 +70,7 @@
             std::string            xmlfilename_;
             XMLFile*               xmlfile_;
             std::list<BaseObject*> objects_;
-            SoundManager*          sndmgr_;
+
             SoundBase*             ambientsound_;
     };
 }

Modified: branches/sound/src/orxonox/objects/items/Engine.cc
===================================================================
--- branches/sound/src/orxonox/objects/items/Engine.cc	2009-05-18 12:06:04 UTC (rev 2979)
+++ branches/sound/src/orxonox/objects/items/Engine.cc	2009-05-18 12:24:34 UTC (rev 2980)
@@ -35,6 +35,7 @@
 #include "objects/Scene.h"
 #include "objects/worldentities/pawns/SpaceShip.h"
 #include "tools/Shader.h"
+#include "sound/SoundBase.h"
 
 namespace orxonox
 {
@@ -94,6 +95,8 @@
         XMLPortParam(Engine, "accelerationback",      setAccelerationBack,      setAccelerationBack,      xmlelement, mode);
         XMLPortParam(Engine, "accelerationleftright", setAccelerationLeftRight, setAccelerationLeftRight, xmlelement, mode);
         XMLPortParam(Engine, "accelerationupdown",    setAccelerationUpDown,    setAccelerationUpDown,    xmlelement, mode);
+
+        XMLPortParamLoadOnly(Engine, "sound", loadSound, xmlelement, mode);
     }
 
     void Engine::setConfigValues()
@@ -218,6 +221,8 @@
     void Engine::addToSpaceShip(SpaceShip* ship)
     {
         this->ship_ = ship;
+        this->sound_->attachToEntity(ship);
+
         if (ship)
         {
             this->shipID_ = ship->getObjectID();
@@ -239,4 +244,19 @@
         else
             return Vector3::ZERO;
     }
+
+    void Engine::loadSound(const std::string filename)
+    {
+        if(filename == "") return;
+        else
+        {
+            if(this->sound_ == NULL)
+            {
+                this->sound_ = new SoundBase(this->ship_);
+            }
+
+            this->sound_->loadFile(filename);
+            this->sound_->play(true);
+        }
+    }
 }

Modified: branches/sound/src/orxonox/objects/items/Engine.h
===================================================================
--- branches/sound/src/orxonox/objects/items/Engine.h	2009-05-18 12:06:04 UTC (rev 2979)
+++ branches/sound/src/orxonox/objects/items/Engine.h	2009-05-18 12:24:34 UTC (rev 2980)
@@ -106,6 +106,8 @@
 
             virtual const Vector3& getDirection() const;
 
+            void loadSound(const std::string filename);
+
         private:
             void networkcallback_shipID();
 
@@ -128,6 +130,8 @@
 
             Shader* boostBlur_;
             float blurStrength_;
+
+            SoundBase* sound_;
     };
 }
 

Modified: branches/sound/src/orxonox/sound/SoundBase.cc
===================================================================
--- branches/sound/src/orxonox/sound/SoundBase.cc	2009-05-18 12:06:04 UTC (rev 2979)
+++ branches/sound/src/orxonox/sound/SoundBase.cc	2009-05-18 12:24:34 UTC (rev 2980)
@@ -30,23 +30,25 @@
 
 #include "orxonox/objects/worldentities/WorldEntity.h"
 #include "util/Math.h"
+#include "SoundBase.h"
 #include "SoundManager.h"
-#include "SoundBase.h"
 
 namespace orxonox 
 {
-    SoundBase::SoundBase()
-    {
-        this->source_ = 0;
-        this->buffer_ = 0;
-        this->entity_ = NULL;
-    }
+    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);
     }
 
     SoundBase::~SoundBase()

Modified: branches/sound/src/orxonox/sound/SoundBase.h
===================================================================
--- branches/sound/src/orxonox/sound/SoundBase.h	2009-05-18 12:06:04 UTC (rev 2979)
+++ branches/sound/src/orxonox/sound/SoundBase.h	2009-05-18 12:24:34 UTC (rev 2980)
@@ -35,6 +35,7 @@
 {
     class SoundManager;
     class WorldEntity;
+
     /**
      * The SoudBase class is the base class for all sound file loader classes.
      * It server as main interface to the OpenAL library.
@@ -43,8 +44,7 @@
     class _OrxonoxExport SoundBase
     {
     public:
-        SoundBase();
-        SoundBase(WorldEntity* entity);
+        SoundBase(WorldEntity* entity = NULL);
         ~SoundBase();
 
         void attachToEntity(WorldEntity* entity);
@@ -66,6 +66,8 @@
         WorldEntity* entity_;
 
         ALint getSourceState();
+
+        static SoundManager* soundmanager_s;
     }; // class SoundBase
 } // namepsace orxonox
 

Modified: branches/sound/src/orxonox/sound/SoundManager.cc
===================================================================
--- branches/sound/src/orxonox/sound/SoundManager.cc	2009-05-18 12:06:04 UTC (rev 2979)
+++ branches/sound/src/orxonox/sound/SoundManager.cc	2009-05-18 12:24:34 UTC (rev 2980)
@@ -53,7 +53,7 @@
             COUT(4) << "OpenAL ALUT supported MIME types:" << alutGetMIMETypes(ALUT_LOADER_BUFFER) << std::endl;
             if(SoundManager::device_s == NULL)
             {
-                COUT(3) << "OpenAL: open sound device..." << std::endl;
+                COUT(3) << "OpenAL: Open sound device..." << std::endl;
                 SoundManager::device_s = alcOpenDevice(NULL);
             }
 
@@ -63,6 +63,7 @@
             }
             else
             {
+                COUT(3) << "OpenAL: Sound device opened";
                 this->context_ = alcCreateContext(SoundManager::device_s, NULL);
                 if(this->context_ == NULL)
                 {
@@ -70,6 +71,7 @@
                 }
                 else
                 {
+                    COUT(3) << "OpenAL: Context " << this->context_ << "loaded";
                     alcMakeContextCurrent(this->context_);
                 }
             }




More information about the Orxonox-commit mailing list