#include "traffic.h" /*TODO: -> world_traffic.h */
#include "world_routes.h"
#include "world_sfd.h"
+#include "world_audio.h"
+#include "network.h"
+#include "network_msg.h"
#include "shaders/terrain.h"
#include "shaders/sky.h"
struct subworld_routes routes;
struct subworld_sfd sfd;
- /* ...
- struct subworld_spawns system_spawns;
- struct subworld_physics system_physics;
- */
-
/* Paths */
traffic_node traffic[128];
u32 traffic_count;
/* TODO Maybe make this less hardcoded */
mdl_submesh sm_geo_std_oob, sm_geo_std, sm_geo_vb,
sm_foliage_main, sm_foliage_alphatest,
- sm_graffiti, sm_subworld;
+ sm_graffiti, sm_subworld, sm_terrain;
glmesh skybox, skydome;
mdl_submesh dome_upper, dome_lower;
* instance_cache;
u32 instance_cache_count,
instance_cache_cap;
+
+ v3f render_gate_pos;
+ int active_route_board;
}
world;
return scene_raycast( &world.geo, pos, dir, hit );
}
+static int ray_hit_is_terrain( ray_hit *hit )
+{
+ u32 valid_start = 0,
+ valid_end = world.sm_terrain.vertex_count;
+
+ return (hit->tri[0] >= valid_start) &&
+ (hit->tri[0] < valid_end);
+}
+
static int ray_hit_is_ramp( ray_hit *hit )
{
- return hit->tri[0] > world.sm_geo_std_oob.vertex_count;
+ u32 valid_start = world.sm_geo_std.vertex_start,
+ valid_end = world.sm_geo_vb.vertex_start;
+
+ return (hit->tri[0] >= valid_start) &&
+ (hit->tri[0] < valid_end);
}
static void world_register(void)
if( ray_world( pos, (v3f){0.0f,-1.0f,0.0f}, &hit ))
{
- if( hit.normal[1] > 0.8f && !ray_hit_is_ramp(&hit) &&
- hit.pos[1] > water_height()+10.0f )
+ if( (hit.normal[1] > 0.8f) && ray_hit_is_terrain(&hit) &&
+ (hit.pos[1] > water_height()+10.0f) )
{
v4f qsurface, qrandom;
v3f axis;
mat_vertex_blend = 0,
mat_alphatest = 0,
mat_graffiti = 0,
- mat_subworld = 0;
+ mat_subworld = 0,
+ mat_terrain = 0;
for( int i=1; i<mworld->material_count; i++ )
{
mat_alphatest = i;
else if( !strcmp( "graffitibox", mat_name ))
mat_graffiti = i;
- else if( !strcmp( "subworld", mat_name ))
- mat_subworld = i;
+ else if( !strcmp( "terrain", mat_name ) )
+ mat_terrain = i;
}
m4x3f midentity;
m4x3_identity( midentity );
+ if( mat_terrain )
+ add_all_if_material( midentity, &world.geo, mworld, mat_terrain );
+ scene_copy_slice( &world.geo, &world.sm_terrain );
+
if( mat_surf_oob )
add_all_if_material( midentity, &world.geo, mworld, mat_surf_oob );
else
add_all_if_material( midentity, &world.geo, mworld, mat_surf );
scene_copy_slice( &world.geo, &world.sm_geo_std );
- if( mat_subworld )
- add_all_if_material( midentity, &world.geo, mworld, mat_subworld );
- scene_copy_slice( &world.geo, &world.sm_subworld );
-
if( mat_vertex_blend )
add_all_if_material( midentity, &world.geo, mworld, mat_vertex_blend );
scene_copy_slice( &world.geo, &world.sm_geo_vb );
/* Other systems */
world_sfd_init();
+ world_audio_init();
}
static void world_update(void)
{
world_routes_update();
world_routes_debug();
+
+ int closest = 0;
+ float min_dist = INFINITY;
+
+ for( int i=0; i<world.routes.route_count; i++ )
+ {
+ float dist = v3_dist2( world.routes.routes[i].scoreboard_transform[3],
+ player_get_pos() );
+
+ if( dist < min_dist )
+ {
+ min_dist = dist;
+ closest = i;
+ }
+ }
+
+ if( (world.active_route_board != closest) || network_scores_updated )
+ {
+ network_scores_updated = 0;
+ world.active_route_board = closest;
+ struct subworld_sfd *sfd = subworld_sfd();
+
+ struct route *route = &world.routes.routes[closest];
+
+ u32 id = route->track_id;
+
+ if( id != 0xffffffff )
+ {
+ struct netmsg_board *local_board = &scoreboard_client_data.boards[id];
+
+ for( int i=0; i<13; i++ )
+ {
+ sfd_encode( &sfd->tester, i, &local_board->data[27*i] );
+ }
+ }
+ }
+
sfd_update( &world.sfd.tester );
#if 0
shader_terrain_uCamera( camera );
scene_bind( &world.geo );
+ mdl_draw_submesh( &world.sm_terrain );
mdl_draw_submesh( &world.sm_geo_std_oob );
mdl_draw_submesh( &world.sm_geo_std );
mdl_draw_submesh( &world.sm_subworld );
glDepthMask( GL_TRUE );
}
-static void render_world_gates( m4x4f projection, m4x3f camera )
+static void render_world_gates( m4x4f projection, v3f playerco, m4x3f camera )
{
float closest = INFINITY;
int id = 0;
}
}
- render_gate( &world.routes.gates[id].gate, camera );
+ render_gate( &world.routes.gates[id].gate, playerco, camera );
+ v3_lerp( world.render_gate_pos,
+ world.routes.gates[id].gate.co[0],
+ 1.0f,
+ world.render_gate_pos );
}
static void render_world( m4x4f projection, m4x3f camera )
render_world_alphatest( projection, camera[3] );
render_terrain( projection, camera[3] );
- m4x3f identity_matrix;
- m4x3_identity( identity_matrix );
- identity_matrix[3][1] = 125.0f;
+ int closest = 0;
+ float min_dist = INFINITY;
+
+ for( int i=0; i<world.routes.route_count; i++ )
+ {
+ float dist = v3_dist2( world.routes.routes[i].scoreboard_transform[3],
+ camera[3] );
- v4f t;
- q_axis_angle( t, (v3f){0.0f,1.0f,0.0f}, 2.3f );
- q_m3x3( t, identity_matrix );
+ if( dist < min_dist )
+ {
+ min_dist = dist;
+ closest = i;
+ }
+ }
- sfd_render( &world.sfd.tester, projection, camera[3], identity_matrix );
+ sfd_render( &world.sfd.tester, projection, camera[3],
+ world.routes.routes[closest].scoreboard_transform );
}
static void render_world_depth( m4x4f projection, m4x3f camera )