From: hgn Date: Sun, 14 Nov 2021 09:35:14 +0000 (+0000) Subject: fix bug with audio fadeout X-Git-Url: https://harrygodden.com/git/?p=fishladder.git;a=commitdiff_plain;h=3a55f20f6b627db61294523f7bf34344514e7166 fix bug with audio fadeout --- diff --git a/fishladder.c b/fishladder.c index 66a3eba..0abe4b5 100644 --- a/fishladder.c +++ b/fishladder.c @@ -502,6 +502,20 @@ static int console_load_map( int argc, char const *argv[] ) } } +static void simulation_stop(void) +{ + world.simulating = 0; + world.num_fishes = 0; + world.sim_frame = 0; + + for( int i = 0; i < arrlen( world.io ); i ++ ) + world.io[i].recv_count = 0; + + sfx_system_fadeout( &audio_system_balls_rolling, 44100 ); + + vg_info( "Stopping simulation!\n" ); +} + static int console_changelevel( int argc, char const *argv[] ) { if( argc >= 1 ) @@ -509,7 +523,10 @@ static int console_changelevel( int argc, char const *argv[] ) // Save current level if( console_save_map( 0, NULL ) ) if( console_load_map( argc, argv ) ) + { + simulation_stop(); return 1; + } } else { @@ -795,22 +812,6 @@ void vg_update(void) if( vg_get_button_down( "prev" ) ) { if( curlevel > 0 ) changelvl --; } else if( vg_get_button_down( "next" ) ) { if( curlevel < vg_list_size( level_pack )-1 ) changelvl ++; } - if( changelvl != curlevel ) - { - console_changelevel( 1, level_pack + changelvl ); - curlevel = changelvl; - - // TEMP!!! code dupe - world.simulating = 0; - world.num_fishes = 0; - world.sim_frame = 0; - - for( int i = 0; i < arrlen( world.io ); i ++ ) - world.io[i].recv_count = 0; - - vg_info( "Stopping simulation!\n" ); - } - // Fit within screen float r1 = (float)vg_window_y / (float)vg_window_x, @@ -866,16 +867,7 @@ void vg_update(void) { if( world.simulating ) { - world.simulating = 0; - world.num_fishes = 0; - world.sim_frame = 0; - - for( int i = 0; i < arrlen( world.io ); i ++ ) - world.io[i].recv_count = 0; - - vg_info( "Stopping simulation!\n" ); - - sfx_system_fadeout( &audio_system_balls_rolling, 44100 ); + simulation_stop(); } else { diff --git a/vg/vg_audio.h b/vg/vg_audio.h index c0a3720..0c9a666 100644 --- a/vg/vg_audio.h +++ b/vg/vg_audio.h @@ -654,13 +654,21 @@ static void sfx_system_fadeout( sfx_system *sys, u32 length_samples ) { if( sfx_begin_edit( sys ) ) { - sys->fadeout_current = length_samples; - sys->fadeout = length_samples; + if( sys->end ) + { + sys->fadeout_current = length_samples; + sys->fadeout = length_samples; + + if( sys->thread_clone ) + sys->cur = sys->thread_clone->cur; - if( sys->thread_clone ) - sys->cur = sys->thread_clone->cur; - - sfx_save( sys ); + sfx_save( sys ); + } + else + { + // Sound was not initialized + MUTEX_UNLOCK( sfx_mux_t01 ); + } } }