projects
/
vg.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
support maths for constraints
[vg.git]
/
vg_input.h
diff --git
a/vg_input.h
b/vg_input.h
index f97a41af28d161fbf95687319ed57931ac5bf862..87109d25e777d2d2f844472ce88e3b62b44ed3ca 100644
(file)
--- 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 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,
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;
}
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;
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
});
.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" );
vg_info( "Checking for controller\n" );
SDL_GameControllerAddMappingsFromFile( "gamecontrollerdb.txt" );
@@
-605,7
+618,7
@@
VG_STATIC void vg_input_init(void)
vg_release_thread_sync();
}
vg_release_thread_sync();
}
-VG_STATIC void vg_input_free(void
*_
)
+VG_STATIC void vg_input_free(void)
{
if( vg_input.controller_handle )
{
{
if( vg_input.controller_handle )
{