Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/sound/WorldAmbientSound.cc @ 11358

Last change on this file since 11358 was 11358, checked in by patricwi, 3 years ago

space race merged

  • Property svn:eol-style set to native
File size: 5.0 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 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "WorldAmbientSound.h"
30
31#include "core/CoreIncludes.h"
32#include "core/EventIncludes.h"
33#include "core/XMLPort.h"
34#include "AmbientSound.h"
35#include "core/command/ConsoleCommandIncludes.h"
36#include <exception>
37
38
39namespace orxonox
40{
41    SetConsoleCommand("WorldAmbientSound", "nextsong",      &WorldAmbientSound::nextSong);
42
43    RegisterClass(WorldAmbientSound);
44
45    WorldAmbientSound::WorldAmbientSound(Context* context) : BaseObject(context), Synchronisable(context)
46    {
47        RegisterObject(WorldAmbientSound);
48
49        this->ambientSound_ = new AmbientSound();
50        this->registerVariables();
51        soundList_.emplace_back("Earth.ogg");
52        soundList_.emplace_back("Jupiter.ogg");
53        soundList_.emplace_back("Mars.ogg");
54        soundList_.emplace_back("allgorythm-lift_up.ogg");
55        soundList_.emplace_back("allgorythm-resonance_blaster.ogg");
56        soundList_.emplace_back("AlphaCentauri.ogg");
57        soundList_.emplace_back("Asteroid_rocks.ogg");
58        soundList_.emplace_back("Ganymede.ogg");
59        soundList_.emplace_back("luke_grey_-_hypermode.ogg");
60        soundList_.emplace_back("racetheme.ogg");
61
62
63    }
64    WorldAmbientSound::~WorldAmbientSound()
65    {
66        if (this->isInitialized())
67        {
68            this->ambientSound_->destroy();
69            WorldAmbientSound::soundList_.clear();
70        }
71    }
72
73    void WorldAmbientSound::registerVariables()
74    {
75        registerVariable(this->ambientSound_->ambientSource_, ObjectDirection::ToClient, new NetworkCallback<AmbientSound>(this->ambientSound_, &AmbientSound::ambientSourceChanged));
76        registerVariable(this->ambientSound_->bLooping_,      ObjectDirection::ToClient, new NetworkCallback<AmbientSound>(this->ambientSound_, &AmbientSound::loopingChanged));
77        registerVariable(this->ambientSound_->pitch_,         ObjectDirection::ToClient, new NetworkCallback<AmbientSound>(this->ambientSound_, &AmbientSound::pitchChanged));
78        registerVariable(this->ambientSound_->bPlayOnLoad_,   ObjectDirection::ToClient, new NetworkCallback<AmbientSound>(this->ambientSound_, &AmbientSound::playOnLoadChanged));
79    }
80
81    void WorldAmbientSound::XMLPort(Element& xmlelement, XMLPort::Mode mode)
82    {
83        SUPER(WorldAmbientSound, XMLPort, xmlelement, mode);
84
85        XMLPortParamExtern(WorldAmbientSound, BaseSound, static_cast<BaseSound*>(this->ambientSound_), "looping", setLooping, getLooping, xmlelement, mode);
86        XMLPortParamExtern(WorldAmbientSound, BaseSound, static_cast<BaseSound*>(this->ambientSound_), "pitch",   setPitch,   getPitch,   xmlelement, mode);
87
88        XMLPortParamExtern(WorldAmbientSound, AmbientSound, this->ambientSound_, "source",     setAmbientSource, getAmbientSource, xmlelement, mode);
89        XMLPortParamExtern(WorldAmbientSound, AmbientSound, this->ambientSound_, "playOnLoad", setPlayOnLoad,    getPlayOnLoad,    xmlelement, mode);
90    }
91
92    void WorldAmbientSound::XMLEventPort(Element& xmlelement, XMLPort::Mode mode)
93    {
94        SUPER(WorldAmbientSound, XMLEventPort, xmlelement, mode);
95
96        XMLPortEventState(WorldAmbientSound, BaseObject, "play", play, xmlelement, mode);
97    }
98
99    void WorldAmbientSound::play()
100    {
101        this->ambientSound_->play();
102    }
103
104    void WorldAmbientSound::changedActivity()
105    {
106        SUPER(WorldAmbientSound, changedActivity);
107
108        if (this->isActive())
109            this->ambientSound_->play();
110        else
111            this->ambientSound_->stop();
112    }
113
114    void WorldAmbientSound::nextSong()
115    {
116
117        //HACK: Assuption - there is only one WorldAmbientSound in a level and only one level is used.
118        for (WorldAmbientSound* sound : ObjectList<WorldAmbientSound>())
119        {
120            while(sound->ambientSound_->setAmbientSource(WorldAmbientSound::soundList_[WorldAmbientSound::soundNumber_]) == false){
121                WorldAmbientSound::soundNumber_ = (WorldAmbientSound::soundNumber_ + 1) % WorldAmbientSound::soundList_.size();
122            }
123            WorldAmbientSound::soundNumber_ = (WorldAmbientSound::soundNumber_ + 1) % WorldAmbientSound::soundList_.size();
124        }
125    }
126}
Note: See TracBrowser for help on using the repository browser.