X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=world.h;h=9d35d304be7e8c6682f73e5cdae665857cd43749;hb=ba5f879f85b9cab1e2b37241399d79709fe4f584;hp=e8c47d22085b8edad828aeccdaac3082739d97a0;hpb=1c97cb161f885ad24d3356d92c8f4fd0e252bc61;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/world.h b/world.h index e8c47d2..9d35d30 100644 --- a/world.h +++ b/world.h @@ -14,7 +14,11 @@ static int ray_world( v3f pos, v3f dir, ray_hit *hit ); #include "bvh.h" #include "lighting.h" #include "model.h" -#include "traffic.h" + +#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" @@ -23,6 +27,7 @@ static int ray_world( v3f pos, v3f dir, ray_hit *hit ); #include "shaders/vblend.h" #include "shaders/gpos.h" #include "shaders/fscolour.h" +#include "shaders/alphatest.h" static struct gworld { @@ -36,24 +41,32 @@ static struct gworld spawns[32]; u32 spawn_count; - teleport_gate gates[64]; - u32 gate_count; + 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; +#if 0 traffic_driver van_man[6]; +#endif /* Physics */ - rigidbody temp_rbs[128]; - u32 rb_count; /* Rendering & geometry */ scene geo, foliage; rigidbody rb_geo; - mdl_submesh sm_geo_std_oob, sm_geo_std, sm_geo_vb; + /* 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_terrain; glmesh skybox, skydome; mdl_submesh dome_upper, dome_lower; @@ -73,15 +86,28 @@ 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", .flags = VG_TEXTURE_CLAMP|VG_TEXTURE_NEAREST }; vg_tex2d tex_terrain_noise = { .path = "textures/garbage.qoi", .flags = VG_TEXTURE_NEAREST }; +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++ ) @@ -93,9 +119,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) @@ -105,11 +144,17 @@ static void world_register(void) shader_planeinf_register(); shader_gpos_register(); shader_fscolour_register(); + 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 ); @@ -153,9 +198,8 @@ static void add_all_if_material( m4x3f transform, scene *pscene, } } -static void world_apply_foliage(void) +static void world_apply_procedural_foliage(void) { - scene_init( &world.foliage ); mdl_header *mfoliage = mdl_load("models/rs_foliage.mdl"); v3f volume; @@ -178,8 +222,8 @@ static void world_apply_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; @@ -197,8 +241,6 @@ static void world_apply_foliage(void) } } } - - scene_upload( &world.foliage ); free( mfoliage ); } @@ -207,8 +249,6 @@ static void world_load(void) mdl_header *mworld = mdl_load( "models/mp_dev.mdl" ); world.spawn_count = 0; - world.gate_count = 0; - world.rb_count = 0; world.traffic_count = 0; world.instance_cache = NULL; @@ -221,40 +261,6 @@ static void world_load(void) if( pnode->classtype == k_classtype_none ) {} - else if( pnode->classtype == k_classtype_gate ) - { - struct classtype_gate *entgate = mdl_get_entdata( mworld, pnode ); - - if( entgate->target ) - { - mdl_node *pother = mdl_node_from_id( mworld, entgate->target ); - - teleport_gate *gate = &world.gates[ world.gate_count ++ ]; - - v3_copy( pnode->co, gate->co[0] ); - v3_copy( pother->co, gate->co[1] ); - v4_copy( pnode->q, gate->q[0] ); - v4_copy( pother->q, gate->q[1] ); - v2_copy( pnode->s, gate->dims ); - - gate_transform_update( gate ); - } - } - else if( pnode->classtype == k_classtype_block ) - { - struct classtype_block *block = mdl_get_entdata( mworld, pnode ); - - m4x3f transform; - mdl_node_transform( pnode, transform ); - - rigidbody *rb = &world.temp_rbs[ world.rb_count ++ ]; - - box_copy( block->bbx, rb->bbx ); /* TODO: apply scale */ - v3_copy( pnode->co, rb->co ); - rb_init( rb ); - v4_copy( pnode->q, rb->q ); - rb_update_transform( rb ); - } else if( pnode->classtype == k_classtype_spawn ) { struct respawn_point *rp = &world.spawns[ world.spawn_count ++ ]; @@ -345,15 +351,17 @@ static void world_load(void) } } } - + world.instance_cache = buffer_fix( world.instance_cache, world.instance_cache_count, &world.instance_cache_cap, sizeof( struct instance_cache ) ); +#if 0 traffic_finalize( world.traffic, world.traffic_count ); for( int i=0; imaterial_count; i++ ) { @@ -375,14 +387,21 @@ static void world_load(void) mat_surf_oob = i; else if( !strcmp( "vertex_blend", mat_name )) 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; } - vg_info( "surf %d\noob %d\nvert_blend %d\n", mat_surf, mat_surf_oob, - mat_vertex_blend ); - 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 @@ -400,7 +419,27 @@ static void world_load(void) scene_upload( &world.geo ); scene_bh_create( &world.geo ); - world_apply_foliage(); + + /* Foliage /nocollide layer. + * TODO: Probably should have material traits for this + */ + scene_init( &world.foliage ); + + world_apply_procedural_foliage(); + scene_copy_slice( &world.foliage, &world.sm_foliage_main ); + + 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 ); + + for( int i=0; igate.co[0], camera[3] ); + + if( dist < closest ) + { + closest = dist; + id = i; + } + } + + render_gate( &world.routes.gates[id].gate, 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_sky( camera ); + render_world_routes( projection, camera[3] ); 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