checkpoint diffs
[carveJwlIkooP6JGAAIwe30JlM.git] / world_routes_ui.c
1 #include "skaterift.h"
2 #include "world_routes_ui.h"
3 #include "world_routes.h"
4
5 static u32 v4_rgba( v4f colour ){
6 u32 r = vg_minf(1.0f,colour[0])*255.0f,
7 g = vg_minf(1.0f,colour[1])*255.0f,
8 b = vg_minf(1.0f,colour[2])*255.0f,
9 a = vg_minf(1.0f,colour[3])*255.0f;
10
11 return r | (g<<8) | (b<<16) | (a<<24);
12 }
13
14 static void ent_route_imgui( world_instance *world, ent_route *route,
15 ui_point inout_cursor ){
16 if( route->flags & k_ent_route_flag_out_of_zone )
17 return;
18
19 u32 last_version=0;
20 f64 last_time = 0.0;
21 ent_checkpoint *last_cp = NULL;
22
23 u32 valid_sections=0;
24
25 struct time_block{
26 f32 length, best;
27 int clean;
28 }
29 blocks[ route->checkpoints_count ];
30
31 for( u32 i=0; i<route->checkpoints_count; i++ ){
32 u32 cpid = i+route->active_checkpoint+1;
33 cpid %= route->checkpoints_count;
34 cpid += route->checkpoints_start;
35
36 ent_checkpoint *cp = mdl_arritm( &world->ent_checkpoint, cpid );
37 ent_gate *rg = mdl_arritm( &world->ent_gate, cp->gate_index );
38 rg = mdl_arritm( &world->ent_gate, rg->target );
39
40 if( last_version+1 == rg->timing_version ) {
41 struct time_block *block = &blocks[ valid_sections ++ ];
42 block->clean = (rg->flags & k_ent_gate_clean_pass)? 1: 0;
43 block->length = rg->timing_time - last_time;
44 block->best = last_cp? last_cp->best_time: 0.0f;
45 }
46 else valid_sections = 0;
47
48 last_version = rg->timing_version;
49 last_time = rg->timing_time;
50 last_cp = cp;
51 }
52
53 if( last_version+1 == world_static.current_run_version ){
54 struct time_block *block = &blocks[ valid_sections ++ ];
55 block->clean = localplayer.rewinded_since_last_gate? 0: 1;
56 block->length = world_static.time - last_time;
57 block->best = last_cp->best_time;
58 }
59 else
60 valid_sections = 0;
61
62 u32 colour = v4_rgba( route->colour ) | 0xff000000;
63
64 ui_px x = 0,
65 h = route->factive * 16.0f;
66
67 for( u32 i=0; i<valid_sections; i ++ ){
68 struct time_block *block = &blocks[ i ];
69 ui_px w = 20 + (block->length * 6.0f);
70 ui_rect rect = { x, inout_cursor[1], w, h };
71 ui_fill( rect, colour );
72
73 if( block->clean )
74 ui_outline( rect, 1, 0xff00ffff, 0 );
75
76 if( block->best != 0.0f ){
77 char buf[32];
78 vg_str str;
79 vg_strnull( &str, buf, 32 );
80
81 f32 diff = block->length - block->best,
82 as = fabsf(diff),
83 s = floorf( as ),
84 ds = floorf( vg_fractf( as ) * 10.0f );
85
86 if( (block->best != 0.0f) && (fabsf(diff) > 0.02f) ){
87 if( diff > 0.0f )
88 vg_strcatch( &str, '+' );
89 else
90 vg_strcatch( &str, '-' );
91
92 vg_strcati32( &str, s );
93 vg_strcatch( &str, '.' );
94 vg_strcati32( &str, ds );
95
96 ui_text( rect, buf, 1, k_ui_align_middle_center, 0 );
97 }
98 }
99
100 x += w + 4;
101 }
102
103 for( u32 i=0; i<route->checkpoints_count-valid_sections; i++ ){
104 struct time_block *block = &blocks[ i ];
105
106 ui_px w = 20;
107 ui_rect rect = { x, inout_cursor[1], w, h };
108 ui_outline( rect, -1, colour, 0 );
109 x += w + 4;
110 }
111
112 inout_cursor[1] += h + 4;
113 }
114
115 static void world_routes_imgui( world_instance *world ){
116 ui_point cursor = { 0, 0 };
117 for( u32 i=0; i<mdl_arrcount(&world->ent_route); i++ ){
118 ent_route_imgui( world, mdl_arritm( &world->ent_route, i ), cursor );
119 }
120 }