Skip to content

Commit

Permalink
Implement new lightgun API
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddenasbestos committed Nov 26, 2017
1 parent 816ffe6 commit 59c188f
Showing 1 changed file with 101 additions and 20 deletions.
121 changes: 101 additions & 20 deletions input/drivers/dinput.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,27 +369,67 @@ static bool dinput_meta_key_pressed(void *data, int key)
return false;
}

static int16_t dinput_lightgun_state(struct dinput_input *di, unsigned id)
static int16_t dinput_lightgun_aiming_state( struct dinput_input *di, unsigned idx, unsigned id )
{
switch (id)
{
case RETRO_DEVICE_ID_LIGHTGUN_X:
return di->mouse_rel_x;
case RETRO_DEVICE_ID_LIGHTGUN_Y:
return di->mouse_rel_y;
case RETRO_DEVICE_ID_LIGHTGUN_TRIGGER:
return di->mouse_l;
case RETRO_DEVICE_ID_LIGHTGUN_CURSOR:
return di->mouse_m;
case RETRO_DEVICE_ID_LIGHTGUN_TURBO:
return di->mouse_r;
case RETRO_DEVICE_ID_LIGHTGUN_START:
return di->mouse_m && di->mouse_r;
case RETRO_DEVICE_ID_LIGHTGUN_PAUSE:
return di->mouse_m && di->mouse_l;
}
const int edge_detect = 32700;
struct video_viewport vp;
bool inside = false;
int x = 0;
int y = 0;
int16_t res_x = 0;
int16_t res_y = 0;
int16_t res_screen_x = 0;
int16_t res_screen_y = 0;
unsigned num = 0;

struct pointer_status* check_pos = di->pointer_head.next;

vp.x = 0;
vp.y = 0;
vp.width = 0;
vp.height = 0;
vp.full_width = 0;
vp.full_height = 0;

while ( check_pos && num < idx )
{
num++;
check_pos = check_pos->next;
}

return 0;
if ( !check_pos && idx > 0 ) /* idx = 0 has mouse fallback. */
return 0;

x = di->mouse_x;
y = di->mouse_y;

if ( check_pos )
{
x = check_pos->pointer_x;
y = check_pos->pointer_y;
}

if ( !( video_driver_translate_coord_viewport_wrap(
&vp, x, y, &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);

switch ( id )
{
case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X:
return inside ? res_x : 0;
case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y:
return inside ? res_y : 0;
case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN:
return !inside;
default:
break;
}

return 0;
}

static int16_t dinput_mouse_state(struct dinput_input *di, unsigned port, unsigned id)
Expand Down Expand Up @@ -583,7 +623,48 @@ static int16_t dinput_input_state(void *data,
device == RARCH_DEVICE_POINTER_SCREEN);

case RETRO_DEVICE_LIGHTGUN:
return dinput_lightgun_state(di, id);
switch ( id )
{
/*aiming*/
case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X:
case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y:
case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN:
return dinput_lightgun_aiming_state( di, idx, id );

/*buttons*/
case RETRO_DEVICE_ID_LIGHTGUN_TRIGGER:
return dinput_is_pressed(di, joypad_info, binds[port], port, RARCH_LIGHTGUN_TRIGGER);
case RETRO_DEVICE_ID_LIGHTGUN_RELOAD:
return dinput_is_pressed(di, joypad_info, binds[port], port, RARCH_LIGHTGUN_RELOAD);
case RETRO_DEVICE_ID_LIGHTGUN_AUX_A:
return dinput_is_pressed(di, joypad_info, binds[port], port, RARCH_LIGHTGUN_AUX_A);
case RETRO_DEVICE_ID_LIGHTGUN_AUX_B:
return dinput_is_pressed(di, joypad_info, binds[port], port, RARCH_LIGHTGUN_AUX_B);
case RETRO_DEVICE_ID_LIGHTGUN_AUX_C:
return dinput_is_pressed(di, joypad_info, binds[port], port, RARCH_LIGHTGUN_AUX_C);
case RETRO_DEVICE_ID_LIGHTGUN_START:
return dinput_is_pressed(di, joypad_info, binds[port], port, RARCH_LIGHTGUN_START);
case RETRO_DEVICE_ID_LIGHTGUN_SELECT:
return dinput_is_pressed(di, joypad_info, binds[port], port, RARCH_LIGHTGUN_SELECT);
case RETRO_DEVICE_ID_LIGHTGUN_DPAD_UP:
return dinput_is_pressed(di, joypad_info, binds[port], port, RARCH_LIGHTGUN_DPAD_UP);
case RETRO_DEVICE_ID_LIGHTGUN_DPAD_DOWN:
return dinput_is_pressed(di, joypad_info, binds[port], port, RARCH_LIGHTGUN_DPAD_DOWN);
case RETRO_DEVICE_ID_LIGHTGUN_DPAD_LEFT:
return dinput_is_pressed(di, joypad_info, binds[port], port, RARCH_LIGHTGUN_DPAD_LEFT);
case RETRO_DEVICE_ID_LIGHTGUN_DPAD_RIGHT:
return dinput_is_pressed(di, joypad_info, binds[port], port, RARCH_LIGHTGUN_DPAD_RIGHT);

/*deprecated*/
case RETRO_DEVICE_ID_LIGHTGUN_X:
return di->mouse_rel_x;
case RETRO_DEVICE_ID_LIGHTGUN_Y:
return di->mouse_rel_y;
case RETRO_DEVICE_ID_LIGHTGUN_PAUSE:
return dinput_is_pressed(di, joypad_info, binds[port], port, RARCH_LIGHTGUN_START);

}
break;
}

return 0;
Expand Down

0 comments on commit 59c188f

Please sign in to comment.