Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/sound3/src/orxonox/sound/AmbientSound.cc @ 6372

Last change on this file since 6372 was 6102, checked in by rgrieder, 15 years ago

Changed "source" parameter of AmbientSound to "ambientSource" to restore consistency with the c++ methods.
Adjusted sound.oxw file.

Also moved XML ports form WorldSound/AmbientSound to BaseSound::XMLPortExtern.
To make that work, I had to insert a dynamic_cast into the XMLPortParamGeneric macro. Shouldn't be a problem though. Just don't use XMLPortParam inside a class that might not be a BaseObject (at least dynamically).

  • 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
[5914]31#include "core/CoreIncludes.h"
[5896]32#include "core/EventIncludes.h"
[6069]33#include "core/GameMode.h"
[6071]34#include "core/Resource.h"
[5896]35#include "core/XMLPort.h"
[5982]36#include "SoundManager.h"
[6071]37#include "MoodManager.h"
[3060]38
[5738]39namespace orxonox
[3060]40{
[5896]41    CreateFactory(AmbientSound);
42
43    AmbientSound::AmbientSound(BaseObject* creator)
44        : BaseObject(creator)
[3060]45    {
[5896]46        RegisterObject(AmbientSound);
[6069]47
48        // Ambient sounds always fade in
49        this->setVolume(0);
[3060]50    }
51
[5896]52    AmbientSound::~AmbientSound()
[3060]53    {
54    }
55
[5896]56    void AmbientSound::XMLPort(Element& xmlelement, XMLPort::Mode mode)
[3060]57    {
[5896]58        SUPER(AmbientSound, XMLPort, xmlelement, mode);
[6102]59        BaseSound::XMLPortExtern(xmlelement, mode);
60        XMLPortParam(AmbientSound, "ambientsource", setAmbientSource, getAmbientSource, xmlelement, mode);
[3060]61    }
62
[5896]63    void AmbientSound::XMLEventPort(Element& xmlelement, XMLPort::Mode mode)
[3060]64    {
[5896]65        SUPER(AmbientSound, XMLEventPort, xmlelement, mode);
66        XMLPortEventState(AmbientSound, BaseObject, "play", play, xmlelement, mode);
[3060]67    }
[5982]68
69    void AmbientSound::play()
70    {
[6069]71        if (GameMode::playsSound())
[6046]72        {
[6069]73            COUT(3) << "Sound: " << this->getSource() << ": Playing" << std::endl;
[6046]74            SoundManager::getInstance().registerAmbientSound(this);
75        }
[5982]76    }
77
[6069]78    void AmbientSound::doPlay()
[5982]79    {
[6069]80        BaseSound::play();
[5982]81    }
82
83    void AmbientSound::stop()
84    {
[6069]85        if (GameMode::playsSound())
[6046]86        {
87            SoundManager::getInstance().unregisterAmbientSound(this);
88        }
[5982]89    }
90
[6046]91    void AmbientSound::doStop()
[5982]92    {
[6069]93        BaseSound::stop();
[5982]94    }
95
[6069]96    void AmbientSound::pause()
97    {
98        if (GameMode::playsSound())
99        {
100            SoundManager::getInstance().pauseAmbientSound(this);
101        }
102    }
103
104    void AmbientSound::doPause()
105    {
106        BaseSound::pause();
107    }
108
[6071]109    void AmbientSound::setAmbientSource(const std::string& source)
[6031]110    {
[6071]111        this->ambientSource_ = source;
[6069]112        if (GameMode::playsSound())
[6031]113        {
[6071]114            std::string path = "ambient/" + MoodManager::getInstance().getMood() + "/" + source;
115            shared_ptr<ResourceInfo> fileInfo = Resource::getInfo(path);
116            if (fileInfo != NULL)
117                this->setSource(path);
118            else
119                COUT(3) << "Sound: " << source << ": Not a valid name! Ambient sound will not change." << std::endl;       
[6031]120        }
121    }
122
[5982]123    void AmbientSound::changedActivity() 
124    {
[6100]125        SUPER(AmbientSound, changedActivity);
[6069]126        if (this->isActive())
[5982]127            this->play();
128        else 
129            this->stop();
130    }
[5896]131}
Note: See TracBrowser for help on using the repository browser.