basic replayable replays
[carveJwlIkooP6JGAAIwe30JlM.git] / player_walk.c
index bacb48c42bb12203fdab132af5beb6eca3495bed..21390c2610ee462aaafa770886a261b98fb1ce9c 100644 (file)
@@ -88,7 +88,7 @@ VG_STATIC void player_walk_drop_in_to_skate( player_instance *player )
    v3_muladds( player->rb.co, player->rb.to_world[1], 1.0f, s->state.cog );
    v3_copy( init_velocity, s->state.cog_v );
    v3_copy( init_velocity, player->rb.v );
-   v3_copy( init_velocity, player->cam_velocity_smooth );
+   v3_copy( init_velocity, player->cam_control.cam_velocity_smooth );
    v3_copy( (v3f){1.0f,0.0f,0.0f}, s->state.trick_euler );
 }
 
@@ -147,7 +147,7 @@ VG_STATIC int player_walk_scan_for_drop_in( player_instance *player )
       if( ray_world( world, pos, ray_dir, ray ) )
       {
          vg_line( pos, ray->pos, VG__RED );
-         vg_line_pt3( ray->pos, 0.025f, VG__BLACK );
+         vg_line_point( ray->pos, 0.025f, VG__BLACK );
          
          sample_count ++;
       }
@@ -225,7 +225,7 @@ VG_STATIC int player_walk_scan_for_drop_in( player_instance *player )
          if( ray_world( world, va, v0, &ray ) )
          {
             vg_line( va, vb, VG__RED );
-            vg_line_pt3( ray.pos, 0.1f, VG__RED );
+            vg_line_point( ray.pos, 0.1f, VG__RED );
             vg_error( "invalidated\n" );
             return 0;
          }
@@ -234,7 +234,7 @@ VG_STATIC int player_walk_scan_for_drop_in( player_instance *player )
          if( ray_world( world, vb, v0, &ray ) )
          {
             vg_line( va, vb, VG__RED );
-            vg_line_pt3( ray.pos, 0.1f, VG__RED );
+            vg_line_point( ray.pos, 0.1f, VG__RED );
             vg_error( "invalidated\n" );
             return 0;
          }
@@ -284,8 +284,11 @@ VG_STATIC void player__walk_pre_update( player_instance *player )
          player->subsystem = k_player_subsystem_drive;
       }
       else{
-         if( !player_get_player_board(player) )
-            return;
+         struct player_board *board = 
+            addon_cache_item_if_loaded( k_addon_type_board,
+                                        player->board_view_slot );
+
+         if( !board ) return;
 
          if( w->state.activity == k_walk_activity_ground ){
             if( player_walk_scan_for_drop_in( player ) ){
@@ -317,6 +320,10 @@ VG_STATIC void player__walk_pre_update( player_instance *player )
          }
       }
    }
+   else if( button_down( k_srbind_jump ) && !player->immobile ){
+      w->state.jump_queued = 1;
+      w->state.jump_input_time = vg.time;
+   }
 }
 
 VG_STATIC int player_walk_normal_standable( player_instance *player, v3f n )
