Turn input_push_analog_dpad into macro

This commit is contained in:
twinaphex 2016-12-04 21:37:47 +01:00
parent 85aa88f665
commit 6cdb823bb4
2 changed files with 30 additions and 47 deletions

View File

@ -252,46 +252,6 @@ float input_sensor_get_input(unsigned port, unsigned id)
return 0.0f;
}
/**
* input_push_analog_dpad:
* @binds : Binds to modify.
* @mode : Which analog stick to bind D-Pad to.
* E.g:
* ANALOG_DPAD_LSTICK
* ANALOG_DPAD_RSTICK
*
* Push analog to D-Pad mappings to binds.
**/
void input_push_analog_dpad(struct retro_keybind *binds, enum analog_dpad_mode mode)
{
unsigned i;
unsigned x_plus = RARCH_ANALOG_RIGHT_X_PLUS;
unsigned y_plus = RARCH_ANALOG_RIGHT_Y_PLUS;
unsigned x_minus = RARCH_ANALOG_RIGHT_X_MINUS;
unsigned y_minus = RARCH_ANALOG_RIGHT_Y_MINUS;
if (mode == ANALOG_DPAD_LSTICK)
{
x_plus = RARCH_ANALOG_LEFT_X_PLUS;
y_plus = RARCH_ANALOG_LEFT_Y_PLUS;
x_minus = RARCH_ANALOG_LEFT_X_MINUS;
y_minus = RARCH_ANALOG_LEFT_Y_MINUS;
}
if (!(
( binds[x_plus].joyaxis == binds[x_minus].joyaxis) ||
( binds[y_plus].joyaxis == binds[y_minus].joyaxis)
)
)
{
unsigned j = x_plus + 3;
/* Inherit joyaxis from analogs. */
for (i = RETRO_DEVICE_ID_JOYPAD_UP; i <= RETRO_DEVICE_ID_JOYPAD_RIGHT; i++)
binds[i].joyaxis = binds[j--].joyaxis;
}
}
/**
* input_translate_coord_viewport:
* @mouse_x : Pointer X coordinate.

View File

@ -179,12 +179,7 @@ bool input_translate_coord_viewport(int mouse_x, int mouse_y,
int16_t *res_x, int16_t *res_y, int16_t *res_screen_x,
int16_t *res_screen_y);
#define input_push_analog_dpad_pre(binds) \
{ \
unsigned k; \
for (k = RETRO_DEVICE_ID_JOYPAD_UP; k <= RETRO_DEVICE_ID_JOYPAD_RIGHT; k++) \
(binds)[k].orig_joyaxis = (binds)[k].joyaxis; \
}
#define inherit_joyaxis(binds) (((binds)[x_plus].joyaxis == (binds)[x_minus].joyaxis) || ( (binds)[y_plus].joyaxis == (binds)[y_minus].joyaxis))
/**
* input_push_analog_dpad:
@ -196,7 +191,35 @@ bool input_translate_coord_viewport(int mouse_x, int mouse_y,
*
* Push analog to D-Pad mappings to binds.
**/
void input_push_analog_dpad(struct retro_keybind *binds, enum analog_dpad_mode mode);
#define input_push_analog_dpad(binds, mode) \
{ \
unsigned k; \
unsigned x_plus = RARCH_ANALOG_RIGHT_X_PLUS; \
unsigned y_plus = RARCH_ANALOG_RIGHT_Y_PLUS; \
unsigned x_minus = RARCH_ANALOG_RIGHT_X_MINUS; \
unsigned y_minus = RARCH_ANALOG_RIGHT_Y_MINUS; \
if ((mode) == ANALOG_DPAD_LSTICK) \
{ \
x_plus = RARCH_ANALOG_LEFT_X_PLUS; \
y_plus = RARCH_ANALOG_LEFT_Y_PLUS; \
x_minus = RARCH_ANALOG_LEFT_X_MINUS; \
y_minus = RARCH_ANALOG_LEFT_Y_MINUS; \
} \
if (!inherit_joyaxis(binds)) \
{ \
unsigned j = x_plus + 3; \
/* Inherit joyaxis from analogs. */ \
for (k = RETRO_DEVICE_ID_JOYPAD_UP; k <= RETRO_DEVICE_ID_JOYPAD_RIGHT; k++) \
(binds)[k].joyaxis = (binds)[j--].joyaxis; \
} \
}
#define input_push_analog_dpad_pre(binds) \
{ \
unsigned k; \
for (k = RETRO_DEVICE_ID_JOYPAD_UP; k <= RETRO_DEVICE_ID_JOYPAD_RIGHT; k++) \
(binds)[k].orig_joyaxis = (binds)[k].joyaxis; \
}
/**
* input_pop_analog_dpad: