38 u32 route_ids
[4]; /* Gates can be linked into up to four routes */
48 static struct subworld_routes
*subworld_routes(void);
52 * when a gate is passed through it needs to trigger into an active state
55 static void world_routes_debug(void)
57 struct subworld_routes
*r
= subworld_routes();
59 for( int i
=0; i
<r
->node_count
; i
++ )
61 struct route_node
*rn
= &r
->nodes
[i
];
62 vg_line_pt3( rn
->co
, 1.0f
, rn
->is_gate
? 0xffffff00: 0xff00b2ff );
66 static void world_routes_free(void)
68 struct subworld_routes
*r
= subworld_routes();
75 static void world_id_fixup( u32
*uid
, mdl_header
*mdl
)
78 *uid
= mdl_node_from_id( mdl
, *uid
)->sub_uid
;
81 static void world_routes_init( mdl_header
*mdl
)
83 struct subworld_routes
*r
= subworld_routes();
94 for( int i
=0; i
<mdl
->node_count
; i
++ )
96 mdl_node
*pnode
= mdl_node_from_id(mdl
,i
);
99 if( pnode
->classtype
== k_classtype_route_node
||
100 pnode
->classtype
== k_classtype_gate
)
102 mdl_node_transform( pnode
, transform
);
103 pnode
->sub_uid
= r
->node_count
;
105 r
->nodes
= buffer_reserve( r
->nodes
, r
->node_count
, &r
->node_cap
, 1,
106 sizeof( struct route_node
) );
108 struct route_node
*rn
= &r
->nodes
[r
->node_count
];
110 v3_copy( transform
[0], rn
->right
);
111 v3_normalize( rn
->right
);
112 v3_copy( transform
[2], rn
->h
);
113 v3_copy( transform
[3], rn
->co
);
115 if( pnode
->classtype
== k_classtype_gate
)
117 r
->gates
= buffer_reserve( r
->gates
, r
->gate_count
, &r
->gate_cap
,
118 1, sizeof( struct route_gate
) );
120 struct classtype_gate
*inf
= mdl_get_entdata( mdl
, pnode
);
122 /* H is later scaled based on link distance */
123 v3_normalize( rn
->h
);
124 rn
->next
[0] = inf
->target
;
126 rn
->gate_id
= r
->gate_count
;
129 struct route_gate
*rg
= &r
->gates
[r
->gate_count
];
130 rg
->node_id
= r
->node_count
;
138 struct classtype_route_node
*inf
= mdl_get_entdata( mdl
, pnode
);
139 rn
->next
[0] = inf
->target
;
140 rn
->next
[1] = inf
->target1
;
146 else if( pnode
->classtype
== k_classtype_route
)
148 struct classtype_route
*inf
= mdl_get_entdata( mdl
, pnode
);
149 r
->routes
= buffer_reserve( r
->routes
, r
->route_count
, &r
->route_cap
,
150 1, sizeof( struct route
) );
152 struct route
*route
= &r
->routes
[r
->route_count
];
154 v4_zero( route
->colour
);
156 route
->start
= inf
->id_start
;
163 * Apply correct system-local ids
165 for( int i
=0; i
<r
->node_count
; i
++ )
167 struct route_node
*rn
= &r
->nodes
[i
];
169 for( int j
=0; j
<2; j
++ )
170 world_id_fixup( &rn
->next
[j
], mdl
);
173 world_id_fixup( &rn
->gate_id
, mdl
);
176 for( int i
=0; i
<r
->gate_count
; i
++ )
178 struct route_gate
*rg
= &r
->gates
[i
];
179 world_id_fixup( &rg
->node_id
, mdl
);
182 for( int i
=0; i
<r
->route_count
; i
++ )
184 struct route
*route
= &r
->routes
[i
];
185 world_id_fixup( &route
->start
, mdl
);
189 #endif /* ROUTES_H */