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