From 079e30a87f46b5f12f16bcd4ec0846afdf0dfcab Mon Sep 17 00:00:00 2001 From: Bradley Bell Date: Fri, 9 Jan 2015 19:02:28 -0800 Subject: [PATCH] do away with Joystick.buttons --- arch/include/joy.h | 6 +-- arch/sdl/joy.c | 102 ++------------------------------------------- 2 files changed, 7 insertions(+), 101 deletions(-) diff --git a/arch/include/joy.h b/arch/include/joy.h index 0a5abce1..fc62ac73 100644 --- a/arch/include/joy.h +++ b/arch/include/joy.h @@ -114,15 +114,15 @@ extern int joy_get_btns(); //========================================================================== // This returns the number of times a button went either down or up since // the last call to this function. -extern int joy_get_button_up_cnt(int btn); -extern int joy_get_button_down_cnt(int btn); +#define joy_get_button_up_cnt(btn) key_up_count(KEY_JB1 + (btn)) +#define joy_get_button_down_cnt(btn) key_down_count(KEY_JB1 + (btn)) //========================================================================== // This returns how long (in approximate milliseconds) that each of the // buttons has been held down since the last call to this function. // It is the total time... say you pressed it down for 3 ticks, released // it, and held it down for 6 more ticks. The time returned would be 9. -extern fix joy_get_button_down_time(int btn); +#define joy_get_button_down_time(btn) key_down_time(KEY_JB1 + (btn)) extern ubyte joy_read_raw_buttons(); extern ubyte joystick_read_raw_axis(ubyte mask, int *axis); diff --git a/arch/sdl/joy.c b/arch/sdl/joy.c index a480f914..4293736a 100644 --- a/arch/sdl/joy.c +++ b/arch/sdl/joy.c @@ -36,14 +36,6 @@ int joy_deadzone = 0; int joy_num_axes = 0; -struct joybutton { - int state; - int last_state; - fix time_went_down; - int num_downs; - int num_ups; -}; - struct joyaxis { int value; int min_val; @@ -58,7 +50,6 @@ static struct joyinfo { int n_axes; int n_buttons; struct joyaxis axes[JOY_MAX_AXES]; - struct joybutton buttons[JOY_MAX_BUTTONS]; } Joystick; /* This struct is an array, with one entry for each physical joystick @@ -81,57 +72,16 @@ void joy_button_handler(SDL_JoyButtonEvent *jbe) button = SDL_Joysticks[jbe->which].button_map[jbe->button]; vkey_handler(KEY_JB1 + button, jbe->state == SDL_PRESSED); - - Joystick.buttons[button].state = jbe->state; - - switch (jbe->type) { - case SDL_JOYBUTTONDOWN: - Joystick.buttons[button].time_went_down - = timer_get_fixed_seconds(); - Joystick.buttons[button].num_downs++; - break; - case SDL_JOYBUTTONUP: - Joystick.buttons[button].num_ups++; - break; - } } void joy_hat_handler(SDL_JoyHatEvent *jhe) { int hat = SDL_Joysticks[jhe->which].hat_map[jhe->hat]; - int hbi; vkey_handler(KEY_JB1 + hat + 0, (jhe->value & SDL_HAT_UP ) > 0); vkey_handler(KEY_JB1 + hat + 1, (jhe->value & SDL_HAT_RIGHT) > 0); vkey_handler(KEY_JB1 + hat + 2, (jhe->value & SDL_HAT_DOWN ) > 0); vkey_handler(KEY_JB1 + hat + 3, (jhe->value & SDL_HAT_LEFT ) > 0); - - //Save last state of the hat-button - Joystick.buttons[hat ].last_state = Joystick.buttons[hat ].state; - Joystick.buttons[hat+1].last_state = Joystick.buttons[hat+1].state; - Joystick.buttons[hat+2].last_state = Joystick.buttons[hat+2].state; - Joystick.buttons[hat+3].last_state = Joystick.buttons[hat+3].state; - - //get current state of the hat-button - Joystick.buttons[hat ].state = ((jhe->value & SDL_HAT_UP)>0); - Joystick.buttons[hat+1].state = ((jhe->value & SDL_HAT_RIGHT)>0); - Joystick.buttons[hat+2].state = ((jhe->value & SDL_HAT_DOWN)>0); - Joystick.buttons[hat+3].state = ((jhe->value & SDL_HAT_LEFT)>0); - - //determine if a hat-button up or down event based on state and last_state - for(hbi=0;hbi<4;hbi++) - { - if( !Joystick.buttons[hat+hbi].last_state && Joystick.buttons[hat+hbi].state) //last_state up, current state down - { - Joystick.buttons[hat+hbi].time_went_down - = timer_get_fixed_seconds(); - Joystick.buttons[hat+hbi].num_downs++; - } - else if(Joystick.buttons[hat+hbi].last_state && !Joystick.buttons[hat+hbi].state) //last_state down, current state up - { - Joystick.buttons[hat+hbi].num_ups++; - } - } } void joy_axis_handler(SDL_JoyAxisEvent *jae) @@ -275,11 +225,11 @@ int joy_get_btns() #if 0 // This is never used? int i, buttons = 0; for (i=0; i++; i