@@ -361,6 +368,7 @@ VG_STATIC void player__walk_update( player_instance *player )
 {
    struct player_walk *w = &player->_walk;
    v3_copy( player->rb.co, w->state.prev_pos );
+   v3_zero( player->rb.w );
 
    world_instance *world = world_current_instance();
 
@@ -384,7 +392,7 @@ VG_STATIC void player__walk_update( player_instance *player )
    m3x3_copy( player->rb.to_world, mtx );
    v3_add( player->rb.co, player->basis[1], mtx[3] );
 
-   debug_capsule( mtx, w->collider.radius, w->collider.height, VG__WHITE );
+   vg_line_capsule( mtx, w->collider.radius, w->collider.height, VG__WHITE );
 
    rb_ct manifold[64];
    int len;
@@ -449,7 +457,7 @@ VG_STATIC void player__walk_update( player_instance *player )
       v3_normalize( surface_avg );
 
       v3f tx, ty;
-      rb_tangent_basis( surface_avg, tx, ty );
+      v3_tangent_basis( surface_avg, tx, ty );
 
       if( v2_length2(steer) > 0.001f ){
          /* clip movement to the surface */
@@ -461,14 +469,19 @@ VG_STATIC void player__walk_update( player_instance *player )
       nominal_speed = k_walkspeed;
 
       /* jump */
-      if( button_down( k_srbind_jump ) ){
-         float d = v3_dot( player->basis[1], player->rb.v );
-         v3_muladds( player->rb.v, player->basis[1], -d, player->rb.v );
-         v3_muladds( player->rb.v, player->basis[1], 5.0f, player->rb.v );
-         w->state.activity = k_walk_activity_air;
-         prev_state = k_walk_activity_air;
-         accel_speed = k_walk_air_accel;
-         nominal_speed = k_airspeed;
+      if( w->state.jump_queued ){
+         w->state.jump_queued = 0;
+
+         f32 t = vg.time - w->state.jump_input_time;
+         if( t < PLAYER_JUMP_EPSILON ){
+            float d = v3_dot( player->basis[1], player->rb.v );
+            v3_muladds( player->rb.v, player->basis[1], -d, player->rb.v );
+            v3_muladds( player->rb.v, player->basis[1], 5.0f, player->rb.v );
+            w->state.activity = k_walk_activity_air;
+            prev_state = k_walk_activity_air;
+            accel_speed = k_walk_air_accel;
+            nominal_speed = k_airspeed;
+         }
       }
       else{
          player_friction( player->rb.v );
@@ -546,7 +559,7 @@ VG_STATIC void player__walk_update( player_instance *player )
 
    v3_muladds( player->rb.co, player->rb.v, k_rb_delta, player->rb.co );
    v3_add( player->rb.co, player->basis[1], mtx[3] );
-   debug_capsule( mtx, w->collider.radius, w->collider.height, VG__GREEN );
+   vg_line_capsule( mtx, w->collider.radius, w->collider.height, VG__GREEN );
 
    /* 
     * CCD routine 
@@ -575,7 +588,7 @@ VG_STATIC void player__walk_update( player_instance *player )
          rb_update_transform( &player->rb );
 
          v3_add( player->rb.co, player->basis[1], mtx[3] );
-         debug_capsule( mtx, w->collider.radius, w->collider.height, VG__RED );
+         vg_line_capsule( mtx, w->collider.radius, w->collider.height, VG__RED );
       }
    }
 
@@ -613,7 +626,7 @@ VG_STATIC void player__walk_post_update( player_instance *player )
 
    float substep = vg.time_fixed_extrapolate;
    v3_muladds( mtx[3], player->rb.v, k_rb_delta*substep, mtx[3] );
-   debug_capsule( mtx, w->collider.radius, w->collider.height, VG__YELOW );
+   vg_line_capsule( mtx, w->collider.radius, w->collider.height, VG__YELOW );
 
 
    /* Calculate header */
@@ -629,7 +642,7 @@ VG_STATIC void player__walk_post_update( player_instance *player )
       q_normalize( player->rb.q );
    }
 
-   vg_line_pt3( w->state.drop_in_target, 0.1f, VG__GREEN );
+   vg_line_point( w->state.drop_in_target, 0.1f, VG__GREEN );
    v3f p1;
    v3_muladds( w->state.drop_in_target, w->state.drop_in_normal, 0.3f, p1 );
    vg_line( w->state.drop_in_target, p1, VG__GREEN );
@@ -637,7 +650,7 @@ VG_STATIC void player__walk_post_update( player_instance *player )
    vg_line( w->state.drop_in_target, p1, VG__GREEN );
 
    vg_line( w->state.drop_in_target, w->state.drop_in_foot_anchor, VG__WHITE );
-   vg_line_pt3( w->state.drop_in_foot_anchor, 0.08f, VG__PINK );
+   vg_line_point( w->state.drop_in_foot_anchor, 0.08f, VG__PINK );
 
 
    float a = player_get_heading_yaw( player );