X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=world.h;h=b76086f8c152a798bbcd65022028ba43ae918747;hb=5f4eb3866525724188461589485ac1aa50d08870;hp=f970b0a3204f68152656d8fa366db6f9817aad44;hpb=46643f969b12c2144a5f15ac5509610f18b467e4;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/world.h b/world.h index f970b0a..b76086f 100644 --- a/world.h +++ b/world.h @@ -18,6 +18,7 @@ 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 "shaders/terrain.h" #include "shaders/sky.h" @@ -65,7 +66,7 @@ static struct gworld /* 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; @@ -115,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) @@ -205,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; @@ -356,7 +370,8 @@ static void world_load(void) mat_vertex_blend = 0, mat_alphatest = 0, mat_graffiti = 0, - mat_subworld = 0; + mat_subworld = 0, + mat_terrain = 0; for( int i=1; imaterial_count; i++ ) { @@ -373,13 +388,17 @@ static void world_load(void) 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 @@ -390,10 +409,6 @@ static void world_load(void) 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 ); @@ -526,6 +541,7 @@ static void world_init(void) /* Other systems */ world_sfd_init(); + world_audio_init(); } static void world_update(void) @@ -635,6 +651,7 @@ 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 ); @@ -737,7 +754,7 @@ static void render_world( m4x4f projection, m4x3f camera ) q_axis_angle( t, (v3f){0.0f,1.0f,0.0f}, 2.3f ); q_m3x3( t, identity_matrix ); - sfd_render( &world.sfd.tester, projection, camera[3], identity_matrix ); + //sfd_render( &world.sfd.tester, projection, camera[3], identity_matrix ); } static void render_world_depth( m4x4f projection, m4x3f camera )