diff options
Diffstat (limited to 'core/input/input.h')
-rw-r--r-- | core/input/input.h | 122 |
1 files changed, 69 insertions, 53 deletions
diff --git a/core/input/input.h b/core/input/input.h index 2e136dbf02..445b7ff0cf 100644 --- a/core/input/input.h +++ b/core/input/input.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -32,11 +32,10 @@ #define INPUT_H #include "core/input/input_event.h" -#include "core/object.h" +#include "core/object/object.h" #include "core/os/thread_safe.h" class Input : public Object { - GDCLASS(Input, Object); _THREAD_SAFE_CLASS_ @@ -100,7 +99,7 @@ public: typedef void (*EventDispatchFunc)(const Ref<InputEvent> &p_event); private: - int mouse_button_mask; + int mouse_button_mask = 0; Set<int> keys_pressed; Set<int> joy_buttons_pressed; @@ -111,24 +110,25 @@ private: Vector3 magnetometer; Vector3 gyroscope; Vector2 mouse_pos; - int64_t mouse_window; + int64_t mouse_window = 0; struct Action { uint64_t physics_frame; - uint64_t idle_frame; + uint64_t process_frame; bool pressed; float strength; + float raw_strength; }; Map<StringName, Action> action_state; - bool emulate_touch_from_mouse; - bool emulate_mouse_from_touch; + bool emulate_touch_from_mouse = false; + bool emulate_mouse_from_touch = false; + bool use_accumulated_input = false; - int mouse_from_touch_index; + int mouse_from_touch_index = -1; struct SpeedTrack { - uint64_t last_tick; Vector2 speed; Vector2 accum; @@ -144,37 +144,20 @@ private: struct Joypad { StringName name; StringName uid; - bool connected; - bool last_buttons[JOY_BUTTON_MAX + 19]; //apparently SDL specifies 35 possible buttons on android - float last_axis[JOY_AXIS_MAX]; - float filter; - int last_hat; - int mapping; - int hat_current; - - Joypad() { - for (int i = 0; i < JOY_AXIS_MAX; i++) { - - last_axis[i] = 0.0f; - } - for (int i = 0; i < JOY_BUTTON_MAX + 19; i++) { - - last_buttons[i] = false; - } - connected = false; - last_hat = HAT_MASK_CENTER; - filter = 0.01f; - mapping = -1; - hat_current = 0; - } + bool connected = false; + bool last_buttons[JOY_BUTTON_MAX] = { false }; + float last_axis[JOY_AXIS_MAX] = { 0.0f }; + int last_hat = HAT_MASK_CENTER; + int mapping = -1; + int hat_current = 0; }; SpeedTrack mouse_speed_track; Map<int, SpeedTrack> touch_speed_track; Map<int, Joypad> joy_names; - int fallback_mapping; + int fallback_mapping = -1; - CursorShape default_shape; + CursorShape default_shape = CURSOR_ARROW; enum JoyType { TYPE_BUTTON, @@ -183,34 +166,68 @@ private: TYPE_MAX, }; + enum JoyAxisRange { + NEGATIVE_HALF_AXIS = -1, + FULL_AXIS = 0, + POSITIVE_HALF_AXIS = 1 + }; + struct JoyEvent { int type; int index; - int value; + float value; }; - struct JoyDeviceMapping { + struct JoyBinding { + JoyType inputType; + union { + int button; + + struct { + int axis; + JoyAxisRange range; + bool invert; + } axis; + + struct { + int hat; + HatMask hat_mask; + } hat; + + } input; + JoyType outputType; + union { + JoyButtonList button; + + struct { + JoyAxisList axis; + JoyAxisRange range; + } axis; + + } output; + }; + + struct JoyDeviceMapping { String uid; String name; - Map<int, JoyEvent> buttons; - Map<int, JoyEvent> axis; - JoyEvent hat[HAT_MAX]; + Vector<JoyBinding> bindings; }; - JoyEvent hat_map_default[HAT_MAX]; - Vector<JoyDeviceMapping> map_db; - JoyEvent _find_to_event(String p_to); + JoyEvent _get_mapped_button_event(const JoyDeviceMapping &mapping, int p_button); + JoyEvent _get_mapped_axis_event(const JoyDeviceMapping &mapping, int p_axis, float p_value); + void _get_mapped_hat_events(const JoyDeviceMapping &mapping, int p_hat, JoyEvent r_events[HAT_MAX]); + JoyButtonList _get_output_button(String output); + JoyAxisList _get_output_axis(String output); void _button_event(int p_device, int p_index, bool p_pressed); void _axis_event(int p_device, int p_axis, float p_value); - float _handle_deadzone(int p_device, int p_axis, float p_value); void _parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_emulated); List<Ref<InputEvent>> accumulated_events; - bool use_accumulated_input; + friend class DisplayServer; static void (*set_mouse_mode_func)(MouseMode); @@ -220,7 +237,7 @@ private: static CursorShape (*get_current_cursor_shape_func)(); static void (*set_custom_mouse_cursor_func)(const RES &, CursorShape, const Vector2 &); - EventDispatchFunc event_dispatch_function; + EventDispatchFunc event_dispatch_function = nullptr; protected: struct VibrationInfo { @@ -237,7 +254,7 @@ protected: public: void set_mouse_mode(MouseMode p_mode); MouseMode get_mouse_mode() const; - void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const; + void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const override; static Input *get_singleton(); @@ -248,6 +265,10 @@ public: bool is_action_just_pressed(const StringName &p_action) const; bool is_action_just_released(const StringName &p_action) const; float get_action_strength(const StringName &p_action) const; + float get_action_raw_strength(const StringName &p_action) const; + + float get_axis(const StringName &p_negative_action, const StringName &p_positive_action) const; + Vector2 get_vector(const StringName &p_negative_x, const StringName &p_positive_x, const StringName &p_negative_y, const StringName &p_positive_y, float p_deadzone = -1.0f) const; float get_joy_axis(int p_device, int p_axis) const; String get_joy_name(int p_idx); @@ -309,11 +330,6 @@ public: void add_joy_mapping(String p_mapping, bool p_update_existing = false); void remove_joy_mapping(String p_guid); - String get_joy_button_string(int p_button); - String get_joy_axis_string(int p_axis); - int get_joy_axis_index_from_string(String p_axis); - int get_joy_button_index_from_string(String p_button); - int get_unused_joy_id(); bool is_joy_known(int p_device); |