initial gui for remote players lobby
[carveJwlIkooP6JGAAIwe30JlM.git] / player_walk.c
index 3645e2dbda6ec1e355fd96243dd06818c5e2a496..193e79a2feba0ecf8f6d28b7431c6456d87b473c 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);
 
@@ -388,27 +425,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 +514,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 +791,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();
 
@@ -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{
@@ -911,6 +943,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;
@@ -1044,15 +1081,22 @@ 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 );
 
-   bitpack_bytes( ctx, 8, &animator->outro_type );
-   if( animator->outro_type ){
-      bitpack_bytes(ctx, sizeof(animator->foot_anchor), animator->foot_anchor );
-      bitpack_qf32( ctx, 8, 0.0f, 1.0f, &animator->outro_t );
-      bitpack_qf32( ctx, 8, 0.0f, 1.0f, &animator->commit_t );
+   for( int i=0; i<1; i++ ){ /* without this you get a warning from gcc. lol */
+      bitpack_bytes( ctx, 8, &animator->outro_type );
+      if( animator->outro_type ){
+         bitpack_bytes( ctx, sizeof(animator->foot_anchor), 
+                        animator->foot_anchor );
+         bitpack_qf32( ctx, 8, 0.0f, 1.0f, &animator->outro_t );
+         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 */