[Orxonox-commit 3161] r7854 - in code/trunk: data/levels src/orxonox src/orxonox/gamestates src/orxonox/sound

landauf at orxonox.net landauf at orxonox.net
Fri Feb 11 13:03:47 CET 2011


Author: landauf
Date: 2011-02-11 13:03:47 +0100 (Fri, 11 Feb 2011)
New Revision: 7854

Added:
   code/trunk/src/orxonox/sound/WorldAmbientSound.cc
   code/trunk/src/orxonox/sound/WorldAmbientSound.h
Modified:
   code/trunk/data/levels/presentationHS09b.oxw
   code/trunk/data/levels/presentationPong.oxw
   code/trunk/data/levels/sound.oxw
   code/trunk/src/orxonox/OrxonoxPrereqs.h
   code/trunk/src/orxonox/gamestates/GSLevel.cc
   code/trunk/src/orxonox/gamestates/GSMainMenu.cc
   code/trunk/src/orxonox/sound/AmbientSound.cc
   code/trunk/src/orxonox/sound/AmbientSound.h
   code/trunk/src/orxonox/sound/BaseSound.h
   code/trunk/src/orxonox/sound/CMakeLists.txt
   code/trunk/src/orxonox/sound/WorldSound.h
Log:
detached AmbientSound from BaseObject - AmbientSound can not be placed directly in a level file anymore
instead added WorldAmbientSound, a BaseObject which can be placed in a level file to create and control ambient sound

with this change, the level can be destroyed completely because WorldAmbientSound can be deleted immediately at the end of the level, while the AmbientSound remains active until it faded out.

Modified: code/trunk/data/levels/presentationHS09b.oxw
===================================================================
--- code/trunk/data/levels/presentationHS09b.oxw	2011-02-11 00:38:36 UTC (rev 7853)
+++ code/trunk/data/levels/presentationHS09b.oxw	2011-02-11 12:03:47 UTC (rev 7854)
@@ -34,7 +34,7 @@
     skybox       = "Orxonox/Starbox"
   >
 
-    <AmbientSound ambientSource="Mars.ogg" looping="true" playOnLoad="true" />
+    <WorldAmbientSound source="Mars.ogg" looping="true" playOnLoad="true" />
 
    <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" />
    
@@ -255,13 +255,13 @@
       </SpaceShip>
     <?lua end ?>
 
-    <AmbientSound ambientSource="Earth.ogg" looping="true" playOnLoad="false">
+    <WorldAmbientSound source="Earth.ogg" looping="true" playOnLoad="false">
       <events>
         <activity>
           <DistanceTrigger position="2000,0,0" distance=500 target="Camera" />
         </activity>
       </events>
-    </AmbientSound>
+    </WorldAmbientSound>
 
     <SpawnPoint position="5000,0,2000" spawnclass=SpaceShip pawndesign=spaceshipassff  team=0 />
     

Modified: code/trunk/data/levels/presentationPong.oxw
===================================================================
--- code/trunk/data/levels/presentationPong.oxw	2011-02-11 00:38:36 UTC (rev 7853)
+++ code/trunk/data/levels/presentationPong.oxw	2011-02-11 12:03:47 UTC (rev 7854)
@@ -50,7 +50,7 @@
     <Template link=lodtemplate_default />
   </templates>
 
-  <AmbientSound ambientSource="mainmenu.ogg" playOnLoad=true />
+  <WorldAmbientSound source="mainmenu.ogg" playOnLoad=true />
 
   <Scene
    ambientlight = "0.5, 0.5, 0.5"

Modified: code/trunk/data/levels/sound.oxw
===================================================================
--- code/trunk/data/levels/sound.oxw	2011-02-11 00:38:36 UTC (rev 7853)
+++ code/trunk/data/levels/sound.oxw	2011-02-11 12:03:47 UTC (rev 7854)
@@ -28,8 +28,8 @@
     skybox       = "Orxonox/Starbox"
   >
 
