Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 25, 2009, 10:23:58 PM (14 years ago)
Author:
rgrieder
Message:

Merged presentation2 branch back to trunk.
Major new features:

  • Actual GUI with settings, etc.
  • Improved space ship steering (human interaction)
  • Rocket fire and more particle effects
  • Advanced sound framework
Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/orxonox/sound/AmbientSound.cc

    r5929 r6417  
    3131#include "core/CoreIncludes.h"
    3232#include "core/EventIncludes.h"
     33#include "core/GameMode.h"
     34#include "core/Resource.h"
    3335#include "core/XMLPort.h"
     36#include "SoundManager.h"
    3437
    3538namespace orxonox
     
    3942    AmbientSound::AmbientSound(BaseObject* creator)
    4043        : BaseObject(creator)
     44        , Synchronisable(creator)
     45        , bPlayOnLoad_(false)
    4146    {
    4247        RegisterObject(AmbientSound);
     48
     49        // Ambient sounds always fade in
     50        this->setVolume(0);
     51        this->registerVariables();
    4352    }
    4453
    45     AmbientSound::~AmbientSound()
     54    void AmbientSound::preDestroy()
    4655    {
     56        if (GameMode::playsSound())
     57        {
     58            // Smoothly fade out by keeping a SmartPtr
     59            SoundManager::getInstance().unregisterAmbientSound(this);
     60        }
     61    }
     62
     63    void AmbientSound::registerVariables()
     64    {
     65        registerVariable(ambientSource_, ObjectDirection::ToClient, new NetworkCallback<AmbientSound>(this, &AmbientSound::ambientSourceChanged));
     66        registerVariable(bLooping_,      ObjectDirection::ToClient, new NetworkCallback<AmbientSound>(this, &AmbientSound::loopingChanged));
     67        registerVariable(pitch_,         ObjectDirection::ToClient, new NetworkCallback<AmbientSound>(this, &AmbientSound::pitchChanged));
     68        registerVariable(bPlayOnLoad_,   ObjectDirection::ToClient, new NetworkCallback<AmbientSound>(this, &AmbientSound::playOnLoadChanged));
    4769    }
    4870
     
    5072    {
    5173        SUPER(AmbientSound, XMLPort, xmlelement, mode);
    52         XMLPortParamExtern(AmbientSound, BaseSound, this, "source", setSource, getSource, xmlelement, mode);
    53         XMLPortParamExtern(AmbientSound, BaseSound, this, "loop", setLoop, getLoop, xmlelement, mode);
    54         XMLPortParamExtern(AmbientSound, BaseSound, this, "playOnLoad", setPlayOnLoad, getPlayOnLoad, xmlelement, mode);
     74        BaseSound::XMLPortExtern(xmlelement, mode);
     75        XMLPortParam(AmbientSound, "ambientSource", setAmbientSource, getAmbientSource, xmlelement, mode);
     76        XMLPortParam(AmbientSound, "playOnLoad", setPlayOnLoad, getPlayOnLoad, xmlelement, mode);
    5577    }
    5678
     
    6082        XMLPortEventState(AmbientSound, BaseObject, "play", play, xmlelement, mode);
    6183    }
     84
     85    void AmbientSound::play()
     86    {
     87        if (GameMode::playsSound())
     88            SoundManager::getInstance().registerAmbientSound(this);
     89    }
     90
     91    void AmbientSound::stop()
     92    {
     93        if (GameMode::playsSound())
     94            SoundManager::getInstance().unregisterAmbientSound(this);
     95    }
     96
     97    void AmbientSound::pause()
     98    {
     99        if (GameMode::playsSound())
     100            SoundManager::getInstance().pauseAmbientSound(this);
     101    }
     102
     103    float AmbientSound::getRealVolume()
     104    {
     105        assert(GameMode::playsSound());
     106        return SoundManager::getInstance().getRealVolume(SoundType::Music);
     107    }
     108
     109    void AmbientSound::setAmbientSource(const std::string& source)
     110    {
     111        this->ambientSource_ = source;
     112        this->moodChanged(this->getMood());
     113    }
     114
     115    void AmbientSound::moodChanged(const std::string& mood)
     116    {
     117        if (GameMode::playsSound())
     118        {
     119            const std::string& path = "ambient/" + MoodManager::getInstance().getMood() + '/' + this->ambientSource_;
     120            shared_ptr<ResourceInfo> fileInfo = Resource::getInfo(path);
     121            if (fileInfo != NULL)
     122                this->setSource(path);
     123            else
     124                COUT(3) << "Sound: " << this->ambientSource_ << ": Not a valid name! Ambient sound will not change." << std::endl;
     125        }
     126    }
     127
     128    void AmbientSound::setPlayOnLoad(bool val)
     129    {
     130        this->bPlayOnLoad_ = val;
     131        if (val)
     132            this->play();
     133    }
     134
     135    void AmbientSound::changedActivity()
     136    {
     137        SUPER(AmbientSound, changedActivity);
     138        if (this->isActive())
     139            this->play();
     140        else
     141            this->stop();
     142    }
    62143}
Note: See TracChangeset for help on using the changeset viewer.