summaryrefslogtreecommitdiff
path: root/src/audio.cpp
diff options
context:
space:
mode:
authorPaweł Redman <pawel.redman@gmail.com>2018-03-26 18:02:37 +0200
committerPaweł Redman <pawel.redman@gmail.com>2018-03-26 18:02:37 +0200
commit2f978ea5085678e98e391317cc50ac991cd726a8 (patch)
treeb1bde0c95639934202ec3f2803f2def772b7b0eb /src/audio.cpp
parent0a7f8a48a9161e16e1366d492655fd7df04f48a3 (diff)
Ambient sounds.
Using Tremulous sounds (CC-BY-SA) as placeholders for wind.ogg and water.ogg.
Diffstat (limited to 'src/audio.cpp')
-rw-r--r--src/audio.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/audio.cpp b/src/audio.cpp
index 2f70fee..af6d24b 100644
--- a/src/audio.cpp
+++ b/src/audio.cpp
@@ -20,6 +20,7 @@ along with Minitrem. If not, see <http://www.gnu.org/licenses/>.
namespace audio {
static std::list<sf::Sound> playing_sounds;
+static std::list<ambient_t*> ambient_sounds;
void clean_sounds(void)
{
@@ -41,4 +42,32 @@ void sound_t::play(void)
sound->play();
}
+void ambient_t::load(const char *path)
+{
+ printf("load %s\n", path);
+ sound.openFromFile(path);
+ sound.setLoop(true);
+ ambient_sounds.push_back(this);
+}
+
+void update_ambience(bool playing)
+{
+ for (ambient_t *ambient : ambient_sounds) {
+ if (!playing) {
+ if (ambient->playing) {
+ ambient->sound.stop();
+ ambient->playing = false;
+ }
+ continue;
+ }
+
+ if (!ambient->playing) {
+ ambient->sound.play();
+ ambient->playing = true;
+ }
+
+ ambient->sound.setVolume(ambient->weight * 100.0f);
+ }
+}
+
} // namespace audio