- struct subworld_routes *r = &world.routes;
- r->nodes = NULL;
- r->node_count = 0; r->node_cap = 0; r->routes = NULL;
- r->route_count = 0;
- r->route_cap = 0;
- r->gates = NULL;
- r->gate_count = 0;
- r->gate_cap = 0;
-
- /* TODO Break this up */
- for( int i=0; i<mdl->node_count; i++ )
- {
- mdl_node *pnode = mdl_node_from_id(mdl,i);
- m4x3f transform;
-
- if( pnode->classtype == k_classtype_route_node ||
- pnode->classtype == k_classtype_gate )
- {
- mdl_node_transform( pnode, transform );
- pnode->sub_uid = r->node_count;
-
- r->nodes = buffer_reserve( r->nodes, r->node_count, &r->node_cap, 1,
- sizeof( struct route_node ) );
-
- struct route_node *rn = &r->nodes[r->node_count];
-
- v3_copy( transform[0], rn->right );
- v3_normalize( rn->right );
- v3_copy( transform[1], rn->up );
- v3_normalize( rn->up );
- v3_muls( transform[2], -1.0f, rn->h );
- 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 )
- {
- 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;
-
- /* TODO */
- if( inf->target )
- {
- mdl_node *pother = mdl_node_from_id( mdl, 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] );
- v4_copy( pnode->q, rg->gate.q[0] );
- v4_copy( pother->q, rg->gate.q[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;