X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=world.h;h=cf721e8402c097d95bcc5a5ba274acb9c43f0a5a;hb=cedb92d590f4578a246a09a96c0fa0eda109d3c7;hp=f015a63e0ae43c93a9b4cd15b762bc133d3a7b18;hpb=1030b1e134d422a3cbc1e06102053447da59ceba;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/world.h b/world.h index f015a63..cf721e8 100644 --- a/world.h +++ b/world.h @@ -17,6 +17,10 @@ static int ray_world( v3f pos, v3f dir, ray_hit *hit ); #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" @@ -40,11 +44,7 @@ static struct gworld u32 spawn_count; struct subworld_routes routes; - - /* ... - struct subworld_spawns system_spawns; - struct subworld_physics system_physics; - */ + struct subworld_sfd sfd; /* Paths */ traffic_node traffic[128]; @@ -60,8 +60,10 @@ static struct gworld scene geo, foliage; rigidbody rb_geo; + /* 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_foliage_main, sm_foliage_alphatest, + sm_graffiti, sm_subworld, sm_terrain; glmesh skybox, skydome; mdl_submesh dome_upper, dome_lower; @@ -81,10 +83,14 @@ static struct gworld * instance_cache; u32 instance_cache_count, instance_cache_cap; + + v3f render_gate_pos; + int active_route_board; } world; static struct subworld_routes *subworld_routes(void) { return &world.routes; } +static struct subworld_sfd *subworld_sfd(void) { return &world.sfd; } vg_tex2d tex_terrain_colours = { .path = "textures/gradients.qoi", @@ -96,6 +102,9 @@ vg_tex2d tex_terrain_noise = { .path = "textures/garbage.qoi", vg_tex2d tex_alphatest = { .path = "textures/alphatest.qoi", .flags = VG_TEXTURE_NEAREST }; +vg_tex2d tex_graffiti = { .path = "textures/graffitibox.qoi", + .flags = VG_TEXTURE_NEAREST }; + static void ray_world_get_tri( ray_hit *hit, v3f tri[3] ) { for( int i=0; i<3; i++ ) @@ -107,9 +116,22 @@ static int ray_world( v3f pos, v3f dir, ray_hit *hit ) 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) @@ -122,11 +144,14 @@ static void world_register(void) shader_alphatest_register(); world_routes_register(); + world_sfd_register(); } static void world_free(void) { /* TODO.. */ + + world_sfd_free(); } static void render_world_depth( m4x4f projection, m4x3f camera ); @@ -194,8 +219,8 @@ static void world_apply_procedural_foliage(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; @@ -343,7 +368,10 @@ static void world_load(void) u32 mat_surf = 0, mat_surf_oob = 0, mat_vertex_blend = 0, - mat_alphatest = 0; + mat_alphatest = 0, + mat_graffiti = 0, + mat_subworld = 0, + mat_terrain = 0; for( int i=1; imaterial_count; i++ ) { @@ -358,11 +386,19 @@ static void world_load(void) mat_vertex_blend = i; else if( !strcmp( "alphatest", mat_name )) mat_alphatest = i; + else if( !strcmp( "graffitibox", mat_name )) + mat_graffiti = 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 @@ -392,6 +428,9 @@ static void world_load(void) add_all_if_material( midentity, &world.foliage, mworld, mat_alphatest ); scene_copy_slice( &world.foliage, &world.sm_foliage_alphatest ); + add_all_if_material( midentity, &world.foliage, mworld, mat_graffiti ); + scene_copy_slice( &world.foliage, &world.sm_graffiti ); + scene_upload( &world.foliage ); world_routes_loadfrom( mworld ); @@ -479,7 +518,8 @@ static void world_init(void) { vg_tex2d_init( (vg_tex2d *[]){ &tex_terrain_colours, &tex_terrain_noise, - &tex_alphatest }, 3 ); + &tex_alphatest, + &tex_graffiti }, 4 ); mdl_header *mcars = mdl_load( "models/rs_cars.mdl" ); mdl_unpack_glmesh( mcars, &world.cars ); @@ -497,11 +537,55 @@ static void world_init(void) world.dome_lower = *mdl_node_submesh( msky, nlower, 0 ); world.dome_upper = *mdl_node_submesh( msky, nupper, 0 ); free(msky); + + + /* 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; itrack_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 rb_solver_reset(); @@ -581,6 +665,10 @@ static void render_world_alphatest( m4x4f projection, v3f camera ) glDisable(GL_CULL_FACE); scene_bind( &world.foliage ); mdl_draw_submesh( &world.sm_foliage_alphatest ); + + vg_tex2d_bind( &tex_graffiti, 1 ); + mdl_draw_submesh( &world.sm_graffiti ); + glEnable(GL_CULL_FACE); } @@ -600,8 +688,10 @@ static void render_terrain( m4x4f projection, v3f camera ) 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 ); /* TODO: Dont draw in reflection */ glDisable(GL_CULL_FACE); @@ -665,17 +755,28 @@ static void render_sky(m4x3f camera) glDepthMask( GL_TRUE ); } -static void render_world_gates( m4x4f projection, m4x3f camera ) +static void render_world_gates( m4x4f projection, v3f playerco, m4x3f camera ) { - int count = 0; + float closest = INFINITY; + int id = 0; + for( int i=0; igate, camera ); + float dist = v3_dist2( rg->gate.co[0], camera[3] ); - if( count == 2 ) - return; + if( dist < closest ) + { + closest = dist; + id = i; + } } + + 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 ) @@ -685,6 +786,24 @@ static void render_world( m4x4f projection, m4x3f camera ) render_world_vb( projection, camera[3] ); render_world_alphatest( projection, camera[3] ); render_terrain( projection, camera[3] ); + + int closest = 0; + float min_dist = INFINITY; + + for( int i=0; i