From 0a7f8a48a9161e16e1366d492655fd7df04f48a3 Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Mon, 26 Mar 2018 14:28:20 +0200 Subject: Destroy sounds that finished playing. --- src/audio.cpp | 11 +++++++++-- src/common.hpp | 2 ++ src/main.cpp | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/audio.cpp b/src/audio.cpp index 012c396..2f70fee 100644 --- a/src/audio.cpp +++ b/src/audio.cpp @@ -19,14 +19,21 @@ along with Minitrem. If not, see . namespace audio { +static std::list playing_sounds; + +void clean_sounds(void) +{ + playing_sounds.remove_if( [](sf::Sound &sound) { + return sound.getStatus() == sf::Sound::Stopped; + }); +} + void sound_t::load(const char *path) { printf("load %s\n", path); buffer.loadFromFile(path); } -static std::list playing_sounds; - void sound_t::play(void) { auto sound = playing_sounds.emplace(playing_sounds.end()); diff --git a/src/common.hpp b/src/common.hpp index df9c8d1..181139f 100644 --- a/src/common.hpp +++ b/src/common.hpp @@ -393,6 +393,8 @@ namespace render { } namespace audio { + void clean_sounds(void); + class sound_t { sf::SoundBuffer buffer; diff --git a/src/main.cpp b/src/main.cpp index 3f60f25..ea0092d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -69,6 +69,7 @@ int main() render.begin_frame(now, dt); render.render(&game); interface.render_to(&render); + audio::clean_sounds(); render.end_frame(); } -- cgit