From 2f978ea5085678e98e391317cc50ac991cd726a8 Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Mon, 26 Mar 2018 18:02:37 +0200 Subject: Ambient sounds. Using Tremulous sounds (CC-BY-SA) as placeholders for wind.ogg and water.ogg. --- src/audio.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/audio.cpp') 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 . namespace audio { static std::list playing_sounds; +static std::list 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 -- cgit