diff options
author | Paweł Redman <pawel.redman@gmail.com> | 2018-03-26 18:02:37 +0200 |
---|---|---|
committer | Paweł Redman <pawel.redman@gmail.com> | 2018-03-26 18:02:37 +0200 |
commit | 2f978ea5085678e98e391317cc50ac991cd726a8 (patch) | |
tree | b1bde0c95639934202ec3f2803f2def772b7b0eb /src/audio.cpp | |
parent | 0a7f8a48a9161e16e1366d492655fd7df04f48a3 (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.cpp | 29 |
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 |