Input refactor to allow arbitrary bindings

This commit is contained in:
Mr-Wiseguy
2023-12-13 02:06:56 -05:00
parent b11e652a20
commit 971d728169
7 changed files with 299 additions and 264 deletions
+33 -44
View File
@@ -5,58 +5,47 @@
#include <variant>
#include <vector>
#include <type_traits>
#include <span>
namespace recomp {
struct ControllerState {
enum Button : uint32_t {
BUTTON_NORTH = 1 << 0,
BUTTON_SOUTH = 1 << 1,
BUTTON_EAST = 1 << 2,
BUTTON_WEST = 1 << 3,
BUTTON_L1 = 1 << 4, // Left Bumper
BUTTON_R1 = 1 << 5, // Right Bumper
BUTTON_L2 = 1 << 6, // Left Trigger Press
BUTTON_R2 = 1 << 7, // Right Trigger Press
BUTTON_L3 = 1 << 8, // Left Joystick Press
BUTTON_R3 = 1 << 9, // Right Joystick Press
BUTTON_DPAD_UP = 1 << 10,
BUTTON_DPAD_DOWN = 1 << 11,
BUTTON_DPAD_RIGHT = 1 << 12,
BUTTON_DPAD_LEFT = 1 << 13,
BUTTON_START = 1 << 14,
};
enum Axis : size_t {
AXIS_LEFT_X,
AXIS_LEFT_Y,
AXIS_RIGHT_X,
AXIS_RIGHT_Y,
AXIS_LEFT_TRIGGER,
AXIS_RIGHT_TRIGGER,
AXIS_MAX
};
uint32_t buttons;
float axes[AXIS_MAX];
struct InputField {
uint32_t device_type;
int32_t input_id;
};
struct MouseState {
enum Button : uint32_t {
LEFT = 1 << 0,
RIGHT = 1 << 1,
MIDDLE = 1 << 2,
BACK = 1 << 3,
FORWARD = 1 << 4,
};
int32_t wheel_pos;
int32_t position_x;
int32_t position_y;
uint32_t buttons;
void poll_inputs();
float get_input_analog(const InputField& field);
float get_input_analog(const std::span<const recomp::InputField> fields);
bool get_input_digital(const InputField& field);
bool get_input_digital(const std::span<const recomp::InputField> fields);
struct DefaultN64Mappings {
std::vector<InputField> a;
std::vector<InputField> b;
std::vector<InputField> l;
std::vector<InputField> r;
std::vector<InputField> z;
std::vector<InputField> start;
std::vector<InputField> c_left;
std::vector<InputField> c_right;
std::vector<InputField> c_up;
std::vector<InputField> c_down;
std::vector<InputField> dpad_left;
std::vector<InputField> dpad_right;
std::vector<InputField> dpad_up;
std::vector<InputField> dpad_down;
std::vector<InputField> analog_left;
std::vector<InputField> analog_right;
std::vector<InputField> analog_up;
std::vector<InputField> analog_down;
};
using InputState = std::variant<ControllerState, MouseState>;
extern const DefaultN64Mappings default_n64_mappings;
void get_keyboard_input(uint16_t* buttons_out, float* x_out, float* y_out);
void get_n64_input(uint16_t* buttons_out, float* x_out, float* y_out);
std::vector<InputState> get_input_states();
void handle_events();
}