nonlocal stuff again
[carveJwlIkooP6JGAAIwe30JlM.git] / player_skate.c
index f1670c827e3b77245d7abe521aff152094a976a7..e9a4f09f4b01cbaca4857b4b0e95c897f82218c4 100644 (file)
@@ -347,7 +347,7 @@ VG_STATIC int create_jumps_to_hit_target( player_instance *player,
 VG_STATIC 
 void player__approximate_best_trajectory( player_instance *player )
 {
-   world_instance *world = get_active_world();
+   world_instance *world0 = get_active_world();
 
    struct player_skate *s = &player->_skate;
    float k_trace_delta = k_rb_delta * 10.0f;
@@ -392,6 +392,7 @@ void player__approximate_best_trajectory( player_instance *player )
       v3_copy( player->rb.co, launch_co );
       v3_copy( player->rb.v,  launch_v );
       v3_copy( launch_co, co0 );
+      world_instance *trace_world = world0;
 
       float vt  = (float)m * (1.0f/30.0f),
             ang = vg_lerpf( angle_begin, angle_end, vt ) * 0.15f;
@@ -431,8 +432,7 @@ void player__approximate_best_trajectory( player_instance *player )
 
          v3f closest={0.0f,0.0f,0.0f};
          if( search_for_grind ){
-            if( bh_closest_point( world->geo_bh, co1, closest, 1.0f ) != -1 ){
-
+            if( bh_closest_point(trace_world->geo_bh,co1,closest,1.0f) != -1 ){
                float min_dist = 0.75f;
                      min_dist *= min_dist;
 
@@ -491,14 +491,18 @@ void player__approximate_best_trajectory( player_instance *player )
             }
          }
 
-         if( world->rendering_gate ){
-            ent_gate *gate = world->rendering_gate;
+         if( trace_world->rendering_gate ){
+            ent_gate *gate = trace_world->rendering_gate;
             if( gate_intersect( gate, co1, co0 ) ){
                m4x3_mulv( gate->transport, co0, co0 );
                m4x3_mulv( gate->transport, co1, co1 );
                m3x3_mulv( gate->transport, launch_v, launch_v);
                m4x3_mulv( gate->transport, launch_co, launch_co );
                m3x3_mul( gate->transport, basis, basis );
+
+               if( gate->type == k_gate_type_nonlocel ){
+                  trace_world = &world_global.worlds[ gate->target ];
+               }
             }
          }
 
@@ -508,15 +512,16 @@ void player__approximate_best_trajectory( player_instance *player )
          float scan_radius = k_board_radius;
                scan_radius *= vg_clampf( t, 0.02f, 1.0f );
 
-         int idx = spherecast_world( world, co0, co1, scan_radius, &t1, n );
+         int idx = spherecast_world(trace_world, co0, co1, scan_radius, &t1, n);
          if( idx != -1 ){
             v3f co;
             v3_lerp( co0, co1, t1, co );
             v3_copy( co, inf->log[ inf->log_length ++ ] ); 
 
             v3_copy( n, inf->n );
-            u32 *tri = &world->scene_geo->arrindices[ idx*3 ];
-            struct world_surface *surf = world_tri_index_surface(world, tri[0]);
+            u32 *tri = &trace_world->scene_geo->arrindices[ idx*3 ];
+            struct world_surface *surf = 
+               world_tri_index_surface( trace_world, tri[0] );
 
             inf->type = k_prediction_land;
 
@@ -591,7 +596,7 @@ void player__approximate_best_trajectory( player_instance *player )
             float t1;
             v3f n;
 
-            int idx = spherecast_world( world, co0,co1,
+            int idx = spherecast_world( world0, co0,co1,
                                         k_board_radius*0.1f, &t1, n);
             if( idx != -1 ){
                goto invalidated_grind;