2 * Copyright (C) 2021-2022 Mt.ZERO Software, Harry Godden - All Rights Reserved
7 static int ray_world( v3f pos
, v3f dir
, ray_hit
*hit
);
12 #include "vg/vg_loader.h"
15 #include "network_msg.h"
18 #include "rigidbody.h"
22 #include "traffic.h" /*TODO: -> world_traffic.h */
24 #include "shaders/terrain.h"
25 #include "shaders/sky.h"
26 #include "shaders/planeinf.h"
27 #include "shaders/standard.h"
28 #include "shaders/vblend.h"
29 #include "shaders/gpos.h"
30 #include "shaders/fscolour.h"
31 #include "shaders/alphatest.h"
33 enum { k_max_ui_segments
= 8 };
34 enum { k_max_ui_splits_per_segment
= 16 };
36 enum { k_max_ui_elements
= k_max_ui_segments
*k_max_ui_splits_per_segment
};
37 enum { k_max_element_verts
= 10 };
38 enum { k_max_element_indices
= 20 };
40 enum { k_route_ui_max_verts
= k_max_ui_elements
*k_max_element_verts
};
41 enum { k_route_ui_max_indices
= k_max_ui_elements
*k_max_element_indices
};
61 struct subworld_routes
68 u32 special_type
, special_id
, current_refs
, ref_count
;
69 u32 route_ids
[4]; /* Gates can be linked into up to four routes */
87 double best_lap
, latest_pass
; /* Session */
98 struct route_ui_segment
101 u32 vertex_start
, vertex_count
,
102 index_start
, index_count
, notches
;
104 segments
[k_max_ui_segments
];
106 u32 segment_start
, segment_count
, fade_start
, fade_count
;
107 double fade_timer_start
;
112 m4x3f scoreboard_transform
;
116 double last_interaction
;
129 m4x3f to_world
, recv_to_world
, transport
;
137 u32 version
; /* Incremented on every teleport */
144 struct route_collector
146 struct route_timing timing
;
165 mdl_submesh
*sm_module
, *sm_card
;
179 traffic_node traffic
[128];
183 traffic_driver van_man
[6];
188 /* Rendering & geometry */
192 /* TODO Maybe make this less hardcoded */
193 mdl_submesh sm_geo_std_oob
, sm_geo_std
, sm_geo_vb
,
194 sm_foliage_main
, sm_foliage_alphatest
,
195 sm_graffiti
, sm_subworld
, sm_terrain
;
197 glmesh skybox
, skydome
;
198 mdl_submesh dome_upper
, dome_lower
;
201 mdl_submesh car_holden
;
205 struct instance_cache
211 u32 instance_cache_count
,
215 int active_route_board
;
223 static int ray_hit_is_ramp( ray_hit
*hit
);
224 static int ray_hit_is_terrain( ray_hit
*hit
);
225 static void ray_world_get_tri( ray_hit
*hit
, v3f tri
[3] );
226 static int ray_world( v3f pos
, v3f dir
, ray_hit
*hit
);
231 #include "world_routes.h"
232 #include "world_sfd.h"
233 #include "world_render.h"
234 #include "world_water.h"
235 #include "world_gen.h"
236 #include "world_gate.h"
239 * -----------------------------------------------------------------------------
241 * -----------------------------------------------------------------------------
244 static void world_init(void)
246 shader_terrain_register();
247 shader_sky_register();
248 shader_planeinf_register();
249 shader_gpos_register();
250 shader_fscolour_register();
251 shader_alphatest_register();
253 vg_info( "Loading world resources\n" );
255 VG_REQUIRED_ASSET( mdl_header
*, mcars
, mdl_load
, "models/rs_cars.mdl" );
256 VG_REQUIRED_ASSET( mdl_header
*, msky
, mdl_load
, "models/rs_skydome.mdl" );
258 mdl_node
*nholden
= mdl_node_from_name( mcars
, "holden" );
259 world
.car_holden
= *mdl_node_submesh( mcars
, nholden
, 0 );
261 mdl_node
*nlower
= mdl_node_from_name( msky
, "dome_lower" ),
262 *nupper
= mdl_node_from_name( msky
, "dome_upper" );
264 world
.dome_lower
= *mdl_node_submesh( msky
, nlower
, 0 );
265 world
.dome_upper
= *mdl_node_submesh( msky
, nupper
, 0 );
267 vg_acquire_thread_sync();
269 mdl_unpack_glmesh( mcars
, &world
.cars
);
270 mdl_unpack_glmesh( msky
, &world
.skydome
);
272 vg_release_thread_sync();
278 vg_info( "Loading other world systems\n" );
280 vg_loader_highwater( world_render_init
, world_render_free
, NULL
);
281 vg_loader_highwater( world_sfd_init
, world_sfd_free
, NULL
);
282 vg_loader_highwater( world_water_init
, world_water_free
, NULL
);
283 vg_loader_highwater( world_gates_init
, world_gates_free
, NULL
);
284 vg_loader_highwater( world_routes_init
, world_routes_free
, NULL
);
287 static void world_free( void *_
)
289 mesh_free( &world
.cars
);
290 mesh_free( &world
.skydome
);
293 static void world_update( v3f pos
)
295 world_routes_update();
296 world_routes_debug();
299 float min_dist
= INFINITY
;
301 for( int i
=0; i
<world
.routes
.route_count
; i
++ )
303 float d
= v3_dist2( world
.routes
.routes
[i
].scoreboard_transform
[3], pos
);
312 if( (world
.active_route_board
!= closest
) || network_scores_updated
)
314 network_scores_updated
= 0;
315 world
.active_route_board
= closest
;
316 struct subworld_sfd
*sfd
= &world
.sfd
;
318 struct route
*route
= &world
.routes
.routes
[closest
];
320 u32 id
= route
->track_id
;
322 if( id
!= 0xffffffff )
324 struct netmsg_board
*local_board
= &scoreboard_client_data
.boards
[id
];
326 for( int i
=0; i
<13; i
++ )
328 sfd_encode( &sfd
->tester
, i
, &local_board
->data
[27*i
] );
333 sfd_update( &world
.sfd
.tester
);
337 * -----------------------------------------------------------------------------
339 * -----------------------------------------------------------------------------
342 static void ray_world_get_tri( ray_hit
*hit
, v3f tri
[3] )
344 for( int i
=0; i
<3; i
++ )
345 v3_copy( world
.geo
.verts
[ hit
->tri
[i
] ].co
, tri
[i
] );
348 static int ray_world( v3f pos
, v3f dir
, ray_hit
*hit
)
350 return scene_raycast( &world
.geo
, pos
, dir
, hit
);
353 static int ray_hit_is_terrain( ray_hit
*hit
)
356 valid_end
= world
.sm_terrain
.vertex_count
;
358 return (hit
->tri
[0] >= valid_start
) &&
359 (hit
->tri
[0] < valid_end
);
362 static int ray_hit_is_ramp( ray_hit
*hit
)
364 u32 valid_start
= world
.sm_geo_std
.vertex_start
,
365 valid_end
= world
.sm_geo_vb
.vertex_start
;
367 return (hit
->tri
[0] >= valid_start
) &&
368 (hit
->tri
[0] < valid_end
);