X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=world.h;h=add08b7c30d1180a1125a8a4c9a10dd2c9102c5e;hb=6d66c67945f84476d6ac75a0497007cc30bcf58c;hp=d8b36165c20d2225dcd90621e98d03c5cc7afdd4;hpb=d8b8c566831e15ef061a66409e1219f44a82097a;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/world.h b/world.h index d8b3616..add08b7 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,6 +38,12 @@ 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]; @@ -45,10 +52,13 @@ static struct gworld /* Rendering & geometry */ scene geo, foliage, props; - mdl_submesh sm_surface; + mdl_submesh sm_surface, sm_other; glmesh skybox, skydome; mdl_submesh dome_upper, dome_lower; + + glmesh cars; + mdl_submesh car_holden; } world; @@ -166,6 +176,7 @@ 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 ); @@ -194,6 +205,9 @@ static void world_load(void) if( mat_surf ) add_all_if_material( &world.geo, mworld, mat_surf ); + if( mat_vertex_blend ) + add_all_if_material( &world.geo, mworld, mat_vertex_blend ); + scene_copy_slice( &world.geo, &world.sm_surface ); @@ -222,17 +236,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,7 +294,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 ); + + 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 ); + + 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(); + } static void world_init(void) @@ -356,6 +396,21 @@ 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) +{ + for( int i=0; i