[Orxonox-commit 1631] r6349 - in code/branches/presentation2/src/orxonox: gamestates sound
rgrieder at orxonox.net
rgrieder at orxonox.net
Mon Dec 14 00:51:34 CET 2009
Author: rgrieder
Date: 2009-12-14 00:51:34 +0100 (Mon, 14 Dec 2009)
New Revision: 6349
Modified:
code/branches/presentation2/src/orxonox/gamestates/GSMainMenu.cc
code/branches/presentation2/src/orxonox/sound/AmbientSound.cc
code/branches/presentation2/src/orxonox/sound/AmbientSound.h
code/branches/presentation2/src/orxonox/sound/SoundManager.cc
code/branches/presentation2/src/orxonox/sound/SoundManager.h
Log:
Overriding preDestroy() in AmbientSound to make them fade out when the level unloads.
@Kevin: this should also prevent the random bug you showed me when reloading a level with ambient sound.
Modified: code/branches/presentation2/src/orxonox/gamestates/GSMainMenu.cc
===================================================================
--- code/branches/presentation2/src/orxonox/gamestates/GSMainMenu.cc 2009-12-13 23:50:22 UTC (rev 6348)
+++ code/branches/presentation2/src/orxonox/gamestates/GSMainMenu.cc 2009-12-13 23:51:34 UTC (rev 6349)
@@ -72,7 +72,7 @@
GSMainMenu::~GSMainMenu()
{
if (GameMode::playsSound())
- delete this->ambient_;
+ this->ambient_->destroy();
InputManager::getInstance().destroyState("mainMenu");
Modified: code/branches/presentation2/src/orxonox/sound/AmbientSound.cc
===================================================================
--- code/branches/presentation2/src/orxonox/sound/AmbientSound.cc 2009-12-13 23:50:22 UTC (rev 6348)
+++ code/branches/presentation2/src/orxonox/sound/AmbientSound.cc 2009-12-13 23:51:34 UTC (rev 6349)
@@ -53,6 +53,15 @@
AmbientSound::~AmbientSound()
{
}
+
+ void AmbientSound::preDestroy()
+ {
+ if (GameMode::playsSound())
+ {
+ // Smoothly fade out by keeping a SmartPtr
+ SoundManager::getInstance().unregisterAmbientSound(this);
+ }
+ }
void AmbientSound::registerVariables()
{
Modified: code/branches/presentation2/src/orxonox/sound/AmbientSound.h
===================================================================
--- code/branches/presentation2/src/orxonox/sound/AmbientSound.h 2009-12-13 23:50:22 UTC (rev 6348)
+++ code/branches/presentation2/src/orxonox/sound/AmbientSound.h 2009-12-13 23:51:34 UTC (rev 6349)
@@ -66,6 +66,7 @@
inline void ambientSourceChanged(){ this->setAmbientSource(this->ambientSource_); }
private:
+ virtual void preDestroy();
void doPlay();
void doStop();
void doPause();
Modified: code/branches/presentation2/src/orxonox/sound/SoundManager.cc
===================================================================
--- code/branches/presentation2/src/orxonox/sound/SoundManager.cc 2009-12-13 23:50:22 UTC (rev 6348)
+++ code/branches/presentation2/src/orxonox/sound/SoundManager.cc 2009-12-13 23:51:34 UTC (rev 6349)
@@ -313,9 +313,8 @@
void SoundManager::unregisterAmbientSound(AmbientSound* oldAmbient)
{
if (oldAmbient == NULL || ambientSounds_.empty())
- {
return;
- }
+
if (this->ambientSounds_.front().first == oldAmbient)
{
this->fadeOut(oldAmbient);
@@ -467,10 +466,10 @@
}
- void SoundManager::fadeIn(AmbientSound* sound)
+ void SoundManager::fadeIn(const SmartPtr<AmbientSound>& sound)
{
// If we're already fading out --> remove that
- for (std::list<AmbientSound*>::iterator it = this->fadeOutList_.begin(); it != this->fadeOutList_.end(); it++)
+ for (std::list<SmartPtr<AmbientSound> >::iterator it = this->fadeOutList_.begin(); it != this->fadeOutList_.end(); it++)
{
if (*it == sound)
{
@@ -483,10 +482,10 @@
this->fadeInList_.push_back(sound);
}
- void SoundManager::fadeOut(AmbientSound* sound)
+ void SoundManager::fadeOut(const SmartPtr<AmbientSound>& sound)
{
// If we're already fading in --> remove that
- for (std::list<AmbientSound*>::iterator it = this->fadeInList_.begin(); it != this->fadeInList_.end(); it++)
+ for (std::list<SmartPtr<AmbientSound> >::iterator it = this->fadeInList_.begin(); it != this->fadeInList_.end(); it++)
{
if (*it == sound)
{
@@ -509,7 +508,7 @@
}
// FADE IN
- for (std::list<AmbientSound*>::iterator it= this->fadeInList_.begin(); it != this->fadeInList_.end(); )
+ for (std::list<SmartPtr<AmbientSound> >::iterator it= this->fadeInList_.begin(); it != this->fadeInList_.end(); )
{
if ((*it)->getVolume() + this->crossFadeStep_*dt > 1.0f)
{
@@ -524,7 +523,7 @@
}
// FADE OUT
- for (std::list<AmbientSound*>::iterator it = this->fadeOutList_.begin(); it != this->fadeOutList_.end(); )
+ for (std::list<SmartPtr<AmbientSound> >::iterator it = this->fadeOutList_.begin(); it != this->fadeOutList_.end(); )
{
if ((*it)->getVolume() - this->crossFadeStep_*dt < 0.0f)
{
Modified: code/branches/presentation2/src/orxonox/sound/SoundManager.h
===================================================================
--- code/branches/presentation2/src/orxonox/sound/SoundManager.h 2009-12-13 23:50:22 UTC (rev 6348)
+++ code/branches/presentation2/src/orxonox/sound/SoundManager.h 2009-12-13 23:51:34 UTC (rev 6349)
@@ -39,6 +39,7 @@
#include "util/Singleton.h"
#include "core/OrxonoxClass.h"
+#include "core/SmartPtr.h"
// forward declaration
typedef int ALenum;
@@ -108,8 +109,8 @@
private:
void processCrossFading(float dt);
- void fadeIn(AmbientSound* sound);
- void fadeOut(AmbientSound* sound);
+ void fadeIn(const SmartPtr<AmbientSound>& sound);
+ void fadeOut(const SmartPtr<AmbientSound>& sound);
void checkFadeStepValidity();
bool checkVolumeValidity(SoundType::Value type);
@@ -132,8 +133,8 @@
AmbientList ambientSounds_;
float crossFadeStep_; //!< Absolute change per second (0.1 means 10% of the nominal volume) for cross fading
- std::list<AmbientSound*> fadeInList_;
- std::list<AmbientSound*> fadeOutList_;
+ std::list<SmartPtr<AmbientSound> > fadeInList_;
+ std::list<SmartPtr<AmbientSound> > fadeOutList_;
float soundVolume_;
float ambientVolume_;
More information about the Orxonox-commit
mailing list