allow reset on death
[carveJwlIkooP6JGAAIwe30JlM.git] / player.h
index b2a69bd4090ec7a6b157324f49051d2497076366..cb36975a266bec614e2ccd53b99b7f377f3f53cd 100644 (file)
--- a/player.h
+++ b/player.h
@@ -11,6 +11,7 @@
 
 #define PLAYER_REWIND_FRAMES 60*4
 
+#include "conf.h"
 #include "audio.h"
 #include "common.h"
 #include "world.h"
@@ -44,7 +45,6 @@ VG_STATIC float
    k_walk_accel            = 150.0f,
    k_walk_friction         = 8.0f;
 
-VG_STATIC int cl_playermdl_id = 0;
 VG_STATIC int freecam = 0;
 VG_STATIC int walk_grid_iterations = 1;
 VG_STATIC float fc_speed = 10.0f;
@@ -69,7 +69,6 @@ VG_STATIC struct gplayer
 
       /* Utility */
       float vswitch, slip, slip_last, reverse;
-
       float grab, jump, pushing, push_time;
       v2f grab_mouse_delta;
 
@@ -293,20 +292,12 @@ VG_STATIC void player_init(void)                                            /* 1
    };
 
    for( int i=0; i<vg_list_size(default_cfg); i++ )
-      execute_console_input(default_cfg[i]);
+      vg_execute_console_input(default_cfg[i]);
 
    rb_init( &player.phys.rb );
    rb_init( &player.collide_front );
    rb_init( &player.collide_back  );
 
-   vg_convar_push( (struct vg_convar){
-      .name = "cl_playermdl_id",
-      .data = &cl_playermdl_id,
-      .data_type = k_convar_dtype_i32,
-      .opt_i32 = { .min=0, .max=2, .clamp=1 },
-      .persistent = 1
-   });
-
    vg_convar_push( (struct vg_convar){
       .name = "gwalk_speed",
       .data = &k_walkspeed,
@@ -446,63 +437,58 @@ VG_STATIC void player_update_pre(void)
    struct player_phys *phys = &player.phys;
 
    if( player.rewinding )
-   {
       return;
-   }
 
    if( vg_input_button_down( player.input_reset ) && !menu_enabled() )
    {
-      if( player.is_dead )
+      double delta = world.time - world.last_use;
+
+      if( (delta <= RESET_MAX_TIME) && (world.last_use != 0.0) )
       {
-         reset_player( 0, NULL );
+         player.rewinding = 1;
+         player.rewind_sound_wait = 1;
+         player.rewind_time = (float)player.rewind_length - 0.0001f;
+         player_save_rewind_frame();
          audio_lock();
-         audio_play_oneshot( &audio_ui[0], 1.0f );
+         audio_play_oneshot( &audio_rewind[0], 1.0f );
          audio_unlock();
-      }
-      else
-      {
-         double delta = world.time - world.last_use;
-
-         if( (delta <= RESET_MAX_TIME) && (world.last_use != 0.0) )
-         {
-            player.rewinding = 1;
-            player.rewind_sound_wait = 1;
-            player.rewind_time = (float)player.rewind_length - 0.0001f;
-            player_save_rewind_frame();
-            audio_lock();
-            audio_play_oneshot( &audio_rewind[0], 1.0f );
-            audio_unlock();
 
-            /* based on analytical testing. DONT CHANGE!
-             
-             *    time taken: y = (x^(4/5)) * 74.5
-             *    inverse   : x = (2/149)^(4/5) * y^(4/5)
-             */
+         /* based on analytical testing. DONT CHANGE!
+          * 
+          *    time taken: y = (x^(4/5)) * 74.5
+          *    inverse   : x = (2/149)^(4/5) * y^(4/5)
+          */
 
