+#include "skaterift.h"
+#include "world_routes_ui.h"
+#include "world_routes.h"
+
+static u32 v4_rgba( v4f colour ){
+ u32 r = vg_minf(1.0f,colour[0])*255.0f,
+ g = vg_minf(1.0f,colour[1])*255.0f,
+ b = vg_minf(1.0f,colour[2])*255.0f,
+ a = vg_minf(1.0f,colour[3])*255.0f;
+
+ return r | (g<<8) | (b<<16) | (a<<24);
+}
+
+static void ent_route_imgui( world_instance *world, ent_route *route,
+ ui_point inout_cursor ){
+ u32 last_version=0;
+ f64 last_time = 0.0;
+
+ u32 valid_sections=0;
+
+ struct time_block{
+ f32 length;
+ int clean;
+ }
+ *blocks = alloca( sizeof(struct time_block) * route->checkpoints_count );
+
+ for( u32 i=0; i<route->checkpoints_count; i++ ){
+ u32 cpid = i+route->active_checkpoint+1;
+ cpid %= route->checkpoints_count;
+ cpid += route->checkpoints_start;
+
+ ent_checkpoint *cp = mdl_arritm( &world->ent_checkpoint, cpid );
+ ent_gate *rg = mdl_arritm( &world->ent_gate, cp->gate_index );
+ rg = mdl_arritm( &world->ent_gate, rg->target );
+
+ if( last_version+1 == rg->timing_version ) {
+ struct time_block *block = &blocks[ valid_sections ++ ];
+ block->clean = (rg->flags & k_ent_gate_clean_pass)? 1: 0;
+ block->length = rg->timing_time - last_time;
+ }
+ else valid_sections = 0;
+
+ last_version = rg->timing_version;
+ last_time = rg->timing_time;
+ }
+
+ if( last_version+1 == world_static.current_run_version ){
+ struct time_block *block = &blocks[ valid_sections ++ ];
+ block->clean = localplayer.rewinded_since_last_gate? 0: 1;
+ block->length = world_static.time - last_time;
+ }
+ else
+ valid_sections = 0;
+
+ u32 colour = v4_rgba( route->colour ) | 0xff000000;
+
+ ui_px x = 0,
+ h = route->factive * 16.0f;
+
+ for( u32 i=0; i<valid_sections; i ++ ){
+ struct time_block *block = &blocks[ i ];
+ ui_px w = block->length * 2.0f;
+ ui_rect rect = { x, inout_cursor[1], w, h };
+ ui_fill( rect, colour );
+
+ if( block->clean )
+ ui_outline( rect, 1, 0xff00ffff, 0 );
+
+ x += w + 4;
+ }
+
+ for( u32 i=0; i<route->checkpoints_count-valid_sections; i++ ){
+ struct time_block *block = &blocks[ i ];
+
+ ui_px w = 20;
+ ui_rect rect = { x, inout_cursor[1], w, h };
+ ui_outline( rect, -1, colour, 0 );
+ x += w + 4;
+ }
+
+ inout_cursor[1] += h + 4;
+}
+
+static void world_routes_imgui( world_instance *world ){
+ ui_point cursor = { 0, 0 };
+ for( u32 i=0; i<mdl_arrcount(&world->ent_route); i++ ){
+ ent_route_imgui( world, mdl_arritm( &world->ent_route, i ), cursor );
+ }
+}