Configurable keyboard mappings

This commit is contained in:
offtkp 2024-03-16 02:54:56 +02:00
parent 27ad7b01f3
commit e576e64736
9 changed files with 162 additions and 125 deletions

23
include/mappings.hpp Normal file
View file

@ -0,0 +1,23 @@
#pragma once
#include <unordered_map>
#include "helpers.hpp"
#include "services/hid.hpp"
struct InputMappings {
using Scancode = u32;
using Container = std::unordered_map<Scancode, u32>;
u32 getMapping(Scancode scancode) const {
auto it = container.find(scancode);
return it != container.end() ? it->second : HID::Keys::Null;
}
void setMapping(Scancode scancode, u32 key) { container[scancode] = key; }
static InputMappings DefaultKeyboardMappings();
private:
Container container;
};

View file

@ -11,6 +11,7 @@
#include <vector>
#include "emulator.hpp"
#include "mappings.hpp"
#include "panda_qt/about_window.hpp"
#include "panda_qt/config_window.hpp"
#include "panda_qt/cheats_window.hpp"
@ -80,6 +81,7 @@ class MainWindow : public QMainWindow {
// This would normally be an std::unique_ptr but it's shared between threads so definitely not
Emulator* emu = nullptr;
InputMappings keyboardMappings;
std::thread emuThread;
std::atomic<bool> appRunning = true; // Is the application itself running?

View file

@ -5,9 +5,11 @@
#include <filesystem>
#include "emulator.hpp"
#include "mappings.hpp"
class FrontendSDL {
Emulator emu;
InputMappings keyboardMappings;
#ifdef PANDA3DS_ENABLE_OPENGL
SDL_GLContext glContext;
#endif
@ -16,6 +18,7 @@ class FrontendSDL {
FrontendSDL();
bool loadROM(const std::filesystem::path& path);
void run();
u32 getMapping(InputMappings::Scancode scancode) { return keyboardMappings.getMapping(scancode); }
SDL_Window* window = nullptr;
SDL_GameController* gameController = nullptr;

View file

@ -10,6 +10,7 @@
namespace HID::Keys {
enum : u32 {
Null = 0,
A = 1 << 0,
B = 1 << 1,
Select = 1 << 2,