yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
input_backend.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EMU_INPUT_INPUT_BACKEND_H_
2#define YAZE_APP_EMU_INPUT_INPUT_BACKEND_H_
3
4#include <cstdint>
5#include <memory>
6#include <string>
7
8namespace yaze {
9namespace emu {
10namespace input {
11
15enum class SnesButton : uint8_t {
16 B = 0, // Bit 0
17 Y = 1, // Bit 1
18 SELECT = 2, // Bit 2
19 START = 3, // Bit 3
20 UP = 4, // Bit 4
21 DOWN = 5, // Bit 5
22 LEFT = 6, // Bit 6
23 RIGHT = 7, // Bit 7
24 A = 8, // Bit 8
25 X = 9, // Bit 9
26 L = 10, // Bit 10
27 R = 11 // Bit 11
28};
29
34 uint16_t buttons = 0; // Bit field matching SNES hardware layout
35
36 bool IsPressed(SnesButton button) const {
37 return (buttons & (1 << static_cast<uint8_t>(button))) != 0;
38 }
39
40 void SetButton(SnesButton button, bool pressed) {
41 if (pressed) {
42 buttons |= (1 << static_cast<uint8_t>(button));
43 } else {
44 buttons &= ~(1 << static_cast<uint8_t>(button));
45 }
46 }
47
48 void Clear() { buttons = 0; }
49};
50
55 // Platform-agnostic key codes (mapped to platform-specific in backend)
56 // Using generic names that can be mapped to SDL2/SDL3/other
57 int key_a = 0; // Default: X key
58 int key_b = 0; // Default: Z key
59 int key_x = 0; // Default: S key
60 int key_y = 0; // Default: A key
61 int key_l = 0; // Default: D key
62 int key_r = 0; // Default: C key
63 int key_start = 0; // Default: Enter
64 int key_select = 0; // Default: RShift
65 int key_up = 0; // Default: Up arrow
66 int key_down = 0; // Default: Down arrow
67 int key_left = 0; // Default: Left arrow
68 int key_right = 0; // Default: Right arrow
69
70 // Enable/disable continuous polling (vs event-based)
71 bool continuous_polling = true;
72
73 // Enable gamepad support
74 bool enable_gamepad = true;
75 int gamepad_index = 0; // Which gamepad to use (0-3)
76};
77
85 public:
86 virtual ~IInputBackend() = default;
87
91 virtual bool Initialize(const InputConfig& config) = 0;
92
96 virtual void Shutdown() = 0;
97
103 virtual ControllerState Poll(int player = 1) = 0;
104
109 virtual void ProcessEvent(void* event) = 0;
110
114 virtual InputConfig GetConfig() const = 0;
115
119 virtual void SetConfig(const InputConfig& config) = 0;
120
124 virtual std::string GetBackendName() const = 0;
125
129 virtual bool IsInitialized() const = 0;
130};
131
136 public:
137 enum class BackendType {
138 SDL2,
139 SDL3, // Future
140 NULL_BACKEND // For testing/replay
141 };
142
143 static std::unique_ptr<IInputBackend> Create(BackendType type);
144};
145
146} // namespace input
147} // namespace emu
148} // namespace yaze
149
150#endif // YAZE_APP_EMU_INPUT_INPUT_BACKEND_H_
151
Abstract input backend interface.
virtual ControllerState Poll(int player=1)=0
Poll current input state (call every frame)
virtual void Shutdown()=0
Shutdown the input backend.
virtual bool IsInitialized() const =0
Check if backend is initialized.
virtual void ProcessEvent(void *event)=0
Process platform-specific events (optional)
virtual InputConfig GetConfig() const =0
Get current configuration.
virtual std::string GetBackendName() const =0
Get backend name for debugging.
virtual ~IInputBackend()=default
virtual void SetConfig(const InputConfig &config)=0
Update configuration (hot-reload)
virtual bool Initialize(const InputConfig &config)=0
Initialize the input backend.
Factory for creating input backends.
static std::unique_ptr< IInputBackend > Create(BackendType type)
SnesButton
SNES controller button mapping (platform-agnostic)
Main namespace for the application.
Definition controller.cc:20
Controller state (16-bit SNES controller format)
void SetButton(SnesButton button, bool pressed)
bool IsPressed(SnesButton button) const
Input configuration (platform-agnostic key codes)