Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6349


Ignore:
Timestamp:
Dec 14, 2009, 12:51:34 AM (14 years ago)
Author:
rgrieder
Message:

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.

Location:
code/branches/presentation2/src/orxonox
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation2/src/orxonox/gamestates/GSMainMenu.cc

    r6313 r6349  
    7373    {
    7474        if (GameMode::playsSound())
    75             delete this->ambient_;
     75            this->ambient_->destroy();
    7676
    7777        InputManager::getInstance().destroyState("mainMenu");
  • code/branches/presentation2/src/orxonox/sound/AmbientSound.cc

    r6326 r6349  
    5353    AmbientSound::~AmbientSound()
    5454    {
     55    }
     56
     57    void AmbientSound::preDestroy()
     58    {
     59        if (GameMode::playsSound())
     60        {
     61            // Smoothly fade out by keeping a SmartPtr
     62            SoundManager::getInstance().unregisterAmbientSound(this);
     63        }
    5564    }
    5665   
  • code/branches/presentation2/src/orxonox/sound/AmbientSound.h

    r6322 r6349  
    6767
    6868    private:
     69        virtual void preDestroy();
    6970        void doPlay();
    7071        void doStop();
  • code/branches/presentation2/src/orxonox/sound/SoundManager.cc

    r6332 r6349  
    314314    {
    315315        if (oldAmbient == NULL || ambientSounds_.empty())
    316         {
    317316            return;
    318         }
     317
    319318        if (this->ambientSounds_.front().first == oldAmbient)
    320319        {
     
    468467   
    469468
    470     void SoundManager::fadeIn(AmbientSound* sound)
     469    void SoundManager::fadeIn(const SmartPtr<AmbientSound>& sound)
    471470    {
    472471        // If we're already fading out --> remove that
    473         for (std::list<AmbientSound*>::iterator it = this->fadeOutList_.begin(); it != this->fadeOutList_.end(); it++)
     472        for (std::list<SmartPtr<AmbientSound> >::iterator it = this->fadeOutList_.begin(); it != this->fadeOutList_.end(); it++)
    474473        {
    475474            if (*it == sound)
     
    484483    }
    485484
    486     void SoundManager::fadeOut(AmbientSound* sound)
     485    void SoundManager::fadeOut(const SmartPtr<AmbientSound>& sound)
    487486    {
    488487        // If we're already fading in --> remove that
    489         for (std::list<AmbientSound*>::iterator it = this->fadeInList_.begin(); it != this->fadeInList_.end(); it++)
     488        for (std::list<SmartPtr<AmbientSound> >::iterator it = this->fadeInList_.begin(); it != this->fadeInList_.end(); it++)
    490489        {
    491490            if (*it == sound)
     
    510509       
    511510        // FADE IN
    512         for (std::list<AmbientSound*>::iterator it= this->fadeInList_.begin(); it != this->fadeInList_.end(); )
     511        for (std::list<SmartPtr<AmbientSound> >::iterator it= this->fadeInList_.begin(); it != this->fadeInList_.end(); )
    513512        {
    514513            if ((*it)->getVolume() + this->crossFadeStep_*dt > 1.0f)
     
    525524
    526525        // FADE OUT
    527         for (std::list<AmbientSound*>::iterator it = this->fadeOutList_.begin(); it != this->fadeOutList_.end(); )
     526        for (std::list<SmartPtr<AmbientSound> >::iterator it = this->fadeOutList_.begin(); it != this->fadeOutList_.end(); )
    528527        {
    529528            if ((*it)->getVolume() - this->crossFadeStep_*dt < 0.0f)
  • code/branches/presentation2/src/orxonox/sound/SoundManager.h

    r6332 r6349  
    4040#include "util/Singleton.h"
    4141#include "core/OrxonoxClass.h"
     42#include "core/SmartPtr.h"
    4243
    4344// forward declaration
     
    109110    private:
    110111        void processCrossFading(float dt);
    111         void fadeIn(AmbientSound* sound);
    112         void fadeOut(AmbientSound* sound);
     112        void fadeIn(const SmartPtr<AmbientSound>& sound);
     113        void fadeOut(const SmartPtr<AmbientSound>& sound);
    113114
    114115        void checkFadeStepValidity();
     
    133134
    134135        float crossFadeStep_;       //!< Absolute change per second (0.1 means 10% of the nominal volume) for cross fading
    135         std::list<AmbientSound*> fadeInList_;
    136         std::list<AmbientSound*> fadeOutList_;
     136        std::list<SmartPtr<AmbientSound> > fadeInList_;
     137        std::list<SmartPtr<AmbientSound> > fadeOutList_;
    137138
    138139        float soundVolume_;
Note: See TracChangeset for help on using the changeset viewer.