heisenbug
[vg.git] / src / vg / vg_input.h
index c33853136ceb01e15dd8ff94dbd7c383ddd8eff6..ac2cce6e2cb4c7dcd8bbf85e829a43c6e67c450c 100644 (file)
@@ -5,10 +5,14 @@
 #include "common.h"
 #include "vg/vg_loader.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 );
+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
 {
@@ -26,7 +30,7 @@ enum EInputMode
 }
 vg_input_mode;
 
-static struct axis_binding
+VG_STATIC struct axis_binding
 {
        const char *name;
        union
@@ -41,7 +45,7 @@ static struct axis_binding
 }
 vg_axis_binds[];
 
-static struct button_binding
+VG_STATIC struct button_binding
 {
        const char *name;
        int bind;
@@ -56,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; i<vg_list_size(vg_button_binds); i ++ )
                if( !strcmp(button,vg_button_binds[i].name) )
@@ -71,7 +75,7 @@ static inline struct button_binding *vg_get_button_ptr( const char *button )
    return NULL;
 }
 
-static inline struct button_binding *vg_get_button_ptr_c( const char *button )
+VG_STATIC struct button_binding *vg_get_button_ptr_c( const char *button )
 {
        for( int i=0; i<vg_list_size(vg_controller_binds); i ++ )
                if( !strcmp(button,vg_controller_binds[i].name) )
@@ -81,9 +85,9 @@ static inline struct button_binding *vg_get_button_ptr_c( const char *button )
 
 #pragma GCC diagnostic pop
 
-static int vg_console_enabled(void);
+VG_STATIC int vg_console_enabled(void);
 
-static inline void vg_get_button_states( const char *name, int *cur, int *prev )
+VG_STATIC void vg_get_button_states( const char *name, int *cur, int *prev )
 {
        struct button_binding *bind = vg_get_button_ptr( name ),
                         *bindc = vg_get_button_ptr_c( name );
@@ -103,7 +107,7 @@ static inline void vg_get_button_states( const char *name, int *cur, int *prev )
    }
 }
 
-static inline int vg_get_button( const char *button )
+VG_STATIC int vg_get_button( const char *button )
 {
    int cur, prev;
    vg_get_button_states( button, &cur, &prev );
@@ -111,23 +115,29 @@ static inline int vg_get_button( const char *button )
        return cur && !vg_console_enabled();
 }
 
-static inline int vg_get_button_down( const char *button )
+VG_STATIC int vg_get_button_down( const char *button )
 {
+   if( vg.engine_stage == k_engine_stage_update_fixed )
+      vg_fatal_exit_loop( "Cannot use that here\n" );
+
    int cur, prev;
    vg_get_button_states( button, &cur, &prev );
 
        return cur & (cur ^ prev) && !vg_console_enabled();
 }
 
-static inline int vg_get_button_up( const char *button )
+VG_STATIC int vg_get_button_up( const char *button )
 {
+   if( vg.engine_stage == k_engine_stage_update_fixed )
+      vg_fatal_exit_loop( "Cannot use that here\n" );
+
    int cur, prev;
    vg_get_button_states( button, &cur, &prev );
 
        return prev & (cur ^ prev) && !vg_console_enabled();
 }
 
-static inline enum vg_button_state vg_get_button_state( const char *button )
+VG_STATIC enum vg_button_state vg_get_button_state( const char *button )
 {
        if(vg_get_button_down( button )) return k_button_state_down;
        if(vg_get_button_up( button )) return k_button_state_up;
@@ -135,7 +145,7 @@ static inline enum vg_button_state vg_get_button_state( const char *button )
        return k_button_state_none;
 }
 
-static inline int key_is_keyboard( int const id )
+VG_STATIC int key_is_keyboard( int const id )
 {
        vg_static_assert( GLFW_MOUSE_BUTTON_LAST < GLFW_KEY_SPACE, 
          "GLFW: Mouse has too many buttons" );
@@ -178,7 +188,7 @@ void vg_update_inputs(void)
        }
 }
 
-static void vg_gamepad_init(void)
+VG_STATIC void vg_gamepad_init(void)
 {
    vg_acquire_thread_sync();
 
@@ -200,6 +210,9 @@ static void vg_gamepad_init(void)
       }
    }
 
+   vg.gamepad.axes[ GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER ] = -1.0f;
+   vg.gamepad.axes[ GLFW_GAMEPAD_AXIS_LEFT_TRIGGER  ] = -1.0f;
+
    vg_release_thread_sync();
 }