[Orxonox-commit 1664] r6382 - in code/branches/presentation2: data/levels data/levels/templates src/orxonox/sound
rgrieder at orxonox.net
rgrieder at orxonox.net
Sat Dec 19 00:18:42 CET 2009
Author: rgrieder
Date: 2009-12-19 00:18:41 +0100 (Sat, 19 Dec 2009)
New Revision: 6382
Modified:
code/branches/presentation2/data/levels/presentationHS09b.oxw
code/branches/presentation2/data/levels/sound.oxw
code/branches/presentation2/data/levels/templates/spaceship_HXY.oxt
code/branches/presentation2/data/levels/templates/spaceship_Transporter.oxt
code/branches/presentation2/src/orxonox/sound/AmbientSound.cc
code/branches/presentation2/src/orxonox/sound/AmbientSound.h
code/branches/presentation2/src/orxonox/sound/BaseSound.cc
code/branches/presentation2/src/orxonox/sound/BaseSound.h
code/branches/presentation2/src/orxonox/sound/WorldSound.cc
code/branches/presentation2/src/orxonox/sound/WorldSound.h
Log:
Several small changes in sound:
- Fixed a bug that caused a sound source to be initialised on pause() even it already existed
- The XML parameter is now called "looping" instead of "loop" because looping was used really all over the code
- The "play" XML parameter doesn't exist anymore, use "playOnLoad" for AmbientSound only.
- Added "pitch" XML parameter
- Changes in synchronisation policy: Ambient sound should not synchronise the state but instead th new playOnLoad parameter
Modified: code/branches/presentation2/data/levels/presentationHS09b.oxw
===================================================================
--- code/branches/presentation2/data/levels/presentationHS09b.oxw 2009-12-18 23:07:32 UTC (rev 6381)
+++ code/branches/presentation2/data/levels/presentationHS09b.oxw 2009-12-18 23:18:41 UTC (rev 6382)
@@ -24,7 +24,7 @@
>
-<AmbientSound ambientSource="Mars.ogg" loop="true" play="true" />
+<AmbientSound ambientSource="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" />
<?lua
@@ -257,7 +257,7 @@
-<AmbientSound ambientSource="Earth.ogg" loop="true" play="false">
+<AmbientSound ambientSource="Earth.ogg" looping="true" playOnLoad="false">
<events>
<activity>
<DistanceTrigger position="2000,0,0" distance=500 target="Camera" />
Modified: code/branches/presentation2/data/levels/sound.oxw
===================================================================
--- code/branches/presentation2/data/levels/sound.oxw 2009-12-18 23:07:32 UTC (rev 6381)
+++ code/branches/presentation2/data/levels/sound.oxw 2009-12-18 23:18:41 UTC (rev 6382)
@@ -17,8 +17,8 @@
skybox = "Orxonox/Starbox"
>
- <AmbientSound ambientSource="Earth.ogg" loop="true" play="true" />
- <AmbientSound ambientSource="Mars.ogg" loop="true" play="false">
+ <AmbientSound ambientSource="Earth.ogg" looping="true" playOnLoad="true" />
+ <AmbientSound ambientSource="Mars.ogg" looping="true">
<events>
<activity>
<DistanceTrigger position="400,0,0" distance=200 target="Camera">
@@ -29,7 +29,7 @@
</activity>
</events>
</AmbientSound>
- <AmbientSound ambientSource="Jupiter.ogg" loop="true" play="false">
+ <AmbientSound ambientSource="Jupiter.ogg" looping="true">
<events>
<activity>
<DistanceTrigger position="400,150,0" distance=200 target="Camera">
Modified: code/branches/presentation2/data/levels/templates/spaceship_HXY.oxt
===================================================================
--- code/branches/presentation2/data/levels/templates/spaceship_HXY.oxt 2009-12-18 23:07:32 UTC (rev 6381)
+++ code/branches/presentation2/data/levels/templates/spaceship_HXY.oxt 2009-12-18 23:18:41 UTC (rev 6382)
@@ -68,7 +68,7 @@
accelerationupdown = 125
>
<EffectContainer condition="idle">
- <WorldSound mainstate="activity" source="sounds/Engine_idle.ogg" loop=1 active=false/>
+ <WorldSound mainstate="activity" source="sounds/Engine_idle.ogg" looping=1 active=false/>
</EffectContainer>
<EffectContainer condition="not idle">
Modified: code/branches/presentation2/data/levels/templates/spaceship_Transporter.oxt
===================================================================
--- code/branches/presentation2/data/levels/templates/spaceship_Transporter.oxt 2009-12-18 23:07:32 UTC (rev 6381)
+++ code/branches/presentation2/data/levels/templates/spaceship_Transporter.oxt 2009-12-18 23:18:41 UTC (rev 6382)
@@ -68,7 +68,7 @@
accelerationupdown = 10
>
<EffectContainer condition="idle">
- <WorldSound mainstate="activity" source="sounds/Engine_idle.ogg" loop=1 active=false/>
+ <WorldSound mainstate="activity" source="sounds/Engine_idle.ogg" looping=1 active=false/>
</EffectContainer>
<EffectContainer condition="not idle">
Modified: code/branches/presentation2/src/orxonox/sound/AmbientSound.cc
===================================================================
--- code/branches/presentation2/src/orxonox/sound/AmbientSound.cc 2009-12-18 23:07:32 UTC (rev 6381)
+++ code/branches/presentation2/src/orxonox/sound/AmbientSound.cc 2009-12-18 23:18:41 UTC (rev 6382)
@@ -41,7 +41,9 @@
CreateFactory(AmbientSound);
AmbientSound::AmbientSound(BaseObject* creator)
- : BaseObject(creator), Synchronisable(creator)
+ : BaseObject(creator)
+ , Synchronisable(creator)
+ , bPlayOnLoad_(false)
{
RegisterObject(AmbientSound);
@@ -50,10 +52,6 @@
this->registerVariables();
}
- AmbientSound::~AmbientSound()
- {
- }
-
void AmbientSound::preDestroy()
{
if (GameMode::playsSound())
@@ -66,16 +64,17 @@
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((int&)(BaseSound::state_), ObjectDirection::ToClient, new NetworkCallback<AmbientSound>(this, &AmbientSound::stateChanged));
+ 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, "ambientSource", setAmbientSource, getAmbientSource, xmlelement, mode);
+ XMLPortParam(AmbientSound, "playOnLoad", setPlayOnLoad, getPlayOnLoad, xmlelement, mode);
}
void AmbientSound::XMLEventPort(Element& xmlelement, XMLPort::Mode mode)
@@ -87,41 +86,19 @@
void AmbientSound::play()
{
if (GameMode::playsSound())
- {
SoundManager::getInstance().registerAmbientSound(this);
- }
- else
- BaseSound::play();
}
- void AmbientSound::doPlay()
- {
- BaseSound::play();
- }
-
void AmbientSound::stop()
{
if (GameMode::playsSound())
- {
SoundManager::getInstance().unregisterAmbientSound(this);
- }
- else
- BaseSound::stop();
}
- void AmbientSound::doStop()
- {
- BaseSound::stop();
- }
-
void AmbientSound::pause()
{
if (GameMode::playsSound())
- {
SoundManager::getInstance().pauseAmbientSound(this);
- }
- else
- BaseSound::pause();
}
float AmbientSound::getRealVolume()
@@ -130,11 +107,6 @@
return SoundManager::getInstance().getRealVolume(SoundType::Music);
}
- void AmbientSound::doPause()
- {
- BaseSound::pause();
- }
-
void AmbientSound::setAmbientSource(const std::string& source)
{
this->ambientSource_ = source;
@@ -149,6 +121,13 @@
}
}
+ void AmbientSound::setPlayOnLoad(bool val)
+ {
+ this->bPlayOnLoad_ = val;
+ if (val)
+ this->play();
+ }
+
void AmbientSound::changedActivity()
{
SUPER(AmbientSound, changedActivity);
Modified: code/branches/presentation2/src/orxonox/sound/AmbientSound.h
===================================================================
--- code/branches/presentation2/src/orxonox/sound/AmbientSound.h 2009-12-18 23:07:32 UTC (rev 6381)
+++ code/branches/presentation2/src/orxonox/sound/AmbientSound.h 2009-12-18 23:18:41 UTC (rev 6382)
@@ -49,7 +49,6 @@
public:
AmbientSound(BaseObject* creator);
- ~AmbientSound();
void XMLPort(Element& xmlelement, XMLPort::Mode mode);
void XMLEventPort(Element& xmlelement, XMLPort::Mode mode);
@@ -60,18 +59,27 @@
void pause();
void setAmbientSource(const std::string& source);
- const std::string& getAmbientSource() const { return this->ambientSource_; }
- inline void ambientSourceChanged(){ this->setAmbientSource(this->ambientSource_); }
+ inline const std::string& getAmbientSource() const
+ { return this->ambientSource_; }
+ void setPlayOnLoad(bool val);
+ bool getPlayOnLoad() const
+ { return this->bPlayOnLoad_; }
+
+ protected:
+ ~AmbientSound() { }
+
private:
- virtual void preDestroy();
- void doPlay();
- void doStop();
- void doPause();
+ void preDestroy();
void registerVariables();
float getRealVolume();
+ inline void ambientSourceChanged()
+ { this->setAmbientSource(this->ambientSource_); }
+ inline void playOnLoadChanged()
+ { this->setPlayOnLoad(this->bPlayOnLoad_); }
std::string ambientSource_; //!< Analogous to source_, but mood independent
+ bool bPlayOnLoad_; //!< Play the sound immediately when loaded
};
}
Modified: code/branches/presentation2/src/orxonox/sound/BaseSound.cc
===================================================================
--- code/branches/presentation2/src/orxonox/sound/BaseSound.cc 2009-12-18 23:07:32 UTC (rev 6381)
+++ code/branches/presentation2/src/orxonox/sound/BaseSound.cc 2009-12-18 23:18:41 UTC (rev 6382)
@@ -63,22 +63,24 @@
void BaseSound::XMLPortExtern(Element& xmlelement, XMLPort::Mode mode)
{
- XMLPortParam(BaseSound, "volume", setVolume, getVolume, xmlelement, mode);
- XMLPortParam(BaseSound, "loop", setLooping, getLooping, xmlelement, mode);
- XMLPortParam(BaseSound, "play", setPlaying, isPlaying, xmlelement, mode);
- XMLPortParam(BaseSound, "source", setSource, getSource, xmlelement, mode);
+ XMLPortParam(BaseSound, "volume", setVolume, getVolume, xmlelement, mode);
+ XMLPortParam(BaseSound, "looping", setLooping, getLooping, xmlelement, mode);
+ XMLPortParam(BaseSound, "pitch", setPitch, getPitch, xmlelement, mode);
+ XMLPortParam(BaseSound, "source", setSource, getSource, xmlelement, mode);
}
- void BaseSound::play()
+ void BaseSound::doPlay()
{
this->state_ = Playing;
if (GameMode::playsSound() && this->getSourceState() != AL_PLAYING && this->soundBuffer_ != NULL)
{
if (!alIsSource(this->audioSource_))
+ {
this->audioSource_ = SoundManager::getInstance().getSoundSource();
- if (!alIsSource(this->audioSource_))
- return;
- this->initialiseSource();
+ if (!alIsSource(this->audioSource_))
+ return;
+ this->initialiseSource();
+ }
alSourcePlay(this->audioSource_);
if (int error = alGetError())
@@ -86,7 +88,7 @@
}
}
- void BaseSound::stop()
+ void BaseSound::doStop()
{
this->state_ = Stopped;
if (alIsSource(this->audioSource_))
@@ -102,7 +104,7 @@
}
}
- void BaseSound::pause()
+ void BaseSound::doPause()
{
if (this->isStopped())
return;
@@ -241,11 +243,11 @@
{
State state = this->state_; // save
if (this->isPlaying() || this->isPaused())
- BaseSound::play();
+ doPlay();
if (state == Paused)
{
this->state_ = Paused;
- BaseSound::pause();
+ doPause();
}
}
}
Modified: code/branches/presentation2/src/orxonox/sound/BaseSound.h
===================================================================
--- code/branches/presentation2/src/orxonox/sound/BaseSound.h 2009-12-18 23:07:32 UTC (rev 6381)
+++ code/branches/presentation2/src/orxonox/sound/BaseSound.h 2009-12-18 23:18:41 UTC (rev 6382)
@@ -50,21 +50,17 @@
{
public:
BaseSound();
- virtual ~BaseSound();
void XMLPortExtern(Element& xmlelement, XMLPort::Mode mode);
- virtual void play();
- virtual void stop();
- virtual void pause();
+ virtual void play() { this->doPlay(); }
+ virtual void stop() { this->doStop(); }
+ virtual void pause() { this->doPause(); }
bool isPlaying() const { return this->state_ == Playing; }
bool isPaused() const { return this->state_ == Paused; }
bool isStopped() const { return this->state_ == Stopped; }
- void setPlaying(bool val)
- { val ? this->play() : this->stop(); }
-
virtual void setSource(const std::string& source);
virtual const std::string& getSource() const
{ return this->source_; }
@@ -90,6 +86,12 @@
Paused
};
+ virtual ~BaseSound();
+
+ void doPlay();
+ void doStop();
+ void doPause();
+
// network callbacks
inline void pitchChanged()
{ this->setPitch(this->pitch_); }
Modified: code/branches/presentation2/src/orxonox/sound/WorldSound.cc
===================================================================
--- code/branches/presentation2/src/orxonox/sound/WorldSound.cc 2009-12-18 23:07:32 UTC (rev 6381)
+++ code/branches/presentation2/src/orxonox/sound/WorldSound.cc 2009-12-18 23:18:41 UTC (rev 6382)
@@ -50,18 +50,14 @@
this->bPooling_ = true;
this->registerVariables();
}
-
- WorldSound::~WorldSound()
- {
- }
void WorldSound::registerVariables()
{
- registerVariable(volume_, ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::volumeChanged));
- registerVariable(source_, ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::sourceChanged));
+ registerVariable(volume_, ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::volumeChanged));
+ registerVariable(source_, ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::sourceChanged));
registerVariable(bLooping_, ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::loopingChanged));
+ registerVariable(pitch_, ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::pitchChanged));
registerVariable((int&)(BaseSound::state_), ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::stateChanged));
- registerVariable(pitch_, ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::pitchChanged));
}
void WorldSound::XMLPort(Element& xmlelement, XMLPort::Mode mode)
@@ -124,6 +120,7 @@
float WorldSound::getRealVolume()
{
+ assert(GameMode::playsSound());
return SoundManager::getInstance().getRealVolume(SoundType::Effects);
}
}
Modified: code/branches/presentation2/src/orxonox/sound/WorldSound.h
===================================================================
--- code/branches/presentation2/src/orxonox/sound/WorldSound.h 2009-12-18 23:07:32 UTC (rev 6381)
+++ code/branches/presentation2/src/orxonox/sound/WorldSound.h 2009-12-18 23:18:41 UTC (rev 6382)
@@ -45,7 +45,6 @@
{
public:
WorldSound(BaseObject* creator);
- ~WorldSound();
void XMLPort(Element& xmlelement, XMLPort::Mode mode);
void XMLEventPort(Element& xmlelement, XMLPort::Mode mode);
@@ -53,6 +52,9 @@
void tick(float dt);
+ protected:
+ ~WorldSound() {}
+
private:
void registerVariables();
void initialiseSource();
More information about the Orxonox-commit
mailing list