summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaweł Redman <pawel.redman@gmail.com>2018-03-26 14:28:20 +0200
committerPaweł Redman <pawel.redman@gmail.com>2018-03-26 14:28:20 +0200
commit0a7f8a48a9161e16e1366d492655fd7df04f48a3 (patch)
tree7d957232d075b390f9bdccfddddc968a2a9214f6
parenta016a156e76f7394c5632da325ab0b453cfb3b37 (diff)
Destroy sounds that finished playing.
-rw-r--r--src/audio.cpp11
-rw-r--r--src/common.hpp2
-rw-r--r--src/main.cpp1
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();
}