Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6031


Ignore:
Timestamp:
Nov 4, 2009, 4:03:03 PM (14 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
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • code/branches/sound3/data/levels/sound.oxw

    r5982 r6031  
    1717    skybox       = "Orxonox/Starbox"
    1818  >
    19   <AmbientSound source="ambient/mainmenu.wav" loop="true" playOnLoad="true" />
    20   <AmbientSound source="ambient/CoreWave.wav" loop="true" playOnLoad="false">
     19  <AmbientSound source="mainmenu.wav" loop="true" playOnLoad="true" />
     20  <AmbientSound source="CoreWave.wav" loop="true" playOnLoad="false">
    2121        <events>
    2222                <activity>
  • code/branches/sound3/src/orxonox/MoodManager.cc

    r5956 r6031  
    4242    {
    4343        RegisterRootObject(MoodManager);
     44        moodOld_ = "default";
    4445        this->setConfigValues();
    4546                CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&MoodManager::setMood, this), "setMood"));
     
    5354    {
    5455        SetConfigValue(mood_, "default")
    55             .description("Sets the mood for the current level.");
     56            .description("Sets the mood for the current level.")
     57            .callback(this, &MoodManager::checkMoodValidity);
    5658    }
    5759
    58         // sets a new mood
     60        /**
     61     *  Sets the mood
     62     *  @note TODO: Inform dependent classes of mood change
     63     */
    5964        void MoodManager::setMood(const std::string& mood) {
    6065                ModifyConfigValue(mood_, set, mood);
     
    6570                return mood_;
    6671        }
     72
     73    void MoodManager::checkMoodValidity()
     74    {
     75        if(mood_ != "default" && mood_ != "dnb")        // Insert new moods here
     76        {
     77            ResetConfigValue(mood_);
     78        }
     79        COUT(0) << "MoodManager: Mood now set to " << mood_ << std::endl;
     80        return;
     81    }
    6782}
  • code/branches/sound3/src/orxonox/MoodManager.h

    r5956 r6031  
    6262            // config values
    6363            std::string mood_;
     64            std::string moodOld_;
     65
     66            void checkMoodValidity();
    6467
    6568            static MoodManager* singletonPtr_s;
  • code/branches/sound3/src/orxonox/gamestates/GSMainMenu.cc

    r5956 r6031  
    128128        void GSMainMenu::setConfigValues()
    129129    {
    130         SetConfigValue(soundPathMain_, "ambient/mainmenu.wav")
     130        SetConfigValue(soundPathMain_, "mainmenu.wav")
    131131            .description("Contains the path to the main menu sound file.")
    132132                        .callback(this, &GSMainMenu::reloadSound);
  • 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.