[Orxonox-commit 1313] r6031 - in code/branches/sound3: data/levels src/orxonox src/orxonox/gamestates src/orxonox/sound
youngk at orxonox.net
youngk at orxonox.net
Wed Nov 4 16:03:03 CET 2009
Author: youngk
Date: 2009-11-04 16:03:03 +0100 (Wed, 04 Nov 2009)
New Revision: 6031
Modified:
code/branches/sound3/data/levels/sound.oxw
code/branches/sound3/src/orxonox/MoodManager.cc
code/branches/sound3/src/orxonox/MoodManager.h
code/branches/sound3/src/orxonox/gamestates/GSMainMenu.cc
code/branches/sound3/src/orxonox/sound/AmbientSound.cc
code/branches/sound3/src/orxonox/sound/AmbientSound.h
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:
Implemented automatic ambient sound file path fetch according to current mood.
Valid moods are: default and dnb
BUG: Loading of a second sound fails (independent of the file used). Probably an error in BaseSound::setSource().
Modified: code/branches/sound3/data/levels/sound.oxw
===================================================================
--- code/branches/sound3/data/levels/sound.oxw 2009-11-04 13:31:29 UTC (rev 6030)
+++ code/branches/sound3/data/levels/sound.oxw 2009-11-04 15:03:03 UTC (rev 6031)
@@ -16,8 +16,8 @@
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">
+ <AmbientSound source="mainmenu.wav" loop="true" playOnLoad="true" />
+ <AmbientSound source="CoreWave.wav" loop="true" playOnLoad="false">
<events>
<activity>
<DistanceTrigger position="300,100,0" distance=200 target="ControllableEntity">
Modified: code/branches/sound3/src/orxonox/MoodManager.cc
===================================================================
--- code/branches/sound3/src/orxonox/MoodManager.cc 2009-11-04 13:31:29 UTC (rev 6030)
+++ code/branches/sound3/src/orxonox/MoodManager.cc 2009-11-04 15:03:03 UTC (rev 6031)
@@ -41,6 +41,7 @@
MoodManager::MoodManager()
{
RegisterRootObject(MoodManager);
+ moodOld_ = "default";
this->setConfigValues();
CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&MoodManager::setMood, this), "setMood"));
}
@@ -52,10 +53,14 @@
void MoodManager::setConfigValues()
{
SetConfigValue(mood_, "default")
- .description("Sets the mood for the current level.");
+ .description("Sets the mood for the current level.")
+ .callback(this, &MoodManager::checkMoodValidity);
}
- // sets a new mood
+ /**
+ * Sets the mood
+ * @note TODO: Inform dependent classes of mood change
+ */
void MoodManager::setMood(const std::string& mood) {
ModifyConfigValue(mood_, set, mood);
}
@@ -64,4 +69,14 @@
const std::string& MoodManager::getMood() {
return mood_;
}
+
+ void MoodManager::checkMoodValidity()
+ {
+ if(mood_ != "default" && mood_ != "dnb") // Insert new moods here
+ {
+ ResetConfigValue(mood_);
+ }
+ COUT(0) << "MoodManager: Mood now set to " << mood_ << std::endl;
+ return;
+ }
}
Modified: code/branches/sound3/src/orxonox/MoodManager.h
===================================================================
--- code/branches/sound3/src/orxonox/MoodManager.h 2009-11-04 13:31:29 UTC (rev 6030)
+++ code/branches/sound3/src/orxonox/MoodManager.h 2009-11-04 15:03:03 UTC (rev 6031)
@@ -61,7 +61,10 @@
// config values
std::string mood_;
+ std::string moodOld_;
+ void checkMoodValidity();
+
static MoodManager* singletonPtr_s;
}; // tolua_export
} // tolua_export
Modified: code/branches/sound3/src/orxonox/gamestates/GSMainMenu.cc
===================================================================
--- code/branches/sound3/src/orxonox/gamestates/GSMainMenu.cc 2009-11-04 13:31:29 UTC (rev 6030)
+++ code/branches/sound3/src/orxonox/gamestates/GSMainMenu.cc 2009-11-04 15:03:03 UTC (rev 6031)
@@ -127,7 +127,7 @@
void GSMainMenu::setConfigValues()
{
- SetConfigValue(soundPathMain_, "ambient/mainmenu.wav")
+ SetConfigValue(soundPathMain_, "mainmenu.wav")
.description("Contains the path to the main menu sound file.")
.callback(this, &GSMainMenu::reloadSound);
}
Modified: code/branches/sound3/src/orxonox/sound/AmbientSound.cc
===================================================================
--- code/branches/sound3/src/orxonox/sound/AmbientSound.cc 2009-11-04 13:31:29 UTC (rev 6030)
+++ code/branches/sound3/src/orxonox/sound/AmbientSound.cc 2009-11-04 15:03:03 UTC (rev 6031)
@@ -84,6 +84,20 @@
SUPER(AmbientSound, pause);
}
+ void AmbientSound::setSource(const std::string& source)
+ {
+ if(source.find('/') == std::string.npos)
+ {
+ std::string filePath = SoundManager::getInstance().getAmbientPath(source);
+ if(!(filePath.empty()))
+ {
+ BaseSound::setSource(filePath);
+ return;
+ }
+ }
+ COUT(3) << source << ": Not a valid name! Ambient sound will not change." << std::endl;
+ }
+
void AmbientSound::changedActivity()
{
COUT(3) << this->getSource() << ": ChangedActivity: " << this->isActive() << std::endl;
Modified: code/branches/sound3/src/orxonox/sound/AmbientSound.h
===================================================================
--- code/branches/sound3/src/orxonox/sound/AmbientSound.h 2009-11-04 13:31:29 UTC (rev 6030)
+++ code/branches/sound3/src/orxonox/sound/AmbientSound.h 2009-11-04 15:03:03 UTC (rev 6031)
@@ -51,6 +51,8 @@
virtual void stop();
virtual void pause();
+ virtual void setSource(const std::string& source);
+
virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode);
virtual void changedActivity();
Modified: code/branches/sound3/src/orxonox/sound/BaseSound.h
===================================================================
--- code/branches/sound3/src/orxonox/sound/BaseSound.h 2009-11-04 13:31:29 UTC (rev 6030)
+++ code/branches/sound3/src/orxonox/sound/BaseSound.h 2009-11-04 15:03:03 UTC (rev 6031)
@@ -57,7 +57,7 @@
bool isPaused();
bool isStopped();
- void setSource(const std::string& source);
+ virtual void setSource(const std::string& source);
const std::string& getSource() { return this->source_; }
bool getPlayOnLoad() { return this->bPlayOnLoad_; }
Modified: code/branches/sound3/src/orxonox/sound/SoundManager.cc
===================================================================
--- code/branches/sound3/src/orxonox/sound/SoundManager.cc 2009-11-04 13:31:29 UTC (rev 6030)
+++ code/branches/sound3/src/orxonox/sound/SoundManager.cc 2009-11-04 15:03:03 UTC (rev 6031)
@@ -33,9 +33,12 @@
#include "util/Exception.h"
#include "util/Math.h"
#include "util/ScopeGuard.h"
+#include "util/StringUtils.h"
#include "core/GameMode.h"
#include "core/ScopedSingletonManager.h"
+#include "core/Resource.h"
#include "BaseSound.h"
+#include "MoodManager.h"
namespace orxonox
{
@@ -126,10 +129,17 @@
void SoundManager::unregisterAmbientSound(BaseSound* currentAmbient)
{
+ if(currentAmbient == NULL || ambientSounds_.empty())
+ {
+ return;
+ }
if(this->ambientSounds_.front() == currentAmbient)
{
this->ambientSounds_.pop_front();
- this->ambientSounds_.front()->replay();
+ if(!(this->ambientSounds_.empty()))
+ {
+ this->ambientSounds_.front()->replay();
+ }
}
else
{
@@ -143,4 +153,16 @@
}
}
}
+
+ // Get the current mood and return the full path string to the requested sound.
+ const std::string& SoundManager::getAmbientPath(const std::string& source)
+ {
+ lastReqPath = "ambient/" + MoodManager::getInstance().getMood() + "/" + source;
+ shared_ptr<ResourceInfo> fileInfo = Resource::getInfo(lastReqPath);
+ if(fileInfo == NULL)
+ {
+ return BLANKSTRING;
+ }
+ return lastReqPath;
+ }
}
Modified: code/branches/sound3/src/orxonox/sound/SoundManager.h
===================================================================
--- code/branches/sound3/src/orxonox/sound/SoundManager.h 2009-11-04 13:31:29 UTC (rev 6030)
+++ code/branches/sound3/src/orxonox/sound/SoundManager.h 2009-11-04 15:03:03 UTC (rev 6031)
@@ -52,11 +52,13 @@
void setListenerOrientation(const Quaternion& orientation);
void registerAmbientSound(BaseSound* newAmbient);
void unregisterAmbientSound(BaseSound* currentAmbient);
+ const std::string& getAmbientPath(const std::string& source);
private:
ALCdevice* device_;
ALCcontext* context_;
std::list<BaseSound*> ambientSounds_;
+ std::string lastReqPath;
static SoundManager* singletonPtr_s;
};
More information about the Orxonox-commit
mailing list