only rebuild map chunks where user clicks
[fishladder.git] / fishladder.c
index 54e1a537926a36f78a3c4adf5a8e719233b81196..eb86953ebe0d5ce3d90fb749d7ae99894d06477b 100644 (file)
@@ -354,6 +354,7 @@ static void map_free(void)
        world.io = NULL;
 }
 
+static void map_reclassify( v2i start, v2i end );
 static int map_load( const char *str )
 {
        map_free();
@@ -470,6 +471,7 @@ static int map_load( const char *str )
                c ++;
        }
        
+       map_reclassify( NULL, NULL );
        vg_success( "Map loaded! (%u:%u)\n", world.w, world.h );
        return 1;
 }
@@ -671,13 +673,20 @@ static int cell_interactive( v2i co )
        return 1;
 }
 
-// Entire world: 2 -> worldx/y-2
-
-static void fl_world_update( v2i start, v2i end )
+static void map_reclassify( v2i start, v2i end )
 {
-       for( int y = start[1]; y < end[1]; y ++ )
+       v2i full_start = { 2,2 };
+       v2i full_end = { world.w-2, world.h-2 };
+       
+       if( !start || !end )
+       {
+               start = full_start;
+               end = full_end;
+       }
+
+       for( int y = vg_max( start[1], full_start[1] ); y < vg_min( end[1], full_end[1] ); y ++ )
        {
-               for( int x = start[0]; x < end[0]; x ++ )
+               for( int x = vg_max( start[0], full_start[0] ); x < vg_min( end[0], full_end[0] ); x ++ )
                {
                        v2i dirs[] = {{1,0},{0,1},{-1,0},{0,-1}};
                        
@@ -691,9 +700,8 @@ static void fl_world_update( v2i start, v2i end )
                                        if( neighbour->state & (FLAG_CANAL|FLAG_INPUT|FLAG_OUTPUT) )
                                                config |= 0x1 << i;
                                }
-                               
-                               
-                       } else config = 0xF;
+                       } 
+                       else config = 0xF;
                        
                        pcell((v2i){x,y})->config = config;
                }
@@ -760,6 +768,8 @@ void vg_update(void)
                                        sfx_set_playrnd( &audio_tile_mod, &audio_system_sfx, 3, 6 );
                                else
                                        sfx_set_playrnd( &audio_tile_mod, &audio_system_sfx, 0, 3 );
+                                       
+                               map_reclassify( (v2i){ tile_x -2, tile_y -2 }, (v2i){ tile_x +2, tile_y +2 } );
                        }
                }
                else
@@ -799,9 +809,6 @@ void vg_update(void)
                }
        }
 
-       // There was world reconfiguarion here previously...
-       fl_world_update( (v2i){2,2}, (v2i){world.w-2,world.h-2} );
-       
        // Fish ticks
        if( world.simulating )
        {