diff options
author | Paweł Redman <pawel.redman@gmail.com> | 2018-03-26 14:28:20 +0200 |
---|---|---|
committer | Paweł Redman <pawel.redman@gmail.com> | 2018-03-26 14:28:20 +0200 |
commit | 0a7f8a48a9161e16e1366d492655fd7df04f48a3 (patch) | |
tree | 7d957232d075b390f9bdccfddddc968a2a9214f6 | |
parent | a016a156e76f7394c5632da325ab0b453cfb3b37 (diff) |
Destroy sounds that finished playing.
-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(); } |