From 5a71c2486c4f69c1befb15db6f991854ea50c404 Mon Sep 17 00:00:00 2001 From: David Griffith Date: Tue, 18 Jun 2019 00:37:21 -0700 Subject: [PATCH] Partial fix of #120. Subsequent hoofbeats block until another key is pressed. end_of_sound() must be called at the end of every sound played so that the next sound can be played. Otherwise only one sound is played per turn. os_tick() seems to be the correct place for end_of_sound() to be called, but I'm not sure about the sem_post(&sound_done) call. Why does process_engine() block until the next key is pressed? --- src/curses/ux_audio.c | 3 +++ src/curses/ux_input.c | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/src/curses/ux_audio.c b/src/curses/ux_audio.c index 845888e..2896f16 100644 --- a/src/curses/ux_audio.c +++ b/src/curses/ux_audio.c @@ -43,6 +43,7 @@ #include "ux_audio.h" f_setup_t f_setup; +sem_t sound_done; /* 1 if the sound is done */ #ifndef NO_SOUND @@ -604,6 +605,7 @@ process_engine(sound_engine_t *e) sound->cleanup(sound); free(sound); e->streams[i] = NULL; + sem_post(&sound_done); } } } @@ -794,6 +796,7 @@ os_init_sound(void) /*No events registered on startup*/ sem_init(&frotz_audio.ev_free, 0, 1); sem_init(&frotz_audio.ev_pending, 0, 0); + sem_init(&sound_done, 0, 0); frotz_audio.event.type = 0; /*Start audio thread*/ diff --git a/src/curses/ux_input.c b/src/curses/ux_input.c index 680226a..f23d264 100644 --- a/src/curses/ux_input.c +++ b/src/curses/ux_input.c @@ -39,6 +39,11 @@ #include #endif +#ifndef NO_SOUND +#include +sem_t sound_done; +#endif + #include "ux_frotz.h" static int start_of_prev_word(int, const zchar*); @@ -145,6 +150,9 @@ void os_tick() terminal_resized = 0; unix_resize_display(); } + + if (sem_trywait(&sound_done) == 0) + end_of_sound(); } -- 2.34.1