X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=world.c;h=ad0372389a54eaff63cdbdb0011098a1877c2915;hb=7f4c71033c06954f3094c9d51219628438b80ac8;hp=af9466c66dfebe37a6b534c5bc9bbd4424e55352;hpb=7e1fe6c7931ba4492aa10ac5eebc316b74fb5dac;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/world.c b/world.c index af9466c..ad03723 100644 --- a/world.c +++ b/world.c @@ -26,13 +26,59 @@ static void world_init(void) VG_MEMORY_SYSTEM ); } -static void world_set_active_instance( u32 index ){ - world_static.challenge_target = NULL; - world_static.challenge_timer = 0.0f; - world_static.focused_entity = 0; - world_static.focus_strength = 0.0f; - world_static.active_trigger_volume_count = 0; +static void world_switch_instance( u32 index ){ + assert( localplayer.subsystem == k_player_subsystem_walk ); + + if( index >= vg_list_size(world_static.instances) ){ + vg_error( "Instance ID out of range (%u)\n", index ); + return; + } + + world_instance *new = &world_static.instances[ index ]; + + if( new->status != k_world_status_loaded ){ + vg_error( "Instance is not loaded (%u)\n", index ); + return; + } + + world_instance *current = + &world_static.instances[ world_static.active_instance ]; + + if( index != world_static.active_instance ){ + v3_copy( localplayer.rb.co, current->player_co ); + v3_copy( localplayer.angles, current->player_angles ); + v3_copy( localplayer.cam.pos, current->cam_co ); + current->player_angles[3] = player_get_heading_yaw(); + } + + v3_copy( new->player_co, localplayer.rb.co ); + v3_copy( new->player_angles, localplayer.angles ); + v3_copy( new->cam_co, localplayer.cam.pos ); + q_axis_angle( localplayer.rb.q, (v3f){0,1,0}, new->player_angles[3] ); + + /* run exit events on triggers */ + for( u32 i=0; ient_volume, idx ); + + ent_call basecall; + basecall.function = k_ent_function_trigger_leave; + basecall.id = mdl_entity_id( k_ent_volume, idx ); + basecall.data = NULL; + entity_call( current, &basecall ); + } + world_static.active_instance = index; + + player__reset(); +} + +static int skaterift_switch_instance_cmd( int argc, const char *argv[] ){ + if( argc ) + world_switch_instance( atoi(argv[0]) ); + else + vg_info( "switch_active_instance \n" ); + return 0; } static void skaterift_world_get_save_path( enum world_purpose which, @@ -58,8 +104,7 @@ static void skaterift_world_get_save_path( enum world_purpose which, #include "world_routes.c" #include "world_traffic.c" -static void world_update( world_instance *world, v3f pos ) -{ +static void world_update( world_instance *world, v3f pos ){ world_render.sky_time += world_render.sky_rate * vg.time_delta; world_render.sky_rate = vg_lerp( world_render.sky_rate, world_render.sky_target_rate,