diff options
-rw-r--r-- | src/audio.cpp | 11 | ||||
-rw-r--r-- | src/common.hpp | 2 | ||||
-rw-r--r-- | src/main.cpp | 1 |
3 files changed, 12 insertions, 2 deletions
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 <http://www.gnu.org/licenses/>. namespace audio { +static std::list<sf::Sound> 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<sf::Sound> 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(); } |