-  <AmbientSound ambientSource="Earth.ogg" looping="true" playOnLoad="true" />
-  <AmbientSound ambientSource="Mars.ogg" looping="true">
+  <WorldAmbientSound source="Earth.ogg" looping="true" playOnLoad="true" />
+  <WorldAmbientSound source="Mars.ogg" looping="true">
     <events>
       <activity>
         <DistanceTrigger position="400,0,0" distance=200 target="Camera">
@@ -39,8 +39,8 @@
         </DistanceTrigger>
       </activity>
     </events>
-  </AmbientSound>
-  <AmbientSound ambientSource="Jupiter.ogg" looping="true">
+  </WorldAmbientSound>
+  <WorldAmbientSound source="Jupiter.ogg" looping="true">
     <events>
       <activity>
         <DistanceTrigger position="400,150,0" distance=200 target="Camera">
@@ -50,7 +50,7 @@
         </DistanceTrigger>
       </activity>
     </events>
-  </AmbientSound>
+  </WorldAmbientSound>
 
 
   <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" />

Modified: code/trunk/src/orxonox/OrxonoxPrereqs.h
===================================================================
--- code/trunk/src/orxonox/OrxonoxPrereqs.h	2011-02-11 00:38:36 UTC (rev 7853)
+++ code/trunk/src/orxonox/OrxonoxPrereqs.h	2011-02-11 12:03:47 UTC (rev 7854)
@@ -150,6 +150,7 @@
     class SoundManager;
     class SoundStreamer;
     class WorldSound;
+    class WorldAmbientSound;
 
     // weaponsystem
     class DefaultWeaponmodeLink;

Modified: code/trunk/src/orxonox/gamestates/GSLevel.cc
===================================================================
--- code/trunk/src/orxonox/gamestates/GSLevel.cc	2011-02-11 00:38:36 UTC (rev 7853)
+++ code/trunk/src/orxonox/gamestates/GSLevel.cc	2011-02-11 12:03:47 UTC (rev 7854)
@@ -153,7 +153,7 @@
             std::set<BaseObject*>::const_iterator find = this->staticObjects_.find(*it);
             if (find == this->staticObjects_.end())
             {
-                COUT(3) << ++i << ": " << it->getIdentifier()->getName() << " (" << *it << ')' << std::endl;
+                COUT(3) << ++i << ": " << it->getIdentifier()->getName() << " (" << *it << "), references: " << it->getReferenceCount() << std::endl;
             }
         }
         COUT(3) << i << " objects remaining.";

Modified: code/trunk/src/orxonox/gamestates/GSMainMenu.cc
===================================================================
--- code/trunk/src/orxonox/gamestates/GSMainMenu.cc	2011-02-11 00:38:36 UTC (rev 7853)
+++ code/trunk/src/orxonox/gamestates/GSMainMenu.cc	2011-02-11 12:03:47 UTC (rev 7854)
@@ -76,8 +76,7 @@
         if (GameMode::playsSound())
         {
             // Load sound
-            this->ambient_ = new AmbientSound(0);
-            this->ambient_->setSyncMode(0x0);
+            this->ambient_ = new AmbientSound();
         }
     }
 

Modified: code/trunk/src/orxonox/sound/AmbientSound.cc
===================================================================
--- code/trunk/src/orxonox/sound/AmbientSound.cc	2011-02-11 00:38:36 UTC (rev 7853)
+++ code/trunk/src/orxonox/sound/AmbientSound.cc	2011-02-11 12:03:47 UTC (rev 7854)
@@ -28,27 +28,17 @@
 
 #include "AmbientSound.h"
 
-#include "core/CoreIncludes.h"
-#include "core/EventIncludes.h"
 #include "core/GameMode.h"
 #include "core/Resource.h"
