server version check
[carveJwlIkooP6JGAAIwe30JlM.git] / player_walk.c
index 952db860a638b5d0218d2c7da0f6a392a34f9eb4..100e21f60e020b4ceea67f39bdcc2436515faf9d 100644 (file)
@@ -10,7 +10,7 @@ static void player_walk_drop_in_vector( v3f vec ){
    v3_cross( localplayer.basis[1], player_walk.state.drop_in_normal, axis );
    v3_cross( axis, player_walk.state.drop_in_normal, init_dir );
    v3_normalize( init_dir );
-   v3_muls( init_dir, 7.0f, vec );
+   v3_muls( init_dir, 4.25f, vec );
 }
 
 static float player_xyspeed2(void){
@@ -228,6 +228,9 @@ static int player_walk_scan_for_drop_in(void){
 static struct skeleton_anim *player_walk_outro_anim( enum walk_outro type ){
    struct player_walk *w = &player_walk;
 
+   if( type >= k_walk_outro_max )
+      return NULL;
+
    return (struct skeleton_anim *[]){ 
             [k_walk_outro_none]        = NULL,
             [k_walk_outro_jump_to_air] = w->anim_jump_to_air,
@@ -243,6 +246,40 @@ static void player__walk_pre_update(void){
    if( !localplayer.immobile )
       player_look( localplayer.angles, skaterift.time_rate );
 
+   v2f steer;
+   joystick_state( k_srjoystick_steer, steer );
+
+   if( w->state.activity == k_walk_activity_sit ){
+      if( w->state.sit_t < 1.0f )
+         w->state.sit_t = vg_minf( 1.0f, w->state.sit_t + vg.time_delta );
+
+      if( button_down(k_srbind_sit) || (v2_length2(steer)>0.2f) ||
+          button_down(k_srbind_jump) ){
+         w->state.activity = k_walk_activity_sit_up;
+      }
+      return;
+   }
+   else if( w->state.activity == k_walk_activity_sit_up ){
+      if( w->state.sit_t > 0.0f )
+         w->state.sit_t = vg_maxf( 0.0f, w->state.sit_t - vg.time_delta );
+      else 
+         w->state.activity = k_walk_activity_ground;
+
+      if( button_down(k_srbind_sit) )
+         w->state.activity = k_walk_activity_sit;
+
+      return;
+   }
+   else if( w->state.activity == k_walk_activity_ground ){
+      if( button_down(k_srbind_sit) ){
+         v3_zero( localplayer.rb.v );
+         w->state.activity = k_walk_activity_sit;
+         return;
+      }
+   }
+
+   w->state.sit_t = 0.0f;
+
    if( w->state.outro_type ){
       struct skeleton_anim *anim = player_walk_outro_anim(w->state.outro_type);
 
@@ -281,9 +318,10 @@ static void player__walk_pre_update(void){
                w->state.outro_start_time = vg.time;
                localplayer.immobile = 1;
 
-               struct player_avatar *av = localplayer.playeravatar;
-               m4x3_mulv( localplayer.final_mtx[ av->id_ik_foot_r ], 
-                          av->sk.bones[ av->id_ik_foot_r ].co, 
+               u32 foot_id = localplayer.id_ik_foot_r;
+
+               m4x3_mulv( localplayer.final_mtx[ foot_id ], 
+                          localplayer.skeleton.bones[ foot_id ].co, 
                           w->state.drop_in_foot_anchor );
             }
             else{
@@ -388,27 +426,10 @@ static void player__walk_update(void){
    v2f steer;
    joystick_state( k_srjoystick_steer, steer );
 
-   if( w->state.activity == k_walk_activity_sit ){
-      if( w->state.sit_t < 1.0f )
-         w->state.sit_t += vg.time_delta;
-      else {
-         w->state.sit_t = 1.0f;
-
-         if( button_down(k_srbind_sit) || (v2_length2(steer)>0.2f) ||
-             button_down(k_srbind_jump) ){
-            w->state.activity = k_walk_activity_sit_up;
-         }
-      }
+   if( (w->state.activity == k_walk_activity_sit) ||
+       (w->state.activity == k_walk_activity_sit_up) ){
       return;
    }
-   else if( w->state.activity == k_walk_activity_sit_up ){
-      if( w->state.sit_t > 0.0f ){
-         w->state.sit_t -= vg.time_delta;
-         return;
-      }
-   }
-   else
-      w->state.sit_t = 0.0f;
 
    v3_copy( localplayer.rb.co, w->state.prev_pos );
    v3_zero( localplayer.rb.w );
@@ -494,11 +515,6 @@ static void player__walk_update(void){
    if( w->state.activity == k_walk_activity_ground ){
       v3_normalize( surface_avg );
 
-      if( button_down(k_srbind_sit) ){
-         w->state.activity = k_walk_activity_sit;
-         return;
-      }
-
       v3f tx, ty;
       v3_tangent_basis( surface_avg, tx, ty );
 
@@ -776,12 +792,13 @@ static void player__walk_animate(void){
    animator->walk_timer = w->state.walk_timer;
 
 
-   if( !localplayer.immobile )
-      rb_extrapolate( &localplayer.rb, animator->root_co, animator->root_q );
-   else{
+   if( localplayer.immobile || (w->state.outro_type == k_walk_outro_drop_in) ){
       v3_copy( localplayer.rb.co, animator->root_co );
       v4_copy( localplayer.rb.q,  animator->root_q );
    }
+   else{
+      rb_extrapolate( &localplayer.rb, animator->root_co, animator->root_q );
+   }
 
    f32 walk_yaw = player_get_heading_yaw();
 
@@ -803,7 +820,6 @@ static void player__walk_animate(void){
    }
 
    if( w->state.outro_type ){
-      struct player_avatar *av = localplayer.playeravatar;
       struct skeleton_anim *anim = 
          player_walk_outro_anim( w->state.outro_type );
       f32 outro_length = (f32)anim->length / anim->rate,
@@ -826,6 +842,15 @@ static void player__walk_animate(void){
 
          v3_lerp( w->state.drop_in_start, w->state.drop_in_target,
                   step_t, localplayer.rb.co );
+         v3_copy( localplayer.rb.co, animator->root_co );
+
+         /* for the camera purposes only */
+         v3f init_velocity;
+         player_walk_drop_in_vector( init_velocity );
+         v3_muls( init_velocity, dop_t, localplayer.rb.v );
+         v3_copy( localplayer.rb.v, 
+                  localplayer.cam_control.cam_velocity_smooth );
+
          q_axis_angle( animator->root_q, (v3f){0.0f,1.0f,0.0f}, 
                        walk_yaw + VG_PIf );
 
@@ -833,15 +858,22 @@ static void player__walk_animate(void){
 
          /* the drop in bit */
          if( step_t >= 1.0f ){
+            v3f final_co;
             v4f final_q;
-            player_walk_drop_in_overhang_transform( dop_t, localplayer.rb.co, 
-                                                    final_q );
+            player_walk_drop_in_overhang_transform( dop_t, final_co, final_q );
+
             q_mul( final_q, animator->root_q, animator->root_q );
+            v3_copy( final_co, animator->root_co );
+
 
             v4_copy( animator->root_q, localplayer.rb.q );
+            rb_update_transform( &localplayer.rb );
+
             v3_muladds( animator->root_co, localplayer.rb.to_world[1], 
                         -0.1f*dop_t, animator->root_co );
+            v3_copy( animator->root_co, localplayer.rb.co );
          }
+
          return;
       }
       else{
@@ -858,8 +890,7 @@ static void player__walk_animate(void){
 static void player__walk_pose( void *_animator, player_pose *pose ){
    struct player_walk *w = &player_walk;
    struct player_walk_animator *animator = _animator;
-   struct skeleton *sk = &localplayer.playeravatar->sk;
-   struct player_avatar *av = localplayer.playeravatar;
+   struct skeleton *sk = &localplayer.skeleton;
 
    v3_copy( animator->root_co, pose->root_co );
    v4_copy( animator->root_q, pose->root_q );
@@ -894,14 +925,14 @@ static void player__walk_pose( void *_animator, player_pose *pose ){
       skeleton_sample_anim( sk, w->anim_sit, st*sit_norm, bpose );
 
       v4f qy,qp;
-      f32 *qh = bpose[av->id_head-1].q;
+      f32 *qh = bpose[localplayer.id_head-1].q;
       q_axis_angle( qy, (v3f){0.0f,1.0f,0.0f}, animator->yaw*0.5f*st );
       q_axis_angle( qp, (v3f){0.0f,0.0f,1.0f}, animator->pitch*st );
       q_mul( qy, qh, qh );
       q_mul( qh, qp, qh );
       q_normalize( qh );
 
-      qh = bpose[av->id_chest-1].q;
+      qh = bpose[localplayer.id_chest-1].q;
       q_axis_angle( qy, (v3f){0.0f,1.0f,0.0f}, animator->yaw*0.5f*st );
       q_mul( qy, qh, qh );
       q_normalize( qh );
@@ -911,6 +942,11 @@ static void player__walk_pose( void *_animator, player_pose *pose ){
 
    if( animator->outro_type ){
       struct skeleton_anim *anim = player_walk_outro_anim(animator->outro_type);
+
+      if( !anim ){
+         skeleton_copy_pose( sk, apose, pose->keyframes );
+         return;
+      }
       
       f32 outro_length = (f32)anim->length / anim->rate,
           outro_time = animator->outro_t*outro_length;
@@ -928,9 +964,10 @@ static void player__walk_pose( void *_animator, player_pose *pose ){
          v3f anchored_pos;
          m4x3_mulv( inverse, animator->foot_anchor, anchored_pos );
 
-         v3_lerp( pose->keyframes[ av->id_ik_foot_r-1 ].co, anchored_pos, 
+         v3_lerp( pose->keyframes[ localplayer.id_ik_foot_r-1 ].co, 
+                  anchored_pos, 
                   1.0f-animator->commit_t,
-                  pose->keyframes[ av->id_ik_foot_r-1 ].co );
+                  pose->keyframes[ localplayer.id_ik_foot_r-1 ].co );
       }
    }
    else
@@ -942,7 +979,6 @@ static void player__walk_post_animate(void){
     * Camera 
     */
    struct player_walk *w = &player_walk;
-   struct player_avatar *av = localplayer.playeravatar;
 
    if( w->state.outro_type ){
       struct skeleton_anim *anim = player_walk_outro_anim(w->state.outro_type);
@@ -993,8 +1029,7 @@ static void player__walk_im_gui(void){
 
 static void player__walk_bind(void){
    struct player_walk *w = &player_walk;
-   struct player_avatar *av = localplayer.playeravatar;
-   struct skeleton *sk = &av->sk;
+   struct skeleton *sk = &localplayer.skeleton;
 
    w->anim_idle         = skeleton_get_anim( sk, "idle_cycle+y" );
    w->anim_walk         = skeleton_get_anim( sk, "walk+y" );
@@ -1044,9 +1079,6 @@ static void player__walk_animator_exchange( bitpack_ctx *ctx, void *data ){
    bitpack_qf32( ctx, 8, 0.0f, 1.0f, &animator->run );
    bitpack_qf32( ctx, 8, 0.0f, 1.0f, &animator->walk );
    bitpack_qf32( ctx, 16, 0.0f, 120.0f, &animator->walk_timer );
-   bitpack_qf32( ctx, 8, -k_sit_yaw_limit, k_sit_yaw_limit, &animator->yaw );
-   bitpack_qf32( ctx, 8, -k_sit_pitch_limit, k_sit_pitch_limit, 
-                  &animator->pitch );
 
    for( int i=0; i<1; i++ ){ /* without this you get a warning from gcc. lol */
       bitpack_bytes( ctx, 8, &animator->outro_type );
@@ -1057,5 +1089,12 @@ static void player__walk_animator_exchange( bitpack_ctx *ctx, void *data ){
          bitpack_qf32( ctx, 8, 0.0f, 1.0f, &animator->commit_t );
       }
    }
+
+   u32 code = bitpack_qf32( ctx, 8, 0.0f, 1.0f, &animator->sit_t );
+   if( code ){
+      bitpack_qf32( ctx, 8, -k_sit_yaw_limit, k_sit_yaw_limit, &animator->yaw );
+      bitpack_qf32( ctx, 8, -k_sit_pitch_limit, k_sit_pitch_limit, 
+                     &animator->pitch );
+   }
 }
 #endif /* PLAYER_DEVICE_WALK_H */