X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=player.h;h=18936a7ade2248844468cc7e182299c46ea14042;hb=6e6c7f31b8f17af3814727109e48fc6f85ef04b1;hp=2c6ee19ef51b94e21e9df556a6ce0bb6a51f2d4c;hpb=a98ce96041b248580c0447bf87d4c6106483cade;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/player.h b/player.h index 2c6ee19..18936a7 100644 --- a/player.h +++ b/player.h @@ -1,347 +1,218 @@ -/* - * 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 = 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 */ - - v3f a, v_last, m, bob, vl; - - /* 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; +#include "skaterift.h" +#include "player_common.h" +#include "network_compression.h" +#include "player_effects.h" + +enum player_subsystem{ + k_player_subsystem_walk = 0, + k_player_subsystem_skate = 1, + k_player_subsystem_dead = 2, + k_player_subsystem_drive = 3, + k_player_subsystem_basic_info = 4, + k_player_subsystem_max, + k_player_subsystem_invalid = 255 +}; - 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; +}; + +struct player_subsystem_interface{ + void(*system_register)(void); + void(*bind)(void); + void(*pre_update)(void); + void(*update)(void); + void(*post_update)(void); + void(*im_gui)(void); + void(*animate)(void); + void(*pose)( void *animator, player_pose *pose ); + void(*effects)( void *animator, m4x3f *final_mtx, struct player_board *board, + struct player_effects_data *effect_data ); + void(*post_animate)(void); + void(*network_animator_exchange)( bitpack_ctx *ctx, void *data ); + void(*sfx_oneshot)( u8 id, v3f pos, f32 volume ); + + void *animator_data; + u32 animator_size; + + const char *name; }; -/* - * 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 ); -} - -/* Deal with input etc */ -static void player_update_pre(void) -{ - struct player_phys *phys = &player.phys; - - 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; +/* subsystem headers */ +#include "player_walk.h" +#include "player_skate.h" +#include "player_dead.h" +#include "player_drive.h" +#include "player_basic_info.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 { + /* transform definition */ + rigidbody rb; + v3f angles; + + /* + * 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; + + int rewinded_since_last_gate; + + /* + * Network + * -------------------------------------------------- + */ + u16 boundary_hash; + struct net_sfx { + u8 system, priority, id; + f32 subframe, volume; + v3f location; } + sfx_buffer[4]; + u32 sfx_buffer_count; + + /* + * Animation + * -------------------------------------------------- + */ + + struct player_ragdoll ragdoll; + struct player_model fallback_model; + struct player_board fallback_board; + + u16 board_view_slot, playermodel_view_slot; + + player_pose pose; + player_pose holdout_pose; + float holdout_time; + + m4x3f *final_mtx; + + /* + * Subsystems + * ------------------------------------------------- + */ + + enum player_subsystem subsystem; /* .. prev */ + + /* + * Rendering + */ + mdl_context skeleton_meta; + struct skeleton skeleton; + + u32 id_hip, + id_chest, + id_ik_hand_l, + id_ik_hand_r, + id_ik_elbow_l, + id_ik_elbow_r, + id_head, + id_ik_foot_l, + id_ik_foot_r, + id_ik_knee_l, + id_ik_knee_r, + id_wheel_l, + id_wheel_r, + id_board, + id_eyes; + + struct player_effects_data effect_data; } - -static void player_update_fixed(void) /* 2 */ -{ - struct player_phys *phys = &player.phys; - - if( player.is_dead ) - { - player_ragdoll_iter(); - } - else - { - player_do_motion(); +static localplayer = { + .rb = { + .co = { 0,0,0 }, + .w = { 0,0,0 }, + .v = { 0,0,0 }, + .q = { 0,0,0,1 }, + .to_world = M4X3_IDENTITY, + .to_local = M4X3_IDENTITY } +}; - 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