Merge branch 'master' of harrygodden.com:/home/fishladder
[fishladder.git] / fishladder.c
index bcb554774c96c1a1b6797eb2a0c83f205fa26c16..68f04febd75e54bd42da4c043bf3d956d0503caf 100644 (file)
@@ -12,7 +12,8 @@ const char *level_pack_1[] = {
        "level4",
        "level5",
        "level6",
-       "level7_combine"
+       "level7_combine",
+       "xor_small"
 };
 
 #pragma pack(push,1)
@@ -197,14 +198,14 @@ struct world
        *data;
 #pragma pack(pop)
        
-       u32 frame;
+       int frame;
        
        int initialzed;
        
-       u32 sim_frame;
+       int sim_frame;
        float sim_start;
        int simulating;
-       u32 sim_run, max_runs;
+       int sim_run, max_runs;
        
        float frame_lerp;
        
@@ -313,15 +314,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 ];
@@ -735,12 +742,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 +760,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 +1030,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}};
 
@@ -1535,6 +1545,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;
@@ -1775,12 +1787,35 @@ void vg_render(void)
                                        int x2 = cell->links[trigger_id] % world.w;
                                        int y2 = (cell->links[trigger_id] - x2) / world.w;
                                        
-                                       v2f drag_to_co;
+                                       v2f startpoint; 
+                                       v2f midpoint;
+                                       v2f endpoint;
+                                       
+                                       startpoint[0] = (float)x2 + (trigger_id? 0.75f: 0.25f);
+                                       startpoint[1] = (float)y2 + 0.25f;
+                                       
+                                       endpoint[0] = x+0.5f;
+                                       endpoint[1] = y+0.5f;
+                                       v2_add( startpoint, endpoint, midpoint );
+                                       v2_muls( midpoint, 0.5f, midpoint );
+                                       midpoint[1] += -0.8f;
                                        
-                                       drag_to_co[0] = (float)x2 + (trigger_id? 0.75f: 0.25f);
-                                       drag_to_co[1] = (float)y2 + 0.25f;
+                                       float t, ta;
+                                       v2f lastpoint; v2f curpoint;
+                                       v2_copy( startpoint, lastpoint );
                                        
-                                       vg_line2( (v2f){x+0.5f,y+0.5f}, drag_to_co, 0xff0000ff, 0xff00ffff );
+                                       for( int i = 0; i < 10; i ++ )
+                                       {
+                                               t = ((float)i+1.f)/10.0f;
+                                               ta = 1.0f-t;
+                                               
+                                               v2_muls( startpoint, ta*ta, curpoint );
+                                               v2_muladds( curpoint, midpoint, 2.0f*ta*t, curpoint );
+                                               v2_muladds( curpoint, endpoint, t*t, curpoint );
+                                               
+                                               vg_line2( lastpoint, curpoint, 0xff444444, 0xff444444 );
+                                               v2_copy( curpoint, lastpoint );
+                                       }
                                }
                        
                                if( cell->config == k_cell_type_split )