X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=player.h;h=ecf595d42c51a731daecfef6b4e99bdbaf43fd5c;hb=9eb3de757a997becb8406417a4bf613f4cb04900;hp=25054e03f38db5040af9c9437364e99d9a4adc71;hpb=8bc80dc83f08a7016f1057f82d00727a2e417fa3;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/player.h b/player.h index 25054e0..ecf595d 100644 --- a/player.h +++ b/player.h @@ -1,352 +1,246 @@ -/* - * Copyright (C) 2021-2022 Mt.ZERO Software, Harry Godden - All Rights Reserved - */ - #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 = 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_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 = 150.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 */ - - v3f a, v_last, m, bob, vl; +#include "skaterift.h" - /* Utility */ - float vswitch, slip, slip_last, - reverse; - - float grab, jump, pushing, push_time; - double start_push; - 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; - - 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" +#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; + + v3f cam_override_pos; + v3f cam_override_angles; + float cam_override_fov; + float cam_override_strength; + 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 holdout_pose; + float holdout_time; + + struct board_pose board_pose; + + /* + * Replay + * ------------------------------------------------- + */ + replay_buffer replay; + + /* + * Subsystems + * ------------------------------------------------- + */ + + enum player_subsystem subsystem; /* .. prev */ + + struct player_skate _skate; + struct player_walk _walk; + struct player_dead _dead; + struct player_drive _drive; +} +static localplayer; -/* - * ----------------------------------------------------------------------------- - * Events - * ----------------------------------------------------------------------------- +/* + * Gameloop tables + * --------------------------------------------------------- */ -static void player_init(void) /* 1 */ +VG_STATIC +void (*_player_system_register[])(void) = { - 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 ); -} + player__walk_register, + player__skate_register, + NULL, + NULL +}; -/* Deal with input etc */ -static void player_update_pre(void) +VG_STATIC +void (*_player_bind[])( player_instance *player ) = { - struct player_phys *phys = &player.phys; - - if( vg_get_button_down( "reset" ) ) - { - 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( phys->on_board ) - { - v3_muladds( phys->rb.v, phys->rb.forward, 0.2f, phys->rb.v ); - } - } -} + player__walk_bind, + player__skate_bind, + NULL, + player__drive_bind +}; -static void player_update_fixed(void) /* 2 */ +VG_STATIC +void (*_player_reset[])( player_instance *player, ent_spawn *rp ) = { - struct player_phys *phys = &player.phys; - - if( player.is_dead ) - { - player_ragdoll_iter(); - } - 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. */ -} + player__walk_reset, + player__skate_reset, + NULL, + player__drive_reset +}; -static void player_update_post(void) +VG_STATIC +void (*_player_pre_update[])( player_instance *player ) = { - for( int i=0; i