-            float constant = powf( 2.0f/149.0f, 4.0f/5.0f ),
-                  curve    = powf( player.rewind_total_length, 4.0f/5.0f );
-            
-            player.rewind_predicted_time = constant * curve;
-            player.diag_rewind_start = vg.time;
-            player.diag_rewind_time  = player.rewind_time;
+         float constant = powf( 2.0f/149.0f, 4.0f/5.0f ),
+               curve    = powf( player.rewind_total_length, 4.0f/5.0f );
+         
+         player.rewind_predicted_time = constant * curve;
+         player.diag_rewind_start = vg.time;
+         player.diag_rewind_time  = player.rewind_time;
 
-            player.is_dead = 0;
-            player.death_tick_allowance = 30;
-            player_restore_frame();
+         player.is_dead = 0;
+         player.death_tick_allowance = 30;
+         player_restore_frame();
 
-            if( !phys->on_board )
-            {
-               player.angles[0] = atan2f( -phys->rb.forward[2], 
-                                          -phys->rb.forward[0] );
-            }
+         if( !phys->on_board )
+         {
+            player.angles[0] = atan2f( -phys->rb.forward[2], 
+                                       -phys->rb.forward[0] );
+         }
 
-            player.mdl.shoes[0] = 1;
-            player.mdl.shoes[1] = 1;
+         player.mdl.shoes[0] = 1;
+         player.mdl.shoes[1] = 1;
 
-            world_routes_notify_reset();
+         world_routes_notify_reset();
 
-            /* apply 1 frame of movement */
-            player_do_motion();
+         /* apply 1 frame of movement */
+         player_do_motion();
+      }
+      else
+      {
+         if( player.is_dead )
+         {
+            reset_player( 0, NULL );
          }
          else
          {
@@ -593,10 +579,9 @@ VG_STATIC void player_update_post(void)
    if( freecam )
       player_freecam();
 
-
    /* CAMERA POSITIONING: LAYER 0 */
-   v2_copy( player.angles, camera_angles );
-   v3_copy( player.camera_pos, camera_pos );
+   v2_copy( player.angles, main_camera.angles );
+   v3_copy( player.camera_pos, main_camera.pos );
 
    if( player.rewinding )
    {
@@ -687,8 +672,6 @@ VG_STATIC void player_update_post(void)
                   player.rewind_sound_wait = 0;
                }
             }
-
-
          }
          
          int i0 = floorf( player.rewind_time ),
@@ -707,17 +690,19 @@ VG_STATIC void player_update_post(void)
          float blend = (4.0f-player.rewind_time) * 0.25f,
                c     = vg_clampf( blend, 0.0f, 1.0f );
 
-         camera_angles[0] = vg_alerpf(override_angles[0], player.angles[0], c);
-         camera_angles[1] = vg_lerpf (override_angles[1], player.angles[1], c);
-         v3_lerp( override_pos, player.camera_pos, c, camera_pos );
+         main_camera.angles[0] = 
+            vg_alerpf(override_angles[0], player.angles[0], c);
+         main_camera.angles[1] = 
+            vg_lerpf (override_angles[1], player.angles[1], c);
+         v3_lerp( override_pos, player.camera_pos, c, main_camera.pos );
       }
    }
 
-   camera_update();
+   camera_update_transform( &main_camera );
    player_audio();
 }
 
-VG_STATIC void draw_player( m4x3f cam )
+VG_STATIC void draw_player( camera *cam )
 {
    if( player.is_dead )
       player_model_copy_ragdoll();
@@ -725,8 +710,8 @@ VG_STATIC void draw_player( m4x3f cam )
    shader_viewchar_use();
    vg_tex2d_bind( &tex_characters, 0 );
    shader_viewchar_uTexMain( 0 );
-   shader_viewchar_uCamera( cam[3] );
-   shader_viewchar_uPv( vg.pv );
+   shader_viewchar_uCamera( cam->transform[3] );
+   shader_viewchar_uPv( cam->mtx.pv );
    shader_link_standard_ub( _shader_viewchar.id, 2 );
    glUniformMatrix4x3fv( _uniform_viewchar_uTransforms, 
                          player.mdl.sk.bone_count,
@@ -754,7 +739,6 @@ VG_STATIC void player_kill(void)
    {
       player.is_dead = 1;
       player_ragdoll_copy_model( player.phys.rb.v );
-      world_routes_clear();
    }
 }