From a1741ec4aed057cbafff2d6bc9e5cf8a15ae322b Mon Sep 17 00:00:00 2001 From: hgn Date: Tue, 8 Nov 2022 04:19:46 +0000 Subject: [PATCH] stuff --- menu.h | 40 +++++++++++++++++++++++++++++++++++----- player.h | 42 +++++++++++++++++++++++++++++++++++++++--- player_animation.h | 7 +++++-- player_physics.h | 16 ++++++++++++---- skaterift.c | 2 +- steam.h | 23 +++++++++++++++++++++++ 6 files changed, 115 insertions(+), 15 deletions(-) diff --git a/menu.h b/menu.h index d5eb90f..f22789e 100644 --- a/menu.h +++ b/menu.h @@ -28,6 +28,12 @@ VG_STATIC const char *playermodels[] = { "ch_new", "ch_jordan", "ch_outlaw" }; vg_tex2d tex_menu = { .path = "textures/menu.qoi",.flags = VG_TEXTURE_NEAREST }; +VG_STATIC struct input_binding input_menu_h, + input_menu_v, + input_menu_press, + input_menu_back, + input_menu_toggle; + VG_STATIC void menu_btn_paused( int event ); VG_STATIC void menu_btn_quit( int event ); VG_STATIC void menu_btn_skater( int event ); @@ -120,6 +126,23 @@ VG_STATIC void steam_on_game_overlay( CallbackMsg_t *msg ) VG_STATIC void menu_init(void) { + vg_create_unnamed_input( &input_menu_h, k_input_type_axis ); + vg_create_unnamed_input( &input_menu_v, k_input_type_axis ); + vg_create_unnamed_input( &input_menu_back, k_input_type_button ); + vg_create_unnamed_input( &input_menu_press, k_input_type_button ); + vg_create_unnamed_input( &input_menu_toggle, k_input_type_button ); + + vg_apply_bind_str( &input_menu_h, "", "gp-ls-h" ); + vg_apply_bind_str( &input_menu_h, "+", "d" ); + vg_apply_bind_str( &input_menu_h, "-", "a" ); + vg_apply_bind_str( &input_menu_v, "", "gp-ls-v" ); + vg_apply_bind_str( &input_menu_v, "+", "w" ); + vg_apply_bind_str( &input_menu_v, "-", "s" ); + vg_apply_bind_str( &input_menu_press, "", "gp-a" ); + vg_apply_bind_str( &input_menu_back, "", "gp-b" ); + vg_apply_bind_str( &input_menu_toggle, "", "\2escape" ); + vg_apply_bind_str( &input_menu_toggle, "", "\2gp-menu" ); + vg_linear_clear( vg_mem.scratch ); mdl_open( &menu_model, "models/rs_menu.mdl" ); @@ -154,7 +177,7 @@ VG_STATIC void menu_run_directional(void) { struct menu_button *btn = &menu_buttons[ menu_loc ]; - if( vg_get_button_down( "jump" ) ) + if( vg_input_button_down( &input_menu_press ) ) { if( btn->fn_press ) { @@ -169,7 +192,8 @@ VG_STATIC void menu_run_directional(void) if( menu_input_cooldown <= 0.0f ) { - v2f dir = { vg_get_axis( "lookh" ), vg_get_axis( "lookv" ) }; + v2f dir = { input_menu_h.axis.value, + input_menu_v.axis.value }; if( v2_length2( dir ) > 0.8f*0.8f ) { @@ -200,7 +224,7 @@ VG_STATIC void menu_run_directional(void) VG_STATIC int menu_page_should_backout(void) { - return vg_get_button_down( "break" ); + return vg_input_button_down( &input_menu_back ); } VG_STATIC void menu_close(void) @@ -247,7 +271,7 @@ VG_STATIC void menu_page_quit(void) VG_STATIC void menu_page_skater(void) { - float h = vg_get_axis( "lookh" ); + float h = input_menu_h.axis.value; menu_fov_target = 97.0f; if( menu_page_should_backout() ) @@ -290,7 +314,13 @@ VG_STATIC void menu_page_skater(void) VG_STATIC void menu_update(void) { - if( vg_get_button_down( "menu" ) ) + vg_input_update( 1, &input_menu_h ); + vg_input_update( 1, &input_menu_v ); + vg_input_update( 1, &input_menu_back ); + vg_input_update( 1, &input_menu_press ); + vg_input_update( 1, &input_menu_toggle ); + + if( vg_input_button_down( &input_menu_toggle ) ) { if( cl_menu ) { diff --git a/player.h b/player.h index 61a1391..1edbc6b 100644 --- a/player.h +++ b/player.h @@ -97,6 +97,7 @@ VG_STATIC struct gplayer *input_js2v, *input_jump, *input_push, + *input_walk, *input_walkh, *input_walkv, *input_switch_mode, @@ -226,7 +227,8 @@ VG_STATIC void player_init(void) /* 1 player.input_js2h = vg_create_named_input( "grab-h", k_input_type_axis ); player.input_js2v = vg_create_named_input( "grab-v", k_input_type_axis ); player.input_jump = vg_create_named_input( "jump", k_input_type_button ); - player.input_push = vg_create_named_input( "push", k_input_type_axis_norm ); + player.input_push = vg_create_named_input( "push", k_input_type_button ); + player.input_walk = vg_create_named_input( "walk", k_input_type_button ); player.input_walkh = vg_create_named_input( "walk-h", k_input_type_axis ); @@ -256,8 +258,11 @@ VG_STATIC void player_init(void) /* 1 "bind jump space", "bind jump gp-a", - "bind push gp-lt", - "bind +push w", + "bind push gp-b", + "bind push w", + + "bind walk shift", + "bind walk gp-ls", "bind walk-h gp-ls-h", "bind walk-v -gp-ls-v", @@ -374,6 +379,37 @@ VG_STATIC void player_mouseview(void) return; v2_muladds( player.angles, vg.mouse_delta, 0.0025f, player.angles ); + + if( vg.gamepad_use_trackpad_look ) + { + static v2f last_input; + static v2f vel; + static v2f vel_smooth; + + v2f input = { player.input_js2h->axis.value, + player.input_js2v->axis.value }; + + if( (v2_length2(last_input) > 0.001f) && (v2_length2(input) > 0.001f) ) + { + v2_sub( input, last_input, vel ); + v2_muls( vel, 1.0f/vg.time_delta, vel ); + } + else + { + v2_zero( vel ); + } + + v2_lerp( vel_smooth, vel, vg.time_delta*8.0f, vel_smooth ); + + v2_muladds( player.angles, vel_smooth, vg.time_delta, player.angles ); + v2_copy( input, last_input ); + } + else + { + player.angles[0] += player.input_js2h->axis.value * vg.time_delta * 4.0f; + player.angles[1] += player.input_js2v->axis.value * vg.time_delta * 4.0f; + } + player.angles[1] = vg_clampf( player.angles[1], -VG_PIf*0.5f, VG_PIf*0.5f ); } diff --git a/player_animation.h b/player_animation.h index 88fe669..9d2c801 100644 --- a/player_animation.h +++ b/player_animation.h @@ -20,7 +20,8 @@ VG_STATIC void player_animate_offboard(void) player.ffly = vg_lerpf( player.ffly, fly, rate*vg.time_delta ); player.frun = vg_lerpf( player.frun, - vg_get_axis("walk/push")*0.5f+0.5f, + player.walk * + (1.0f + player.input_walk->button.value*0.5f), 2.0f*vg.time_delta ); } @@ -224,7 +225,7 @@ VG_STATIC void player_animate(void) mdl_keyframe air_pose[32]; { - float target = -vg_get_axis("lookh"); + float target = -player.input_js1h->axis.value; player.fairdir = vg_lerpf( player.fairdir, target, 2.4f*vg.time_delta ); float air_frame = (player.fairdir*0.5f+0.5f) * (15.0f/30.0f); @@ -360,11 +361,13 @@ VG_STATIC void player_animate_camera(void) else { float speed = vg.time_delta * k_look_speed; +#if 0 player.angles[0] += vg_get_axis( "lookh" ) * speed; player.angles[1] += vg_get_axis( "lookv" ) * speed; player.angles[1] = vg_clampf( player.angles[1], -k_pitch_limit, k_pitch_limit ); +#endif float s = sinf(player.angles[0]) * 0.2f, c = -cosf(player.angles[0]) * 0.2f; diff --git a/player_physics.h b/player_physics.h index 52e4c30..20ce7f5 100644 --- a/player_physics.h +++ b/player_physics.h @@ -161,7 +161,7 @@ VG_STATIC void player_physics_control(void) } static int push_thresh_last = 0; - float push = player.input_push->axis.value; + float push = player.input_push->button.value; int push_thresh = push>0.15f? 1: 0; if( push_thresh && !push_thresh_last ) @@ -401,10 +401,14 @@ VG_STATIC void player_walk_physics(void) player.input_walkv->axis.value }; if( v2_length2(walk) > 0.001f ) - v2_normalize( walk ); + v2_normalize_clamp( walk ); - v2_muls( walk, vg_maxf( player.input_push->axis.value, 0.5f ) * - k_walkspeed * VG_TIMESTEP_FIXED, walk ); + player.walk = v2_length( walk ); + + if( player.input_walk->button.value ) + v2_muls( walk, 0.5f, walk ); + + v2_muls( walk, k_walkspeed * VG_TIMESTEP_FIXED, walk ); v3f walk_apply; v3_zero( walk_apply ); @@ -829,6 +833,9 @@ VG_STATIC void player_freecam(void) m3x3_mulv( camera_mtx, sidedir, sidedir ); static v3f move_vel = { 0.0f, 0.0f, 0.0f }; + + /* TODO */ +#if 0 if( vg_get_button( "forward" ) ) v3_muladds( move_vel, lookdir, VG_TIMESTEP_FIXED * movespeed, move_vel ); if( vg_get_button( "back" ) ) @@ -837,6 +844,7 @@ VG_STATIC void player_freecam(void) v3_muladds( move_vel, sidedir, VG_TIMESTEP_FIXED *-movespeed, move_vel ); if( vg_get_button( "right" ) ) v3_muladds( move_vel, sidedir, VG_TIMESTEP_FIXED * movespeed, move_vel ); +#endif v3_muls( move_vel, 0.7f, move_vel ); v3_add( move_vel, player.camera_pos, player.camera_pos ); diff --git a/skaterift.c b/skaterift.c index 7c094b0..21a7981 100644 --- a/skaterift.c +++ b/skaterift.c @@ -157,7 +157,7 @@ VG_STATIC void render_main_game(void) float fov_target = 108.0f; if( player.phys.on_board ) - fov_target = 125.0f; + fov_target = 118.0f; if( cl_menu ) fov_target = menu_fov_target; diff --git a/steam.h b/steam.h index a92c325..a417622 100644 --- a/steam.h +++ b/steam.h @@ -240,6 +240,29 @@ VG_STATIC int steam_init(void) .function = steam_set_achievemnt_test }); + vg_info( "Checking controller type\n" ); + + ISteamInput *hInput = SteamAPI_SteamInput(); + SteamAPI_ISteamInput_Init( hInput, 0 ); + SteamAPI_ISteamInput_RunFrame( hInput, 0 ); + InputHandle_t joy0 = SteamAPI_ISteamInput_GetControllerForGamepadIndex( + hInput, 0 ); + + if( joy0 != 0 ) + { + ESteamInputType type = SteamAPI_ISteamInput_GetInputTypeForHandle( + hInput, joy0 ); + + if( type == k_ESteamInputType_SteamController ) + vg.gamepad_use_trackpad_look = 1; + + vg_info( "Type: %d\n", type ); + } + else + { + vg_warn( "none found\n" ); + } + #endif /* TODO: On username update callback */ -- 2.25.1