X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=input.h;fp=input.h;h=c6710f2696809e56b2c05b375cc78eef6b6a09bb;hb=b3ca3b7a45eec11c46eb19772e10021177665adb;hp=0000000000000000000000000000000000000000;hpb=c34dde859968ced3dc7e8dd7be29f676689813d3;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/input.h b/input.h new file mode 100644 index 0000000..c6710f2 --- /dev/null +++ b/input.h @@ -0,0 +1,174 @@ +#ifndef INPUT_H +#define INPUT_H + +#define VG_GAME +#include "vg/vg.h" +#include "vg/vg_platform.h" +#include "vg/vg_console.h" +#include "vg/vg_input.h" +#include "vg/vg_m.h" +#include "conf.h" + +enum sr_bind{ + k_srbind_jump = 0, + k_srbind_push, + k_srbind_trick0, + k_srbind_trick1, + k_srbind_trick2, + k_srbind_use, + k_srbind_reset, + k_srbind_camera, + k_srbind_mleft, + k_srbind_mright, + k_srbind_mup, + k_srbind_mdown, + k_srbind_mback, + k_srbind_maccept, + k_srbind_max +}; + +struct { + v2f joy_steer, + joy_grab, + joy_look; + + float axis_grab; + + u8 button_states[ k_srbind_max ][2]; + float repeaters[4]; +} +static srinput; + +static int button_down( enum sr_bind button ) +{ + if( vg_console.enabled ) + return 0; + + if( vg.engine_stage == k_engine_stage_update_fixed ) + if( vg.fixed_iterations > 0 ) + return 0; + + if( srinput.button_states[ button ][0] && + !srinput.button_states[ button ][1] ) + return 1; + else + return 0; +} + +static int button_up( enum sr_bind button ) +{ + if( vg_console.enabled ) + return 0; + + if( vg.engine_stage == k_engine_stage_update_fixed ) + if( vg.fixed_iterations > 0 ) + return 0; + + if( !srinput.button_states[ button ][0] && + srinput.button_states[ button ][1] ) + return 1; + else + return 0; +} + +static int button_press( enum sr_bind button ) +{ + if( vg_console.enabled ) + return 0; + + return srinput.button_states[ button ][0]; +} + +static void setbtn( enum sr_bind button, u8 value ) +{ + srinput.button_states[button][0] |= value; +} + +static void skaterift_preupdate_inputs(void) +{ + for( u32 i=0; ibuttons; + setbtn( k_srbind_jump, buttons[ SDL_CONTROLLER_BUTTON_A ] ); + setbtn( k_srbind_push, buttons[ SDL_CONTROLLER_BUTTON_B ] ); + setbtn( k_srbind_trick0, buttons[ SDL_CONTROLLER_BUTTON_A ] ); + setbtn( k_srbind_trick1, buttons[ SDL_CONTROLLER_BUTTON_B ] ); + setbtn( k_srbind_trick2, buttons[ SDL_CONTROLLER_BUTTON_X ] ); + setbtn( k_srbind_use, buttons[ SDL_CONTROLLER_BUTTON_Y ] ); + setbtn( k_srbind_reset, buttons[ SDL_CONTROLLER_BUTTON_LEFTSHOULDER ] ); + setbtn( k_srbind_camera, buttons[ SDL_CONTROLLER_BUTTON_RIGHTSHOULDER ] ); + setbtn( k_srbind_mleft, buttons[ SDL_CONTROLLER_BUTTON_DPAD_LEFT ] ); + setbtn( k_srbind_mright, buttons[ SDL_CONTROLLER_BUTTON_DPAD_RIGHT ] ); + setbtn( k_srbind_mup, buttons[ SDL_CONTROLLER_BUTTON_DPAD_UP ] ); + setbtn( k_srbind_mdown, buttons[ SDL_CONTROLLER_BUTTON_DPAD_DOWN ] ); + + float *axis = controller->axises; + + srinput.joy_steer[0] += axis[ SDL_CONTROLLER_AXIS_LEFTX ], + srinput.joy_steer[1] += axis[ SDL_CONTROLLER_AXIS_LEFTY ], + srinput.joy_look[0] += axis[ SDL_CONTROLLER_AXIS_RIGHTX ]; + srinput.joy_look[1] += axis[ SDL_CONTROLLER_AXIS_RIGHTY ]; + srinput.joy_grab[0] += axis[ SDL_CONTROLLER_AXIS_RIGHTX ]; + srinput.joy_grab[1] += axis[ SDL_CONTROLLER_AXIS_RIGHTY ]; + srinput.axis_grab += vg_maxf( 0.0f, + axis[ SDL_CONTROLLER_AXIS_TRIGGERRIGHT ] ); + + float lh = axis[ SDL_CONTROLLER_AXIS_LEFTX ], + lv = axis[ SDL_CONTROLLER_AXIS_LEFTY ], + sensitivity = 0.35f; + + if( lh > sensitivity ) setbtn( k_srbind_mright, 1 ); + if( lh < -sensitivity ) setbtn( k_srbind_mleft, 1 ); + if( lv > sensitivity ) setbtn( k_srbind_mup, 1 ); + if( lv < -sensitivity ) setbtn( k_srbind_mdown, 1 ); + } + + //v2_normalize_clamp( srinput.joy_steer ); + //v2_normalize_clamp( srinput.joy_grab ); + srinput.axis_grab = vg_minf( 1.0f, srinput.axis_grab ); +} + +#endif /* INPUT_H */