Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10938 was 10624, checked in by landauf, 9 years ago

merged branch core7 back to trunk

  • Property svn:eol-style set to native
File size: 5.0 KB
RevLine 
[7854]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"
[10624]35#include "core/command/ConsoleCommandIncludes.h"
[9939]36#include <exception>
[7854]37
[9939]38
[7854]39namespace orxonox
40{
[9945]41    SetConsoleCommand("WorldAmbientSound", "nextsong",      &WorldAmbientSound::nextSong);
[9939]42
[9667]43    RegisterClass(WorldAmbientSound);
[7854]44
[9667]45    WorldAmbientSound::WorldAmbientSound(Context* context) : BaseObject(context), Synchronisable(context)
[7854]46    {
47        RegisterObject(WorldAmbientSound);
48
49        this->ambientSound_ = new AmbientSound();
50        this->registerVariables();
[9939]51        soundList_.push_back("Earth.ogg");
52        soundList_.push_back("Jupiter.ogg");
53        soundList_.push_back("Mars.ogg");
54        soundList_.push_back("allgorythm-lift_up.ogg");
55        soundList_.push_back("allgorythm-resonance_blaster.ogg");
56        soundList_.push_back("AlphaCentauri.ogg");
57        soundList_.push_back("Asteroid_rocks.ogg");
58        soundList_.push_back("Ganymede.ogg");
59        soundList_.push_back("luke_grey_-_hypermode.ogg");
60
[7854]61    }
62    WorldAmbientSound::~WorldAmbientSound()
63    {
64        if (this->isInitialized())
65        {
66            this->ambientSound_->destroy();
[9939]67            WorldAmbientSound::soundList_.clear();
[7854]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    }
[9939]111
112    void WorldAmbientSound::nextSong()
113    {
114
[9945]115        //HACK: Assuption - there is only one WorldAmbientSound in a level and only one level is used.
116        for (ObjectList<WorldAmbientSound>::iterator it = ObjectList<WorldAmbientSound>::begin();
117             it != ObjectList<WorldAmbientSound>::end(); ++it)
118        {
119            while(it->ambientSound_->setAmbientSource(WorldAmbientSound::soundList_[WorldAmbientSound::soundNumber_]) == false){
120                WorldAmbientSound::soundNumber_ = (WorldAmbientSound::soundNumber_ + 1) % WorldAmbientSound::soundList_.size();
121            }
122            WorldAmbientSound::soundNumber_ = (WorldAmbientSound::soundNumber_ + 1) % WorldAmbientSound::soundList_.size();
123        }
[9939]124    }
[7854]125}
Note: See TracBrowser for help on using the repository browser.