Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5982


Ignore:
Timestamp:
Oct 21, 2009, 5:28:13 PM (15 years ago)
Author:
youngk
Message:

Ambient Sounds are now locationally triggerable, i.e if the player comes close to an object, it's own ambient sound starts playing, while the sound of the outer object is paused. Upon leaving proximity of that object, the old sound is resumed. —> Triggerable by changing active state.

Location:
code/branches/sound3
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • code/branches/sound3/src/orxonox/sound/AmbientSound.cc

    r5929 r5982  
    3232#include "core/EventIncludes.h"
    3333#include "core/XMLPort.h"
     34#include "SoundManager.h"
    3435
    3536namespace orxonox
     
    6061        XMLPortEventState(AmbientSound, BaseObject, "play", play, xmlelement, mode);
    6162    }
     63
     64    void AmbientSound::play()
     65    {
     66        COUT(3) << this->getSource() << ": Playing" << std::endl;
     67        SoundManager::getInstance().registerAmbientSound(this);
     68        SUPER(AmbientSound, play);
     69    }
     70
     71    void AmbientSound::replay()
     72    {
     73        SUPER(AmbientSound, play);
     74    }
     75
     76    void AmbientSound::stop()
     77    {
     78        SUPER(AmbientSound, stop);
     79        SoundManager::getInstance().unregisterAmbientSound(this);
     80    }
     81
     82    void AmbientSound::pause()
     83    {
     84        SUPER(AmbientSound, pause);
     85    }
     86
     87    void AmbientSound::changedActivity()
     88    {
     89        COUT(3) << this->getSource() << ": ChangedActivity: " << this->isActive() << std::endl;
     90        SUPER(AmbientSound, changedActivity);
     91        if(this->isActive())
     92        {
     93            this->play();
     94        }
     95        else
     96        {
     97            this->stop();
     98        }
     99    }
     100
    62101}
  • code/branches/sound3/src/orxonox/sound/AmbientSound.h

    r5929 r5982  
    4747        virtual ~AmbientSound();
    4848
     49        virtual void play();
     50        virtual void replay();      // is only needed for the AmbientSound list in SoundManager
     51        virtual void stop();
     52        virtual void pause();
     53
    4954        virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    5055        virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode);
     56        virtual void changedActivity();
     57
    5158
    5259    private:
  • code/branches/sound3/src/orxonox/sound/BaseSound.cc

    r5962 r5982  
    7070    }
    7171
     72    void BaseSound::replay()
     73    {
     74        BaseSound::play();
     75    }
     76
    7277    void BaseSound::stop()
    7378    {
     
    105110    void BaseSound::setPlayOnLoad(bool val)
    106111    {
    107         this->bPlayOnLoad_ = true;
    108         this->play();
     112        this->bPlayOnLoad_ = val;
     113        if(val)
     114        {
     115            this->play();
     116        }
    109117    }
    110118
  • code/branches/sound3/src/orxonox/sound/BaseSound.h

    r5929 r5982  
    4949        virtual ~BaseSound();
    5050
    51         void play();
    52         void stop();
    53         void pause();
     51        virtual void play();
     52        virtual void replay();      // is only needed for the AmbientSound list in SoundManager
     53        virtual void stop();
     54        virtual void pause();
    5455
    5556        bool isPlaying();
  • code/branches/sound3/src/orxonox/sound/SoundManager.cc

    r5946 r5982  
    3636#include "core/GameMode.h"
    3737#include "core/ScopedSingletonManager.h"
     38#include "BaseSound.h"
    3839
    3940namespace orxonox
     
    114115            COUT(2) << "Sound: OpenAL: Invalid listener orientation" << std::endl;
    115116    }
     117
     118    void SoundManager::registerAmbientSound(BaseSound* newAmbient)
     119    {
     120        if (!(this->ambientSounds_.empty()))
     121        {
     122            this->ambientSounds_.front()->pause();
     123        }
     124        this->ambientSounds_.push_front(newAmbient);
     125    }
     126
     127    void SoundManager::unregisterAmbientSound(BaseSound* currentAmbient)
     128    {
     129        if(this->ambientSounds_.front() == currentAmbient)
     130        {
     131            this->ambientSounds_.pop_front();
     132            this->ambientSounds_.front()->replay();
     133        }
     134        else
     135        {
     136            for(std::list<BaseSound*>::iterator it= this->ambientSounds_.begin(); it != this->ambientSounds_.end(); it++)
     137            {
     138                if(*it == currentAmbient)
     139                {
     140                    this->ambientSounds_.erase(it);
     141                    break;
     142                }
     143            }
     144        }
     145    }
    116146}
  • code/branches/sound3/src/orxonox/sound/SoundManager.h

    r5929 r5982  
    5151        void setListenerPosition(const Vector3& position);
    5252        void setListenerOrientation(const Quaternion& orientation);
     53        void registerAmbientSound(BaseSound* newAmbient);
     54        void unregisterAmbientSound(BaseSound* currentAmbient);
    5355
    5456    private:
    5557        ALCdevice* device_;
    5658        ALCcontext* context_;
     59        std::list<BaseSound*> ambientSounds_;
    5760
    5861        static SoundManager* singletonPtr_s;
Note: See TracChangeset for help on using the changeset viewer.