X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=src%2Fvg%2Fvg_input.h;h=f7df7511b860b16c4c21ccea526ea2d94eacc0e9;hb=9917df2d289c6c35d6bf54319aed3aed421b53f1;hp=76b3b95e7781934783363c6cb3345f0cf526661e;hpb=deb49cc59884e298467c497d46518243ddb5a209;p=vg.git diff --git a/src/vg/vg_input.h b/src/vg/vg_input.h index 76b3b95..f7df751 100644 --- a/src/vg/vg_input.h +++ b/src/vg/vg_input.h @@ -2,10 +2,17 @@ #ifndef VG_INPUT_H #define VG_INPUT_H -static inline float vg_get_axis( const char *axis ); -static inline int vg_get_button( const char *button ); -static inline int vg_get_button_down( const char *button ); -static inline int vg_get_button_up( const char *button ); +#include "common.h" +#include "vg/vg_loader.h" + +VG_STATIC inline float vg_get_axis( const char *axis ); +VG_STATIC inline int vg_get_button( const char *button ); + +/* + * Cannot be used in fixed update + */ +VG_STATIC inline int vg_get_button_down( const char *button ); +VG_STATIC inline int vg_get_button_up( const char *button ); enum vg_button_state { @@ -15,11 +22,6 @@ enum vg_button_state k_button_state_none = 0 }; -GLFWgamepadstate vg_gamepad; -int vg_gamepad_ready = 0; -const char *vg_gamepad_name = NULL; -int vg_gamepad_id; - /* TODO: Fix this... */ enum EInputMode { @@ -28,7 +30,7 @@ enum EInputMode } vg_input_mode; -static struct axis_binding +VG_STATIC struct axis_binding { const char *name; union @@ -43,7 +45,7 @@ static struct axis_binding } vg_axis_binds[]; -static struct button_binding +VG_STATIC struct button_binding { const char *name; int bind; @@ -58,14 +60,14 @@ vg_controller_binds[]; #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wreturn-type" -static inline float vg_get_axis( const char *axis ) +VG_STATIC float vg_get_axis( const char *axis ) { for( int i = 0; i < vg_list_size( vg_axis_binds ); i ++ ) if( !strcmp( axis, vg_axis_binds[i].name ) ) return vg_axis_binds[i].value; } -static inline struct button_binding *vg_get_button_ptr( const char *button ) +VG_STATIC struct button_binding *vg_get_button_ptr( const char *button ) { for( int i=0; iprev = binding->value; - binding->value = vg_gamepad.buttons[ binding->bind ]; + binding->value = vg.gamepad.buttons[ binding->bind ]; } /* Update axis inputs */ for( int i = 0; i < vg_list_size( vg_axis_binds ); i ++ ) { struct axis_binding *binding = vg_axis_binds + i; - binding->value = vg_gamepad.axes[ binding->bind ]; + binding->value = vg.gamepad.axes[ binding->bind ]; } } -static void vg_gamepad_init(void) +VG_STATIC void vg_gamepad_init(void) { - for( int id = 0; id <= GLFW_JOYSTICK_LAST; id ++ ) + vg_acquire_thread_sync(); + + for( int id=0; id<=GLFW_JOYSTICK_LAST; id ++ ) { if( glfwJoystickPresent( id ) ) { @@ -193,15 +205,19 @@ static void vg_gamepad_init(void) if( glfwJoystickIsGamepad( id ) ) { - vg_gamepad_name = glfwGetGamepadName( id ); - vg_success( "Gamepad with mapping registered: %s\n", vg_gamepad_name ); - - vg_gamepad_ready = 1; - vg_gamepad_id = id; + vg.gamepad_name = glfwGetGamepadName( id ); + vg_success( "Gamepad mapping registered: %s\n", vg.gamepad_name ); + vg.gamepad_ready = 1; + vg.gamepad_id = id; break; } } + + vg.gamepad.axes[ GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER ] = -1.0f; + vg.gamepad.axes[ GLFW_GAMEPAD_AXIS_LEFT_TRIGGER ] = -1.0f; + + vg_release_thread_sync(); } #endif