fix grind not resuming from replay
authorhgn <hgodden00@gmail.com>
Sun, 8 Sep 2024 16:08:59 +0000 (17:08 +0100)
committerhgn <hgodden00@gmail.com>
Sun, 8 Sep 2024 16:08:59 +0000 (17:08 +0100)
src/client.c
src/player_skate.c
src/player_skate.h

index e06c2538d3e50191e527f544c1a4a0ad9773520b..595afcfa667c31ea650578829cae8ef9d4188992 100644 (file)
@@ -79,7 +79,7 @@ void vg_launch_opt(void)
 int main( int argc, char *argv[] )
 {
    network_set_host( "skaterift.com", NULL );
-   vg_mem.use_libc_malloc = 1;
+   vg_mem.use_libc_malloc = 0;
    vg_set_mem_quota( 160*1024*1024 );
    vg_enter( argc, argv, "Voyager Game Engine" ); 
    return 0;
index aea7027140484443df9905496e44159cd0b3d2dc..387f1ec46d05e4d6a1ea428be5b66ea7e56f62db 100644 (file)
@@ -861,9 +861,9 @@ static void skate_apply_steering_model(void){
 
          v4f q;
          q_axis_angle( q, localplayer.rb.to_world[1], a );
-         q_mulv( q, player_skate.grind_vec, player_skate.grind_vec );
+         q_mulv( q, state->grind_vec, state->grind_vec );
 
-         v3_normalize( player_skate.grind_vec );
+         v3_normalize( state->grind_vec );
       }
 
       else if( state->manual_direction ){
@@ -1026,10 +1026,10 @@ static void skate_apply_jump_model(void){
 
          float tilt  = steer[0] * 0.3f;
                tilt *= vg_signf(v3_dot( localplayer.rb.v, 
-                                        player_skate.grind_dir ));
+                                        state->grind_dir ));
 
          v4f qtilt;
-         q_axis_angle( qtilt, player_skate.grind_dir, tilt );
+         q_axis_angle( qtilt, state->grind_dir, tilt );
          q_mulv( qtilt, jumpdir, jumpdir );
       }
       state->surface_cooldown = 10;
