mirror of
https://github.com/libretro/RetroArch.git
synced 2026-11-23 00:36:42 -10:00
Three more joypad drivers on the bridge that copies a controller out of its driver once a poll. Each was held first to what the bridge assumes - that get_buttons() says what button() says, that hats and axes answer through button() and axis(), that state() is the common loop - and two of the three were not there yet. linuxraw: get_buttons() copied sixteen of the thirty-two buttons that button() reads. Nothing but the bridge calls a joypad driver's get_buttons(), so it showed nowhere; on the bridge, buttons 16 to 31 would have been dead. It copies all thirty-two. sdl2: it had no get_buttons(). It has one, a walk of the pad's buttons through the call button() makes. A read in this driver is a call into SDL, so here the copy saves those as well: a core that read sixteen buttons one by one made sixteen calls into SDL a frame. xinput, the XInput-only driver (UWP, Xbox, builds without DirectInput): it had no get_buttons() either, and has one, so it is served like the hybrid driver of the same name. While there: for a port with no controller the driver indexed its state table with -1 - button(), axis() and state() all read the entry before the first one before finding it not connected. They return before indexing now. samples/input/joypad_bridge_checked has a test for each, with udev's and DirectInput's: linuxraw's pad table filled by hand; the XInput-only driver's state table filled by hand, under Wine; and for SDL2, which keeps no table to fill, two virtual joysticks given to SDL - one it takes for a game controller, one it does not - opened by the driver as it opens any and set through SDL. Random pads, binds and thresholds: what the bridge would read is what the driver's own button(), axis() and state() say, in all five. With linuxraw's old sixteen-button copy put back, its test reports 93704 disagreements. Not run with a controller, and the XInput-only driver not on the platforms that use it. sdl3 has no get_buttons() and is left reading its driver directly.
40 lines
1.1 KiB
C
40 lines
1.1 KiB
C
/* The linuxraw joypad driver, held to what the snapshot bridge assumes
|
|
* of a driver it serves (see bridge_view.h). The driver source is
|
|
* included for its pad table, which is filled here by hand. */
|
|
#include "../../../input/drivers_joypad/linuxraw_joypad.c"
|
|
|
|
#include "bridge_view.h"
|
|
|
|
int main(void)
|
|
{
|
|
unsigned n, i, bad = 0;
|
|
|
|
for (n = 0; n < 4000; n++)
|
|
{
|
|
struct linuxraw_joypad *pad = &linuxraw_pads[n % 3];
|
|
|
|
pad->fd = 1;
|
|
/* all thirty-two: the upper sixteen are the ones get_buttons()
|
|
* used to leave out */
|
|
pad->buttons = bv_rand();
|
|
for (i = 0; i < NUM_AXES; i++)
|
|
{
|
|
unsigned r = bv_rand() % 8;
|
|
pad->axes[i] = (r == 0) ? 0
|
|
: (r == 1) ? 0x7fff
|
|
: (r == 2) ? -0x7fff
|
|
: (int16_t)bv_rand();
|
|
}
|
|
bad += bv_compare(&linuxraw_joypad, n % 3);
|
|
}
|
|
|
|
if (bad)
|
|
{
|
|
printf("FAIL linuxraw_checked_test: %u disagreements\n", bad);
|
|
return 1;
|
|
}
|
|
printf("PASS linuxraw_checked_test: 4000 random pads; what the bridge would"
|
|
" read is what the driver says\n");
|
|
return 0;
|
|
}
|