#include "shaders/vblend.h"
#include "shaders/route.h"
+enum route_special_type
+{
+ k_route_special_type_gate = 1,
+ k_route_special_type_collector = 2
+};
+
struct subworld_routes
{
struct route_node
v3f co, right, up, h;
u32 next[2];
- u32 is_gate, gate_id, current_refs, ref_count;
+ u32 special_type, special_id, current_refs, ref_count;
u32 route_ids[4]; /* Gates can be linked into up to four routes */
}
*nodes;
{
teleport_gate gate;
- u32 route_count,
- node_id;
+ u32 node_id;
+
+ struct route_timing
+ {
+ u32 version; /* Incremented on every teleport */
+ double time;
+ }
+ timing;
}
*gates;
+ struct route_collector
+ {
+ struct route_timing timing;
+ }
+ *collectors;
+
u32 gate_count,
- gate_cap;
+ gate_cap,
+ collector_count,
+ collector_cap;
- u32 active_gate;
+ u32 active_gate,
+ current_run_version;
scene scene_lines;
};
}
}
-static void world_routes_activate_gate( u32 id )
-{
- struct subworld_routes *r = subworld_routes();
- struct route_gate *ig = &r->gates[id];
- struct route_node *pnode = &r->nodes[ig->node_id],
- *pdest = &r->nodes[pnode->next[0]];
-
- r->active_gate = id;
-
- for( int i=0; i<r->route_count; i++ )
- {
- struct route *route = &r->routes[i];
-
- route->active = 0;
- for( int j=0; j<pdest->ref_count; j++ )
- {
- if( pdest->route_ids[j] == i )
- {
- route->active = 1;
- break;
- }
- }
- }
-}
-
-static u32 world_routes_get_path( struct route *route, u32 stack[64] )
+/*
+ * Get a list of node ids in stack, and return how many there is
+ */
+static u32 world_routes_get_path( u32 starter, u32 stack[64] )
{
struct subworld_routes *r = subworld_routes();
u32 stack_i[64];
- stack[0] = route->start;
+ stack[0] = starter;
stack_i[0] = 0;
u32 si = 1;
return 0;
}
+/*
+ * Will scan the whole run for two things;
+ * 1: we set a new record for the total, complete loop around the course
+ * 2: the time of each segment will be recorded into the data buffer
+ * (not implemented: TODO)
+ */
+static void world_routes_verify_run( u32 route )
+{
+ struct subworld_routes *r = subworld_routes();
+
+ u32 stack[64];
+ u32 si = world_routes_get_path( r->routes[route].start, stack );
+
+ /*
+ * we only care about gates that ref gates, so shuffle down the array
+ */
+ struct route_timing *timings[64];
+ u32 sj = 0, maxv = 0, begin = 0;
+ for( u32 i=0; i<si; i++ )
+ {
+ if( r->nodes[stack[i]].special_type == k_route_special_type_collector )
+ timings[sj ++] = &r->collectors[r->nodes[stack[i]].special_id].timing;
+ else if( r->nodes[stack[i]].special_type == k_route_special_type_gate )
+ timings[sj ++] = &r->gates[r->nodes[stack[i]].special_id].timing;
+ }
+
+ for( u32 i=0; i<sj; i++ )
+ {
+ if( timings[i]->version > maxv )
+ {
+ maxv = timings[i]->version;
+ begin = i;
+ }
+ }
+
+ vg_info( "== begin verification (%u) ==\n", route );
+ vg_info( " current version: %u\n", r->current_run_version );
+
+ int verified = 0;
+ if( timings[begin]->version == r->current_run_version )
+ verified = 1;
+
+ double lap_time = 0.0;
+
+ for( u32 i=0; i<sj; i++ )
+ {
+ u32 j = (sj+begin-i-1) % sj,
+ j1 = (j+1) % sj;
+
+ double diff = 0.0;
+
+ if( i<sj-1 )
+ {
+ /* j1v should equal jv+1 */
+ if( timings[j1]->version == timings[j]->version+1 )
+ {
+ diff = timings[j1]->time - timings[j]->time;
+ lap_time += diff;
+ }
+ else
+ verified = 0;
+ }
+
+ if( verified )
+ vg_success( " [ %u %f ] %f\n", timings[j1]->time,
+ timings[j1]->version, diff );
+ else
+ vg_warn( " [ %u %f ]\n", timings[j1]->time, timings[j1]->version );
+ }
+
+ if( verified )
+ vg_success( " NEW LAP TIME: %f\n", lap_time );
+ else
+ vg_info( " ctime: %f\n", lap_time );
+}
+
+/*
+ * When going through a gate this is called for bookkeeping purposes
+ */
+static void world_routes_activate_gate( u32 id )
+{
+ struct subworld_routes *r = subworld_routes();
+ struct route_gate *rg = &r->gates[id];
+ struct route_node *pnode = &r->nodes[rg->node_id],
+ *pdest = &r->nodes[pnode->next[0]];
+
+ struct route_collector *rc = &r->collectors[ pdest->special_id ];
+
+ r->active_gate = id;
+ rg->timing.version = r->current_run_version;
+ rg->timing.time = vg_time;
+ for( u32 i=0; i<r->route_count; i++ )
+ {
+ struct route *route = &r->routes[i];
+
+ route->active = 0;
+ for( u32 j=0; j<pdest->ref_count; j++ )
+ {
+ if( pdest->route_ids[j] == i )
+ {
+ world_routes_verify_run( i );
+ route->active = 1;
+ break;
+ }
+ }
+ }
+
+ r->current_run_version ++;
+
+ rc->timing.version = r->current_run_version;
+ rc->timing.time = vg_time;
+ r->current_run_version ++;
+}
+
static void world_routes_debug(void)
{
struct subworld_routes *r = subworld_routes();
for( int i=0; i<r->node_count; i++ )
{
struct route_node *rn = &r->nodes[i];
- vg_line_pt3( rn->co, 1.0f, rn->is_gate? 0xffffff00: 0xff00b2ff );
+ vg_line_pt3( rn->co, 1.0f, rn->special_type? 0xffffff00: 0xff00b2ff );
}
for( int i=0; i<r->route_count; i++ )
struct route *route = &r->routes[i];
u32 stack[64];
- u32 si = world_routes_get_path( route, stack );
+ u32 si = world_routes_get_path( route->start, stack );
u32 colours[] = { 0xfff58142, 0xff42cbf5, 0xff42f56c, 0xfff542b3,
0xff5442f5 };
*uid = 0xffffffff;
}
+/*
+ * Create the strips of colour that run through the world along course paths
+ */
static void world_routes_gen_meshes(void)
{
struct subworld_routes *r = subworld_routes();
struct route *route = &r->routes[i];
u32 stack[64];
- u32 si = world_routes_get_path( route, stack );
+ u32 si = world_routes_get_path( route->start, stack );
u32 last_valid = 0;
*rnk = &r->nodes[ stack[sk] ],
*rnl;
- if( rnj->is_gate && rnk->is_gate )
+ if( rnj->special_type && rnk->special_type )
{
last_valid = 0;
continue;
float base_x0 = (float)rnj->ref_count*-0.5f + (float)rnj->current_refs,
base_x1 = (float)rnk->ref_count*-0.5f + (float)rnk->current_refs;
- if( rnk->is_gate )
+ if( rnk->special_type )
{
rnl = &r->nodes[ rnk->next[0] ];
base_x1 = (float)rnl->ref_count*-0.5f + (float)rnl->current_refs;
static void world_routes_register(void)
{
+ struct subworld_routes *r = subworld_routes();
+ r->current_run_version = 2;
+
shader_route_register();
}
v3_copy( transform[3], rn->co );
rn->ref_count = 0;
rn->current_refs = 0;
+ rn->special_type = 0;
+ rn->special_id = 0;
if( pnode->classtype == k_classtype_gate )
{
- r->gates = buffer_reserve( r->gates, r->gate_count, &r->gate_cap,
- 1, sizeof( struct route_gate ) );
-
struct classtype_gate *inf = mdl_get_entdata( mdl, pnode );
/* H is later scaled based on link distance */
v3_normalize( rn->h );
rn->next[0] = inf->target;
rn->next[1] = 0;
- rn->gate_id = r->gate_count;
- rn->is_gate = 1;
/* TODO */
if( inf->target )
if( pother->classtype == k_classtype_gate )
{
+ r->gates = buffer_reserve( r->gates, r->gate_count,
+ &r->gate_cap,
+ 1, sizeof( struct route_gate ) );
+
struct route_gate *rg = &r->gates[r->gate_count];
rg->node_id = r->node_count;
+ rg->timing.time = 0.0;
+ rg->timing.version = 0;
v3_copy( pnode->co, rg->gate.co[0] );
v3_copy( pother->co, rg->gate.co[1] );
v2_copy( inf->dims, rg->gate.dims );
gate_transform_update( &rg->gate );
+ rn->special_type = k_route_special_type_gate;
+ rn->special_id = r->gate_count;
r->gate_count ++;
}
}
+
+ if( rn->special_type == 0 )
+ {
+ r->collectors = buffer_reserve(
+ r->collectors, r->collector_count, &r->collector_cap,
+ 1, sizeof( struct route_collector ));
+
+ struct route_collector *rc = &r->collectors[r->collector_count];
+ rc->timing.time = 0.0;
+ rc->timing.version = 0;
+
+ rn->special_type = k_route_special_type_collector;
+ rn->special_id = r->collector_count;
+
+ r->collector_count ++;
+ }
}
else
{
struct classtype_route_node *inf = mdl_get_entdata( mdl, pnode );
rn->next[0] = inf->target;
rn->next[1] = inf->target1;
- rn->is_gate = 0;
}
r->node_count ++;
struct route *route = &r->routes[i];
u32 stack[64];
- u32 si = world_routes_get_path( route, stack );
+ u32 si = world_routes_get_path( route->start, stack );
for( int sj=0; sj<si; sj++ )
{