@@ -1388,7 +1388,7 @@ void player__skate_comp_audio( void *_animator ){
          else{
 #if 0
             float a = v3_dot( localplayer.rb.to_world[2], 
-                              player_skate.grind_dir );
+                              state->grind_dir );
             if( fabsf(a) > 0.70710678118654752f )
                sample_type = k_skate_sample_concrete_scrape_wood;
             else 
@@ -1610,7 +1610,7 @@ int skate_compute_surface_alignment( v3f ra, u32 colour,
 
 static void skate_weight_distribute(void){
    struct player_skate_state *state = &player_skate.state;
-   v3_zero( player_skate.weight_distribution );
+   v3_zero( state->weight_distribution );
 
    int reverse_dir = v3_dot( localplayer.rb.to_world[2], 
                              localplayer.rb.v ) < 0.0f?1:-1;
@@ -1636,22 +1636,22 @@ static void skate_weight_distribute(void){
 
    if( state->manual_direction ){
       float amt = vg_minf( steer[1] * 8.0f, 1.0f );
-      player_skate.weight_distribution[2] = k_board_length * amt * 
+      state->weight_distribution[2] = k_board_length * amt * 
                                           (float)state->manual_direction;
    }
 
    if( state->manual_direction ){
       v3f plane_z;
 
-      m3x3_mulv( localplayer.rb.to_world, player_skate.weight_distribution, 
+      m3x3_mulv( localplayer.rb.to_world, state->weight_distribution, 
                  plane_z );
       v3_negate( plane_z, plane_z );
 
-      v3_muladds( plane_z, player_skate.surface_picture,
-                  -v3_dot( plane_z, player_skate.surface_picture ), plane_z );
+      v3_muladds( plane_z, state->surface_picture,
+                  -v3_dot( plane_z, state->surface_picture ), plane_z );
       v3_normalize( plane_z );
 
-      v3_muladds( plane_z, player_skate.surface_picture, 0.3f, plane_z );
+      v3_muladds( plane_z, state->surface_picture, 0.3f, plane_z );
       v3_normalize( plane_z );
 
       v3f p1;
@@ -1673,9 +1673,9 @@ static void skate_adjust_up_direction(void){
 
    if( state->activity == k_skate_activity_ground ){
       v3f target;
-      v3_copy( player_skate.surface_picture, target );
+      v3_copy( state->surface_picture, target );
 
-      target[1] += 2.0f * player_skate.surface_picture[1];
+      target[1] += 2.0f * state->surface_picture[1];
       v3_normalize( target );
 
       v3_lerp( state->up_dir, target,
@@ -1752,7 +1752,7 @@ static void skate_grind_truck_apply( float sign, struct grind_info *inf,
    m3x3_mulv( localplayer.rb.to_world, ra, raw );
    v3_add( localplayer.rb.co, raw, wsp );
 
-   v3_copy( ra, player_skate.weight_distribution );
+   v3_copy( ra, state->weight_distribution );
 
    v3f delta;
    v3_sub( inf->co, wsp, delta );
@@ -1774,7 +1774,7 @@ static void skate_grind_truck_apply( float sign, struct grind_info *inf,
    m3x3f mtx;
    skate_grind_orient( inf, mtx );
    v3f target_fwd, fwd, up, target_up;
-   m3x3_mulv( mtx, player_skate.grind_vec, target_fwd );
+   m3x3_mulv( mtx, state->grind_vec, target_fwd );
    v3_copy( raw_nplane, fwd );
    v3_copy( localplayer.rb.to_world[1], up );
    v3_copy( inf->n, target_up );
@@ -1809,16 +1809,14 @@ static void skate_grind_truck_apply( float sign, struct grind_info *inf,
    vg_line_arrow( localplayer.rb.co, fwd, 0.8f, VG__RED );
    vg_line_arrow( localplayer.rb.co, target_fwd, 1.0f, VG__YELOW );
 
-   player_skate.grind_strength = strength;
-
    /* Fake contact */
    struct grind_limit *limit = 
-      &player_skate.limits[ player_skate.limit_count ++ ];
+      &state->limits[ state->limit_count ++ ];
    m4x3_mulv( localplayer.rb.to_local, wsp, limit->ra );
    m3x3_mulv( localplayer.rb.to_local, inf->n, limit->n );
    limit->p = 0.0f;
 
-   v3_copy( inf->dir, player_skate.grind_dir );
+   v3_copy( inf->dir, state->grind_dir );
 }
 
 static void skate_5050_apply( struct grind_info *inf_front,
@@ -1855,8 +1853,8 @@ static void skate_5050_apply( struct grind_info *inf_front,
    q_axis_angle( q, localplayer.rb.to_world[0], VG_PIf*0.25f * -way );
    q_mulv( q, target_up,  target_up );
 
-   v3_zero( player_skate.weight_distribution );
-   player_skate.weight_distribution[2] = k_board_length * -way;
+   v3_zero( state->weight_distribution );
+   state->weight_distribution[2] = k_board_length * -way;
 
    rb_effect_spring_target_vector( &localplayer.rb, up, target_up,
                                     k_grind_spring, 
@@ -1899,12 +1897,12 @@ static void skate_5050_apply( struct grind_info *inf_front,
 
    /* Fake contact */
    struct grind_limit *limit = 
-      &player_skate.limits[ player_skate.limit_count ++ ];
+      &state->limits[ state->limit_count ++ ];
    v3_zero( limit->ra );
    m3x3_mulv( localplayer.rb.to_local, inf_avg.n, limit->n );
    limit->p = 0.0f;
 
-   v3_copy( inf_avg.dir, player_skate.grind_dir );
+   v3_copy( inf_avg.dir, state->grind_dir );
 }
 
 static int skate_grind_truck_renew( f32 sign, struct grind_info *inf ){
@@ -1931,10 +1929,10 @@ static int skate_grind_truck_renew( f32 sign, struct grind_info *inf ){
    if( dv < minv )
       return 0;
 
-   if( fabsf(v3_dot( inf->dir, player_skate.grind_dir )) < k_grind_max_edge_angle )
+   if( fabsf(v3_dot( inf->dir, state->grind_dir )) < k_grind_max_edge_angle )
       return 0;
 
-   v3_copy( inf->dir, player_skate.grind_dir );
+   v3_copy( inf->dir, state->grind_dir );
    return 1;
 }
 
@@ -2002,7 +2000,7 @@ static void skate_boardslide_apply( struct grind_info *inf ){
    v3f intersection;
    v3_muladds( local_co, local_dir, local_co[0]/-local_dir[0], 
                intersection );
-   v3_copy( intersection, player_skate.weight_distribution );
+   v3_copy( intersection, state->weight_distribution );
 
    skate_grind_decay( inf, 0.0125f );
    skate_grind_friction( inf, 0.25f );
@@ -2033,7 +2031,7 @@ static void skate_boardslide_apply( struct grind_info *inf ){
    vg_line_arrow( localplayer.rb.co, dir, 0.5f, VG__GREEN );
    vg_line_arrow( localplayer.rb.co, perp, 0.5f, VG__BLUE );
 
-   v3_copy( inf->dir, player_skate.grind_dir );
+   v3_copy( inf->dir, state->grind_dir );
 }
 
 static int skate_boardslide_entry( struct grind_info *inf ){
@@ -2082,7 +2080,7 @@ static int skate_boardslide_renew( struct grind_info *inf ){
    if( dv < minv )
       return 0;
 
-   if( fabsf(v3_dot( inf->dir, player_skate.grind_dir )) < k_grind_max_edge_angle )
+   if( fabsf(v3_dot( inf->dir, state->grind_dir )) < k_grind_max_edge_angle )
       return 0;
 
    return 1;
@@ -2098,9 +2096,9 @@ static void skate_store_grind_vec( struct grind_info *inf ){
    v3f raw;
    v3_sub( inf->co, localplayer.rb.co, raw );
 
-   m3x3_mulv( mtx, raw, player_skate.grind_vec );
-   v3_normalize( player_skate.grind_vec );
-   v3_copy( inf->dir, player_skate.grind_dir );
+   m3x3_mulv( mtx, raw, state->grind_vec );
+   v3_normalize( state->grind_vec );
+   v3_copy( inf->dir, state->grind_dir );
 }
 
 static enum skate_activity skate_availible_grind(void){
@@ -2296,11 +2294,11 @@ void player__skate_update(void){
 
    player_skate.substep = vg.time_fixed_delta;
    player_skate.substep_delta = player_skate.substep;
-   player_skate.limit_count = 0;
+   state->limit_count = 0;
 
    int substep_count = 0;
 
-   v3_zero( player_skate.surface_picture );
+   v3_zero( state->surface_picture );
 
    int prev_contacts[2];
 
@@ -2330,8 +2328,8 @@ void player__skate_update(void){
                                           k_surface_spring, k_surface_dampener,
                                           player_skate.substep_delta );
 
-         v3_add( normal, player_skate.surface_picture, 
-                 player_skate.surface_picture );
+         v3_add( normal, state->surface_picture, 
+                 state->surface_picture );
          contact_count ++;
          player_skate.wheel_contacts[i] = 1;
       }
@@ -2362,7 +2360,7 @@ void player__skate_update(void){
    if( contact_count ){
       state->activity = k_skate_activity_ground;
       state->gravity_bias = k_gravity;
-      v3_normalize( player_skate.surface_picture );
+      v3_normalize( state->surface_picture );
 
       skate_apply_friction_model();
       skate_weight_distribute();
@@ -2371,7 +2369,7 @@ void player__skate_update(void){
       if( state->activity > k_skate_activity_air_to_grind )
          state->activity = k_skate_activity_air;
 
-      v3_zero( player_skate.weight_distribution );
+      v3_zero( state->weight_distribution );
       skate_apply_air_model();
    }
 
@@ -2433,8 +2431,8 @@ begin_collision:;
       v4_copy( localplayer.rb.q, future_q );
 
    v3f future_cg, current_cg, cg_offset;
-   q_mulv( localplayer.rb.q, player_skate.weight_distribution, current_cg );
-   q_mulv( future_q, player_skate.weight_distribution, future_cg );
+   q_mulv( localplayer.rb.q, state->weight_distribution, current_cg );
+   q_mulv( future_q, state->weight_distribution, future_cg );
    v3_sub( future_cg, current_cg, cg_offset );
 
    /* calculate the minimum time we can move */
@@ -2484,7 +2482,7 @@ begin_collision:;
       q_mul( rotation, localplayer.rb.q, localplayer.rb.q );
       q_normalize( localplayer.rb.q );
 
-      q_mulv( localplayer.rb.q, player_skate.weight_distribution, future_cg );
+      q_mulv( localplayer.rb.q, state->weight_distribution, future_cg );
       v3_sub( current_cg, future_cg, cg_offset );
       v3_add( localplayer.rb.co, cg_offset, localplayer.rb.co );
    }
@@ -2564,8 +2562,8 @@ begin_collision:;
 
    /* add limits */
    if( state->activity >= k_skate_activity_grind_any ){
-      for( int i=0; i<player_skate.limit_count; i++ ){
-         struct grind_limit *limit = &player_skate.limits[i];
+      for( int i=0; i<state->limit_count; i++ ){
+         struct grind_limit *limit = &state->limits[i];
          rb_ct *ct = &manifold[ manifold_len ++ ];
          m4x3_mulv( localplayer.rb.to_world, limit->ra, ct->co );
          m3x3_mulv( localplayer.rb.to_world, limit->n, ct->n );
@@ -2582,7 +2580,7 @@ begin_collision:;
 
    v3f world_cog;
    m4x3_mulv( localplayer.rb.to_world, 
-              player_skate.weight_distribution, world_cog );
+              state->weight_distribution, world_cog );
    vg_line_point( world_cog, 0.02f, VG__BLACK );
 
    for( int i=0; i<manifold_len; i ++ ){
@@ -2915,7 +2913,7 @@ void player__skate_animate(void){
 
    float dirz = state->reverse > 0.0f? 0.0f: 1.0f,
          fly  = iair?                  1.0f: 0.0f,
-         wdist= player_skate.weight_distribution[2] / k_board_length;
+         wdist= state->weight_distribution[2] / k_board_length;
 
    if( state->activity >= k_skate_activity_grind_any )
       wdist = 0.0f;
@@ -3572,9 +3570,9 @@ void player__skate_clear_mechanics(void)
    state->surface_cooldown = 0;
    v3_muladds( localplayer.rb.co, localplayer.rb.to_world[1], 1.0f, state->cog );
    v3_copy( localplayer.rb.to_world[1], state->up_dir );
-   v3_copy( localplayer.rb.to_world[1], player_skate.surface_picture );
+   v3_copy( localplayer.rb.to_world[1], state->surface_picture );
    v3_copy( localplayer.rb.co, state->prev_pos );
-   v3_zero( player_skate.weight_distribution );
+   v3_zero( state->weight_distribution );
 
    v3f head = { 0.0f, 1.8f, 0.0f };
    m4x3_mulv( localplayer.rb.to_world, head, state->head_position );
index 8adb024758084645b2f516c1d0b5a8bede87d1eb..3795c6e6112b095a878000587c44f918d3a021e3 100644 (file)
@@ -84,6 +84,18 @@ struct player_skate{
 
       v3f store_cog_v, store_cog, store_co;
       v4f store_smoothed, store_q;
+
+      v3f surface_picture,
+          weight_distribution,
+          grind_vec,
+          grind_dir;
+
+      struct grind_limit{
+         v3f ra, n;
+         float p;
+      }
+      limits[3];
+      u32 limit_count;
    }
    state;
 
@@ -195,19 +207,6 @@ struct player_skate{
    }
    possible_jumps[36];
    u32 possible_jump_count;
-
-   v3f surface_picture,
-       weight_distribution,
-       grind_vec,
-       grind_dir;
-
-   float grind_strength;
-   struct grind_limit{
-      v3f ra, n;
-      float p;
-   }
-   limits[3];
-   u32 limit_count;
 }
 extern player_skate;
 extern struct player_subsystem_interface player_subsystem_skate;