TurboFisto
[carveJwlIkooP6JGAAIwe30JlM.git] / player.h
index e625b0baf735c95de4180c7af173a754afd77599..cd7fd57a5996b28554968ed1c2b626fa043783c1 100644 (file)
--- a/player.h
+++ b/player.h
@@ -1,3 +1,224 @@
+#ifndef PLAYER_H
+#define PLAYER_H
+
+#include "player_api.h"
+
+#include "player_common.h"
+#include "player_walk.h"
+#include "player_skate.h"
+#include "player_dead.h"
+
+#define PLAYER_REWIND_FRAMES 60*4
+
+struct player_instance
+{
+   /* transform definition */
+   rigidbody rb, rb_gate_storage;
+   v3f angles, angles_storage;
+
+   v4f   qbasis;
+   m3x3f basis, invbasis, basis_gate;
+   world_instance *viewable_world;
+
+   /*
+    * Camera management
+    * ---------------------------
+    */
+   camera cam;
+
+   enum camera_mode
+   {
+      k_cam_firstperson = 0,
+      k_cam_thirdperson = 1
+   }
+   camera_mode;
+   float camera_type_blend;
+
+   v3f fpv_offset,         /* expressed relative to rigidbody */
+       tpv_offset,
+       fpv_viewpoint,      /* expressed relative to neck bone inverse final */
+       fpv_offset_smooth,
+       fpv_viewpoint_smooth,
+       tpv_offset_smooth,
+       tpv_lpf,
+       cam_velocity_smooth;
+
+   v3f cam_override_pos;
+   v2f cam_override_angles;
+   float cam_override_strength;
+
+   float cam_velocity_influence,
+         cam_velocity_coefficient,
+         cam_velocity_constant,
+         cam_velocity_coefficient_smooth,
+         cam_velocity_constant_smooth,
+         cam_velocity_influence_smooth,
+         cam_land_punch,
+         cam_land_punch_v;
+
+   ent_gate *gate_waiting;
+
+   /*
+    * Input 
+    * --------------------------------
+    */
+   struct input_binding *input_js1h,
+                        *input_js1v,
+                        *input_js2h,
+                        *input_js2v,
+                        *input_jump,
+                        *input_push,
+                        *input_trick0,
+                        *input_trick1,
+                        *input_trick2,
+                        *input_walk,
+                        *input_walkh,
+                        *input_walkv,
+                        *input_use,
+                        *input_reset,
+                        *input_grab,
+                        *input_camera;
+
+   /*
+    * Animation
+    * --------------------------------------------------
+    */
+
+   struct player_avatar  *playeravatar;
+   glmesh                *playermesh;
+   struct player_ragdoll  ragdoll;
+   vg_tex2d              *playertex;
+
+   player_pose            holdout_pose;
+   float                  holdout_time;
+
+   /*
+    * Rewind
+    * ----------------------------------------------------
+    */
+   int rewinding, rewind_sound_wait;
+
+   struct rewind_frame{
+      v3f pos;
+      v3f ang;
+   }
+   *rewind_buffer;
+   u32 rewind_length;
+   float rewind_accum;
+   ent_gate *rewind_gate;
+
+   float rewind_total_length, rewind_predicted_time,
+         dist_accum;
+   double rewind_start, rewind_time;
+
+   /*
+    * Subsystems
+    * -------------------------------------------------
+    */
+
+   enum player_subsystem
+   {
+      k_player_subsystem_walk = 0,
+      k_player_subsystem_skate = 1,
+      k_player_subsystem_dead = 2
+   }
+   subsystem,
+   subsystem_gate;
+
+   struct player_skate  _skate;
+   struct player_walk   _walk;
+   struct player_dead   _dead;
+};
+
+/*
+ * Gameloop tables
+ * ---------------------------------------------------------
+ */
+
+VG_STATIC
+void (*_player_bind[])( player_instance *player ) =
+{
+   player__walk_bind,
+   player__skate_bind,
+   NULL
+};
+
+VG_STATIC
+void (*_player_reset[])( player_instance *player, ent_spawn *rp ) =
+{
+   player__walk_reset,
+   player__skate_reset,
+   NULL
+};
+
+VG_STATIC
+void (*_player_pre_update[])( player_instance *player ) = 
+{
+   player__walk_pre_update,
+   player__skate_pre_update,
+   NULL
+};
+
+VG_STATIC
+void( *_player_update[])( player_instance *player ) =
+{
+   player__walk_update,
+   player__skate_update,
+   player__dead_update,
+};
+
+VG_STATIC 
+void( *_player_post_update[])( player_instance *player ) =
+{
+   player__walk_post_update,
+   player__skate_post_update,
+   NULL
+};
+
+VG_STATIC
+void( *_player_im_gui[])( player_instance *player ) =
+{
+   player__walk_im_gui,
+   player__skate_im_gui,
+   NULL
+};
+
+VG_STATIC
+void( *_player_animate[])( player_instance *player, player_animation *dest ) =
+{
+   player__walk_animate,
+   player__skate_animate,
+   player__dead_animate
+};
+
+VG_STATIC
+void( *_player_post_animate[])( player_instance *player ) =
+{
+   player__walk_post_animate,
+   player__skate_post_animate,
+   player__dead_post_animate
+};
+
+VG_STATIC
+void( *_player_restore[] )( player_instance *player ) =
+{
+   player__walk_restore,
+   player__skate_restore,
+   NULL
+};
+
+/* implementation */
+
+#include "player.c"
+#include "player_common.c"
+#include "player_walk.c"
+#include "player_skate.c"
+#include "player_dead.c"
+
+#endif /* PLAYER_H */
+
+
+#if 0
 /*
  * Copyright (C) 2021-2023 Mt.ZERO Software, Harry Godden - All Rights Reserved
  */
 #include "bvh.h"
 
 
