Propagate for variables in common/arch/sdl/joy.cpp
This commit is contained in:
parent
b642c1ba43
commit
e2d6174694
|
@ -76,7 +76,6 @@ void joy_button_handler(SDL_JoyButtonEvent *jbe)
|
||||||
void joy_hat_handler(SDL_JoyHatEvent *jhe)
|
void joy_hat_handler(SDL_JoyHatEvent *jhe)
|
||||||
{
|
{
|
||||||
int hat = SDL_Joysticks[jhe->which].hat_map[jhe->hat];
|
int hat = SDL_Joysticks[jhe->which].hat_map[jhe->hat];
|
||||||
int hbi;
|
|
||||||
d_event_joystickbutton event;
|
d_event_joystickbutton event;
|
||||||
|
|
||||||
//Save last state of the hat-button
|
//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);
|
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
|
//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
|
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()
|
void joy_init()
|
||||||
{
|
{
|
||||||
int i,j,n;
|
int n;
|
||||||
|
|
||||||
if (SDL_Init(SDL_INIT_JOYSTICK) < 0) {
|
if (SDL_Init(SDL_INIT_JOYSTICK) < 0) {
|
||||||
con_printf(CON_NORMAL, "sdl-joystick: initialisation failed: %s.",SDL_GetError());
|
con_printf(CON_NORMAL, "sdl-joystick: initialisation failed: %s.",SDL_GetError());
|
||||||
|
@ -150,7 +149,7 @@ void joy_init()
|
||||||
n = SDL_NumJoysticks();
|
n = SDL_NumJoysticks();
|
||||||
|
|
||||||
con_printf(CON_NORMAL, "sdl-joystick: found %d joysticks", n);
|
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));
|
con_printf(CON_NORMAL, "sdl-joystick %d: %s", i, SDL_JoystickName(i));
|
||||||
SDL_Joysticks[num_joysticks].handle = SDL_JoystickOpen(i);
|
SDL_Joysticks[num_joysticks].handle = SDL_JoystickOpen(i);
|
||||||
if (SDL_Joysticks[num_joysticks].handle) {
|
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);
|
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);
|
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);
|
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++;
|
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));
|
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);
|
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++;
|
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;
|
SDL_Joysticks[num_joysticks].hat_map[j] = Joystick.n_buttons;
|
||||||
//a hat counts as four 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()
|
void joy_flush()
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
|
|
||||||
if (!num_joysticks)
|
if (!num_joysticks)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (i = 0; i < Joystick.n_buttons; i++)
|
for (int i = 0; i < Joystick.n_buttons; i++)
|
||||||
Joystick.button_state[i] = SDL_RELEASED;
|
Joystick.button_state[i] = SDL_RELEASED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue