| [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] | 39 | namespace 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(); |
|---|
| [11071] | 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"); |
|---|
| [11358] | 60 | soundList_.emplace_back("racetheme.ogg"); |
|---|
| [9939] | 61 | |
|---|
| [11358] | 62 | |
|---|
| [7854] | 63 | } |
|---|
| 64 | WorldAmbientSound::~WorldAmbientSound() |
|---|
| 65 | { |
|---|
| 66 | if (this->isInitialized()) |
|---|
| 67 | { |
|---|
| 68 | this->ambientSound_->destroy(); |
|---|
| [9939] | 69 | WorldAmbientSound::soundList_.clear(); |
|---|
| [7854] | 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 | } |
|---|
| [9939] | 113 | |
|---|
| 114 | void WorldAmbientSound::nextSong() |
|---|
| 115 | { |
|---|
| 116 | |
|---|
| [9945] | 117 | //HACK: Assuption - there is only one WorldAmbientSound in a level and only one level is used. |
|---|
| [11071] | 118 | for (WorldAmbientSound* sound : ObjectList<WorldAmbientSound>()) |
|---|
| [9945] | 119 | { |
|---|
| [11071] | 120 | while(sound->ambientSound_->setAmbientSource(WorldAmbientSound::soundList_[WorldAmbientSound::soundNumber_]) == false){ |
|---|
| [9945] | 121 | WorldAmbientSound::soundNumber_ = (WorldAmbientSound::soundNumber_ + 1) % WorldAmbientSound::soundList_.size(); |
|---|
| 122 | } |
|---|
| 123 | WorldAmbientSound::soundNumber_ = (WorldAmbientSound::soundNumber_ + 1) % WorldAmbientSound::soundList_.size(); |
|---|
| 124 | } |
|---|
| [9939] | 125 | } |
|---|
| [7854] | 126 | } |
|---|