Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core7/src/orxonox/sound/AmbientSound.cc @ 10420

Last change on this file since 10420 was 10380, checked in by landauf, 10 years ago

registered missing classes.
WorldEntityCollisionShape is the only class which was really missing, all other classes are singletons or part of the framework.

  • Property svn:eol-style set to native
File size: 3.4 KB
Line 
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:
23 *      Reto Grieder
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "AmbientSound.h"
30
31#include "core/CoreIncludes.h"
32#include "core/GameMode.h"
33#include "core/Resource.h"
34#include "SoundManager.h"
35
36namespace orxonox
37{
38    RegisterAbstractClass(AmbientSound).inheritsFrom<BaseSound>().inheritsFrom<MoodListener>();
39
40    AmbientSound::AmbientSound()
41        : bPlayOnLoad_(false)
42    {
43        RegisterObject(AmbientSound);
44
45        // Ambient sounds always fade in
46        this->setVolume(0.0f);
47    }
48
49    void AmbientSound::preDestroy()
50    {
51        if (GameMode::playsSound())
52        {
53            // Smoothly fade out by keeping a SmartPtr
54            SoundManager::getInstance().unregisterAmbientSound(this);
55        }
56    }
57
58    void AmbientSound::play()
59    {
60        if (GameMode::playsSound())
61            SoundManager::getInstance().registerAmbientSound(this);
62    }
63
64    bool AmbientSound::stop()
65    {
66        if (GameMode::playsSound())
67            SoundManager::getInstance().unregisterAmbientSound(this);
68        return false; // sound source not (yet) destroyed - return false
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
83    bool AmbientSound::setAmbientSource(const std::string& source)
84    {
85        this->ambientSource_ = source;
86        return(this->moodChanged(MoodManager::getInstance().getMood()));
87    }
88
89    bool AmbientSound::moodChanged(const std::string& mood)
90    {
91        if (GameMode::playsSound())
92        {
93            const std::string& path = "ambient/" + mood + '/' + this->ambientSource_;
94            shared_ptr<ResourceInfo> fileInfo = Resource::getInfo(path);
95            if (fileInfo != NULL)
96            {
97                orxout(user_info) << "Loading ambient sound " << path << "..." << endl; // TODO: make this output internal if we implement sound streaming
98                this->setSource(path);
99
100                // all went fine
101                return true;
102            }
103            else
104            {
105                orxout(internal_warning, context::sound) << this->ambientSource_ << ": Not a valid name! Ambient sound will not change." << endl;
106
107                // everything went southways
108                return false;
109            }
110        }
111        return false;
112    }
113
114    void AmbientSound::setPlayOnLoad(bool val)
115    {
116        this->bPlayOnLoad_ = val;
117        if (val)
118            this->play();
119    }
120}
Note: See TracBrowser for help on using the repository browser.