Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6321 was 6320, checked in by scheusso, 16 years ago

various fixes for client: NHC, sound, callback handling of Vector4 & Quaternion

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