Standardize input lightgun code

This commit is contained in:
twinaphex 2020-06-11 16:58:49 +02:00
parent f9c771b4a8
commit cd01e0a048
4 changed files with 40 additions and 18 deletions

View File

@ -409,19 +409,27 @@ static int16_t rwebinput_pointer_device_state(rwebinput_mouse_state_t *mouse,
res_y = res_screen_y;
}
inside = (res_x >= -0x7fff) && (res_y >= -0x7fff);
if (!inside)
return 0;
inside = (res_x >= -edge_detect)
&& (res_y >= -edge_detect)
&& (res_x <= edge_detect)
&& (res_y <= edge_detect);
switch (id)
{
case RETRO_DEVICE_ID_POINTER_X:
return res_x;
if (inside)
return res_x;
break;
case RETRO_DEVICE_ID_POINTER_Y:
return res_y;
if (inside)
return res_y;
break;
case RETRO_DEVICE_ID_POINTER_PRESSED:
return !!(mouse->buttons & (1 << RWEBINPUT_MOUSE_BTNL));
case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN:
return !inside;
default:
break;
}
return 0;

View File

@ -178,10 +178,10 @@ static int16_t sdl_pointer_device_state(sdl_input_t *sdl,
res_y = res_screen_y;
}
inside = (res_x >= -0x7fff) && (res_y >= -0x7fff);
if (!inside)
return 0;
inside = (res_x >= -edge_detect)
&& (res_y >= -edge_detect)
&& (res_x <= edge_detect)
&& (res_y <= edge_detect);
switch (id)
{
@ -191,6 +191,8 @@ static int16_t sdl_pointer_device_state(sdl_input_t *sdl,
return res_y;
case RETRO_DEVICE_ID_POINTER_PRESSED:
return sdl->mouse_l;
case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN:
return !inside;
}
return 0;

View File

@ -216,17 +216,22 @@ static int16_t input_wl_pointer_state(input_ctx_wayland_data_t *wl,
inside = (res_x >= -0x7fff) && (res_y >= -0x7fff);
if (!inside)
return 0;
switch (id)
{
case RETRO_DEVICE_ID_POINTER_X:
return res_x;
if (inside)
return res_x;
break;
case RETRO_DEVICE_ID_POINTER_Y:
return res_y;
if (inside)
return res_y;
break;
case RETRO_DEVICE_ID_POINTER_PRESSED:
return wl->mouse.left;
case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN:
return !inside;
default:
break;
}
return 0;

View File

@ -198,14 +198,21 @@ static int16_t x_lightgun_aiming_state(
&res_x, &res_y, &res_screen_x, &res_screen_y)))
return 0;
inside = (res_x >= -edge_detect) && (res_y >= -edge_detect) && (res_x <= edge_detect) && (res_y <= edge_detect);
inside = (res_x >= -edge_detect)
&& (res_y >= -edge_detect)
&& (res_x <= edge_detect)
&& (res_y <= edge_detect);
switch ( id )
{
case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X:
return inside ? res_x : 0;
if (inside)
return res_x;
break;
case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y:
return inside ? res_y : 0;
if (inside)
return res_y;
break;
case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN:
return !inside;
default: