[Orxonox-commit 1264] r5982 - in code/branches/sound3: data/levels src/orxonox/sound

youngk at orxonox.net youngk at orxonox.net
Wed Oct 21 17:28:14 CEST 2009


Author: youngk
Date: 2009-10-21 17:28:13 +0200 (Wed, 21 Oct 2009)
New Revision: 5982

Added:
   code/branches/sound3/data/levels/sound.oxw
Modified:
   code/branches/sound3/src/orxonox/sound/AmbientSound.cc
   code/branches/sound3/src/orxonox/sound/AmbientSound.h
   code/branches/sound3/src/orxonox/sound/BaseSound.cc
   code/branches/sound3/src/orxonox/sound/BaseSound.h
   code/branches/sound3/src/orxonox/sound/SoundManager.cc
   code/branches/sound3/src/orxonox/sound/SoundManager.h
Log:
Ambient Sounds are now locationally triggerable, i.e if the player comes close to an object, it's own ambient sound starts playing, while the sound of the outer object is paused. Upon leaving proximity of that object, the old sound is resumed. --> Triggerable by changing active state.

Added: code/branches/sound3/data/levels/sound.oxw
===================================================================
--- code/branches/sound3/data/levels/sound.oxw	                        (rev 0)
+++ code/branches/sound3/data/levels/sound.oxw	2009-10-21 15:28:13 UTC (rev 5982)
@@ -0,0 +1,34 @@
+<?lua
+  include("stats.oxo")
+  include("hudtemplates3.oxo")
+?>
+
+<?lua
+  include("templates/spaceship_assff.oxt")
+  include("templates/spaceship_pirate.oxt")
+?>
+
+<Level
+ name         = "Sample"
+ description  = "Just a few tests"
+>
+  <Scene
+    ambientlight = "0.8, 0.8, 0.8"
+    skybox       = "Orxonox/Starbox"
+  >
+  <AmbientSound source="ambient/mainmenu.wav" loop="true" playOnLoad="true" />
+  <AmbientSound source="ambient/CoreWave.wav" loop="true" playOnLoad="false">
+	<events>
+		<activity>
+			<DistanceTrigger position="300,100,0" distance=200 target="ControllableEntity">
+				<attached>
+					<ParticleSpawner position="0,0,0" source="Orxonox/fire3" lifetime=0 loop=0 autostart=1 />
+				</attached>
+			</DistanceTrigger>
+		</activity>
+	</events>
+  </AmbientSound>
+    <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0" />
+    <SpawnPoint position="0,0,0" spawnclass=SpaceShip pawndesign=spaceshippirate />
+  </Scene>
+</Level>

Modified: code/branches/sound3/src/orxonox/sound/AmbientSound.cc
===================================================================
--- code/branches/sound3/src/orxonox/sound/AmbientSound.cc	2009-10-21 15:17:05 UTC (rev 5981)
+++ code/branches/sound3/src/orxonox/sound/AmbientSound.cc	2009-10-21 15:28:13 UTC (rev 5982)
@@ -31,6 +31,7 @@
 #include "core/CoreIncludes.h"
 #include "core/EventIncludes.h"
 #include "core/XMLPort.h"
+#include "SoundManager.h"
 
 namespace orxonox
 {
@@ -59,4 +60,42 @@
         SUPER(AmbientSound, XMLEventPort, xmlelement, mode);
         XMLPortEventState(AmbientSound, BaseObject, "play", play, xmlelement, mode);
     }
+
+    void AmbientSound::play()
+    {
+        COUT(3) << this->getSource() << ": Playing" << std::endl;
+        SoundManager::getInstance().registerAmbientSound(this);
+        SUPER(AmbientSound, play);
+    }
+
+    void AmbientSound::replay()
+    {
+        SUPER(AmbientSound, play);
+    }
+
+    void AmbientSound::stop()
+    {
+        SUPER(AmbientSound, stop);
+        SoundManager::getInstance().unregisterAmbientSound(this);
+    }
+
+    void AmbientSound::pause()
+    {
+        SUPER(AmbientSound, pause);
+    }
+
+    void AmbientSound::changedActivity() 
+    {
+        COUT(3) << this->getSource() << ": ChangedActivity: " << this->isActive() << std::endl;
+        SUPER(AmbientSound, changedActivity);
+        if(this->isActive())
+        {
+            this->play();
+        }
+        else 
+        {
+            this->stop();
+        }
+    }
+
 }

Modified: code/branches/sound3/src/orxonox/sound/AmbientSound.h
===================================================================
--- code/branches/sound3/src/orxonox/sound/AmbientSound.h	2009-10-21 15:17:05 UTC (rev 5981)
+++ code/branches/sound3/src/orxonox/sound/AmbientSound.h	2009-10-21 15:28:13 UTC (rev 5982)
@@ -46,9 +46,16 @@
         AmbientSound(BaseObject* creator);
         virtual ~AmbientSound();
 
+        virtual void play();
+        virtual void replay();      // is only needed for the AmbientSound list in SoundManager
+        virtual void stop();
+        virtual void pause();
+
         virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
         virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode);
+        virtual void changedActivity();
 
+
     private:
     };
 }

Modified: code/branches/sound3/src/orxonox/sound/BaseSound.cc
===================================================================
--- code/branches/sound3/src/orxonox/sound/BaseSound.cc	2009-10-21 15:17:05 UTC (rev 5981)
+++ code/branches/sound3/src/orxonox/sound/BaseSound.cc	2009-10-21 15:28:13 UTC (rev 5982)
@@ -69,6 +69,11 @@
         }
     }
 
+    void BaseSound::replay()
+    {
+        BaseSound::play();
+    }
+
     void BaseSound::stop()
     {
         if (alIsSource(this->audioSource_))
@@ -104,8 +109,11 @@
 
     void BaseSound::setPlayOnLoad(bool val)
     {
-        this->bPlayOnLoad_ = true;
-        this->play();
+        this->bPlayOnLoad_ = val;
+        if(val)
+        {
+            this->play();
+        }
     }
 
     void BaseSound::setSource(const std::string& source)

Modified: code/branches/sound3/src/orxonox/sound/BaseSound.h
===================================================================
--- code/branches/sound3/src/orxonox/sound/BaseSound.h	2009-10-21 15:17:05 UTC (rev 5981)
+++ code/branches/sound3/src/orxonox/sound/BaseSound.h	2009-10-21 15:28:13 UTC (rev 5982)
@@ -48,9 +48,10 @@
         BaseSound();
         virtual ~BaseSound();
 
-        void play();
-        void stop();
-        void pause();
+        virtual void play();
+        virtual void replay();      // is only needed for the AmbientSound list in SoundManager
+        virtual void stop();
+        virtual void pause();
 
         bool isPlaying();
         bool isPaused();

Modified: code/branches/sound3/src/orxonox/sound/SoundManager.cc
===================================================================
--- code/branches/sound3/src/orxonox/sound/SoundManager.cc	2009-10-21 15:17:05 UTC (rev 5981)
+++ code/branches/sound3/src/orxonox/sound/SoundManager.cc	2009-10-21 15:28:13 UTC (rev 5982)
@@ -35,6 +35,7 @@
 #include "util/ScopeGuard.h"
 #include "core/GameMode.h"
 #include "core/ScopedSingletonManager.h"
+#include "BaseSound.h"
 
 namespace orxonox
 {
@@ -113,4 +114,33 @@
         if (error == AL_INVALID_VALUE)
             COUT(2) << "Sound: OpenAL: Invalid listener orientation" << std::endl;
     }
+
+    void SoundManager::registerAmbientSound(BaseSound* newAmbient)
+    {
+        if (!(this->ambientSounds_.empty())) 
+        {
+            this->ambientSounds_.front()->pause();
+        }
+        this->ambientSounds_.push_front(newAmbient);
+    }
+
+    void SoundManager::unregisterAmbientSound(BaseSound* currentAmbient)
+    {
+        if(this->ambientSounds_.front() == currentAmbient) 
+        {
+            this->ambientSounds_.pop_front();
+            this->ambientSounds_.front()->replay();
+        }
+        else
+        {
+            for(std::list<BaseSound*>::iterator it= this->ambientSounds_.begin(); it != this->ambientSounds_.end(); it++)
+            {
+                if(*it == currentAmbient)
+                {
+                    this->ambientSounds_.erase(it);
+                    break;
+                }
+            }
+        }
+    }
 }

Modified: code/branches/sound3/src/orxonox/sound/SoundManager.h
===================================================================
--- code/branches/sound3/src/orxonox/sound/SoundManager.h	2009-10-21 15:17:05 UTC (rev 5981)
+++ code/branches/sound3/src/orxonox/sound/SoundManager.h	2009-10-21 15:28:13 UTC (rev 5982)
@@ -50,10 +50,13 @@
 
         void setListenerPosition(const Vector3& position);
         void setListenerOrientation(const Quaternion& orientation);
+        void registerAmbientSound(BaseSound* newAmbient);
+        void unregisterAmbientSound(BaseSound* currentAmbient);
 
     private:
         ALCdevice* device_;
         ALCcontext* context_;
+        std::list<BaseSound*> ambientSounds_;
 
         static SoundManager* singletonPtr_s;
     };




More information about the Orxonox-commit mailing list