-/*
- * Copyright 2021-2022 (C) Mount0 Software, Harry Godden - All Rights Reserved
- * -----------------------------------------------------------------------------
- *
- * Player head module
- *
- * -----------------------------------------------------------------------------
- */
-
#ifndef PLAYER_H
#define PLAYER_H
-#include "audio.h"
-#include "common.h"
-#include "world.h"
-#include "skeleton.h"
-#include "bvh.h"
-
-static float
- k_walkspeed = 7.0f, /* no longer used */
- k_runspeed = 14.0f,
- k_board_radius = 0.3f,
- k_board_length = 0.45f,
- k_board_allowance = 0.04f,
- k_friction_lat = 8.8f,
- k_friction_resistance = 0.01f,
- k_max_push_speed = 16.0f,
- k_push_accel = 10.0f,
- k_push_cycle_rate = 8.0f,
- k_steer_ground = 2.5f,
- k_steer_air = 3.6f,
- k_steer_air_lerp = 0.3f,
- k_pump_force = 0.0f,
- k_downforce = 5.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_friction = 8.0f;
-
-static int freecam = 0;
-static int walk_grid_iterations = 1;
-static float fc_speed = 10.0f;
-
-/*
- * -----------------------------------------------------------------------------
- * Memory
- * -----------------------------------------------------------------------------
- */
-
-static struct gplayer
-{
- /* Physics */
- rigidbody collide_front, collide_back;
-
- struct player_phys
- {
- rigidbody rb, rb_gate_frame;
- float iY, siY; /* Yaw inertia */
+#include "skaterift.h"
- v3f a, v_last, m, bob, vl;
-
- /* Utility */
- float vswitch, slip, slip_last,
- reverse;
-
- float grab, jump;
- int in_air, on_board, jump_charge, jump_dir;
+enum player_subsystem{
+ k_player_subsystem_walk = 0,
+ k_player_subsystem_skate = 1,
+ k_player_subsystem_dead = 2,
+ k_player_subsystem_drive = 3
+};
- m3x3f vr,vr_pstep;
+struct player_cam_controller {
+ enum camera_mode{
+ k_cam_firstperson = 1,
+ k_cam_thirdperson = 0
}
- phys,
- phys_gate_frame;
-
- float pushing, push_time;
- int is_dead;
-
- v3f land_target;
- v3f land_target_log[22];
- u32 land_target_colours[22];
- int land_log_count;
-
- v3f handl_target, handr_target,
- handl, handr;
-
- /* Camera */
- float air_blend;
-
- v3f camera_pos, smooth_localcam;
- v2f angles;
- m4x3f camera, camera_inverse;
-
- /* animation */
- double jump_time;
- float fslide,
- fdirz, fdirx,
- fstand,
- ffly,
- fpush,
- fairdir,
- fsetup,
- walk_timer,
- fjump,
- fonboard;
-
- int step_phase;
-
- /* player model */
- struct player_model
- {
- glmesh mesh;
- struct skeleton sk;
- struct skeleton_anim *anim_stand,
- *anim_highg,
- *anim_slide,
- *anim_air,
- *anim_push, *anim_push_reverse,
- *anim_ollie, *anim_ollie_reverse,
- *anim_grabs, *anim_stop,
- *anim_walk, *anim_run, *anim_idle;
-
- u32 id_hip,
- id_ik_hand_l,
- id_ik_hand_r,
- id_ik_elbow_l,
- id_ik_elbow_r,
- id_head;
-
- v3f cam_pos;
-
- struct ragdoll_part
- {
- u32 bone_id;
- v3f offset;
-
- u32 use_limits;
- v3f limits[2];
-
- rigidbody rb;
- u32 parent;
- }
- *ragdoll;
- u32 ragdoll_count;
-
- int shoes[2];
- }
- mdl;
-}
-player =
-{
- .collide_front = { .type = k_rb_shape_sphere, .inf.sphere.radius = 0.3f },
- .collide_back = { .type = k_rb_shape_sphere, .inf.sphere.radius = 0.3f }
+ camera_mode;
+ f32 camera_type_blend;
+
+ v3f fpv_offset, /* expressed relative to rigidbody */
+ tpv_offset,
+ tpv_offset_extra,
+ fpv_viewpoint, /* expressed relative to neck bone inverse final*/
+ fpv_offset_smooth,
+ fpv_viewpoint_smooth,
+ tpv_offset_smooth,
+ tpv_lpf,
+ cam_velocity_smooth;
};
-/*
- * API
- */
-static float *player_get_pos(void);
-static void player_kill(void);
-static float *player_cam_pos(void);
-static void player_save_frame(void);
-static void player_restore_frame(void);
-
-/*
- * Submodules
- */
-#include "player_physics.h"
#include "player_ragdoll.h"
+#include "player_render.h"
#include "player_model.h"
-#include "player_animation.h"
-#include "player_audio.h"
-
-/*
- * -----------------------------------------------------------------------------
- * Events
- * -----------------------------------------------------------------------------
- */
-
-static void player_init(void) /* 1 */
-{
- rb_init( &player.phys.rb );
- rb_init( &player.collide_front );
- rb_init( &player.collide_back );
-
- vg_convar_push( (struct vg_convar){
- .name = "walk_speed",
- .data = &k_walkspeed,
- .data_type = k_convar_dtype_f32,
- .opt_f32 = { .clamp = 0 },
- .persistent = 1
- });
-
- vg_convar_push( (struct vg_convar){
- .name = "run_speed",
- .data = &k_runspeed,
- .data_type = k_convar_dtype_f32,
- .opt_f32 = { .clamp = 0 },
- .persistent = 1
- });
-
- vg_convar_push( (struct vg_convar){
- .name = "walk_accel",
- .data = &k_walk_accel,
- .data_type = k_convar_dtype_f32,
- .opt_f32 = { .clamp = 0 },
- .persistent = 1
- });
-
- vg_convar_push( (struct vg_convar){
- .name = "fc",
- .data = &freecam,
- .data_type = k_convar_dtype_i32,
- .opt_i32 = { .min=0, .max=1, .clamp=1 },
- .persistent = 1
- });
-
- vg_convar_push( (struct vg_convar){
- .name = "fcs",
- .data = &fc_speed,
- .data_type = k_convar_dtype_f32,
- .opt_f32 = { .clamp = 0 },
- .persistent = 1
- });
-
- vg_function_push( (struct vg_cmd){
- .name = "reset",
- .function = reset_player
- });
-
- /* other systems */
- vg_loader_highwater( player_model_init, player_model_free, NULL );
+#include "player_common.h"
+#include "player_walk.h"
+#include "player_skate.h"
+#include "player_dead.h"
+#include "player_drive.h"
+#include "player_replay.h"
+
+#define PLAYER_REWIND_FRAMES 60*4
+#define RESET_MAX_TIME 45.0
+
+static i32 k_cinema_fixed = 0;
+static f32 k_cinema = 0.0f;
+static i32 k_invert_y = 0;
+
+struct player_instance{
+ /* transform definition */
+ rigidbody rb;
+ v3f angles;
+
+ v4f qbasis;
+ m3x3f basis, invbasis, basis_gate;
+ world_instance *viewable_world;
+
+ /*
+ * Camera management
+ * ---------------------------
+ */
+ camera cam;
+ struct player_cam_controller cam_control;
+ f32 cam_trackshake;
+
+ float cam_velocity_influence,
+ cam_velocity_coefficient,
+ cam_velocity_constant,
+ cam_velocity_coefficient_smooth,
+ cam_velocity_constant_smooth,
+ cam_velocity_influence_smooth;
+
+ v3f cam_land_punch, cam_land_punch_v;
+ ent_gate *gate_waiting;
+
+ int immobile;
+
+ /*
+ * Animation
+ * --------------------------------------------------
+ */
+
+ struct player_avatar *playeravatar;
+ struct player_ragdoll ragdoll;
+ struct player_model fallback_model;
+
+ u16 board_view_slot, playermodel_view_slot;
+
+ player_pose pose;
+ player_pose holdout_pose;
+ float holdout_time;
+
+ /*
+ * Subsystems
+ * -------------------------------------------------
+ */
+
+ enum player_subsystem subsystem; /* .. prev */
+
+ struct player_skate _skate;
+ struct player_walk _walk;
+ struct player_dead _dead;
+ struct player_drive _drive;
}
+static localplayer;
-static void player_update(void) /* 2 */
-{
- 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)
- {
- player.is_dead = 0;
- player_restore_frame();
-
- 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;
-
- world_routes_notify_reset();
- }
-
- if( vg_get_button_down( "switchmode" ) )
- {
- phys->on_board ^= 0x1;
- }
-
-#if 0
- if( (glfwGetKey( vg_window, GLFW_KEY_O ) ))
- {
- player_ragdoll_copy_model( phys->rb.v );
- player.is_dead = 1;
- }
-#endif
+/*
+ * Gameloop tables
+ * ---------------------------------------------------------
+ */
- if( player.is_dead )
- {
- player_ragdoll_iter();
- player_debug_ragdoll();
+VG_STATIC
+void (*_player_system_register[])(void) = {
+ player__walk_register,
+ player__skate_register,
+ NULL,
+ NULL
+};
- if( !freecam )
- player_animate_death_cam();
- }
- else
- {
- player_do_motion();
- player_animate();
+VG_STATIC
+void (*_player_bind[])( player_instance *player ) = {
+ player__walk_bind,
+ player__skate_bind,
+ NULL,
+ player__drive_bind
+};
- if( !freecam )
- player_animate_camera();
- }
+VG_STATIC
+void (*_player_reset[])( player_instance *player, ent_spawn *rp ) = {
+ player__walk_reset,
+ player__skate_reset,
+ NULL,
+ player__drive_reset
+};
- if( freecam )
- player_freecam();
+VG_STATIC
+void (*_player_pre_update[])( player_instance *player ) = {
+ player__walk_pre_update,
+ player__skate_pre_update,
+ NULL,
+ player__drive_pre_update
+};
- player_camera_update();
- player_audio();
-}
+VG_STATIC
+void( *_player_update[])( player_instance *player ) = {
+ player__walk_update,
+ player__skate_update,
+ player__dead_update,
+ player__drive_update
+};
-static void draw_player(void) /* 3 */
-{
- if( player.is_dead )
- player_model_copy_ragdoll();
-
- 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_link_standard_ub( _shader_viewchar.id, 2 );
- glUniformMatrix4x3fv( _uniform_viewchar_uTransforms,
- player.mdl.sk.bone_count,
- 0,
- (float *)player.mdl.sk.final_mtx );
-
- mesh_bind( &player.mdl.mesh );
- mesh_draw( &player.mdl.mesh );
-}
+VG_STATIC
+void( *_player_post_update[])( player_instance *player ) = {
+ player__walk_post_update,
+ player__skate_post_update,
+ player__dead_post_update,
+ player__drive_post_update
+};
-/*
- * -----------------------------------------------------------------------------
- * API implementation
- * -----------------------------------------------------------------------------
- */
+VG_STATIC
+void( *_player_im_gui[])( player_instance *player ) = {
+ player__walk_im_gui,
+ player__skate_im_gui,
+ NULL,
+ player__drive_im_gui
+};
-static float *player_get_pos(void)
-{
- return player.phys.rb.co;
-}
+VG_STATIC
+void( *_player_animate[])( player_instance *player ) = {
+ player__walk_animate,
+ player__skate_animate,
+ player__dead_animate,
+ player__drive_animate
+};
-static void player_kill(void)
-{
- player.is_dead = 1;
- player_ragdoll_copy_model( player.phys.rb.v );
-}
+VG_STATIC
+void( *_player_pose[] )( player_instance *player, player_pose *pose ) = {
+ player__walk_pose,
+ player__skate_pose,
+ player__dead_pose,
+ player__drive_pose,
+};
-static float *player_cam_pos(void)
-{
- return player.camera_pos;
-}
+VG_STATIC
+void( *_player_post_animate[])( player_instance *player ) = {
+ player__walk_post_animate,
+ player__skate_post_animate,
+ player__dead_post_animate,
+ player__drive_post_animate
+};
+PLAYER_API void player__debugtext( int size, const char *fmt, ... );
+PLAYER_API void player__create( player_instance *inst );
+PLAYER_API void player__use_avatar( player_instance *player,
+ struct player_avatar *av );
+PLAYER_API void player__use_mesh( player_instance *player, glmesh *mesh );
+PLAYER_API void player__use_texture( player_instance *player, vg_tex2d *tex );
+PLAYER_API void player__use_model( player_instance *player, u16 reg_id );
+
+PLAYER_API void player__bind( player_instance *player );
+PLAYER_API void player__pre_update( player_instance *player );
+PLAYER_API void player__update( player_instance *player );
+PLAYER_API void player__post_update( player_instance *player );
+
+PLAYER_API void player__pass_gate( player_instance *player, ent_gate *gate );
+PLAYER_API void player__im_gui( player_instance *player );
+PLAYER_API void player__setpos( player_instance *player, v3f pos );
+PLAYER_API void player__spawn( player_instance *player, ent_spawn *rp );
+PLAYER_API void player__kill( player_instance *player );
+PLAYER_API void player__begin_holdout( player_instance *player );
+
+VG_STATIC int localplayer_cmd_respawn( int argc, const char *argv[] );
+VG_STATIC void player_apply_transport_to_cam( m4x3f transport );
#endif /* PLAYER_H */