fix bug with audio fadeout
[fishladder.git] / fishladder.c
index 66a3eba09c6987d391f27df522135e8022294ede..0abe4b52946b9490dfa3f85bd8c53291a9020136 100644 (file)
@@ -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
                {