the route strips are back
authorhgn <hgodden00@gmail.com>
Fri, 24 Nov 2023 15:09:13 +0000 (15:09 +0000)
committerhgn <hgodden00@gmail.com>
Fri, 24 Nov 2023 15:09:13 +0000 (15:09 +0000)
skaterift.c
world.h
world_load.c
world_routes.c
world_routes_ui.c [new file with mode: 0644]
world_routes_ui.h [new file with mode: 0644]

index eb51c9054da51df3aec74bfe6cad8fa3ea868efc..d8aae1bde47d3b99950d19b32a394b98ffb5fc77 100644 (file)
@@ -55,6 +55,7 @@
 #include "network.c"
 #include "player_remote.c"
 #include "vg/vg_audio_dsp.h"
+#include "world_routes_ui.c"
 
 static int k_tools_mode = 0;
 
@@ -647,6 +648,7 @@ static void vg_gui(void){
    player__im_gui();
    world_instance *world = world_current_instance();
 
+   world_routes_imgui( world );
    skaterift_replay_imgui();
    workshop_form_gui();
    render_view_framebuffer_ui();
diff --git a/world.h b/world.h
index 02355013aaf362ac621ddb5cd0839a33c865bd8f..ebf18c6a503d37e4c9cddbee202b82b112794d97 100644 (file)
--- a/world.h
+++ b/world.h
@@ -49,6 +49,7 @@ static void skaterift_world_get_save_path( enum world_purpose which,
 #include "world_water.h"
 #include "world_audio.h"
 #include "world_routes.h"
+#include "world_routes_ui.h"
 
 /* console variables */
 
@@ -216,6 +217,9 @@ struct world_instance {
 
    /* leaderboards */
    struct leaderboard_cache *leaderboard_cache;
+
+   /* ui */
+   struct route_ui *routes_ui;
 };
 
 struct world_static {
index 18f405e03735e2cd3ac5caf7fe010c0a26488c08..379a7de3ee60049999f69401b65af7819a44df5b 100644 (file)
@@ -128,6 +128,9 @@ static void world_instance_load_mdl( u32 instance_id, const char *path ){
       board->data_len = 0;
    }
 
+   world->routes_ui = vg_linear_alloc( heap, 
+         sizeof(struct route_ui)*mdl_arrcount(&world->ent_route) );
+
    vg_async_call( async_world_postprocess, world, 0 );
    vg_async_stall();
 }
index 48df26729b91483e61c0fd4183e4d4a8f25b4e93..4deccaa754308cbc8566123243b05ee3c0e32d6e 100644 (file)
@@ -39,16 +39,15 @@ static void world_routes_clear( world_instance *world )
    world_static.last_use = 0.0;
 }
 
-static void world_routes_time_lap( world_instance *world, ent_route *route )
-{
+static void world_routes_time_lap( world_instance *world, ent_route *route ){
    vg_info( "------- time lap %s -------\n", 
             mdl_pstr(&world->meta,route->pstr_name) );
 
    double start_time = 0.0;
    u32 last_version=0;
 
-   u32 valid_count=0;
-   int clean = 1;
+   u32 valid_sections=0;
+   int clean = !localplayer.rewinded_since_last_gate;
 
    for( u32 i=0; i<route->checkpoints_count; i++ ){
       u32 cpid  = (i+route->active_checkpoint) % route->checkpoints_count;
@@ -65,31 +64,34 @@ static void world_routes_time_lap( world_instance *world, ent_route *route )
       if( i == 0 )
          start_time = rg->timing_time;
       else{
-         if( last_version+1 == rg->timing_version ) valid_count ++;
-         else valid_count = 0;
+         if( last_version+1 == rg->timing_version ) valid_sections ++;
+         else valid_sections = 0;
       }
 
       last_version = rg->timing_version;
 
       vg_info( "%u %f [%s]\n", rg->timing_version, rg->timing_time,
-               (rg->flags & k_ent_gate_clean_pass)? "CLEAN": "-----");
+            i? ((rg->flags & k_ent_gate_clean_pass)? "CLEAN": "     "):
+                " N/A ");
 
       if( !(rg->flags & k_ent_gate_clean_pass) )
          clean = 0;
    }
 
    if( world_static.current_run_version == last_version+1 ){
-      valid_count ++;
+      valid_sections ++;
 
       if( route->checkpoints_count == 1 ){
          route->timing_base = world_static.time;
       }
    }
-   else valid_count = 0;
+   else valid_sections = 0;
 
-   vg_info( "%u %f\n", world_static.current_run_version, world_static.time );
+   vg_info( "%u %f [%s]\n", 
+            world_static.current_run_version, world_static.time,
+           !localplayer.rewinded_since_last_gate? "CLEAN": "     " );
 
-   if( valid_count==route->checkpoints_count ){
+   if( valid_sections==route->checkpoints_count ){
       f64 lap_time = world_static.time - start_time;
 
       if( (route->best_laptime == 0.0) || (lap_time < route->best_laptime) ){
@@ -119,9 +121,9 @@ static void world_routes_time_lap( world_instance *world, ent_route *route )
                                lap_time );
    }
 
-   route->valid_checkpoints = valid_count+1;
+   route->valid_checkpoints = valid_sections+1;
 
-   vg_info( "valid: %u\n", valid_count );
+   vg_info( "valid sections: %u\n", valid_sections );
    vg_info( "----------------------------\n" );
 }
 
@@ -134,13 +136,6 @@ static void world_routes_activate_entry_gate( world_instance *world,
    world_static.last_use = world_static.time;
    ent_gate *dest = mdl_arritm( &world->ent_gate, rg->target );
 
-   if( localplayer.rewinded_since_last_gate ){
-      localplayer.rewinded_since_last_gate = 0;
-      dest->flags &= ~k_ent_gate_clean_pass;
-   }
-   else
-      dest->flags |= k_ent_gate_clean_pass;
-
    for( u32 i=0; i<mdl_arrcount(&world->ent_route); i++ ){
       ent_route *route = mdl_arritm( &world->ent_route, i );
 
@@ -169,6 +164,13 @@ static void world_routes_activate_entry_gate( world_instance *world,
    dest->timing_version = world_static.current_run_version;
    dest->timing_time = world_static.time;
 
+   if( localplayer.rewinded_since_last_gate ){
+      localplayer.rewinded_since_last_gate = 0;
+      dest->flags &= ~k_ent_gate_clean_pass;
+   }
+   else
+      dest->flags |= k_ent_gate_clean_pass;
+
    world_static.current_run_version ++;
 }
 
diff --git a/world_routes_ui.c b/world_routes_ui.c
new file mode 100644 (file)
index 0000000..7becb73
--- /dev/null
@@ -0,0 +1,89 @@
+#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 );
+   }
+}
diff --git a/world_routes_ui.h b/world_routes_ui.h
new file mode 100644 (file)
index 0000000..318e124
--- /dev/null
@@ -0,0 +1,9 @@
+#ifndef WORLD_ROUTES_UI_H
+#define WORLD_ROUTES_UI_H
+
+#include "world_routes.h"
+
+struct route_ui{
+};
+
+#endif /* WORLD_ROUTES_UI_H */