Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/sound/AmbientSound.cc @ 12302

Last change on this file since 12302 was 11071, checked in by landauf, 9 years ago

merged branch cpp11_v3 back to trunk

  • Property svn:eol-style set to native
File size: 3.5 KB
RevLine 
[3060]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
[5896]23 *      Reto Grieder
[3060]24 *   Co-authors:
25 *      ...
26 *
27 */
[3196]28
[5896]29#include "AmbientSound.h"
[3196]30
[8079]31#include "core/CoreIncludes.h"
[6417]32#include "core/GameMode.h"
33#include "core/Resource.h"
34#include "SoundManager.h"
[3060]35
[5738]36namespace orxonox
[3060]37{
[10624]38    RegisterAbstractClass(AmbientSound).inheritsFrom<BaseSound>().inheritsFrom<MoodListener>();
39
[7854]40    AmbientSound::AmbientSound()
41        : bPlayOnLoad_(false)
[3060]42    {
[8079]43        RegisterObject(AmbientSound);
44
[6417]45        // Ambient sounds always fade in
[8351]46        this->setVolume(0.0f);
[3060]47    }
48
[6417]49    void AmbientSound::preDestroy()
[3060]50    {
[6417]51        if (GameMode::playsSound())
52        {
[10624]53            // Smoothly fade out by keeping a StrongPtr
[6417]54            SoundManager::getInstance().unregisterAmbientSound(this);
55        }
[3060]56    }
57
[6417]58    void AmbientSound::play()
59    {
60        if (GameMode::playsSound())
61            SoundManager::getInstance().registerAmbientSound(this);
62    }
63
[7856]64    bool AmbientSound::stop()
[6417]65    {
66        if (GameMode::playsSound())
67            SoundManager::getInstance().unregisterAmbientSound(this);
[7856]68        return false; // sound source not (yet) destroyed - return false
[6417]69    }
70
71    void AmbientSound::pause()
72    {
73        if (GameMode::playsSound())
74            SoundManager::getInstance().pauseAmbientSound(this);
75    }
76
77    float AmbientSound::getRealVolume()
78    {
79        assert(GameMode::playsSound());
80        return SoundManager::getInstance().getRealVolume(SoundType::Music);
81    }
82
[9939]83    bool AmbientSound::setAmbientSource(const std::string& source)
[6417]84    {
85        this->ambientSource_ = source;
[9939]86        return(this->moodChanged(MoodManager::getInstance().getMood()));
[6417]87    }
88
[9939]89    bool AmbientSound::moodChanged(const std::string& mood)
[6417]90    {
91        if (GameMode::playsSound())
92        {
[8706]93            const std::string& path = "ambient/" + mood + '/' + this->ambientSource_;
[11071]94            std::shared_ptr<ResourceInfo> fileInfo = Resource::getInfo(path);
95            if (fileInfo != nullptr)
[8861]96            {
97                orxout(user_info) << "Loading ambient sound " << path << "..." << endl; // TODO: make this output internal if we implement sound streaming
[6417]98                this->setSource(path);
[9939]99
100                // all went fine
101                return true;
[8861]102            }
[6417]103            else
[8861]104            {
[8858]105                orxout(internal_warning, context::sound) << this->ambientSource_ << ": Not a valid name! Ambient sound will not change." << endl;
[9939]106
107                // everything went southways
108                return false;
[8861]109            }
[6417]110        }
[9939]111        return false;
[6417]112    }
113
114    void AmbientSound::setPlayOnLoad(bool val)
115    {
116        this->bPlayOnLoad_ = val;
117        if (val)
118            this->play();
119    }
[5896]120}
Note: See TracBrowser for help on using the repository browser.