X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=world.h;h=9242023a31d7ffade26696bfecb3ee9eec52b876;hb=344f0153cf1907da87dd041db3ec517325b1c429;hp=d8b36165c20d2225dcd90621e98d03c5cc7afdd4;hpb=9c85e110fa8b965195438d96625ff9753af362a6;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/world.h b/world.h index d8b3616..9242023 100644 --- a/world.h +++ b/world.h @@ -14,6 +14,7 @@ static int ray_world( v3f pos, v3f dir, ray_hit *hit ); #include "bvh.h" #include "lighting.h" #include "model.h" +#include "traffic.h" #include "shaders/terrain.h" #include "shaders/sky.h" @@ -37,18 +38,29 @@ static struct gworld teleport_gate gates[64]; u32 gate_count; + + /* Paths */ + traffic_node traffic[128]; + u32 traffic_count; + + traffic_driver van_man[6]; /* Physics */ rigidbody temp_rbs[128]; u32 rb_count; - bh_tree bhcubes; /* Rendering & geometry */ - scene geo, foliage, props; - mdl_submesh sm_surface; + scene geo, foliage; + + mdl_submesh sm_geo_std_oob, sm_geo_std, sm_geo_vb; glmesh skybox, skydome; mdl_submesh dome_upper, dome_lower; + + glmesh cars; + mdl_submesh car_holden; + + rigidbody mr_ball; } world; @@ -71,7 +83,7 @@ static int ray_world( v3f pos, v3f dir, ray_hit *hit ) static int ray_hit_is_ramp( ray_hit *hit ) { - return hit->tri[0] < world.sm_surface.vertex_count; + return hit->tri[0] > world.sm_geo_std_oob.vertex_count; } static void world_register(void) @@ -166,9 +178,9 @@ static void world_load(void) world.spawn_count = 0; world.gate_count = 0; world.rb_count = 0; + world.traffic_count = 0; scene_init( &world.geo ); - scene_init( &world.props ); /* * Compile meshes into the world scenes @@ -192,23 +204,22 @@ static void world_load(void) mat_vertex_blend = i; } - if( mat_surf ) - add_all_if_material( &world.geo, mworld, mat_surf ); - - scene_copy_slice( &world.geo, &world.sm_surface ); - if( mat_surf_oob ) add_all_if_material( &world.geo, mworld, mat_surf_oob ); else vg_warn( "No OOB surface\n" ); + scene_copy_slice( &world.geo, &world.sm_geo_std_oob ); - scene_bh_create( &world.geo ); - scene_upload( &world.geo ); + if( mat_surf ) + add_all_if_material( &world.geo, mworld, mat_surf ); + scene_copy_slice( &world.geo, &world.sm_geo_std ); if( mat_vertex_blend ) - add_all_if_material( &world.props, mworld, mat_vertex_blend ); + add_all_if_material( &world.geo, mworld, mat_vertex_blend ); + scene_copy_slice( &world.geo, &world.sm_geo_vb ); - /* TODO bvh? */ + scene_upload( &world.geo ); + scene_bh_create( &world.geo ); /* * Process entities @@ -222,17 +233,21 @@ static void world_load(void) else if( pnode->classtype == k_classtype_gate ) { struct classtype_gate *entgate = mdl_get_entdata( mworld, pnode ); - 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 ); + 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 ) { @@ -276,12 +291,28 @@ static void world_load(void) water_set_surface( &surf, pnode->co[1] ); } } - } + else if( pnode->classtype == k_classtype_car_path ) + { + struct classtype_car_path *p = mdl_get_entdata( mworld, pnode ); + traffic_node *tn = &world.traffic[ world.traffic_count ]; + tn->mn_next = NULL; + tn->mn_next1 = NULL; + + if( p->target ) tn->mn_next = mdl_node_from_id( mworld, p->target ); + if( p->target1 ) tn->mn_next1 = mdl_node_from_id( mworld, p->target1 ); - scene_upload( &world.props ); + m4x3f transform; + mdl_node_transform( pnode, transform ); + m3x3_mulv( transform, (v3f){1.0f,0.0f,0.0f}, tn->h ); + v3_copy( transform[3], tn->co ); - bh_create( &world.bhcubes, - &bh_system_rigidbodies, world.temp_rbs, world.rb_count ); + pnode->sub_uid = world.traffic_count ++; + } + } + + traffic_finalize( world.traffic, world.traffic_count ); + for( int i=0; ig_water_fog = 0.04f; render_update_lighting_ub(); + + + world.mr_ball.type = k_rb_shape_sphere; + world.mr_ball.inf.sphere.radius = 2.0f; + v3_copy( (v3f){ 0.0f, 110.0f, 0.0f }, world.mr_ball.co ); + + q_identity(world.mr_ball.q); + rb_init( &world.mr_ball ); } static void world_init(void) @@ -356,6 +395,31 @@ 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); + + mdl_header *mcars = mdl_load( "models/rs_cars.mdl" ); + mdl_unpack_glmesh( mcars, &world.cars ); + mdl_node *nholden = mdl_node_from_name( mcars, "holden" ); + world.car_holden = *mdl_node_submesh( mcars, nholden, 0 ); + free(mcars); +} + +static void world_update(void) +{ + rb_solver_reset(); + rb_build_manifold_terrain_sphere( &world.mr_ball ); + + for( int i=0; i<5; i++ ) + rb_solve_contacts( rb_contact_buffer, rb_contact_count ); + + rb_iter( &world.mr_ball ); + rb_update_transform( &world.mr_ball ); + rb_debug( &world.mr_ball, 0 ); + + for( int i=0; i