mirror of
https://github.com/libretro/RetroArch.git
synced 2026-11-25 03:25:16 -10:00
A core calls set_rumble_state and set_led_state from inside retro_run(), and both went straight to the driver: an ioctl or a transfer for a motor; for an LED a sysfs open, write and close, an X11 round trip, or an injected key press. As many times a frame as the core called, on the core's own stack. A core that reports its rumble level every frame paid for a device write every frame, and one that sets it several times a frame paid for each. The calls now store what was asked for (input/input_output_store.h), and the frame loop writes it once the core has run: one driver call for each motor or LED that was set, with the frame's last value. - An output set to the value it already had is still written once that frame. Drivers whose effects run out rely on a core repeating itself, so the store remembers that a slot was set, not only what to. - The write happens after the cheats, which can rumble too, and so after run-ahead and netplay replays: several runs of the core in one iterate are one write. - What a core sets while loading or unloading is written when that call returns. No frame follows an unload to write an LED it turned off. - CMD_EVENT_RUMBLE_STOP writes its zeros at once, as before, and drops whatever was waiting so it cannot restart a motor. - Posting is safe from any thread, since some cores call from one of their own; the driver is now only ever called from the main thread. What a core can notice: - A motor or LED changes up to a frame later than it did: at the end of the frame in which the core asked, not in the middle of it. - set_rumble_state returns what the driver answered the last time that motor was written, and before the first write whether a driver with motors is loaded, where it used to return the answer to this very call. The port and effect are now checked: a port past MAX_USERS indexed the joypad-index setting out of bounds. This is the first part of the output scheduler in the input plan (WP-09). The write is still on the main thread; moving it to the device's own thread comes with per-device sessions. Tests: - samples/input/output_store builds the store on a host: a post writes nothing, many posts in a frame are one write with the last value, a repeat is still written, a drop forgets, and with three threads posting against a taker every output ends on its last value. Run under ASan + UBSan and under TSan. - samples/runloop/frontend_overhead gains a lane in which the harness core makes six rumble calls a frame and the joypad driver's set_rumble is counted. Before: 1800 calls, 1800 driver writes inside retro_run(). After: none inside, one per motor after it, each with the last strength; a stop writes zeros and leaves nothing behind. The frame costs 2.9 us in the harness before and after. Compiled through the Android unity build; the menu harnesses pass.
56 lines
1.5 KiB
C
56 lines
1.5 KiB
C
/* RetroArch - A frontend for libretro.
|
|
*
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
*
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef __LED_DRIVER__H
|
|
#define __LED_DRIVER__H
|
|
|
|
#include <stdint.h>
|
|
#include <stdlib.h>
|
|
#include <stddef.h>
|
|
#include <sys/types.h>
|
|
|
|
#include <boolean.h>
|
|
#include <libretro.h>
|
|
#include <retro_common_api.h>
|
|
#include <retro_environment.h>
|
|
|
|
RETRO_BEGIN_DECLS
|
|
|
|
typedef struct led_driver
|
|
{
|
|
void (*init)(void);
|
|
void (*free)(void);
|
|
void (*set_led)(int led, int value);
|
|
const char *ident;
|
|
} led_driver_t;
|
|
|
|
void led_driver_init(const char *led_driver);
|
|
|
|
void led_driver_free(void);
|
|
|
|
void led_driver_set_led(int led, int value);
|
|
|
|
/* Write the LED states a core's calls left this frame. Main thread,
|
|
* once the core has run. */
|
|
void led_driver_flush(void);
|
|
|
|
extern const led_driver_t overlay_led_driver;
|
|
extern const led_driver_t rpi_led_driver;
|
|
extern const led_driver_t keyboard_led_driver;
|
|
extern const led_driver_t sys_led_driver;
|
|
|
|
RETRO_END_DECLS
|
|
|
|
#endif
|