Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation2/src/orxonox/sound/AmbientSound.cc @ 6310

Last change on this file since 6310 was 6307, checked in by scheusso, 15 years ago

Approach to make sounds synchronisable (not yet working)

  • Property svn:eol-style set to native
File size: 4.5 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/EventIncludes.h"
33#include "core/GameMode.h"
34#include "core/Resource.h"
35#include "core/XMLPort.h"
36#include "SoundManager.h"
37#include "MoodManager.h"
38
39namespace orxonox
40{
41    CreateFactory(AmbientSound);
42
43    AmbientSound::AmbientSound(BaseObject* creator)
44        : BaseObject(creator), Synchronisable(creator)
45    {
46        RegisterObject(AmbientSound);
47
48        // Ambient sounds always fade in
49        this->setVolume(0);
50        this->registerVariables();
51    }
52
53    AmbientSound::~AmbientSound()
54    {
55    }
56   
57    void AmbientSound::registerVariables()
58    {
59        registerVariable(volume_, ObjectDirection::ToClient, new NetworkCallback<BaseSound>(static_cast<BaseSound*>(this), &BaseSound::volumeChanged));
60//         registerVariable(source_, ObjectDirection::ToClient, new NetworkCallback<BaseSound>(static_cast<BaseSound*>(this), &BaseSound::sourceChanged));
61        registerVariable(ambientSource_, ObjectDirection::ToClient, new NetworkCallback<AmbientSound>(this, &AmbientSound::ambientSourceChanged));
62        registerVariable(bLooping_, ObjectDirection::ToClient, new NetworkCallback<BaseSound>(static_cast<BaseSound*>(this), &BaseSound::loopingChanged));
63        registerVariable(pitch_, ObjectDirection::ToClient, new NetworkCallback<BaseSound>(static_cast<BaseSound*>(this), &BaseSound::pitchChanged));
64        registerVariable((int&)(BaseSound::state_), ObjectDirection::ToClient);
65    }
66
67    void AmbientSound::XMLPort(Element& xmlelement, XMLPort::Mode mode)
68    {
69        SUPER(AmbientSound, XMLPort, xmlelement, mode);
70        BaseSound::XMLPortExtern(xmlelement, mode);
71        XMLPortParam(AmbientSound, "ambientsource", setAmbientSource, getAmbientSource, xmlelement, mode);
72    }
73
74    void AmbientSound::XMLEventPort(Element& xmlelement, XMLPort::Mode mode)
75    {
76        SUPER(AmbientSound, XMLEventPort, xmlelement, mode);
77        XMLPortEventState(AmbientSound, BaseObject, "play", play, xmlelement, mode);
78    }
79
80    void AmbientSound::play()
81    {
82        if (GameMode::playsSound())
83        {
84            SoundManager::getInstance().registerAmbientSound(this);
85        }
86    }
87
88    void AmbientSound::doPlay()
89    {
90        BaseSound::play();
91    }
92
93    void AmbientSound::stop()
94    {
95        if (GameMode::playsSound())
96        {
97            SoundManager::getInstance().unregisterAmbientSound(this);
98        }
99    }
100
101    void AmbientSound::doStop()
102    {
103        BaseSound::stop();
104    }
105
106    void AmbientSound::pause()
107    {
108        if (GameMode::playsSound())
109        {
110            SoundManager::getInstance().pauseAmbientSound(this);
111        }
112    }
113   
114    float AmbientSound::getVolumeGain()
115    {
116        return SoundManager::getInstance().getVolume(SoundType::ambient);
117    }
118
119    void AmbientSound::doPause()
120    {
121        BaseSound::pause();
122    }
123
124    void AmbientSound::setAmbientSource(const std::string& source)
125    {
126        this->ambientSource_ = source;
127        if (GameMode::playsSound())
128        {
129            std::string path = "ambient/" + MoodManager::getInstance().getMood() + "/" + source;
130            shared_ptr<ResourceInfo> fileInfo = Resource::getInfo(path);
131            if (fileInfo != NULL)
132                this->setSource(path);
133            else
134                COUT(3) << "Sound: " << source << ": Not a valid name! Ambient sound will not change." << std::endl;       
135        }
136    }
137
138    void AmbientSound::changedActivity() 
139    {
140        SUPER(AmbientSound, changedActivity);
141        if (this->isActive())
142            this->play();
143        else 
144            this->stop();
145    }
146}
Note: See TracBrowser for help on using the repository browser.