-VG_STATIC int freecam = 0;
-VG_STATIC int walk_grid_iterations = 1;
-VG_STATIC float fc_speed = 10.0f;
-VG_STATIC int cl_thirdperson = 0;
-
 /* 
  * -----------------------------------------------------------------------------
  *                                  Memory
@@ -218,68 +434,6 @@ VG_STATIC void reset_player_poll( int argc, char const *argv[] );
 
 VG_STATIC void player_init(void)                                         /* 1 */
 {
-#if 0
-   player.input_js1h = vg_create_named_input( "steer-h", k_input_type_axis );
-   player.input_js1v = vg_create_named_input( "steer-v", k_input_type_axis );
-   player.input_grab = vg_create_named_input( "grab", k_input_type_axis_norm );
-   player.input_js2h = vg_create_named_input( "grab-h", k_input_type_axis );
-   player.input_js2v = vg_create_named_input( "grab-v", k_input_type_axis );
-   player.input_jump = vg_create_named_input( "jump", k_input_type_button );
-   player.input_push = vg_create_named_input( "push", k_input_type_button );
-   player.input_walk = vg_create_named_input( "walk", k_input_type_button );
-
-   player.input_walkh = vg_create_named_input( "walk-h", 
-                                               k_input_type_axis );
-   player.input_walkv = vg_create_named_input( "walk-v", 
-                                               k_input_type_axis );
-
-
-   player.input_switch_mode = vg_create_named_input( "switch-mode",
-                                                     k_input_type_button );
-   player.input_reset = vg_create_named_input( "reset", k_input_type_button );
-
-   const char *default_cfg[] = 
-   {
-      "bind  steer-h gp-ls-h",
-      "bind -steer-h a",
-      "bind +steer-h d",
-
-      "bind  steer-v gp-ls-v",
-      "bind -steer-v w",
-      "bind +steer-v s",
-
-      "bind  grab gp-rt",
-      "bind +grab shift",
-      "bind  grab-h gp-rs-h",
-      "bind  grab-v gp-rs-v",
-
-      "bind jump space",
-      "bind jump gp-a",
-
-      "bind push gp-b",
-      "bind push w",
-
-      "bind walk shift",
-      "bind walk gp-ls",
-      
-      "bind  walk-h  gp-ls-h",
-      "bind  walk-v -gp-ls-v",
-      "bind +walk-h d",
-      "bind -walk-h a",
-      "bind +walk-v w",
-      "bind -walk-v s",
-
-      "bind reset gp-lb",
-      "bind reset r",
-
-      "bind switch-mode gp-y",
-      "bind switch-mode e",
-   };
-
-   for( int i=0; i<vg_list_size(default_cfg); i++ )
-      vg_execute_console_input(default_cfg[i]);
-#endif
-
    rb_init( &player.rb );
 
    VG_VAR_F32( k_walkspeed );
@@ -287,14 +441,12 @@ VG_STATIC void player_init(void)                                         /* 1 */
    VG_VAR_F32( k_airspeed );
    VG_VAR_F32( k_walk_friction );
    VG_VAR_F32( k_walk_air_accel );
-   VG_VAR_F32( k_runspeed );
    VG_VAR_F32( k_walk_accel );
 
    VG_VAR_I32( freecam );
    VG_VAR_I32( cl_thirdperson );
    VG_VAR_F32_PERSISTENT( fc_speed );
 
-   /* TODO: NOT PERSISTENT */
    VG_VAR_F32( k_ragdoll_limit_scale );
    VG_VAR_I32( k_ragdoll_div );
    VG_VAR_I32( k_ragdoll_debug_collider );
@@ -913,3 +1065,4 @@ VG_STATIC void player_restore_frame(void)
 }
 
 #endif /* PLAYER_H */
+#endif