routes - auto disappear
authorhgn <hgodden00@gmail.com>
Tue, 4 Oct 2022 16:26:49 +0000 (17:26 +0100)
committerhgn <hgodden00@gmail.com>
Tue, 4 Oct 2022 16:26:49 +0000 (17:26 +0100)
world.h
world_routes.h

diff --git a/world.h b/world.h
index 007d6721b93a0cf5294487ec667f9ab604b2cc26..8779df9ef8790e7b0d6ad0dbd63960e38e759365 100644 (file)
--- a/world.h
+++ b/world.h
@@ -27,9 +27,15 @@ static int ray_world( v3f pos, v3f dir, ray_hit *hit );
 #include "shaders/fscolour.h"
 #include "shaders/alphatest.h"
 
-enum { k_max_ui_segments = 32 };
-enum { k_route_ui_max_verts = 2000 };
-enum { k_route_ui_max_indices = 3000 };
+enum { k_max_ui_segments = 8 };
+enum { k_max_ui_splits_per_segment = 16 };
+
+enum { k_max_ui_elements = k_max_ui_segments*k_max_ui_splits_per_segment };
+enum { k_max_element_verts = 10 };
+enum { k_max_element_indices = 20 };
+
+enum { k_route_ui_max_verts = k_max_ui_elements*k_max_element_verts };
+enum { k_route_ui_max_indices = k_max_ui_elements*k_max_element_indices };
 
 static struct gworld
 {
@@ -84,7 +90,7 @@ static struct gworld
             {
                float length;
                u32 vertex_start, vertex_count,
-                   index_start, index_count;
+                   index_start, index_count, notches;
             }
             segments[k_max_ui_segments];
 
@@ -98,6 +104,8 @@ static struct gworld
       }
       *routes;
 
+      double last_interaction;
+
       u32 route_count,
           route_cap;
 
index 7f108aa88d89463ed12121e8db0de1d4116322ec..2b85f877e3bc8ebf0d5ee70f837f613fbfa1328b 100644 (file)
@@ -14,6 +14,11 @@ enum route_special_type
    k_route_special_type_collector = 2
 };
 
+static void world_routes_interact(void)
+{
+   world.routes.last_interaction = vg_time;
+}
+
 static void debug_sbpath( struct route_node *rna, struct route_node *rnb,
                           u32 colour, float xoffset )
 {
@@ -265,6 +270,7 @@ static void world_routes_ui_newseg( u32 route )
    segment->vertex_count = 4;
    segment->index_start  = pr->ui.indices_head;
    segment->index_count  = 6;
+   segment->notches      = 0;
 
    world_routes_ui_set_indices( pr, indices, 6 );
 }
@@ -302,6 +308,12 @@ static void world_routes_ui_notch( u32 route, float time )
 
    if( (time - pr->ui.last_notch) > 1.0 )
    {
+      struct route_ui_segment *segment = world_routes_ui_curseg(pr);
+      if( segment->notches == k_max_ui_splits_per_segment )
+         return;
+
+      segment->notches ++;
+
       v2f verts[8];
       
       float const k_notch_width = 1.0f;
@@ -360,7 +372,6 @@ static void world_routes_ui_notch( u32 route, float time )
 
       pr->ui.last_notch = time;
 
-      struct route_ui_segment *segment = world_routes_ui_curseg(pr);
       segment->vertex_count += 6;
       segment->index_count  += 18;
    }
@@ -414,12 +425,15 @@ static void world_routes_ui_draw( u32 route, v4f colour, float offset )
    v4_copy( colour, fade_colour );
    fade_colour[3] *= 1.0f-fade_amt;
 
+   float timer_delta = (vg_time - world.routes.last_interaction) * (1.0/60.0),
+         timer_scale = 1.0f - vg_minf( timer_delta, 1.0f );
+
    /* 
     * Draw fadeout bar
     */
 
-   float height = pr->factive*k_bar_height,
-         base = -1.0f + (offset+0.5f)*k_bar_height;
+   float height = pr->factive*k_bar_height * timer_scale,
+         base = -1.0f + (offset+0.5f)*k_bar_height * timer_scale;
 
    shader_routeui_uColour( fade_colour );
    for( u32 i=0; i<pr->ui.fade_count; i++ )
@@ -592,6 +606,8 @@ static void world_routes_verify_run( u32 route )
  */
 static void world_routes_activate_gate( u32 id )
 {
+   world_routes_interact();
+
    struct subworld_routes *r = &world.routes;
    struct route_gate *rg = &r->gates[id];
    struct route_node *pnode = &r->nodes[rg->node_id],
@@ -644,6 +660,7 @@ static void world_routes_activate_gate( u32 id )
 static void world_routes_notify_reset(void)
 {
    struct subworld_routes *r = &world.routes;
+   world_routes_interact();
 
    for( int i=0; i<r->route_count; i++ )
    {