sorted aborted
authorhgn <hgodden00@gmail.com>
Tue, 23 Aug 2022 01:10:26 +0000 (02:10 +0100)
committerhgn <hgodden00@gmail.com>
Tue, 23 Aug 2022 01:10:26 +0000 (02:10 +0100)
shaders/routeui.h
shaders/routeui.vs
world_routes.h

index eeb351a7d9f5fc6e9b2c7465c1c3e3ee25727d14..a909d17c3e148c5b2927a4019fbac20ae6fdad00 100644 (file)
@@ -15,10 +15,7 @@ static struct vg_shader _shader_routeui = {
 "\n"
 "void main()\n"
 "{\n"
-"   float fbarx = (a_co.x+uOffset.x) * uOffset.z;\n"
-"   float fbary = a_co.y*uOffset.w + uOffset.y;\n"
-"\n"
-"   vec2 vpos = vec2( fbarx, fbary );\n"
+"   vec2 vpos = a_co * uOffset.zw + uOffset.xy;\n"
 "   gl_Position = vec4(vpos,0.0,1.0);\n"
 "}\n"
 ""},
index ba5cbce9bf74340b199c70915c8d9e264d97df17..e824d4a8becfdc49db2fcb691230cff3035e3eb0 100644 (file)
@@ -4,9 +4,6 @@ uniform vec4 uOffset;
 
 void main()
 {
-   float fbarx = (a_co.x+uOffset.x) * uOffset.z;
-   float fbary = a_co.y*uOffset.w + uOffset.y;
-
-   vec2 vpos = vec2( fbarx, fbary );
+   vec2 vpos = a_co * uOffset.zw + uOffset.xy;
    gl_Position = vec4(vpos,0.0,1.0);
 }
index d714ff3f70ed9e77481eb4fa446b2f2a82490c5f..5ebcbcc97a47df87a9e7b9d4a10bc4b3ff821bf2 100644 (file)
@@ -66,6 +66,7 @@ struct subworld_routes
 
          u32 segment_start, segment_count, fade_start, fade_count;
          double fade_timer_start;
+         float xpos;
       }
       ui;
    }
@@ -460,12 +461,30 @@ static void world_routes_ui_notch( u32 route, float time )
    }
 }
 
+static void world_routes_ui_draw_segment( struct route_ui_segment *segment )
+{
+   u32 c0, c1;
+   world_routes_ui_split_indices( segment->index_start, 
+                                  segment->index_count, &c0, &c1 );
+   if( c0 )
+      glDrawElements( GL_TRIANGLES, c0, GL_UNSIGNED_SHORT,
+                        (void *)(segment->index_start*sizeof(u16)));
+   if( c1 )
+      glDrawElements( GL_TRIANGLES, c1, GL_UNSIGNED_SHORT, (void *)(0) );
+}
+
+/*
+ * Draws full bar at Y offset(offset).
+ */
 static void world_routes_ui_draw( u32 route, v4f colour, float offset )
 {
+   float const k_bar_height = 0.05f,
+               k_bar_scale_x = 0.005f;
+
    struct subworld_routes *r = subworld_routes();
    struct route *pr = &r->routes[route];
 
-   float cx = 0.0f;
+   float cx = pr->ui.xpos;
 
    shader_routeui_use();
    glBindVertexArray( pr->ui.vao );
@@ -473,7 +492,9 @@ static void world_routes_ui_draw( u32 route, v4f colour, float offset )
    float fade_amt = vg_time - pr->ui.fade_timer_start;
    fade_amt = vg_clampf( fade_amt / 1.0f, 0.0f, 1.0f );
    
-   float fade_block_size = 0.0f;
+   float fade_block_size = 0.0f,
+         main_block_size = 0.0f;
+
    for( u32 i=0; i<pr->ui.fade_count; i++ )
    {
       u32 j = (pr->ui.fade_start + i) % k_max_ui_segments;
@@ -488,7 +509,12 @@ 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 height = pr->factive*0.1f;
+   /* 
+    * Draw fadeout bar
+    */
+
+   float height = pr->factive*k_bar_height,
+         base = -1.0f + (offset+0.5f)*k_bar_height;
 
    shader_routeui_uColour( fade_colour );
    for( u32 i=0; i<pr->ui.fade_count; i++ )
@@ -496,39 +522,32 @@ static void world_routes_ui_draw( u32 route, v4f colour, float offset )
       u32 j = (pr->ui.fade_start + i) % k_max_ui_segments;
       struct route_ui_segment *segment = &pr->ui.segments[j];
 
-      u32 c0, c1;
-      world_routes_ui_split_indices( segment->index_start, 
-            segment->index_count, &c0, &c1 );
-
-      shader_routeui_uOffset( (v4f){ cx, offset, 0.005f, height } );
-      if( c0 )
-         glDrawElements( GL_TRIANGLES, c0, GL_UNSIGNED_SHORT,
-                           (void *)(segment->index_start*sizeof(u16)));
-      if( c1 )
-         glDrawElements( GL_TRIANGLES, c1, GL_UNSIGNED_SHORT, (void *)(0) );
+      shader_routeui_uOffset( (v4f){ cx*k_bar_scale_x, base,
+                                     k_bar_scale_x, height } );
 
+      world_routes_ui_draw_segment( segment );
       cx += segment->length;
    }
 
+   /*
+    * Draw main bar 
+    */
    shader_routeui_uColour( colour );
    for( u32 i=0; i<pr->ui.segment_count; i++ )
    {
       u32 j = (pr->ui.segment_start + i) % k_max_ui_segments;
       struct route_ui_segment *segment = &pr->ui.segments[j];
 
-      u32 c0, c1;
-      world_routes_ui_split_indices( segment->index_start, 
-            segment->index_count, &c0, &c1 );
-
-      shader_routeui_uOffset( (v4f){ cx, offset, 0.005f, height } );
-      if( c0 )
-         glDrawElements( GL_TRIANGLES, c0, GL_UNSIGNED_SHORT,
-                           (void *)(segment->index_start*sizeof(u16)));
-      if( c1 )
-         glDrawElements( GL_TRIANGLES, c1, GL_UNSIGNED_SHORT, (void *)(0) );
+      shader_routeui_uOffset( (v4f){ cx*k_bar_scale_x, base,
+                                     k_bar_scale_x, height } );
 
+      world_routes_ui_draw_segment( segment );
       cx += segment->length;
+
+      main_block_size += segment->length;
    }
+
+   pr->ui.xpos = vg_lerpf( pr->ui.xpos, -main_block_size * 0.5f, 0.03f );
 }
 
 /* 
@@ -958,7 +977,7 @@ static void render_world_routes_ui(void)
    for( int i=0; i<r->route_count; i++ )
    {
       struct route *route = &r->routes[i];
-      world_routes_ui_draw( i, route->colour, active_offset*0.1f );
+      world_routes_ui_draw( i, route->colour, active_offset );
       active_offset += route->factive;
    }