Implement bindings for keyboard and controller button input in libretro builds

This commit is contained in:
刘皓 2025-05-02 14:53:21 -04:00
parent c9e7c4d02d
commit df1dbccf5a
No known key found for this signature in database
GPG key ID: 7901753DB465B711
3 changed files with 910 additions and 102 deletions

View file

@ -30,6 +30,7 @@
#include "mkxp-polyfill.h" // std::mutex
#include "git-hash.h"
#include "core.h"
#include "binding-sandbox.h"
#include "al-util.h"
@ -158,6 +159,7 @@ namespace mkxp_retro {
retro_input_state_t input_state;
struct retro_perf_callback perf;
retro_hw_render_callback hw_render;
bool keyboard_state[RETROK_LAST];
bool input_polled;
uint64_t get_ticks_ms() noexcept {
@ -427,6 +429,16 @@ extern "C" RETRO_API void retro_set_environment(retro_environment_t cb) {
log_printf = fallback_log;
}
static const struct retro_keyboard_callback keyboard = {
.callback = [](bool down, unsigned int keycode, uint32_t character, uint16_t key_modifiers) {
if (keycode < RETROK_LAST) {
keyboard_state[keycode] = down;
}
}
};
std::memset(keyboard_state, 0, sizeof keyboard_state);
cb(RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK, (void *)&keyboard);
perf = {
.get_time_usec = nullptr,
.get_cpu_features = nullptr,

View file

@ -42,6 +42,7 @@ namespace mkxp_retro {
extern retro_input_state_t input_state;
extern struct retro_perf_callback perf;
extern struct retro_hw_render_callback hw_render;
extern bool keyboard_state[RETROK_LAST];
extern bool input_polled;
uint64_t get_ticks_ms() noexcept;

File diff suppressed because it is too large Load diff