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>
|
2023-11-24 22:10:21 +00:00
|
|
|
|
|
|
|
namespace recomp {
|
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-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;
|
|
|
|
|
2024-01-15 03:49:04 +00:00
|
|
|
// Loads the user's saved controller mapping if one exists, loads the default mappings if no saved mapping exists.
|
|
|
|
void init_control_mappings();
|
2024-01-16 02:06:52 +00:00
|
|
|
size_t get_num_inputs();
|
2024-01-17 07:22:36 +00:00
|
|
|
const std::string& get_input_name(size_t input_index);
|
|
|
|
const std::string& get_input_enum_name(size_t input_index);
|
2024-01-16 02:06:52 +00:00
|
|
|
InputField& get_input_binding(size_t input_index, size_t binding_index, InputDevice device);
|
|
|
|
void set_input_binding(size_t input_index, 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
|