-#include "core/XMLPort.h"
 #include "SoundManager.h"
 
 namespace orxonox
 {
-    CreateFactory(AmbientSound);
-
-    AmbientSound::AmbientSound(BaseObject* creator)
-        : BaseObject(creator)
-        , Synchronisable(creator)
-        , bPlayOnLoad_(false)
+    AmbientSound::AmbientSound()
+        : bPlayOnLoad_(false)
     {
-        RegisterObject(AmbientSound);
-
         // Ambient sounds always fade in
         this->setVolume(0);
-        this->registerVariables();
     }
 
     void AmbientSound::preDestroy()
@@ -60,28 +50,6 @@
         }
     }
 
-    void AmbientSound::registerVariables()
-    {
-        registerVariable(ambientSource_, ObjectDirection::ToClient, new NetworkCallback<AmbientSound>(this, &AmbientSound::ambientSourceChanged));
-        registerVariable(bLooping_,      ObjectDirection::ToClient, new NetworkCallback<AmbientSound>(this, &AmbientSound::loopingChanged));
-        registerVariable(pitch_,         ObjectDirection::ToClient, new NetworkCallback<AmbientSound>(this, &AmbientSound::pitchChanged));
-        registerVariable(bPlayOnLoad_,   ObjectDirection::ToClient, new NetworkCallback<AmbientSound>(this, &AmbientSound::playOnLoadChanged));
-    }
-
-    void AmbientSound::XMLPort(Element& xmlelement, XMLPort::Mode mode)
-    {
-        SUPER(AmbientSound, XMLPort, xmlelement, mode);
-        BaseSound::XMLPortExtern(xmlelement, mode);
-        XMLPortParam(AmbientSound, "ambientSource", setAmbientSource, getAmbientSource, xmlelement, mode);
-        XMLPortParam(AmbientSound, "playOnLoad", setPlayOnLoad, getPlayOnLoad, xmlelement, mode);
-    }
-
-    void AmbientSound::XMLEventPort(Element& xmlelement, XMLPort::Mode mode)
-    {
-        SUPER(AmbientSound, XMLEventPort, xmlelement, mode);
-        XMLPortEventState(AmbientSound, BaseObject, "play", play, xmlelement, mode);
-    }
-
     void AmbientSound::play()
     {
         if (GameMode::playsSound())
@@ -131,13 +99,4 @@
         if (val)
             this->play();
     }
-
-    void AmbientSound::changedActivity()
-    {
-        SUPER(AmbientSound, changedActivity);
-        if (this->isActive())
-            this->play();
-        else
-            this->stop();
-    }
 }

Modified: code/trunk/src/orxonox/sound/AmbientSound.h
===================================================================
--- code/trunk/src/orxonox/sound/AmbientSound.h	2011-02-11 00:38:36 UTC (rev 7853)
+++ code/trunk/src/orxonox/sound/AmbientSound.h	2011-02-11 12:03:47 UTC (rev 7854)
@@ -32,29 +32,23 @@
 
 #include "OrxonoxPrereqs.h"
 
