diff --git a/common/arch/sdl/joy.cpp b/common/arch/sdl/joy.cpp index 14210f049..d1eb00d4f 100644 --- a/common/arch/sdl/joy.cpp +++ b/common/arch/sdl/joy.cpp @@ -76,7 +76,6 @@ void joy_button_handler(SDL_JoyButtonEvent *jbe) void joy_hat_handler(SDL_JoyHatEvent *jhe) { int hat = SDL_Joysticks[jhe->which].hat_map[jhe->hat]; - int hbi; d_event_joystickbutton event; //Save last state of the hat-button @@ -92,7 +91,7 @@ void joy_hat_handler(SDL_JoyHatEvent *jhe) Joystick.button_state[hat+3] = ((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++) + for(int hbi=0;hbi<4;hbi++) { if( !Joystick.button_last_state[hat+hbi] && Joystick.button_state[hat+hbi]) //last_state up, current state down { @@ -136,7 +135,7 @@ int joy_axis_handler(SDL_JoyAxisEvent *jae) void joy_init() { - int i,j,n; + int n; if (SDL_Init(SDL_INIT_JOYSTICK) < 0) { con_printf(CON_NORMAL, "sdl-joystick: initialisation failed: %s.",SDL_GetError()); @@ -150,7 +149,7 @@ void joy_init() n = SDL_NumJoysticks(); con_printf(CON_NORMAL, "sdl-joystick: found %d joysticks", n); - for (i = 0; i < n; i++) { + for (int i = 0; i < n; i++) { con_printf(CON_NORMAL, "sdl-joystick %d: %s", i, SDL_JoystickName(i)); SDL_Joysticks[num_joysticks].handle = SDL_JoystickOpen(i); if (SDL_Joysticks[num_joysticks].handle) { @@ -184,18 +183,18 @@ void joy_init() con_printf(CON_NORMAL, "sdl-joystick: %d hats", SDL_Joysticks[num_joysticks].n_hats); joyaxis_text.resize(joyaxis_text.size() + SDL_Joysticks[num_joysticks].n_axes); - for (j=0; j < SDL_Joysticks[num_joysticks].n_axes; j++) + for (int j=0; j < SDL_Joysticks[num_joysticks].n_axes; j++) { snprintf(&joyaxis_text[Joystick.n_axes][0], sizeof(joyaxis_text[Joystick.n_axes]), "J%d A%d", i + 1, j + 1); SDL_Joysticks[num_joysticks].axis_map[j] = Joystick.n_axes++; } joybutton_text.resize(joybutton_text.size() + SDL_Joysticks[num_joysticks].n_buttons + (4 * SDL_Joysticks[num_joysticks].n_hats)); - for (j=0; j < SDL_Joysticks[num_joysticks].n_buttons; j++) + for (int j=0; j < SDL_Joysticks[num_joysticks].n_buttons; j++) { snprintf(&joybutton_text[Joystick.n_buttons][0], sizeof(joybutton_text[Joystick.n_buttons]), "J%d B%d", i + 1, j + 1); SDL_Joysticks[num_joysticks].button_map[j] = Joystick.n_buttons++; } - for (j=0; j < SDL_Joysticks[num_joysticks].n_hats; j++) + for (int j=0; j < SDL_Joysticks[num_joysticks].n_hats; j++) { SDL_Joysticks[num_joysticks].hat_map[j] = Joystick.n_buttons; //a hat counts as four buttons @@ -233,12 +232,10 @@ void event_joystick_get_axis(d_event *event, int *axis, int *value) void joy_flush() { - int i; - if (!num_joysticks) return; - for (i = 0; i < Joystick.n_buttons; i++) + for (int i = 0; i < Joystick.n_buttons; i++) Joystick.button_state[i] = SDL_RELEASED; }