From: hgn Date: Sat, 31 Dec 2022 16:06:18 +0000 (+0000) Subject: deadzones adjustable & other fixes X-Git-Url: https://harrygodden.com/git/?p=vg.git;a=commitdiff_plain;h=f54d25963e8f226982f6b269cb8c031d87014bc7 deadzones adjustable & other fixes --- diff --git a/submodules/SDL b/submodules/SDL index 06492c5..eef4d3c 160000 --- a/submodules/SDL +++ b/submodules/SDL @@ -1 +1 @@ -Subproject commit 06492c598158cf825a18aececaf7511d7fd04f48 +Subproject commit eef4d3c86a653f91b7221c80809ba8ab56f94cf1 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" ); diff --git a/vg_mem.h b/vg_mem.h index a214674..5edbd9c 100644 --- a/vg_mem.h +++ b/vg_mem.h @@ -111,8 +111,8 @@ VG_STATIC void *vg_linear_alloc( void *buffer, u32 size ) { if( size % 8 ) { - vg_error( "Requested size: %u\n", size ); - vg_fatal_exit_loop( "8 byte alignment required" ); + vg_error( "alloc(%u) is not 8 byte aligned\n", size ); + size = vg_align8( size ); } vg_linear_allocator *alloc = vg_linear_header( buffer ); diff --git a/vg_tex.h b/vg_tex.h index 5c7c7f6..dcc297a 100644 --- a/vg_tex.h +++ b/vg_tex.h @@ -2,6 +2,7 @@ #ifndef VG_TEX_H #define VG_TEX_H +#define VG_GAME #include "vg/vg.h" #include "vg/vg_log.h" diff --git a/vg_ui.h b/vg_ui.h index 0c88b2f..ba428b0 100644 --- a/vg_ui.h +++ b/vg_ui.h @@ -180,6 +180,7 @@ VG_STATIC void _vg_ui_init(void) vg_uictx.max_indices = 20000; vg_uictx.max_verts = 30000; + vg_uictx.colours = &ui_default_colours; /* Generate the buffer we are gonna be drawing to */ glGenVertexArrays( 1, &vg_uictx.vao );