2023-11-24 22:10:21 +00:00
|
|
|
#ifndef __RECOMP_INPUT_H__
|
|
|
|
#define __RECOMP_INPUT_H__
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
#include <variant>
|
|
|
|
#include <vector>
|
|
|
|
#include <type_traits>
|
2023-12-13 07:06:56 +00:00
|
|
|
#include <span>
|
2024-01-16 02:06:52 +00:00
|
|
|
#include <string>
|
2024-01-21 19:04:56 +00:00
|
|
|
#include <string_view>
|
2023-11-24 22:10:21 +00:00
|
|
|
|
|
|
|
namespace recomp {
|
2024-01-21 19:04:56 +00:00
|
|
|
// x-macros to build input enums and arrays.
|
|
|
|
// First parameter is the enum name, second parameter is the bit field for the input (or 0 if there is no associated one), third is the readable name.
|
|
|
|
#define DEFINE_N64_BUTTON_INPUTS() \
|
|
|
|
DEFINE_INPUT(A, 0x8000, "[A Button]") \
|
|
|
|
DEFINE_INPUT(B, 0x4000, "[B Button]") \
|
|
|
|
DEFINE_INPUT(Z, 0x2000, "[Z Button]") \
|
|
|
|
DEFINE_INPUT(START, 0x1000, "[Start Button]") \
|
|
|
|
DEFINE_INPUT(DPAD_UP, 0x0800, "[Dpad Up]") \
|
|
|
|
DEFINE_INPUT(DPAD_DOWN, 0x0400, "[Dpad Down]") \
|
|
|
|
DEFINE_INPUT(DPAD_LEFT, 0x0200, "[Dpad Left]") \
|
|
|
|
DEFINE_INPUT(DPAD_RIGHT, 0x0100, "[Dpad Right]") \
|
|
|
|
DEFINE_INPUT(L, 0x0020, "[L Button]") \
|
|
|
|
DEFINE_INPUT(R, 0x0010, "[R Button]") \
|
|
|
|
DEFINE_INPUT(C_UP, 0x0008, "[C Up]") \
|
|
|
|
DEFINE_INPUT(C_DOWN, 0x0004, "[C Down]") \
|
|
|
|
DEFINE_INPUT(C_LEFT, 0x0002, "[C Left]") \
|
|
|
|
DEFINE_INPUT(C_RIGHT, 0x0001, "[C Right]")
|
|
|
|
|
|
|
|
#define DEFINE_N64_AXIS_INPUTS() \
|
|
|
|
DEFINE_INPUT(X_AXIS_NEG, 0, "[Analog Left]") \
|
|
|
|
DEFINE_INPUT(X_AXIS_POS, 0, "[Analog Right]") \
|
|
|
|
DEFINE_INPUT(Y_AXIS_NEG, 0, "[Analog Down]") \
|
|
|
|
DEFINE_INPUT(Y_AXIS_POS, 0, "[Analog Up]") \
|
|
|
|
|
|
|
|
#define DEFINE_ALL_INPUTS() \
|
|
|
|
DEFINE_N64_BUTTON_INPUTS() \
|
|
|
|
DEFINE_N64_AXIS_INPUTS()
|
|
|
|
|
|
|
|
// Enum containing every recomp input.
|
|
|
|
#define DEFINE_INPUT(name, value, readable) name,
|
|
|
|
enum class GameInput {
|
|
|
|
DEFINE_ALL_INPUTS()
|
|
|
|
|
|
|
|
COUNT,
|
|
|
|
N64_BUTTON_START = A,
|
|
|
|
N64_BUTTON_COUNT = C_RIGHT - N64_BUTTON_START + 1,
|
|
|
|
N64_AXIS_START = X_AXIS_NEG,
|
|
|
|
N64_AXIS_COUNT = Y_AXIS_POS - N64_AXIS_START + 1,
|
|
|
|
};
|
|
|
|
#undef DEFINE_INPUT
|
|
|
|
|
2023-12-13 07:06:56 +00:00
|
|
|
struct InputField {
|
2024-01-16 02:06:52 +00:00
|
|
|
uint32_t input_type;
|
2023-12-13 07:06:56 +00:00
|
|
|
int32_t input_id;
|
2024-01-16 02:06:52 +00:00
|
|
|
std::string to_string() const;
|
|
|
|
auto operator<=>(const InputField& rhs) const = default;
|
2023-11-24 22:10:21 +00:00
|
|
|
};
|
|
|
|
|
2023-12-13 07:06:56 +00:00
|
|
|
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);
|
2024-01-23 04:08:59 +00:00
|
|
|
void get_gyro_deltas(float* x, float* y);
|
2024-01-16 02:06:52 +00:00
|
|
|
|
|
|
|
enum class InputDevice {
|
|
|
|
Controller,
|
|
|
|
Keyboard,
|
|
|
|
COUNT
|
|
|
|
};
|
|
|
|
|
|
|
|
void start_scanning_input(InputDevice device);
|
|
|
|
void finish_scanning_input(InputField scanned_field);
|
|
|
|
InputField get_scanned_input();
|
2023-12-13 07:06:56 +00:00
|
|
|
|
|
|
|
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;
|
2023-11-24 22:10:21 +00:00
|
|
|
};
|
|
|
|
|
2024-01-08 08:38:05 +00:00
|
|
|
extern const DefaultN64Mappings default_n64_keyboard_mappings;
|
|
|
|
extern const DefaultN64Mappings default_n64_controller_mappings;
|
2023-11-24 22:10:21 +00:00
|
|
|
|
2024-01-16 02:06:52 +00:00
|
|
|
constexpr size_t bindings_per_input = 2;
|
|
|
|
|
|
|
|
size_t get_num_inputs();
|
2024-01-21 19:04:56 +00:00
|
|
|
const std::string& get_input_name(GameInput input);
|
|
|
|
const std::string& get_input_enum_name(GameInput input);
|
|
|
|
GameInput get_input_from_enum_name(const std::string_view name);
|
|
|
|
InputField& get_input_binding(GameInput input, size_t binding_index, InputDevice device);
|
|
|
|
void set_input_binding(GameInput input, size_t binding_index, InputDevice device, InputField value);
|
2024-01-15 03:49:04 +00:00
|
|
|
|
2023-11-24 22:10:21 +00:00
|
|
|
void get_n64_input(uint16_t* buttons_out, float* x_out, float* y_out);
|
|
|
|
void handle_events();
|
2024-01-08 08:38:05 +00:00
|
|
|
|
|
|
|
bool game_input_disabled();
|
2024-01-16 02:06:52 +00:00
|
|
|
bool all_input_disabled();
|
2024-01-13 06:39:08 +00:00
|
|
|
|
|
|
|
// TODO move these
|
|
|
|
void quicksave_save();
|
|
|
|
void quicksave_load();
|
2023-11-24 22:10:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|