review save method
[carveJwlIkooP6JGAAIwe30JlM.git] / player_walk.c
index c3b6c2eba2418dc50ec546a1cea3ddbb0c55bbd1..815e4b4a70f81ade5c718023fa6ec1cd82b719a5 100644 (file)
@@ -3,6 +3,7 @@
 
 #include "player.h"
 #include "input.h"
+#include "audio.h"
 
 VG_STATIC void player_walk_drop_in_vector( player_instance *player, v3f vec )
 {
@@ -58,6 +59,7 @@ VG_STATIC void player_walk_generic_to_skate( player_instance *player,
    v3_copy( v, s->state.cog_v );
    v3_copy( v, player->rb.v );
 
+   player__begin_holdout( player );
    player__skate_reset_animator( player );
    player__skate_clear_mechanics( player );
    rb_update_transform( &player->rb );
@@ -77,6 +79,7 @@ VG_STATIC void player_walk_drop_in_to_skate( player_instance *player )
    s->state.activity_prev = k_skate_activity_ground;
    s->state.activity = k_skate_activity_ground;
 
+   player__begin_holdout( player );
    player__skate_clear_mechanics( player );
    player__skate_reset_animator( player );
 
@@ -87,7 +90,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 );
 }
 
@@ -120,7 +123,7 @@ VG_STATIC void player_walk_drop_in_overhang_transform( player_instance *player,
 VG_STATIC int player_walk_scan_for_drop_in( player_instance *player )
 {
    struct player_walk *w = &player->_walk;
-   world_instance *world = get_active_world();
+   world_instance *world = world_current_instance();
 
    v3f dir, center;
    q_mulv( player->rb.q, (v3f){0.0f,0.0f,1.0f}, dir );
@@ -146,7 +149,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 ++;
       }
@@ -155,25 +158,21 @@ VG_STATIC int player_walk_scan_for_drop_in( player_instance *player )
    float min_a = 0.70710678118654752f;
    ray_hit *candidate = NULL;
 
-   if( sample_count >= 2 )
-   {
-      for( int i=0; i<sample_count-1; i++ )
-      {
+   if( sample_count >= 2 ){
+      for( int i=0; i<sample_count-1; i++ ){
          ray_hit *s0 = &samples[i],
                  *s1 = &samples[i+1];
 
          float a = v3_dot( s0->normal, s1->normal );
 
-         if( (a < min_a) && (a >= -0.1f) && (s0->normal[1]>s1->normal[1]) )
-         {
+         if( (a < min_a) && (a >= -0.1f) && (s0->normal[1]>s1->normal[1]) ){
             min_a = a;
             candidate = s0;
          }
       }
    }
 
-   if( candidate )
-   {
+   if( candidate ){
       v4f pa, pb, pc;
       
       ray_hit *s0 = candidate,
@@ -191,8 +190,7 @@ VG_STATIC int player_walk_scan_for_drop_in( player_instance *player )
       pc[3] = v3_dot( pc, player->rb.co );
 
       v3f edge;
-      if( plane_intersect3( pa, pb, pc, edge ) )
-      {
+      if( plane_intersect3( pa, pb, pc, edge ) ){
          v3_copy( edge, w->state.drop_in_target );
          v3_copy( s1->normal, w->state.drop_in_normal );
          v3_copy( player->rb.co, w->state.drop_in_start );
@@ -224,7 +222,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;
          }
@@ -233,7 +231,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;
          }
@@ -250,20 +248,34 @@ VG_STATIC int player_walk_scan_for_drop_in( player_instance *player )
    return 0;
 }
 
+VG_STATIC struct skeleton_anim *player_walk_outro_anim( player_instance *player,
+                                                        enum walk_outro type ){
+   struct player_walk *w = &player->_walk;
+
+   return (struct skeleton_anim *[]){ 
+            [k_walk_outro_none]        = NULL,
+            [k_walk_outro_jump_to_air] = w->anim_jump_to_air,
+            [k_walk_outro_regular]     = w->anim_intro,
+            [k_walk_outro_drop_in]     = w->anim_drop_in
+          }[ type ];
+}
+
+
 VG_STATIC void player__walk_pre_update( player_instance *player )
 {
    struct player_walk *w = &player->_walk;
 
    if( !player->immobile )
-      player_look( player, player->angles );
+      player_look( player->angles, skaterift.time_rate );
+
+   if( w->state.outro_type ){
+      struct skeleton_anim *anim = 
+         player_walk_outro_anim( player, w->state.outro_type );
 
-   if( w->state.outro_anim ){
-      float outro_length = (float)w->state.outro_anim->length /
-                                  w->state.outro_anim->rate,
-            outro_time   = vg.time - w->state.outro_start_time;
+      f32 outro_length = (f32)anim->length / anim->rate,
+            outro_time = vg.time - w->state.outro_start_time;
 
       if( outro_time >= outro_length ){
-         w->state.outro_anim = NULL;
          if( w->state.outro_type == k_walk_outro_drop_in ){
             player_walk_drop_in_to_skate( player );
          }
@@ -275,6 +287,7 @@ VG_STATIC void player__walk_pre_update( player_instance *player )
                                           k_skate_activity_ground, 1.0f );
          }
 
+         w->state.outro_type = k_walk_outro_none;
          return;
       }
    }
@@ -283,13 +296,15 @@ 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 ) ){
                w->state.outro_type = k_walk_outro_drop_in;
-               w->state.outro_anim = w->anim_drop_in;
                w->state.outro_start_time = vg.time;
                player->immobile = 1;
 
@@ -300,7 +315,6 @@ VG_STATIC void player__walk_pre_update( player_instance *player )
             }
             else{
                w->state.outro_type = k_walk_outro_regular;
-               w->state.outro_anim = w->anim_intro;
                w->state.outro_start_time = vg.time;
                w->state.activity = k_walk_activity_lockedmove;
 
@@ -310,21 +324,22 @@ VG_STATIC void player__walk_pre_update( player_instance *player )
          }
          else{
             w->state.outro_type = k_walk_outro_jump_to_air;
-            w->state.outro_anim = w->anim_jump_to_air;
             w->state.outro_start_time = vg.time;
             return;
          }
       }
    }
+   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 )
-{
+VG_STATIC int player_walk_normal_standable( player_instance *player, v3f n ){
    return v3_dot( n, player->basis[1] ) > 0.70710678118f;
 }
 
-VG_STATIC void player_accelerate( v3f v, v3f movedir, float speed, float accel )
-{
+VG_STATIC void player_accelerate( v3f v, v3f movedir, f32 speed, f32 accel ){
    float currentspeed = v3_dot( v, movedir ),
          addspeed     = speed - currentspeed;
 
@@ -339,8 +354,7 @@ VG_STATIC void player_accelerate( v3f v, v3f movedir, float speed, float accel )
    v3_muladds( v, movedir, accelspeed, v );
 }
 
-VG_STATIC void player_friction( v3f v )
-{
+VG_STATIC void player_friction( v3f v ){
    float speed = v3_length( v ),
          drop  = 0.0f,
          control = vg_maxf( speed, k_stopspeed );
@@ -356,10 +370,20 @@ VG_STATIC void player_friction( v3f v )
    v3_muls( v, newspeed, v );
 }
 
-VG_STATIC void player__walk_update( player_instance *player )
-{
+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();
+
+   if( world->water.enabled ){
+      if( player->rb.co[1]+0.4f < world->water.height ){
+         audio_oneshot_3d( &audio_splash, player->rb.co, 40.0f, 1.0f );
+         player__dead_transition( player );
+         return;
+      }
+   }
 
    enum walk_activity prev_state = w->state.activity;
 
@@ -373,7 +397,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;
@@ -390,7 +414,6 @@ VG_STATIC void player__walk_update( player_instance *player )
    joystick_state( k_srjoystick_steer, steer );
 
    w->move_speed = v2_length( steer );
-   world_instance *world = get_active_world();
 
    /* 
     * Collision detection
@@ -439,7 +462,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 */
@@ -451,14 +474,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 );
@@ -536,7 +564,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 
@@ -565,7 +593,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 );
       }
    }
 
