summaryrefslogtreecommitdiffstats
path: root/core/input/input.h
diff options
context:
space:
mode:
Diffstat (limited to 'core/input/input.h')
-rw-r--r--core/input/input.h49
1 files changed, 35 insertions, 14 deletions
diff --git a/core/input/input.h b/core/input/input.h
index bedc3fa0e3..d1f284e8f7 100644
--- a/core/input/input.h
+++ b/core/input/input.h
@@ -44,6 +44,8 @@ class Input : public Object {
static Input *singleton;
+ static constexpr uint64_t MAX_EVENT = 32;
+
public:
enum MouseMode {
MOUSE_MODE_VISIBLE,
@@ -98,19 +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;
- int pressed = 0;
- bool axis_pressed = false;
bool exact = true;
- float strength = 0.0f;
- float raw_strength = 0.0f;
+
+ 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;
+
+ // 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;
@@ -131,12 +145,14 @@ private:
struct VelocityTrack {
uint64_t last_tick = 0;
Vector2 velocity;
+ Vector2 screen_velocity;
Vector2 accum;
+ Vector2 screen_accum;
float accum_t = 0.0f;
float min_ref_frame;
float max_ref_frame;
- void update(const Vector2 &p_delta_p);
+ void update(const Vector2 &p_delta_p, const Vector2 &p_screen_delta_p);
void reset();
VelocityTrack();
};
@@ -223,10 +239,11 @@ private:
JoyEvent _get_mapped_button_event(const JoyDeviceMapping &mapping, JoyButton p_button);
JoyEvent _get_mapped_axis_event(const JoyDeviceMapping &mapping, JoyAxis p_axis, float p_value, JoyAxisRange &r_range);
void _get_mapped_hat_events(const JoyDeviceMapping &mapping, HatDir p_hat, JoyEvent r_events[(size_t)HatDir::MAX]);
- JoyButton _get_output_button(String output);
- JoyAxis _get_output_axis(String output);
+ JoyButton _get_output_button(const String &output);
+ JoyAxis _get_output_axis(const 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_cache(const StringName &p_action_name, ActionState &r_action_state);
void _parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_emulated);
@@ -253,7 +270,10 @@ protected:
public:
void set_mouse_mode(MouseMode p_mode);
MouseMode get_mouse_mode() const;
+
+#ifdef TOOLS_ENABLED
void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const override;
+#endif
static Input *get_singleton();
@@ -278,7 +298,7 @@ public:
Vector2 get_joy_vibration_strength(int p_device);
float get_joy_vibration_duration(int p_device);
uint64_t get_joy_vibration_timestamp(int p_device);
- void joy_connection_changed(int p_idx, bool p_connected, String p_name, String p_guid = "", Dictionary p_joypad_info = Dictionary());
+ void joy_connection_changed(int p_idx, bool p_connected, const String &p_name, const String &p_guid = "", const Dictionary &p_joypad_info = Dictionary());
Vector3 get_gravity() const;
Vector3 get_accelerometer() const;
@@ -287,6 +307,7 @@ public:
Point2 get_mouse_position() const;
Vector2 get_last_mouse_velocity();
+ Vector2 get_last_mouse_screen_velocity();
BitField<MouseButtonMask> get_mouse_button_mask() const;
void warp_mouse(const Vector2 &p_position);
@@ -321,13 +342,13 @@ public:
CursorShape get_current_cursor_shape() const;
void set_custom_mouse_cursor(const Ref<Resource> &p_cursor, CursorShape p_shape = Input::CURSOR_ARROW, const Vector2 &p_hotspot = Vector2());
- void parse_mapping(String p_mapping);
+ void parse_mapping(const String &p_mapping);
void joy_button(int p_device, JoyButton p_button, bool p_pressed);
void joy_axis(int p_device, JoyAxis p_axis, float p_value);
void joy_hat(int p_device, BitField<HatMask> p_val);
- void add_joy_mapping(String p_mapping, bool p_update_existing = false);
- void remove_joy_mapping(String p_guid);
+ void add_joy_mapping(const String &p_mapping, bool p_update_existing = false);
+ void remove_joy_mapping(const String &p_guid);
int get_unused_joy_id();
@@ -335,7 +356,7 @@ public:
String get_joy_guid(int p_device) const;
bool should_ignore_device(int p_vendor_id, int p_product_id) const;
Dictionary get_joy_info(int p_device) const;
- void set_fallback_mapping(String p_guid);
+ void set_fallback_mapping(const String &p_guid);
void flush_buffered_events();
bool is_using_input_buffering();