X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=player.h;h=c718c5ac57eb4ccc66f5cc311ab472001293ddcb;hb=137d40d96fe923600d8378b8e138e3c276f27ff4;hp=fa9335cde0b1bd769f92b54b5a43edf5326b4d09;hpb=1740c935bfdacc65c5c7e4bb95fba1ada1f7118a;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/player.h b/player.h index fa9335c..c718c5a 100644 --- a/player.h +++ b/player.h @@ -1,298 +1,187 @@ -/* - * 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 */ - - 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; - - m3x3f vr,vr_pstep; - } - 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; +#include "skaterift.h" +#include "player_common.h" +#include "network_compression.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_max, + k_player_subsystem_invalid = 255 +}; - int shoes[2]; +struct player_cam_controller { + enum camera_mode{ + k_cam_firstperson = 1, + k_cam_thirdperson = 0 } - 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); +struct player_subsystem_interface{ + void(*system_register)(void); + void(*bind)(void); + void(*reset)( ent_spawn *rp ); + 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(*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; +}; -/* - * 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_register(void) /* 0 */ -{ - player_model_register(); -} - -static void player_init(void) /* 1 */ -{ - player_model_init(); - - rb_init( &player.collide_front ); - rb_init( &player.collide_back ); -} - -static void player_update(void) /* 2 */ -{ - struct player_phys *phys = &player.phys; - - for( int i=0; i0.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(); +#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 { + /* 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; + + /* + * Network + * -------------------------------------------------- + */ + u16 boundary_hash; + struct net_sfx { + u8 system, priority, id; + f32 subframe, volume; + v3f location; } + sfx_buffer[4]; + u32 sfx_buffer_count; - if( vg_get_button_down( "switchmode" ) ) - { - phys->on_board ^= 0x1; - } + /* + * Animation + * -------------------------------------------------- + */ -#if 0 - if( (glfwGetKey( vg_window, GLFW_KEY_O ) )) - { - player_ragdoll_copy_model( phys->rb.v ); - player.is_dead = 1; - } -#endif + struct player_avatar *playeravatar; + struct player_ragdoll ragdoll; + struct player_model fallback_model; - if( player.is_dead ) - { - player_ragdoll_iter(); - player_debug_ragdoll(); + u16 board_view_slot, playermodel_view_slot; - if( !freecam ) - player_animate_death_cam(); - } - else - { - player_do_motion(); - player_animate(); + player_pose pose; + player_pose holdout_pose; + float holdout_time; - if( !freecam ) - player_animate_camera(); - } + m4x3f *final_mtx; - if( freecam ) - player_freecam(); + /* + * Subsystems + * ------------------------------------------------- + */ - player_camera_update(); - player_audio(); + enum player_subsystem subsystem; /* .. prev */ } +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 + } +}; -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 ); -} +struct player_subsystem_interface static *player_subsystems[] = { + [k_player_subsystem_walk] = &player_subsystem_walk, + [k_player_subsystem_dead] = &player_subsystem_dead, + [k_player_subsystem_drive] = &player_subsystem_drive, + [k_player_subsystem_skate] = &player_subsystem_skate +}; -/* - * ----------------------------------------------------------------------------- - * API implementation - * ----------------------------------------------------------------------------- +/* + * Gameloop tables + * --------------------------------------------------------- */ -static float *player_get_pos(void) -{ - return player.phys.rb.co; -} - -static void player_kill(void) -{ - player.is_dead = 1; - player_ragdoll_copy_model( player.phys.rb.v ); -} - -static float *player_cam_pos(void) -{ - return player.camera_pos; -} - +static void player__debugtext( int size, const char *fmt, ... ); +static void player__use_avatar( struct player_avatar *av ); +static void player__use_mesh( glmesh *mesh ); +static void player__use_texture( vg_tex2d *tex ); +static void player__use_model( u16 reg_id ); + +static void player__bind(void); +static void player__pre_update(void); +static void player__update(void); +static void player__post_update(void); + +static void player__pass_gate( u32 id ); +static void player__im_gui(void); +static void player__setpos( v3f pos ); +static void player__spawn( ent_spawn *rp ); +static void player__kill(void); +static void player__begin_holdout( v3f offset ); + +static int localplayer_cmd_respawn( int argc, const char *argv[] ); +static void player_apply_transport_to_cam( m4x3f transport ); + +static void player__clear_sfx_buffer(void); +static void player__networked_sfx( u8 system, u8 priority, u8 id, + v3f pos, f32 volume ); +static void net_sfx_exchange( bitpack_ctx *ctx, struct net_sfx *sfx ); +static void net_sfx_play( struct net_sfx *sfx ); #endif /* PLAYER_H */