-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;
+ }
+
+ if( index != world_static.active_instance ){
+ world_instance *current =
+ &world_static.instances[ world_static.active_instance ];
+ v3_copy( localplayer.rb.co, current->player_co );
+ v3_copy( localplayer.angles, current->player_angles );
+ current->player_angles[3] = player_get_heading_yaw();
+ }
+
+ v3_copy( new->player_co, localplayer.rb.co );
+ v3_copy( new->player_angles, localplayer.angles );
+ q_axis_angle( localplayer.rb.q, (v3f){0,1,0}, new->player_angles[3] );
+