-#ifndef ROUTES_H
-#define ROUTES_H
-
-#include "common.h"
-#include "model.h"
-#include "gate.h"
-
-struct subworld_routes
-{
- struct route_node
- {
- v3f co, right, h;
- u32 next[2];
-
- u32 is_gate, gate_id;
- }
- *nodes;
-
- u32 node_count,
- node_cap;
-
- struct route
- {
- const char *name;
- v4f colour;
-
- u32 start;
- }
- *routes;
-
- u32 route_count,
- route_cap;
-
- struct route_gate
- {
- teleport_gate gate;
-
- u32 route_ids[4]; /* Gates can be linked into up to four routes */
- u32 route_count,
- node_id;
- }
- *gates;
-
- u32 gate_count,
- gate_cap;
-};
-
-static struct subworld_routes *subworld_routes(void);
-
-/*
- * TODO list:
- * when a gate is passed through it needs to trigger into an active state
+/*
+ * Copyright (C) 2021-2023 Mt.ZERO Software, Harry Godden - All Rights Reserved
*/
-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 );
- }
-}
-
-static void world_routes_free(void)
-{
- struct subworld_routes *r = subworld_routes();
-
- free( r->nodes );
- free( r->routes );
- free( r->gates );
-}
-
-static void world_id_fixup( u32 *uid, mdl_header *mdl )
-{
- if( *uid )
- *uid = mdl_node_from_id( mdl, *uid )->sub_uid;
-}
-
-static void world_routes_init( mdl_header *mdl )
-{
- struct subworld_routes *r = subworld_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;
-
- 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[2], rn->h );
- v3_copy( transform[3], rn->co );
-
- 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;
-
- struct route_gate *rg = &r->gates[r->gate_count];
- rg->node_id = r->node_count;
-
- /* TODO */
-
- r->gate_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 ++;
- }
- else if( pnode->classtype == k_classtype_route )
- {
- struct classtype_route *inf = mdl_get_entdata( mdl, pnode );
- r->routes = buffer_reserve( r->routes, r->route_count, &r->route_cap,
- 1, sizeof( struct route ) );
-
- struct route *route = &r->routes[r->route_count];
-
- v4_zero( route->colour );
- route->name = NULL;
- route->start = inf->id_start;
-
- r->route_count ++;
- }
- }
-
- /*
- * Apply correct system-local ids
- */
- for( int i=0; i<r->node_count; i++ )
- {
- struct route_node *rn = &r->nodes[i];
-
- for( int j=0; j<2; j++ )
- world_id_fixup( &rn->next[j], mdl );
-
- if( rn->is_gate )
- world_id_fixup( &rn->gate_id, mdl );
- }
-
- for( int i=0; i<r->gate_count; i++ )
- {
- struct route_gate *rg = &r->gates[i];
- world_id_fixup( &rg->node_id, mdl );
- }
+#ifndef ROUTES_H
+#define ROUTES_H
- for( int i=0; i<r->route_count; i++ )
- {
- struct route *route = &r->routes[i];
- world_id_fixup( &route->start, mdl );
- }
-}
+#include "world.h"
+
+VG_STATIC void world_routes_init(void);
+VG_STATIC void world_routes_fracture( world_instance *world, ent_gate *gate,
+ v3f imp_co, v3f imp_v );
+VG_STATIC void world_routes_activate_entry_gate( world_instance *world,
+ ent_gate *rg );
+VG_STATIC void render_world_routes( world_instance *world, camera *cam,
+ int layer_depth );
+
+VG_STATIC void world_gen_routes_ent_init( world_instance *world );
+VG_STATIC void world_gen_routes_generate( u32 instance_id );
+VG_STATIC void world_routes_update_timer_texts( world_instance *world );
+VG_STATIC void world_routes_update( world_instance *world );
+VG_STATIC void world_routes_fixedupdate( world_instance *world );
#endif /* ROUTES_H */