@@ -580,21 +608,12 @@ VG_STATIC void player__walk_update( player_instance *player )
       q_mul( transport_rotation, player->rb.q, player->rb.q );
 
       rb_update_transform( &player->rb );
-
-      w->state_gate_storage = w->state;
       player__pass_gate( player, gate );
    }
    rb_update_transform( &player->rb );
 }
 
-VG_STATIC void player__walk_restore( player_instance *player )
-{
-   struct player_walk *w = &player->_walk;
-   w->state = w->state_gate_storage;
-}
-
-VG_STATIC void player__walk_post_update( player_instance *player )
-{
+VG_STATIC void player__walk_post_update( player_instance *player ){
    struct player_walk *w = &player->_walk;
 
    m4x3f mtx;
@@ -603,7 +622,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 */
@@ -619,7 +638,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 );
@@ -627,7 +646,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 );
@@ -641,12 +660,12 @@ VG_STATIC void player__walk_post_update( player_instance *player )
 
 
    int walk_phase = 0;
-   if( vg_fractf(w->walk_timer) > 0.5f )
+   if( vg_fractf(w->state.walk_timer) > 0.5f )
       walk_phase = 1;
    else
       walk_phase = 0;
 
-   if( (w->step_phase != walk_phase) && 
+   if( (w->state.step_phase != walk_phase) && 
        (w->state.activity == k_walk_activity_ground ) )
    {
       audio_lock();
@@ -658,170 +677,191 @@ VG_STATIC void player__walk_post_update( player_instance *player )
       }
       else if( w->surface == k_surface_prop_grass ){
          audio_oneshot_3d( 
-           &audio_footsteps_grass[vg_randu32()%vg_list_size(audio_footsteps_grass)],
+           &audio_footsteps_grass[ vg_randu32()%
+                                    vg_list_size(audio_footsteps_grass)],
             player->rb.co, 40.0f, 1.0f 
          );
       }
       else if( w->surface == k_surface_prop_wood ){
          audio_oneshot_3d( 
-           &audio_footsteps_wood[vg_randu32()%vg_list_size(audio_footsteps_wood)],
+           &audio_footsteps_wood[ vg_randu32()%
+                                    vg_list_size(audio_footsteps_wood)],
             player->rb.co, 40.0f, 1.0f 
          );
       }
       audio_unlock();
    }
 
