Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 4, 2009, 4:03:03 PM (15 years ago)
Author:
youngk
Message:

Implemented automatic ambient sound file path fetch according to current mood.
Valid moods are: default and dnb
BUG Loading of a second sound fails (independent of the file used). Probably an error in BaseSound::setSource().

Location:
code/branches/sound3/src/orxonox/sound
Files:
5 edited

Legend:

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

    r5982 r6031  
    8585    }
    8686
     87    void AmbientSound::setSource(const std::string& source)
     88    {
     89        if(source.find('/') == std::string.npos)
     90        {
     91            std::string filePath = SoundManager::getInstance().getAmbientPath(source);
     92            if(!(filePath.empty()))
     93            {
     94                BaseSound::setSource(filePath);
     95                return;
     96            }
     97        }
     98        COUT(3) << source << ": Not a valid name! Ambient sound will not change." << std::endl;       
     99    }
     100
    87101    void AmbientSound::changedActivity()
    88102    {
  • code/branches/sound3/src/orxonox/sound/AmbientSound.h

    r5982 r6031  
    5252        virtual void pause();
    5353
     54        virtual void setSource(const std::string& source);
     55
    5456        virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    5557        virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode);
  • code/branches/sound3/src/orxonox/sound/BaseSound.h

    r5982 r6031  
    5858        bool isStopped();
    5959
    60         void setSource(const std::string& source);
     60        virtual void setSource(const std::string& source);
    6161        const std::string& getSource() { return this->source_; }
    6262
  • code/branches/sound3/src/orxonox/sound/SoundManager.cc

    r5982 r6031  
    3434#include "util/Math.h"
    3535#include "util/ScopeGuard.h"
     36#include "util/StringUtils.h"
    3637#include "core/GameMode.h"
    3738#include "core/ScopedSingletonManager.h"
     39#include "core/Resource.h"
    3840#include "BaseSound.h"
     41#include "MoodManager.h"
    3942
    4043namespace orxonox
     
    127130    void SoundManager::unregisterAmbientSound(BaseSound* currentAmbient)
    128131    {
     132        if(currentAmbient == NULL || ambientSounds_.empty())
     133        {
     134            return;
     135        }
    129136        if(this->ambientSounds_.front() == currentAmbient)
    130137        {
    131138            this->ambientSounds_.pop_front();
    132             this->ambientSounds_.front()->replay();
     139            if(!(this->ambientSounds_.empty()))
     140            {
     141                this->ambientSounds_.front()->replay();
     142            }
    133143        }
    134144        else
     
    144154        }
    145155    }
     156
     157    // Get the current mood and return the full path string to the requested sound.
     158    const std::string& SoundManager::getAmbientPath(const std::string& source)
     159    {
     160        lastReqPath = "ambient/" + MoodManager::getInstance().getMood() + "/" + source;
     161        shared_ptr<ResourceInfo> fileInfo = Resource::getInfo(lastReqPath);
     162        if(fileInfo == NULL)
     163        {
     164            return BLANKSTRING;
     165        }
     166        return lastReqPath;
     167    }
    146168}
  • code/branches/sound3/src/orxonox/sound/SoundManager.h

    r5982 r6031  
    5353        void registerAmbientSound(BaseSound* newAmbient);
    5454        void unregisterAmbientSound(BaseSound* currentAmbient);
     55        const std::string& getAmbientPath(const std::string& source);
    5556
    5657    private:
     
    5859        ALCcontext* context_;
    5960        std::list<BaseSound*> ambientSounds_;
     61        std::string lastReqPath;
    6062
    6163        static SoundManager* singletonPtr_s;
Note: See TracChangeset for help on using the changeset viewer.