Merge branch 'musicfadefix' into 'master'

Do music fade callback on main thread

See merge request KartKrew/Kart-Public!336
This commit is contained in:
Sal 2024-03-30 01:23:43 +00:00
commit c4a31f99d5

View file

@ -90,6 +90,7 @@ static UINT32 fading_timer;
static UINT32 fading_duration; static UINT32 fading_duration;
static INT32 fading_id; static INT32 fading_id;
static void (*fading_callback)(void); static void (*fading_callback)(void);
static boolean fading_do_callback;
#ifdef HAVE_LIBGME #ifdef HAVE_LIBGME
static Music_Emu *gme; static Music_Emu *gme;
@ -106,6 +107,7 @@ static void var_cleanup(void)
is_fading = false; is_fading = false;
fading_callback = NULL; fading_callback = NULL;
fading_do_callback = false;
internal_volume = 100; internal_volume = 100;
} }
@ -202,6 +204,13 @@ void I_ShutdownSound(void)
void I_UpdateSound(void) void I_UpdateSound(void)
{ {
if (fading_do_callback)
{
if (fading_callback)
(*fading_callback)();
fading_callback = NULL;
fading_do_callback = false;
}
} }
/// ------------------------ /// ------------------------
@ -526,9 +535,8 @@ static UINT32 get_adjusted_position(UINT32 position)
static void do_fading_callback(void) static void do_fading_callback(void)
{ {
if (fading_callback) // TODO: Should I use a mutex here or something?
(*fading_callback)(); fading_do_callback = true;
fading_callback = NULL;
} }
/// ------------------------ /// ------------------------