maths api changes
[carveJwlIkooP6JGAAIwe30JlM.git] / player_walk.c
index 1e92bb1a26015e4118361c957284daabd16f1600..c3b6c2eba2418dc50ec546a1cea3ddbb0c55bbd1 100644 (file)
@@ -2,6 +2,7 @@
 #define PLAYER_WALK_C
 
 #include "player.h"
+#include "input.h"
 
 VG_STATIC void player_walk_drop_in_vector( player_instance *player, v3f vec )
 {
@@ -68,6 +69,7 @@ VG_STATIC void player_walk_generic_to_skate( player_instance *player,
 
 VG_STATIC void player_walk_drop_in_to_skate( player_instance *player )
 {
+   player->immobile = 0;
    player->subsystem = k_player_subsystem_skate;
 
    struct player_walk *w = &player->_walk;
@@ -252,28 +254,23 @@ VG_STATIC void player__walk_pre_update( player_instance *player )
 {
    struct player_walk *w = &player->_walk;
 
-   if( w->state.activity != k_walk_activity_immobile )
+   if( !player->immobile )
       player_look( player, player->angles );
 
-   if( w->state.outro_anim )
-   {
+   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( outro_time >= outro_length )
-      {
+      if( outro_time >= outro_length ){
          w->state.outro_anim = NULL;
-         if( w->state.outro_type == k_walk_outro_drop_in )
-         {
+         if( w->state.outro_type == k_walk_outro_drop_in ){
             player_walk_drop_in_to_skate( player );
          }
-         else if( w->state.outro_type == k_walk_outro_jump_to_air )
-         {
+         else if( w->state.outro_type == k_walk_outro_jump_to_air ){
             player_walk_generic_to_skate( player, k_skate_activity_air, 0.0f );
          }
-         else
-         {
+         else{
             player_walk_generic_to_skate( player, 
                                           k_skate_activity_ground, 1.0f );
          }
@@ -281,40 +278,43 @@ VG_STATIC void player__walk_pre_update( player_instance *player )
          return;
       }
    }
-   else if( vg_input_button_down( player->input_use ) )
-   {
-      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;
-            w->state.activity = k_walk_activity_immobile;
-
-            struct player_avatar *av = player->playeravatar;
-            m4x3_mulv( av->sk.final_mtx[ av->id_ik_foot_r ], 
-                       av->sk.bones[ av->id_ik_foot_r ].co, 
-                       w->state.drop_in_foot_anchor );
+   else if( button_down( k_srbind_use ) && !player->immobile ){
+      if( v3_dist2( player->rb.co, gzoomer.obj.rb.co ) <= 4.0f*4.0f ){
+         player->subsystem = k_player_subsystem_drive;
+      }
+      else{
+         if( !player_get_player_board(player) )
+            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;
+
+               struct player_avatar *av = player->playeravatar;
+               m4x3_mulv( av->sk.final_mtx[ av->id_ik_foot_r ], 
+                          av->sk.bones[ av->id_ik_foot_r ].co, 
+                          w->state.drop_in_foot_anchor );
+            }
+            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;
+
+               if( player_xyspeed2(player) < 0.1f * 0.1f )
+                  q_mulv( player->rb.q, (v3f){0.0f,0.0f,1.6f}, player->rb.v );
+            }
          }
-         else
-         {
-            w->state.outro_type = k_walk_outro_regular;
-            w->state.outro_anim = w->anim_intro;
+         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;
-            w->state.activity = k_walk_activity_lockedmove;
-
-            if( player_xyspeed2(player) < 0.1f * 0.1f )
-               q_mulv( player->rb.q, (v3f){0.0f,0.0f,1.6f}, player->rb.v );
+            return;
          }
       }
-      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;
-      }
    }
 }
 
@@ -363,7 +363,7 @@ VG_STATIC void player__walk_update( player_instance *player )
 
    enum walk_activity prev_state = w->state.activity;
 
-   if( w->state.activity == k_walk_activity_immobile )
+   if( player->immobile )
       return;
 
    w->collider.height = 2.0f;
@@ -380,20 +380,16 @@ VG_STATIC void player__walk_update( player_instance *player )
 
    float yaw = player->angles[0];
 
-   v3f forward_dir = { sinf(yaw),          0.0f, -cosf(yaw) };
-   v3f right_dir   = { -forward_dir[2],    0.0f,  forward_dir[0] };
+   v3f forward_dir = { -sinf(yaw),         0.0f,  cosf(yaw) };
+   v3f right_dir   = {  forward_dir[2],    0.0f, -forward_dir[0] };
 
    m3x3_mulv( player->basis, forward_dir, forward_dir );
    m3x3_mulv( player->basis, right_dir,   right_dir );
 
+   v2f steer;
+   joystick_state( k_srjoystick_steer, steer );
 
-   v2f walk = { player->input_walkh->axis.value,
-                player->input_walkv->axis.value };
-
-   if( v2_length2(walk) > 0.001f )
-      v2_normalize_clamp( walk );
-
-   w->move_speed = v2_length( walk );
+   w->move_speed = v2_length( steer );
    world_instance *world = get_active_world();
 
    /* 
@@ -435,8 +431,9 @@ VG_STATIC void player__walk_update( player_instance *player )
     */
    float accel_speed = 0.0f, nominal_speed = 0.0f;
    v3f movedir;
-   v3_muls( right_dir,  walk[0], movedir );
-   v3_muladds( movedir, forward_dir, walk[1], movedir );
+
+   v3_muls( right_dir, steer[0], movedir );
+   v3_muladds( movedir, forward_dir, steer[1], movedir );
 
    if( w->state.activity == k_walk_activity_ground ){
       v3_normalize( surface_avg );
@@ -444,7 +441,7 @@ VG_STATIC void player__walk_update( player_instance *player )
       v3f tx, ty;
       rb_tangent_basis( surface_avg, tx, ty );
 
-      if( v2_length2(walk) > 0.001f ){
+      if( v2_length2(steer) > 0.001f ){
          /* clip movement to the surface */
          float d = v3_dot(surface_avg,movedir);
          v3_muladds( movedir, surface_avg, -d, movedir );
@@ -454,7 +451,7 @@ VG_STATIC void player__walk_update( player_instance *player )
       nominal_speed = k_walkspeed;
 
       /* jump */
-      if( player->input_jump->button.value ){
+      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 );
@@ -472,7 +469,7 @@ VG_STATIC void player__walk_update( player_instance *player )
       nominal_speed = k_airspeed;
    }
 
-   if( v2_length2(walk) > 0.001f ){
+   if( v2_length2( steer ) > 0.001f ){
       player_accelerate( player->rb.v, movedir, nominal_speed, accel_speed );
       v3_normalize( movedir );
    }
@@ -604,7 +601,7 @@ VG_STATIC void player__walk_post_update( player_instance *player )
    m3x3_copy( player->rb.to_world, mtx );
    v3_add( player->rb.co, player->basis[1], mtx[3] );
 
-   float substep = vg_clampf( vg.accumulator / k_rb_delta, 0.0f, 1.0f );
+   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 );
 
@@ -655,19 +652,19 @@ VG_STATIC void player__walk_post_update( player_instance *player )
       audio_lock();
       if( w->surface == k_surface_prop_concrete ){
          audio_oneshot_3d( 
-               &audio_footsteps[rand()%vg_list_size(audio_footsteps)], 
+               &audio_footsteps[vg_randu32()%vg_list_size(audio_footsteps)], 
                player->rb.co, 40.0f, 1.0f 
          );
       }
       else if( w->surface == k_surface_prop_grass ){
          audio_oneshot_3d( 
-           &audio_footsteps_grass[rand()%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[rand()%vg_list_size(audio_footsteps_wood)],
+           &audio_footsteps_wood[vg_randu32()%vg_list_size(audio_footsteps_wood)],
             player->rb.co, 40.0f, 1.0f 
          );
       }
@@ -693,10 +690,7 @@ VG_STATIC void player__walk_animate( player_instance *player,
          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 *
-                               (1.0f + player->input_walk->button.value*0.5f),
-                               2.0f*vg.time_delta );
+      w->blend_run = vg_lerpf( w->blend_run, w->move_speed, 2.0f*vg.time_delta);
    }
 
    player_pose apose, bpose;
@@ -849,7 +843,6 @@ VG_STATIC void player__walk_im_gui( player_instance *player )
                            (const char *[]){ "k_walk_activity_air",
                                              "k_walk_activity_ground",
                                              "k_walk_activity_sleep",
-                                             "k_walk_activity_immobile",
                                              "k_walk_activity_lockedmove" }
                                              [w->state.activity] );
    player__debugtext( 1, "surface: %s\n",