X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=player.h;h=82381c27b84e14fbb0f706c62dc151e7f06fa04e;hb=c33e4f46d864b2fde0c5938bf5a9388b1e8b5c04;hp=92db1fbca3ddf564550b47614405116719bfa04e;hpb=2ca677a0ec9d00db46a8b97bec30dbea8280a79b;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/player.h b/player.h index 92db1fb..82381c2 100644 --- a/player.h +++ b/player.h @@ -1,10 +1,5 @@ /* - * Copyright 2021-2022 (C) Mount0 Software, Harry Godden - All Rights Reserved - * ----------------------------------------------------------------------------- - * - * Player head module - * - * ----------------------------------------------------------------------------- + * Copyright (C) 2021-2022 Mt.ZERO Software, Harry Godden - All Rights Reserved */ #ifndef PLAYER_H @@ -17,8 +12,8 @@ #include "bvh.h" static float - k_walkspeed = 7.0f, /* no longer used */ - k_runspeed = 14.0f, + 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, @@ -32,11 +27,12 @@ static float k_steer_air_lerp = 0.3f, k_pump_force = 0.0f, k_downforce = 5.0f, + k_walk_downforce = 8.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_accel = 150.0f, k_walk_friction = 8.0f; static int freecam = 0; @@ -52,33 +48,37 @@ static float fc_speed = 10.0f; static struct gplayer { /* Physics */ - rigidbody rb, collide_front, collide_back, rb_gate_frame; + rigidbody collide_front, collide_back; + + struct player_phys + { + rigidbody rb, rb_gate_frame; + float iY, siY; /* Yaw inertia */ - /* TODO: eugh */ - m3x3f gate_vr_frame, gate_vr_pstep_frame; - int on_board_frame, in_air_frame; + v3f a, v_last, m, bob, vl; - v3f a, v_last, m, bob, vl; + /* Utility */ + float vswitch, slip, slip_last, + reverse; - /* 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; - float iY; /* Yaw inertia */ - int in_air, is_dead, on_board; + m3x3f vr,vr_pstep; + } + phys, + phys_gate_frame; + + m4x3f visual_transform, + inv_visual_transform; + + int is_dead, death_tick_allowance; - v2f board_xy; - float grab; - float pitch; - float pushing, push_time; - float jump; - int jump_charge, jump_dir; - v3f land_target; v3f land_target_log[22]; u32 land_target_colours[22]; int land_log_count; - m3x3f vr,vr_pstep; v3f handl_target, handr_target, handl, handr; @@ -100,7 +100,11 @@ static struct gplayer fairdir, fsetup, walk_timer, - fonboard; + fjump, + fonboard, + frun; + + float walk; int step_phase; /* player model */ @@ -115,7 +119,8 @@ static struct gplayer *anim_push, *anim_push_reverse, *anim_ollie, *anim_ollie_reverse, *anim_grabs, *anim_stop, - *anim_walk, *anim_run, *anim_idle; + *anim_walk, *anim_run, *anim_idle, + *anim_jump; u32 id_hip, id_ik_hand_l, @@ -146,8 +151,6 @@ static struct gplayer } player = { - .on_board = 0, - .collide_front = { .type = k_rb_shape_sphere, .inf.sphere.radius = 0.3f }, .collide_back = { .type = k_rb_shape_sphere, .inf.sphere.radius = 0.3f } }; @@ -158,6 +161,8 @@ player = 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 @@ -174,44 +179,78 @@ static float *player_cam_pos(void); * ----------------------------------------------------------------------------- */ -static void player_register(void) /* 0 */ -{ - player_model_register(); -} - static void player_init(void) /* 1 */ { - player_model_init(); - + 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 ); } -static void player_update(void) /* 2 */ +/* Deal with input etc */ +static void player_update_pre(void) { - for( int i=0; i0.0f) + if( vg_get_button_down( "reset" ) ) { - player.rb = player.rb_gate_frame; - player.on_board = player.on_board_frame; - player.in_air = player.in_air_frame; - m3x3_copy( player.gate_vr_frame, player.vr ); - m3x3_copy( player.gate_vr_pstep_frame, player.vr_pstep ); player.is_dead = 0; - player.in_air = 1; + player.death_tick_allowance = 30; + player_restore_frame(); - - if( !player.on_board ) + if( !phys->on_board ) { - player.angles[0] = atan2f( -player.rb.forward[2], - -player.rb.forward[0] ); + player.angles[0] = atan2f( -phys->rb.forward[2], + -phys->rb.forward[0] ); } - m3x3_identity( player.vr ); - player.mdl.shoes[0] = 1; player.mdl.shoes[1] = 1; @@ -220,19 +259,45 @@ static void player_update(void) /* 2 */ if( vg_get_button_down( "switchmode" ) ) { - player.on_board ^= 0x1; + phys->on_board ^= 0x1; + + if( phys->on_board ) + { + v3_muladds( phys->rb.v, phys->rb.forward, 0.2f, phys->rb.v ); + } } +} + +static void player_update_fixed(void) /* 2 */ +{ + if( player.death_tick_allowance ) + player.death_tick_allowance --; - if( (glfwGetKey( vg_window, GLFW_KEY_O ) || (player.rb.co[1] < 0.0f)) && - !player.is_dead) + struct player_phys *phys = &player.phys; + + if( player.is_dead ) { - player_ragdoll_copy_model( player.rb.v ); - player.is_dead = 1; + 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. */ +} + +static void player_update_post(void) +{ + for( int i=0; i