X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=vg_input.h;h=87109d25e777d2d2f844472ce88e3b62b44ed3ca;hb=a1c1af2679576d938c8c662805516e12cf217295;hp=d8e398cf8d9edd9e8c995445913307ea1b811a59;hpb=a7938c00a8c486ad0e2a765c3092017487ba761e;p=vg.git diff --git a/vg_input.h b/vg_input.h index d8e398c..87109d2 100644 --- a/vg_input.h +++ b/vg_input.h @@ -14,6 +14,8 @@ VG_STATIC inline int vg_get_button( const char *button ); VG_STATIC inline int vg_get_button_down( const char *button ); VG_STATIC inline int vg_get_button_up( const char *button ); +VG_STATIC float g_controller_deadzone = 0.05f; + enum vg_button_state { k_button_state_down = 1, @@ -482,8 +484,11 @@ VG_STATIC void vg_input_update( u32 num, struct input_binding *binds ) gamepad_value *= -1.0f; } - if( fabsf(gamepad_value) <= 0.01f ) - gamepad_value = 0.0f; + float deadz = vg_clampf( g_controller_deadzone, 0.0f, 0.999f ), + high = vg_maxf( 0.0f, fabsf(gamepad_value) - deadz ), + norm = high / (1.0f-deadz); + + gamepad_value = vg_signf( gamepad_value ) * norm; if( fabsf(keyboard_value) > fabsf(gamepad_value) ) bind->axis.value = keyboard_value; @@ -586,6 +591,14 @@ VG_STATIC void vg_input_init(void) .function = vg_rebind_input_cmd }); + vg_convar_push( (struct vg_convar){ + .name = "controller_deadzone", + .data = &g_controller_deadzone, + .data_type = k_convar_dtype_f32, + .opt_f32 = { .clamp = 0 }, + .persistent = 1 + }); + vg_info( "Checking for controller\n" ); SDL_GameControllerAddMappingsFromFile( "gamecontrollerdb.txt" );