Rework action pressed state to support multiple controllers

This commit is contained in:
Gilles Roudière
2023-11-15 17:42:56 +01:00
parent c851a46065
commit 8cfcd36253
2 changed files with 108 additions and 99 deletions

View File

@ -44,7 +44,7 @@ class Input : public Object {
static Input *singleton;
static constexpr uint64_t MAX_EVENT = 31;
static constexpr uint64_t MAX_EVENT = 32;
public:
enum MouseMode {
@ -100,30 +100,31 @@ private:
int64_t mouse_window = 0;
bool legacy_just_pressed_behavior = false;
struct Action {
struct ActionState {
uint64_t pressed_physics_frame = UINT64_MAX;
uint64_t pressed_process_frame = UINT64_MAX;
uint64_t released_physics_frame = UINT64_MAX;
uint64_t released_process_frame = UINT64_MAX;
uint64_t pressed = 0;
bool exact = true;
float strength = 0.0f;
float raw_strength = 0.0f;
LocalVector<float> strengths;
LocalVector<float> raw_strengths;
Action() {
strengths.resize(MAX_EVENT + 1);
raw_strengths.resize(MAX_EVENT + 1);
struct DeviceState {
bool pressed[MAX_EVENT] = { false };
float strength[MAX_EVENT] = { 0.0 };
float raw_strength[MAX_EVENT] = { 0.0 };
};
bool api_pressed = false;
float api_strength = 0.0;
HashMap<int, DeviceState> device_states;
for (uint64_t i = 0; i <= MAX_EVENT; i++) {
strengths[i] = 0.0;
raw_strengths[i] = 0.0;
}
}
// Cache.
struct ActionStateCache {
bool pressed = false;
float strength = false;
float raw_strength = false;
} cache;
};
HashMap<StringName, Action> action_state;
HashMap<StringName, ActionState> action_states;
bool emulate_touch_from_mouse = false;
bool emulate_mouse_from_touch = false;
@ -240,8 +241,7 @@ private:
JoyAxis _get_output_axis(String output);
void _button_event(int p_device, JoyButton p_index, bool p_pressed);
void _axis_event(int p_device, JoyAxis p_axis, float p_value);
void _update_action_strength(Action &p_action, int p_event_index, float p_strength);
void _update_action_raw_strength(Action &p_action, int p_event_index, float p_strength);
void _update_action_cache(const StringName &p_action_name, ActionState &r_action_state);
void _parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_emulated);