MENY
[carveJwlIkooP6JGAAIwe30JlM.git] / player.h
index 5dd9401dbfca38fd3b922622aeff98b11de9eb4e..38c3224de7fd1ab06f2b4034c467ca23c6c3ed4d 100644 (file)
--- a/player.h
+++ b/player.h
 #include "bvh.h"
 
 static float 
-   k_walkspeed             = 7.0f,  /* no longer used */
-   k_runspeed              = 14.0f,
+   k_walkspeed             = 20.0f,  /* no longer used */
+   k_runspeed              = 20.0f,
    k_board_radius          = 0.3f,
    k_board_length          = 0.45f,
    k_board_allowance       = 0.04f,
-   k_friction_lat          = 8.8f,
+   //k_friction_lat          = 8.8f,
+   k_friction_lat          = 12.0f,
    k_friction_resistance   = 0.01f,
    k_max_push_speed        = 16.0f,
    k_push_accel            = 10.0f,
@@ -27,11 +28,12 @@ static float
    k_steer_air_lerp        = 0.3f,
    k_pump_force            = 0.0f,
    k_downforce             = 5.0f,
+   k_walk_downforce        = 8.0f,
    k_jump_charge_speed     = (1.0f/1.0f),
    k_jump_force            = 5.0f,
    k_pitch_limit           = 1.5f,
    k_look_speed            = 2.0f,
-   k_walk_accel            = 5.0f,
+   k_walk_accel            = 150.0f,
    k_walk_friction         = 8.0f;
 
 static int freecam = 0;
@@ -60,7 +62,8 @@ static struct gplayer
       float vswitch, slip, slip_last,
             reverse;
 
-      float grab, jump;
+      float grab, jump, pushing, push_time;
+      double start_push;
       int in_air, on_board, jump_charge, jump_dir;
 
       m3x3f vr,vr_pstep;
@@ -68,8 +71,10 @@ static struct gplayer
    phys, 
    phys_gate_frame;
 
-   float pushing, push_time;
-   int is_dead;
+   m4x3f visual_transform,
+         inv_visual_transform;
+
+   int is_dead, death_tick_allowance;
 
    v3f land_target;
    v3f land_target_log[22];
@@ -97,8 +102,10 @@ static struct gplayer
          fsetup,
          walk_timer,
          fjump,
-         fonboard;
+         fonboard,
+         frun;
 
+   float walk;
    int step_phase;
 
    /* player model */
@@ -113,7 +120,8 @@ static struct gplayer
                            *anim_push, *anim_push_reverse,
                            *anim_ollie, *anim_ollie_reverse,
                            *anim_grabs, *anim_stop,
-                           *anim_walk, *anim_run, *anim_idle;
+                           *anim_walk, *anim_run, *anim_idle,
+                           *anim_jump;
 
       u32 id_hip,
           id_ik_hand_l,
@@ -227,17 +235,15 @@ static void player_init(void)                                            /* 1 */
    vg_loader_highwater( player_model_init, player_model_free, NULL );
 }
 
-static void player_update(void)                                          /* 2 */
+/* Deal with input etc */
+static void player_update_pre(void)
 {
    struct player_phys *phys = &player.phys;
 
-   for( int i=0; i<player.land_log_count; i++ )
-      vg_line_cross( player.land_target_log[i], 
-            player.land_target_colours[i], 0.25f);
-
-   if( vg_get_axis("grabl")>0.0f)
+   if( vg_get_button_down( "reset" ) )
    {
       player.is_dead = 0;
+      player.death_tick_allowance = 30;
       player_restore_frame();
 
       if( !phys->on_board )
@@ -255,19 +261,44 @@ static void player_update(void)                                          /* 2 */
    if( vg_get_button_down( "switchmode" ) )
    {
       phys->on_board ^= 0x1;
+
+      if( phys->on_board )
+      {
+         v3_muladds( phys->rb.v, phys->rb.forward, 0.2f, phys->rb.v );
+      }
    }
+}
+
+static void player_update_fixed(void)                                    /* 2 */
+{
+   if( player.death_tick_allowance )
+      player.death_tick_allowance --;
+
+   struct player_phys *phys = &player.phys;
 
-#if 0
-   if( (glfwGetKey( vg_window, GLFW_KEY_O ) ))
+   if( player.is_dead )
    {
-      player_ragdoll_copy_model( phys->rb.v );
-      player.is_dead = 1;
+      player_ragdoll_iter();
    }
-#endif
+   else
+   {
+      player_do_motion();
+   }
+
+   player_audio(); /* FUTURE: can probably move this to post()
+                              BUT, it uses deltas from fixed step physics,
+                              AND this *might* be what we want for realtime
+                              audio, anyway. */
+}
+
+static void player_update_post(void)
+{
+   for( int i=0; i<player.land_log_count; i++ )
+      vg_line_cross( player.land_target_log[i], 
+            player.land_target_colours[i], 0.25f);
 
    if( player.is_dead )
    {
-      player_ragdoll_iter();
       player_debug_ragdoll();
 
       if( !freecam )
@@ -275,7 +306,6 @@ static void player_update(void)                                          /* 2 */
    }
    else
    {
-      player_do_motion();
       player_animate();
 
       if( !freecam )
@@ -286,10 +316,9 @@ static void player_update(void)                                          /* 2 */
       player_freecam();
 
    player_camera_update();
-   player_audio();
 }
 
-static void draw_player(void)                                            /* 3 */
+static void draw_player( m4x3f cam )
 {
    if( player.is_dead )
       player_model_copy_ragdoll();
@@ -297,8 +326,8 @@ static void draw_player(void)                                            /* 3 */
    shader_viewchar_use();
    vg_tex2d_bind( &tex_characters, 0 );
    shader_viewchar_uTexMain( 0 );
-   shader_viewchar_uCamera( player.camera[3] );
-   shader_viewchar_uPv( vg_pv );
+   shader_viewchar_uCamera( cam[3] );
+   shader_viewchar_uPv( vg.pv );
    shader_link_standard_ub( _shader_viewchar.id, 2 );
    glUniformMatrix4x3fv( _uniform_viewchar_uTransforms, 
                          player.mdl.sk.bone_count,
@@ -322,8 +351,11 @@ static float *player_get_pos(void)
 
 static void player_kill(void)
 {
-   player.is_dead = 1;
-   player_ragdoll_copy_model( player.phys.rb.v );
+   if( player.death_tick_allowance == 0 )
+   {
+      player.is_dead = 1;
+      player_ragdoll_copy_model( player.phys.rb.v );
+   }
 }
 
 static float *player_cam_pos(void)