-#include "core/BaseObject.h"
-#include "network/synchronisable/Synchronisable.h"
 #include "BaseSound.h"
 #include "MoodManager.h"
 
 namespace orxonox
 {
     /**
-     * The AmbientSound class is the base class for all sound file loader classes.
-     * It server as main interface to the OpenAL library.
-     *
+     * The AmbientSound class is used to play background music. It can not be placed
+     * directly in a level file, use WorldAmbientSound instead.
      */
-    class _OrxonoxExport AmbientSound : public BaseSound, public BaseObject, public Synchronisable, public MoodListener
+    class _OrxonoxExport AmbientSound : public BaseSound, public MoodListener
     {
         friend class SoundManager;
+        friend class WorldAmbientSound;
 
     public:
-        AmbientSound(BaseObject* creator);
+        AmbientSound();
 
-        void XMLPort(Element& xmlelement, XMLPort::Mode mode);
-        void XMLEventPort(Element& xmlelement, XMLPort::Mode mode);
-        void changedActivity();
-
         void play();
         void stop();
         void pause();
@@ -72,7 +66,6 @@
 
     private:
         void preDestroy();
-        void registerVariables();
         float getRealVolume();
         void moodChanged(const std::string& mood);
         inline void ambientSourceChanged()

Modified: code/trunk/src/orxonox/sound/BaseSound.h
===================================================================
--- code/trunk/src/orxonox/sound/BaseSound.h	2011-02-11 00:38:36 UTC (rev 7853)
+++ code/trunk/src/orxonox/sound/BaseSound.h	2011-02-11 12:03:47 UTC (rev 7854)
@@ -40,8 +40,7 @@
 {
     /**
      * The BaseSound class is the base class for all sound file loader classes.
-     * It server as main interface to the OpenAL library.
-     *
+     * It serves as main interface to the OpenAL library.
      */
     class _OrxonoxExport BaseSound : virtual public OrxonoxClass
     {

Modified: code/trunk/src/orxonox/sound/CMakeLists.txt
===================================================================
--- code/trunk/src/orxonox/sound/CMakeLists.txt	2011-02-11 00:38:36 UTC (rev 7853)
+++ code/trunk/src/orxonox/sound/CMakeLists.txt	2011-02-11 12:03:47 UTC (rev 7854)
@@ -1,9 +1,10 @@
 ADD_SOURCE_FILES(ORXONOX_SRC_FILES
-    AmbientSound.cc
-    BaseSound.cc
-    SoundBuffer.cc
-    SoundManager.cc
-    WorldSound.cc
-    SoundStreamer.cc
+  AmbientSound.cc
+  BaseSound.cc
+  SoundBuffer.cc
+  SoundManager.cc
+  SoundStreamer.cc
+  WorldAmbientSound.cc
+  WorldSound.cc
 )
 

Added: code/trunk/src/orxonox/sound/WorldAmbientSound.cc
===================================================================
--- code/trunk/src/orxonox/sound/WorldAmbientSound.cc	                        (rev 0)
+++ code/trunk/src/orxonox/sound/WorldAmbientSound.cc	2011-02-11 12:03:47 UTC (rev 7854)
@@ -0,0 +1,96 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Fabian 'x3n' Landau
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "WorldAmbientSound.h"
+
+#include "core/CoreIncludes.h"
+#include "core/EventIncludes.h"
+#include "core/XMLPort.h"
+#include "AmbientSound.h"
+
+namespace orxonox
+{
+    CreateFactory(WorldAmbientSound);
+
+    WorldAmbientSound::WorldAmbientSound(BaseObject* creator) : BaseObject(creator), Synchronisable(creator)
+    {
+        RegisterObject(WorldAmbientSound);
+
+        this->ambientSound_ = new AmbientSound();
+        this->registerVariables();
+    }
+
+    WorldAmbientSound::~WorldAmbientSound()
+    {
+        if (this->isInitialized())
+        {
+            this->ambientSound_->destroy();
+        }
+    }
+
+    void WorldAmbientSound::registerVariables()
+    {
+        registerVariable(this->ambientSound_->ambientSource_, ObjectDirection::ToClient, new NetworkCallback<AmbientSound>(this->ambientSound_, &AmbientSound::ambientSourceChanged));
+        registerVariable(this->ambientSound_->bLooping_,      ObjectDirection::ToClient, new NetworkCallback<AmbientSound>(this->ambientSound_, &AmbientSound::loopingChanged));
+        registerVariable(this->ambientSound_->pitch_,         ObjectDirection::ToClient, new NetworkCallback<AmbientSound>(this->ambientSound_, &AmbientSound::pitchChanged));
+        registerVariable(this->ambientSound_->bPlayOnLoad_,   ObjectDirection::ToClient, new NetworkCallback<AmbientSound>(this->ambientSound_, &AmbientSound::playOnLoadChanged));
+    }
+
+    void WorldAmbientSound::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+    {
+        SUPER(WorldAmbientSound, XMLPort, xmlelement, mode);
+
+        XMLPortParamExtern(WorldAmbientSound, BaseSound, static_cast<BaseSound*>(this->ambientSound_), "looping", setLooping, getLooping, xmlelement, mode);
+        XMLPortParamExtern(WorldAmbientSound, BaseSound, static_cast<BaseSound*>(this->ambientSound_), "pitch",   setPitch,   getPitch,   xmlelement, mode);
+
+        XMLPortParamExtern(WorldAmbientSound, AmbientSound, this->ambientSound_, "source",     setAmbientSource, getAmbientSource, xmlelement, mode);
+        XMLPortParamExtern(WorldAmbientSound, AmbientSound, this->ambientSound_, "playOnLoad", setPlayOnLoad,    getPlayOnLoad,    xmlelement, mode);
+    }
+
+    void WorldAmbientSound::XMLEventPort(Element& xmlelement, XMLPort::Mode mode)
+    {
+        SUPER(WorldAmbientSound, XMLEventPort, xmlelement, mode);
+
+        XMLPortEventState(WorldAmbientSound, BaseObject, "play", play, xmlelement, mode);
+    }
+
+    void WorldAmbientSound::play()
+    {
+        this->ambientSound_->play();
+    }
+
+    void WorldAmbientSound::changedActivity()
+    {
+        SUPER(WorldAmbientSound, changedActivity);
+
+        if (this->isActive())
+            this->ambientSound_->play();
+        else
+            this->ambientSound_->stop();
+    }
+}


Property changes on: code/trunk/src/orxonox/sound/WorldAmbientSound.cc
___________________________________________________________________
Added: svn:eol-style
   + native

Added: code/trunk/src/orxonox/sound/WorldAmbientSound.h
===================================================================
--- code/trunk/src/orxonox/sound/WorldAmbientSound.h	                        (rev 0)
+++ code/trunk/src/orxonox/sound/WorldAmbientSound.h	2011-02-11 12:03:47 UTC (rev 7854)
@@ -0,0 +1,63 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Fabian 'x3n' Landau
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _WorldAmbientSound_H__
+#define _WorldAmbientSound_H__
+
+#include "OrxonoxPrereqs.h"
+
+#include "core/BaseObject.h"
+#include "network/synchronisable/Synchronisable.h"
+
+namespace orxonox
+{
+    /**
+        @brief This class is used to play and control ambient sound in a level file. See AmbientSound for the
+        actual implementation of the background music player.
+    */
+    class _OrxonoxExport WorldAmbientSound : public BaseObject, public Synchronisable
+    {
+        public:
+            WorldAmbientSound(BaseObject* creator);
+            virtual ~WorldAmbientSound();
+
+            void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+            void XMLEventPort(Element& xmlelement, XMLPort::Mode mode);
+
+            virtual void changedActivity();
+
+            void play();
+
+        private:
+            void registerVariables();
+
+            AmbientSound* ambientSound_;
+    };
+}
+
+#endif /* _WorldAmbientSound_H__ */


Property changes on: code/trunk/src/orxonox/sound/WorldAmbientSound.h
___________________________________________________________________
Added: svn:eol-style
   + native

Modified: code/trunk/src/orxonox/sound/WorldSound.h
===================================================================
--- code/trunk/src/orxonox/sound/WorldSound.h	2011-02-11 00:38:36 UTC (rev 7853)
+++ code/trunk/src/orxonox/sound/WorldSound.h	2011-02-11 12:03:47 UTC (rev 7854)
@@ -37,7 +37,7 @@
 
 namespace orxonox
 {
-    /*
+    /**
     @brief
         The WorldSound class is to be used for sounds with position and orientation.
     */




More information about the Orxonox-commit mailing list