-   w->step_phase = walk_phase;
+   w->state.step_phase = walk_phase;
 }
 
-VG_STATIC void player__walk_animate( player_instance *player, 
-                                    player_animation *dest )
-{
+VG_STATIC void player__walk_animate( player_instance *player ){
    struct player_walk *w = &player->_walk;
-   struct skeleton *sk = &player->playeravatar->sk;
+   player_pose *pose = &player->pose;
+   struct player_walk_animator *animator = &w->animator;
+
+   animator->outro_type = w->state.outro_type;
 
    {
-      float fly = (w->state.activity == k_walk_activity_air)? 1.0f: 0.0f,
-            rate;
+      f32 fly = (w->state.activity == k_walk_activity_air)? 1.0f: 0.0f, 
+          rate;
 
-      if( w->state.activity == k_walk_activity_air )
-         rate = 2.4f;
-      else
-         rate = 9.0f;
+      if( w->state.activity == k_walk_activity_air ) rate = 2.4f;
+      else rate = 9.0f;
 
-      w->blend_fly = vg_lerpf( w->blend_fly, fly, rate*vg.time_delta );
-      w->blend_run = vg_lerpf( w->blend_run, w->move_speed, 2.0f*vg.time_delta);
+      animator->fly = vg_lerpf( animator->fly, fly, rate*vg.time_delta );
+      animator->run = vg_lerpf( animator->run, w->move_speed, 
+                                2.0f*vg.time_delta);
    }
 
-   player_pose apose, bpose;
-
    if( w->move_speed > 0.025f ){
       /* TODO move */
       float walk_norm = 30.0f/(float)w->anim_walk->length,
             run_norm  = 30.0f/(float)w->anim_run->length,
             walk_adv  = vg_lerpf( walk_norm, run_norm, w->move_speed );
 
-      w->walk_timer += walk_adv * vg.time_delta;
+      w->state.walk_timer += walk_adv * vg.time_delta;
    }
+   else
+      w->state.walk_timer = 0.0f;
+   animator->walk_timer = w->state.walk_timer;
+
+   if( !player->immobile )
+      rb_extrapolate( &player->rb, animator->root_co, animator->root_q );
    else{
-      w->walk_timer = 0.0f;
+      v3_copy( player->rb.co, animator->root_co );
+      v4_copy( player->rb.q,  animator->root_q );
    }
 
-   float walk_norm = (float)w->anim_walk->length/30.0f,
-         run_norm  = (float)w->anim_run->length/30.0f,
-         t = w->walk_timer,
-         l = vg_clampf( w->blend_run*15.0f, 0.0f, 1.0f ),
-         idle_walk = vg_clampf( (w->blend_run-0.1f)/(1.0f-0.1f), 0.0f, 1.0f );
-
-   /* walk/run */
-   skeleton_sample_anim( sk, w->anim_walk, t*walk_norm, apose );
-   skeleton_sample_anim( sk, w->anim_run,  t*run_norm, bpose );
-
-   skeleton_lerp_pose( sk, apose, bpose, l, apose );
-
-   /* idle */
-   skeleton_sample_anim( sk, w->anim_idle, vg.time*0.1f, bpose );
-   skeleton_lerp_pose( sk, apose, bpose, 1.0f-idle_walk, apose );
-
-   /* air */
-   skeleton_sample_anim( sk, w->anim_jump, vg.time*0.6f, bpose );
-   skeleton_lerp_pose( sk, apose, bpose, w->blend_fly, apose );
-
-   /* Create transform */
-   rb_extrapolate( &player->rb, dest->root_co, dest->root_q );
-
-   float walk_yaw = player_get_heading_yaw( player );
-
-   if( w->state.outro_anim ){
+   f32 walk_yaw = player_get_heading_yaw( player );
+   if( w->state.outro_type ){
       struct player_avatar *av = player->playeravatar;
-      float outro_length = (float)w->state.outro_anim->length /
-                                  w->state.outro_anim->rate,
-            outro_time   = vg.time - w->state.outro_start_time,
-            outro_t      = outro_time / outro_length;
-
-      /* TODO: Compression */
-      skeleton_sample_anim_clamped( sk, w->state.outro_anim, 
-                                    outro_time, bpose );
-      skeleton_lerp_pose( sk, apose, bpose, outro_t * 10.0f, dest->pose );
+      struct skeleton_anim *anim = 
+         player_walk_outro_anim( player, w->state.outro_type );
+      f32 outro_length = (f32)anim->length / anim->rate,
+          outro_time = vg.time - w->state.outro_start_time;
+      animator->outro_t = outro_time / outro_length;
 
       if( w->state.outro_type == k_walk_outro_drop_in ){
-         float inv_rate      = 1.0f / w->state.outro_anim->rate,
-               anim_frames   = w->state.outro_anim->length * inv_rate,
+         float inv_rate      = 1.0f / anim->rate,
+               anim_frames   = anim->length * inv_rate,
                step_frames   = 12.0f * inv_rate,
                commit_frames = 6.0f * inv_rate,
                drop_frames   = anim_frames - step_frames,
                step_t        = vg_minf( 1.0f, outro_time / step_frames ),
                remaind_time  = vg_maxf( 0.0f, outro_time - step_frames ),
-               dop_t         = vg_minf( 1.0f, remaind_time / drop_frames ),
-               commit_t      = vg_minf( 1.0f, remaind_time / commit_frames );
+               dop_t         = vg_minf( 1.0f, remaind_time / drop_frames );
+         animator->commit_t  = vg_minf( 1.0f, remaind_time / commit_frames );
 
          walk_yaw = vg_alerpf( w->state.drop_in_start_angle, 
                                w->state.drop_in_angle, step_t );
 
          v3_lerp( w->state.drop_in_start, w->state.drop_in_target,
                   step_t, player->rb.co );
-         q_axis_angle( dest->root_q, (v3f){0.0f,1.0f,0.0f}, walk_yaw + VG_PIf );
-
-         m4x3f transform, inverse;
-         q_m3x3( dest->root_q, transform );
-         v3_copy( dest->root_co, transform[3] );
-         m4x3_invert_affine( transform, inverse );
-
-         v3f anchored_pos;
-         m4x3_mulv( inverse, w->state.drop_in_foot_anchor, anchored_pos );
+         q_axis_angle( animator->root_q, (v3f){0.0f,1.0f,0.0f}, 
+                       walk_yaw + VG_PIf );
 
-         v3_lerp( dest->pose[ av->id_ik_foot_r-1 ].co, anchored_pos, 
-                  1.0f-commit_t,
-                  dest->pose[ av->id_ik_foot_r-1 ].co );
-         
+         v3_copy( w->state.drop_in_foot_anchor, animator->foot_anchor );
 
          /* the drop in bit */
          if( step_t >= 1.0f ){
             v4f final_q;
             player_walk_drop_in_overhang_transform( player, dop_t, 
                                                     player->rb.co, final_q );
-            q_mul( final_q, dest->root_q, dest->root_q );
-
-            v4_copy( dest->root_q, player->rb.q );
-            v3_muladds( dest->root_co, player->rb.to_world[1], 
-                        -0.1f * dop_t, dest->root_co );
+            q_mul( final_q, animator->root_q, animator->root_q );
 
-            skeleton_copy_pose( sk, dest->pose, player->holdout_pose );
-            player->holdout_time = 1.0f;
+            v4_copy( animator->root_q, player->rb.q );
+            v3_muladds( animator->root_co, player->rb.to_world[1], 
+                        -0.1f*dop_t, animator->root_co );
          }
          return;
       }
       else{
-         v3_muladds( dest->root_co, player->rb.to_world[1], 
-                     -0.1f * outro_t, dest->root_co );
-
-         skeleton_copy_pose( sk, dest->pose, player->holdout_pose );
-         player->holdout_time = 1.0f;
+         v3_muladds( animator->root_co, player->rb.to_world[1], 
+                     -0.1f*animator->outro_t, animator->root_co );
       }
    }
-   else{
-      skeleton_copy_pose( sk, apose, dest->pose );
-   }
 
-   q_axis_angle( dest->root_q, (v3f){0.0f,1.0f,0.0f}, walk_yaw + VG_PIf );
-   q_mul( player->qbasis, dest->root_q, dest->root_q );
-   q_normalize( dest->root_q );
+   q_axis_angle( animator->root_q, (v3f){0.0f,1.0f,0.0f}, walk_yaw + VG_PIf );
+   q_mul( player->qbasis, animator->root_q, animator->root_q );
+   q_normalize( animator->root_q );
 }
 
-VG_STATIC void player__walk_post_animate( player_instance *player )
-{
+VG_STATIC void player__walk_pose( player_instance *player, player_pose *pose ){
+   struct player_walk *w = &player->_walk;
+   struct player_walk_animator *animator = &w->animator;
+   struct skeleton *sk = &player->playeravatar->sk;
+   struct player_avatar *av = player->playeravatar;
+
+   v3_copy( animator->root_co, pose->root_co );
+   v4_copy( animator->root_q, pose->root_q );
+   pose->board.lean = 0.0f;
+   pose->type = k_player_pose_type_ik;
+
+   float walk_norm = (float)w->anim_walk->length/30.0f,
+         run_norm  = (float)w->anim_run->length/30.0f,
+         t = animator->walk_timer,
+         l = vg_clampf( animator->run*15.0f, 0.0f, 1.0f ),
+         idle_walk = vg_clampf( (animator->run-0.1f)/(1.0f-0.1f), 0.0f, 1.0f );
+
+   /* walk/run */
+   mdl_keyframe apose[32], bpose[32];
+   skeleton_sample_anim( sk, w->anim_walk, t*walk_norm, apose );
+   skeleton_sample_anim( sk, w->anim_run,  t*run_norm, bpose );
+
+   skeleton_lerp_pose( sk, apose, bpose, l, apose );
+
+   /* idle */
+   skeleton_sample_anim( sk, w->anim_idle, vg.time*0.1f, bpose );
+   skeleton_lerp_pose( sk, apose, bpose, 1.0f-idle_walk, apose );
+
+   /* air */
+   skeleton_sample_anim( sk, w->anim_jump, vg.time*0.6f, bpose );
+   skeleton_lerp_pose( sk, apose, bpose, animator->fly, apose );
+
+   if( animator->outro_type ){
+      struct skeleton_anim *anim = 
+         player_walk_outro_anim( player, animator->outro_type );
+      
+      f32 outro_length = (f32)anim->length / anim->rate,
+          outro_time = animator->outro_t*outro_length;
+
+      skeleton_sample_anim_clamped( sk, anim, outro_time, bpose );
+      skeleton_lerp_pose( sk, apose, bpose, animator->outro_t*10.0f, 
+                          pose->keyframes );
+
+      if( animator->outro_type == k_walk_outro_drop_in ){
+         m4x3f transform, inverse;
+         q_m3x3( pose->root_q, transform );
+         v3_copy( pose->root_co, transform[3] );
+         m4x3_invert_affine( transform, inverse );
+
+         v3f anchored_pos;
+         m4x3_mulv( inverse, animator->foot_anchor, anchored_pos );
+
+         v3_lerp( pose->keyframes[ av->id_ik_foot_r-1 ].co, anchored_pos, 
+                  1.0f-animator->commit_t,
+                  pose->keyframes[ av->id_ik_foot_r-1 ].co );
+      }
+   }
+   else
+      skeleton_copy_pose( sk, apose, pose->keyframes );
+}
+
+VG_STATIC void player__walk_post_animate( player_instance *player ){
    /* 
     * Camera 
     */
    struct player_walk *w = &player->_walk;
    struct player_avatar *av = player->playeravatar;
 
-   if( w->state.outro_anim )
-   {
-      float outro_length = (float)w->state.outro_anim->length /
-                                  w->state.outro_anim->rate,
-            outro_time   = vg.time - w->state.outro_start_time,
-            outro_t      = outro_time / outro_length;
+   if( w->state.outro_type ){
+      struct skeleton_anim *anim = 
+         player_walk_outro_anim( player, w->state.outro_type );
+
+      f32 outro_length = (f32)anim->length / anim->rate,
+          outro_time   = vg.time - w->state.outro_start_time,
+          outro_t      = outro_time / outro_length;
 
       player->cam_velocity_influence = outro_t;
    }
@@ -829,9 +869,7 @@ VG_STATIC void player__walk_post_animate( player_instance *player )
       player->cam_velocity_influence = 0.0f;
 }
 
-
-VG_STATIC void player__walk_im_gui( player_instance *player )
-{
+VG_STATIC void player__walk_im_gui( player_instance *player ){
    struct player_walk *w = &player->_walk;
    player__debugtext( 1, "V:  %5.2f %5.2f %5.2f",player->rb.v[0],
                                                  player->rb.v[1],
@@ -853,16 +891,17 @@ VG_STATIC void player__walk_im_gui( player_instance *player )
                                              "metal" }
                                              [w->surface] );
 
-   if( w->state.outro_anim ){
-      float outro_length = (float)w->state.outro_anim->length /
-                                  w->state.outro_anim->rate,
-            outro_time   = vg.time - w->state.outro_start_time;
+   if( w->state.outro_type ){
+      struct skeleton_anim *anim = 
+         player_walk_outro_anim( player, w->state.outro_type );
+
+      f32 outro_length = (f32)anim->length / anim->rate,
+          outro_time   = vg.time - w->state.outro_start_time;
       player__debugtext( 1, "outro time: %f / %f", outro_time, outro_length );
    }
 }
 
-VG_STATIC void player__walk_bind( player_instance *player )
-{
+VG_STATIC void player__walk_bind( player_instance *player ){
    struct player_walk *w = &player->_walk;
    struct player_avatar *av = player->playeravatar;
    struct skeleton *sk = &av->sk;
@@ -876,8 +915,7 @@ VG_STATIC void player__walk_bind( player_instance *player )
    w->anim_intro        = skeleton_get_anim( sk, "into_skate" );
 }
 
-VG_STATIC void player__walk_transition( player_instance *player, v3f angles )
-{
+VG_STATIC void player__walk_transition( player_instance *player ){
    struct player_walk *w = &player->_walk;
    w->state.activity = k_walk_activity_air;
 
@@ -892,12 +930,10 @@ VG_STATIC void player__walk_transition( player_instance *player, v3f angles )
    rb_update_transform( &player->rb );
 }
 
-VG_STATIC void player__walk_reset( player_instance *player, ent_spawn *rp )
-{
+VG_STATIC void player__walk_reset( player_instance *player, ent_spawn *rp ){
    struct player_walk *w = &player->_walk;
    w->state.activity = k_walk_activity_air;
    w->state.outro_type = k_walk_outro_none;
-   w->state.outro_anim = NULL;
    w->state.outro_start_time = 0.0;
 }