X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=vg%2Fvg.h;h=bd518c48bf6cea24de85413027c300f945f9b01c;hb=75e990f8ee2499b86106a2634eb6f30db773cbc0;hp=b7abeb634dfeb9f158d4270024d162899ae6d426;hpb=55a8be84b66e264a6af476689f9499f41cc98e64;p=fishladder.git diff --git a/vg/vg.h b/vg/vg.h index b7abeb6..bd518c4 100644 --- a/vg/vg.h +++ b/vg/vg.h @@ -28,19 +28,7 @@ m3x3f vg_pv; #ifndef VG_TOOLS -#include "vg/vg_audio.h" -#include "vg/vg_shader.h" -#include "vg/vg_lines.h" -#include "vg/vg_tex.h" - -#include "steam/steamworks_thin.h" - -static inline float vg_get_axis( const char *axis ) __attribute__((unused)); -static inline int vg_get_button( const char *button ) __attribute__((unused)); -static inline int vg_get_button_down( const char *button ) __attribute__((unused)); -static inline int vg_get_button_up( const char *button ) __attribute__((unused)); - -// Globals +// Engine globals GLFWwindow* vg_window; int vg_window_x = 1280; int vg_window_y = 720; @@ -52,141 +40,15 @@ float vg_time; float vg_time_last; float vg_time_delta; -// Input -// =========================================================================================================== -GLFWgamepadstate vg_gamepad; -int vg_gamepad_ready = 0; -const char *vg_gamepad_name = NULL; -int vg_gamepad_id; - -enum EInputMode -{ - k_EInputMode_pc, - k_EInputMode_gamepad -} -vg_input_mode; - -static struct axis_binding -{ - const char *name; - union - { - int positive; - int bind; - }; - int negative; - - float value; -} -vg_axis_binds[]; - -static struct button_binding -{ - const char *name; - int bind; - - int value; int prev; -} -vg_button_binds[]; - -#include "vg/config.h" - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wreturn-type" - -static inline 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 ) -{ - for( int i = 0; i < vg_list_size( vg_button_binds ); i ++ ) - { - if( !strcmp( button, vg_button_binds[i].name ) ) - { - return vg_button_binds + i; - } - } -} -#pragma GCC diagnostic pop - -static inline int vg_get_button( const char *button ) -{ - return vg_get_button_ptr( button )->value; -} - -static inline int vg_get_button_down( const char *button ) -{ - struct button_binding *bind = vg_get_button_ptr( button ); - return bind->value & (bind->value ^ bind->prev); -} - -static inline int vg_get_button_up( const char *button ) -{ - struct button_binding *bind = vg_get_button_ptr( button ); - return bind->prev & (bind->value ^ bind->prev); -} - -static inline int key_is_keyboard( int const id ) -{ - vg_static_assert( GLFW_MOUSE_BUTTON_LAST < GLFW_KEY_SPACE, "GLFW: Mouse has too many buttons" ); - return id > GLFW_MOUSE_BUTTON_LAST; -} - -// Mouse AND Keyboard get button press -int get_button_cross_device( int const id ) -{ - if( key_is_keyboard( id ) ) - { - return glfwGetKey( vg_window, id ); - } - else - { - return glfwGetMouseButton( vg_window, id ) == GLFW_PRESS; - } -} +// Engine components +#include "vg/vg_audio.h" +#include "vg/vg_shader.h" +#include "vg/vg_lines.h" +#include "vg/vg_tex.h" +#include "vg/vg_input.h" +#include "vg/vg_ui.h" -void vg_update_inputs(void) -{ - // Update button inputs - for( int i = 0; i < vg_list_size( vg_button_binds ); i ++ ) - { - struct button_binding *binding = vg_button_binds + i; - binding->prev = binding->value; - - if( vg_input_mode == k_EInputMode_pc ) - { - binding->value = get_button_cross_device( binding->bind ); - } - else - { - 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; - - if( vg_input_mode == k_EInputMode_pc ) - { - binding->value = get_button_cross_device( binding->positive ); - binding->value -= get_button_cross_device( binding->negative ); - } - else - { - binding->value = vg_gamepad.axes[ binding->bind ]; - } - } -} +#include "steam/steamworks_thin.h" // Engine main // =========================================================================================================== @@ -348,6 +210,8 @@ static void vg_init( int argc, char *argv[], const char *window_name ) vg_register_exit( &vg_audio_free, "vg_audio_free" ); vg_lines_init(); vg_register_exit( &vg_lines_free, "vg_lines_free" ); + ui_default_init(); + vg_register_exit( &ui_default_free, "UI" ); vg_register(); vg_register_exit( &vg_free, "vg_free" ); @@ -373,7 +237,7 @@ static void vg_init( int argc, char *argv[], const char *window_name ) vg_update(); vg_render(); - vg_lines_drawall(); + vg_lines_drawall((float*)vg_pv); vg_ui();