+ float scaled_time = 0.0f;
+ scaled_time = (vg_time-world.sim_start)*2.0f;
+ world.frame_lerp = scaled_time - (float)world.sim_frame;
+
+ // Update positions
+ for( int i = 0; i < world.num_fishes; i ++ )
+ {
+ struct fish *fish = &world.fishes[i];
+
+ if( fish->alive == 0 )
+ continue;
+
+ if( fish->alive == -1 && (world.frame_lerp > fish->death_time) )
+ continue; // Todo: particle thing?
+
+ if( fish->alive == -2 )
+ {
+ v2_muladds( fish->physics_v, (v2f){ 0.0, -9.8f }, vg_time_delta, fish->physics_v );
+ v2_muladds( fish->physics_co, fish->physics_v, vg_time_delta, fish->physics_co );
+ }
+ else
+ {
+ struct cell *cell = pcell(fish->pos);
+ v2f const *curve;
+
+ float t = world.frame_lerp;
+
+ v2_copy( fish->physics_co, fish->physics_v );
+
+ switch( cell->config )
+ {
+ case 13:
+ if( fish->dir[0] == 1 )
+ curve = curve_12;
+ else
+ curve = curve_9;
+ break;
+ case 3: curve = curve_3; break;
+ case 6: curve = curve_6; break;
+ case 9: curve = curve_9; break;
+ case 12: curve = curve_12; break;
+ case 7:
+ if( t > curve_7_linear_section )
+ {
+ t -= curve_7_linear_section;
+ t *= (1.0f/(1.0f-curve_7_linear_section));
+
+ curve = cell->state & FLAG_FLIP_FLOP? curve_7: curve_7_1;
+ }
+ else curve = NULL;
+ break;
+ default: curve = NULL; break;
+ }
+
+ if( curve )
+ {
+ float t2 = t * t;
+ float t3 = t * t * t;
+
+ float cA = 3.0f*t2 - 3.0f*t3;
+ float cB = 3.0f*t3 - 6.0f*t2 + 3.0f*t;
+ float cC = 3.0f*t2 - t3 - 3.0f*t + 1.0f;
+
+ fish->physics_co[0] = t3*curve[3][0] + cA*curve[2][0] + cB*curve[1][0] + cC*curve[0][0];
+ fish->physics_co[1] = t3*curve[3][1] + cA*curve[2][1] + cB*curve[1][1] + cC*curve[0][1];
+ fish->physics_co[0] += (float)fish->pos[0];
+ fish->physics_co[1] += (float)fish->pos[1];
+ }
+ else
+ {
+ v2f origin;
+ origin[0] = (float)fish->pos[0] + (float)fish->dir[0]*-0.5f + 0.5f;
+ origin[1] = (float)fish->pos[1] + (float)fish->dir[1]*-0.5f + 0.5f;
+
+ fish->physics_co[0] = origin[0] + (float)fish->dir[0]*t;
+ fish->physics_co[1] = origin[1] + (float)fish->dir[1]*t;
+ }
+ }
+ }
+ }
+}
+
+static void render_tiles( v2i start, v2i end, v4f const regular_colour, v4f const selected_colour )
+{
+ v2i full_start = { 0,0 };
+ v2i full_end = { world.w, world.h };
+
+ if( !start || !end )
+ {
+ start = full_start;
+ end = full_end;
+ }
+
+ glUniform4fv( SHADER_UNIFORM( shader_tile_main, "uColour" ), 1, regular_colour );
+
+ for( int y = start[1]; y < end[1]; y ++ )
+ {
+ for( int x = start[0]; x < end[0]; x ++ )
+ {
+ struct cell *cell = pcell((v2i){x,y});
+ int selected = world.selected == y*world.w + x;
+
+ int tile_offsets[][2] =
+ {
+ {2, 0}, {0, 3}, {0, 2}, {2, 2},
+ {1, 0}, {2, 3}, {3, 2}, {1, 3},
+ {3, 1}, {0, 1}, {1, 2}, {2, 1},
+ {1, 1}, {3, 3}, {2, 1}, {2, 1}
+ };
+
+ int uv[2] = { 3, 0 };
+
+ if( cell->state & (FLAG_CANAL|FLAG_INPUT|FLAG_OUTPUT) )
+ {
+ uv[0] = tile_offsets[ cell->config ][0];
+ uv[1] = tile_offsets[ cell->config ][1];
+ } else continue;
+
+ glUniform4f( SHADER_UNIFORM( shader_tile_main, "uOffset" ), (float)x, (float)y, uv[0], uv[1] );
+ if( selected )
+ {
+ glUniform4fv( SHADER_UNIFORM( shader_tile_main, "uColour" ), 1, selected_colour );
+ draw_mesh( 0, 2 );
+ glUniform4fv( SHADER_UNIFORM( shader_tile_main, "uColour" ), 1, regular_colour );
+ }
+ else
+ draw_mesh( 0, 2 );
+ }