some maps, update QOI, fix bug/UB with too many fishes
[fishladder.git] / fishladder.c
index bcbc37428b6335433bd2ff7306feb337aeab982d..b6c220fbd76f6d5f95e929270d4fd7959492f640 100644 (file)
@@ -12,7 +12,9 @@ const char *level_pack_1[] = {
        "level4",
        "level5",
        "level6",
-       "level7_combine"
+       "level7_combine",
+       "xor_small",
+       "sort"
 };
 
 #pragma pack(push,1)
@@ -277,6 +279,17 @@ static void map_free(void)
        world.initialzed = 0;
 }
 
+static void io_reset(void)
+{
+       for( int i = 0; i < arrlen( world.io ); i ++ )
+       {
+               struct cell_terminal *term = &world.io[i];
+               
+               for( int j = 0; j < term->run_count; j ++ )
+                       term->runs[j].recv_count = 0;
+       }
+}
+
 static void map_reclassify( v2i start, v2i end, int update_texbuffer );
 static int map_load( const char *str, const char *name )
 {
@@ -313,15 +326,21 @@ static int map_load( const char *str, const char *name )
                if( !*c )
                        break;
        
+               if( *c == '\r' ) { c ++; continue; } // fuck off windows
+       
                if( *c == ';' )
                {
                        c ++;
-
+                       
+                       if( *c == '\r' ) c ++;
+                       
                        // Parse attribs
                        if( *c != '\n' )
                        {
                                while( *c )
                                {
+                                       if( *c == '\r' ) { c ++; continue; }
+                                       
                                        if( reg_start < reg_end )
                                        {
                                                struct cell_terminal *terminal = &world.io[ reg_start ];
@@ -533,6 +552,8 @@ static int map_load( const char *str, const char *name )
        
        vg_success( "Map '%s' loaded! (%u:%u)\n", name, world.w, world.h );
        
+       io_reset();
+       
        strncpy( world.map_name, name, vg_list_size( world.map_name )-1 );
        world.initialzed = 1;
        return 1;
@@ -706,17 +727,6 @@ static int console_load_map( int argc, char const *argv[] )
        }
 }
 
-static void io_reset(void)
-{
-       for( int i = 0; i < arrlen( world.io ); i ++ )
-       {
-               struct cell_terminal *term = &world.io[i];
-               
-               for( int j = 0; j < term->run_count; j ++ )
-                       term->runs[j].recv_count = 0;
-       }
-}
-
 static void simulation_stop(void)
 {
        world.simulating = 0;
@@ -735,12 +745,12 @@ static int console_changelevel( int argc, char const *argv[] )
        if( argc >= 1 )
        {
                // Save current level
-               if( console_save_map( 0, NULL ) )
-                       if( console_load_map( argc, argv ) )
-                       {                               
-                               simulation_stop();
-                               return 1;
-                       }
+               console_save_map( 0, NULL );
+               if( console_load_map( argc, argv ) )
+               {                               
+                       simulation_stop();
+                       return 1;
+               }
        }
        else
        {
@@ -753,17 +763,17 @@ static int console_changelevel( int argc, char const *argv[] )
 void vg_start(void)
 {
        vg_function_push( (struct vg_cmd){
-               .name = "map_write",
+               .name = "_map_write",
                .function = console_save_map
        });
        
        vg_function_push( (struct vg_cmd){
-               .name = "map_load",
+               .name = "_map_load",
                .function = console_load_map
        });
        
        vg_function_push( (struct vg_cmd){
-               .name = "changelevel",
+               .name = "map",
                .function = console_changelevel
        });
 
@@ -1023,11 +1033,14 @@ static void map_reclassify( v2i start, v2i end, int update_texbuffer )
        }
 }
 
+
 v2f const curve_3[] = {{0.5f,1.0f},{0.5f,0.625f},{0.625f,0.5f},{1.0f,0.5f}};
 v2f const curve_6[] = {{0.5f,1.0f},{0.5f,0.625f},{0.375f,0.5f},{0.0f,0.5f}};
 v2f const curve_9[] = {{1.0f,0.5f},{0.625f,0.5f},{0.5f,0.375f},{0.5f,0.0f}};
 v2f const curve_12[]= {{0.0f,0.5f},{0.375f,0.5f},{0.5f,0.375f},{0.5f,0.0f}};
 
+v2f const curve_1[] = {{1.0f,0.5f},{0.8f,0.5f},{0.3f,0.5f},{0.2f,0.5f}};
+v2f const curve_4[] = {{0.0f,0.5f},{0.3f,0.5f},{0.5f,0.5f},{0.8f,0.5f}};
 v2f const curve_2[] = {{0.5f,1.0f},{0.5f,0.8f},{0.5f,0.3f},{0.5f,0.2f}};
 v2f const curve_8[] = {{0.5f,0.8f},{0.5f,0.5f},{0.5f,0.3f},{0.5f,0.0f}};
 
@@ -1463,6 +1476,7 @@ void vg_update(void)
                                                world.sim_run ++;
                                                world.sim_frame = 0;
                                                world.sim_start = vg_time;
+                                               world.num_fishes = 0;
                                                continue;
                                        }
                                        else
@@ -1535,6 +1549,8 @@ void vg_update(void)
                                                else
                                                        curve = curve_9;
                                        break;
+                                       case 1: curve = curve_1; break;
+                                       case 4: curve = curve_4; break;
                                        case 2: curve = curve_2; break;
                                        case 8: curve = curve_8; break;
                                        case 3: curve = curve_3; break;