Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 11134 was 11071, checked in by landauf, 9 years ago

merged branch cpp11_v3 back to trunk

  • Property svn:eol-style set to native
File size: 4.9 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
61    }
62    WorldAmbientSound::~WorldAmbientSound()
63    {
64        if (this->isInitialized())
65        {
66            this->ambientSound_->destroy();
67            WorldAmbientSound::soundList_.clear();
68        }
69    }
70
71    void WorldAmbientSound::registerVariables()
72    {
73        registerVariable(this->ambientSound_->ambientSource_, ObjectDirection::ToClient, new NetworkCallback<AmbientSound>(this->ambientSound_, &AmbientSound::ambientSourceChanged));
74        registerVariable(this->ambientSound_->bLooping_,      ObjectDirection::ToClient, new NetworkCallback<AmbientSound>(this->ambientSound_, &AmbientSound::loopingChanged));
75        registerVariable(this->ambientSound_->pitch_,         ObjectDirection::ToClient, new NetworkCallback<AmbientSound>(this->ambientSound_, &AmbientSound::pitchChanged));
76        registerVariable(this->ambientSound_->bPlayOnLoad_,   ObjectDirection::ToClient, new NetworkCallback<AmbientSound>(this->ambientSound_, &AmbientSound::playOnLoadChanged));
77    }
78
79    void WorldAmbientSound::XMLPort(Element& xmlelement, XMLPort::Mode mode)
80    {
81        SUPER(WorldAmbientSound, XMLPort, xmlelement, mode);
82
83        XMLPortParamExtern(WorldAmbientSound, BaseSound, static_cast<BaseSound*>(this->ambientSound_), "looping", setLooping, getLooping, xmlelement, mode);
84        XMLPortParamExtern(WorldAmbientSound, BaseSound, static_cast<BaseSound*>(this->ambientSound_), "pitch",   setPitch,   getPitch,   xmlelement, mode);
85
86        XMLPortParamExtern(WorldAmbientSound, AmbientSound, this->ambientSound_, "source",     setAmbientSource, getAmbientSource, xmlelement, mode);
87        XMLPortParamExtern(WorldAmbientSound, AmbientSound, this->ambientSound_, "playOnLoad", setPlayOnLoad,    getPlayOnLoad,    xmlelement, mode);
88    }
89
90    void WorldAmbientSound::XMLEventPort(Element& xmlelement, XMLPort::Mode mode)
91    {
92        SUPER(WorldAmbientSound, XMLEventPort, xmlelement, mode);
93
94        XMLPortEventState(WorldAmbientSound, BaseObject, "play", play, xmlelement, mode);
95    }
96
97    void WorldAmbientSound::play()
98    {
99        this->ambientSound_->play();
100    }
101
102    void WorldAmbientSound::changedActivity()
103    {
104        SUPER(WorldAmbientSound, changedActivity);
105
106        if (this->isActive())
107            this->ambientSound_->play();
108        else
109            this->ambientSound_->stop();
110    }
111
112    void WorldAmbientSound::nextSong()
113    {
114
115        //HACK: Assuption - there is only one WorldAmbientSound in a level and only one level is used.
116        for (WorldAmbientSound* sound : ObjectList<WorldAmbientSound>())
117        {
118            while(sound->ambientSound_->setAmbientSource(WorldAmbientSound::soundList_[WorldAmbientSound::soundNumber_]) == false){
119                WorldAmbientSound::soundNumber_ = (WorldAmbientSound::soundNumber_ + 1) % WorldAmbientSound::soundList_.size();
120            }
121            WorldAmbientSound::soundNumber_ = (WorldAmbientSound::soundNumber_ + 1) % WorldAmbientSound::soundList_.size();
122        }
123    }
124}
Note: See TracBrowser for help on using the repository browser.