#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;
u32 node_id;
- double time_passed; /* When did we last pass this gate? */
- u32 passed_version; /* Incremented on every reset */
+ 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,
current_run_version;
}
}
+/*
+ * 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();
return 0;
}
-static void world_routes_verify_run( u32 route, double new_pass_time )
+/*
+ * 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();
- if( r->current_run_version == 0 ) return;
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
*/
- u32 sj = 0;
+ struct route_timing *timings[64];
+ u32 sj = 0, maxv = 0, begin = 0;
for( u32 i=0; i<si; i++ )
- if( r->nodes[stack[i]].is_gate && r->nodes[stack[(i+1)%si]].is_gate )
- stack[sj ++] = r->nodes[stack[i]].gate_id;
+ {
+ 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;
+ }
+ }
- /*
- * run versions & times must always ASCEND apart from exactly once, where
- * the tail connects to the head
- */
+ vg_info( "== begin verification (%u) ==\n", route );
+ vg_info( " current version: %u\n", r->current_run_version );
- vg_info("Verifying run (%u)\n", route);
+ int verified = 0;
+ if( timings[begin]->version == r->current_run_version )
+ verified = 1;
- u32 descend_allowance = 1;
double lap_time = 0.0;
for( u32 i=0; i<sj; i++ )
{
- struct route_gate *pa = &r->gates[stack[i]],
- *pb = &r->gates[stack[(i+1) % sj]];
+ u32 j = (sj+begin-i-1) % sj,
+ j1 = (j+1) % sj;
- vg_info( " pa: %u, pb: %u\n", pa->passed_version, pb->passed_version );
-
- int version_inorder = 0;
double diff = 0.0;
-
- if( pb->passed_version == pa->passed_version+1 )
- {
- version_inorder = 1;
- diff = pb->time_passed - pa->time_passed;
- }
- else if( pb->passed_version == pa->passed_version+1-sj &&
- pa->passed_version+1 == r->current_run_version )
+
+ if( i<sj-1 )
{
- version_inorder = 1;
- diff = new_pass_time - pa->time_passed;
+ /* 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( !version_inorder )
- return;
-
- lap_time += diff;
+
+ 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 );
}
- /* We've now verified the run was completed correctly */
- vg_success( "Lap time set. route %u: %lf\n", route, lap_time );
+ 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 *ig = &r->gates[id];
- struct route_node *pnode = &r->nodes[ig->node_id],
+ struct route_gate *rg = &r->gates[id];
+ struct route_node *pnode = &r->nodes[rg->node_id],
*pdest = &r->nodes[pnode->next[0]];
- r->active_gate = id;
+ 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];
{
if( pdest->route_ids[j] == i )
{
- world_routes_verify_run( i, vg_time );
+ world_routes_verify_run( i );
route->active = 1;
break;
}
}
}
- ig->time_passed = vg_time;
- ig->passed_version = r->current_run_version;
+ r->current_run_version ++;
+
+ rc->timing.version = r->current_run_version;
+ rc->timing.time = vg_time;
r->current_run_version ++;
}
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++ )
*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();
*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->passed_version = 0;
- rg->time_passed = 0.0;
+ 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 ++;