summaryrefslogtreecommitdiff
path: root/core/input
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2020-05-12 17:01:17 +0200
committerRémi Verschelde <rverschelde@gmail.com>2020-05-14 10:01:56 +0200
commit1f6f364a56319eabd02c050746fe7df3f55ffee3 (patch)
tree8bebdce946466ce8e9476ccd46c9dba62c323938 /core/input
parente7c9d818766a119089873e4941e4865fb36883ec (diff)
Port member initialization from constructor to declaration (C++11)
Using `clang-tidy`'s `modernize-use-default-member-init` check and manual review of the changes, and some extra manual changes that `clang-tidy` failed to do. Also went manually through all of `core` to find occurrences that `clang-tidy` couldn't handle, especially all initializations done in a constructor without using initializer lists.
Diffstat (limited to 'core/input')
-rw-r--r--core/input/input.cpp10
-rw-r--r--core/input/input.h48
-rw-r--r--core/input/input_event.cpp120
-rw-r--r--core/input/input_event.h109
4 files changed, 87 insertions, 200 deletions
diff --git a/core/input/input.cpp b/core/input/input.cpp
index 91ff676211..38a71994d8 100644
--- a/core/input/input.cpp
+++ b/core/input/input.cpp
@@ -1433,16 +1433,6 @@ int Input::get_joy_axis_index_from_string(String p_axis) {
Input::Input() {
singleton = this;
- use_accumulated_input = true;
- mouse_button_mask = 0;
- mouse_window = 0;
- emulate_touch_from_mouse = false;
- emulate_mouse_from_touch = false;
- mouse_from_touch_index = -1;
- event_dispatch_function = nullptr;
- default_shape = CURSOR_ARROW;
-
- fallback_mapping = -1;
// Parse default mappings.
{
diff --git a/core/input/input.h b/core/input/input.h
index 9accf14a4f..f3150a8127 100644
--- a/core/input/input.h
+++ b/core/input/input.h
@@ -36,7 +36,6 @@
#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,7 +110,7 @@ private:
Vector3 magnetometer;
Vector3 gyroscope;
Vector2 mouse_pos;
- int64_t mouse_window;
+ int64_t mouse_window = 0;
struct Action {
uint64_t physics_frame;
@@ -122,10 +121,11 @@ private:
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 {
@@ -144,35 +144,21 @@ private:
struct Joypad {
StringName name;
StringName uid;
- bool connected;
- bool last_buttons[JOY_BUTTON_MAX];
- 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; 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 };
+ float filter = 0.01f;
+ 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,
@@ -243,7 +229,7 @@ private:
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);
@@ -253,7 +239,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 {
diff --git a/core/input/input_event.cpp b/core/input/input_event.cpp
index 4b8c104f39..9d3f8f9424 100644
--- a/core/input/input_event.cpp
+++ b/core/input/input_event.cpp
@@ -132,11 +132,7 @@ void InputEvent::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "device"), "set_device", "get_device");
}
-InputEvent::InputEvent() {
-
- device = 0;
-}
-////////////////
+///////////////////////////////////
void InputEventFromWindow::_bind_methods() {
@@ -152,11 +148,7 @@ int64_t InputEventFromWindow::get_window_id() const {
return window_id;
}
-InputEventFromWindow::InputEventFromWindow() {
- window_id = 0;
-}
-
-//////////////////
+///////////////////////////////////
void InputEventWithModifiers::set_shift(bool p_enabled) {
@@ -236,15 +228,7 @@ void InputEventWithModifiers::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "command"), "set_command", "get_command");
}
-InputEventWithModifiers::InputEventWithModifiers() {
-
- alt = false;
- shift = false;
- control = false;
- meta = false;
-}
-
-//////////////////////////////////
+///////////////////////////////////
void InputEventKey::set_pressed(bool p_pressed) {
@@ -411,16 +395,7 @@ void InputEventKey::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "echo"), "set_echo", "is_echo");
}
-InputEventKey::InputEventKey() {
-
- pressed = false;
- keycode = 0;
- physical_keycode = 0;
- unicode = 0; ///unicode
- echo = false;
-}
-
-////////////////////////////////////////
+///////////////////////////////////
void InputEventMouse::set_button_mask(int p_mask) {
@@ -465,12 +440,7 @@ void InputEventMouse::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "global_position"), "set_global_position", "get_global_position");
}
-InputEventMouse::InputEventMouse() {
-
- button_mask = 0;
-}
-
-///////////////////////////////////////
+///////////////////////////////////
void InputEventMouseButton::set_factor(float p_factor) {
@@ -608,15 +578,7 @@ void InputEventMouseButton::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "doubleclick"), "set_doubleclick", "is_doubleclick");
}
-InputEventMouseButton::InputEventMouseButton() {
-
- factor = 1;
- button_index = 0;
- pressed = false;
- doubleclick = false;
-}
-
-////////////////////////////////////////////
+///////////////////////////////////
void InputEventMouseMotion::set_tilt(const Vector2 &p_tilt) {
@@ -773,12 +735,7 @@ void InputEventMouseMotion::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "speed"), "set_speed", "get_speed");
}
-InputEventMouseMotion::InputEventMouseMotion() {
-
- pressure = 0;
-}
-
-////////////////////////////////////////
+///////////////////////////////////
void InputEventJoypadMotion::set_axis(int p_axis) {
@@ -849,12 +806,7 @@ void InputEventJoypadMotion::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "axis_value"), "set_axis_value", "get_axis_value");
}
-InputEventJoypadMotion::InputEventJoypadMotion() {
-
- axis = 0;
- axis_value = 0;
-}
-/////////////////////////////////
+///////////////////////////////////
void InputEventJoypadButton::set_button_index(int p_index) {
@@ -931,14 +883,7 @@ void InputEventJoypadButton::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
}
-InputEventJoypadButton::InputEventJoypadButton() {
-
- button_index = 0;
- pressure = 0;
- pressed = false;
-}
-
-//////////////////////////////////////////////
+///////////////////////////////////
void InputEventScreenTouch::set_index(int p_index) {
@@ -1001,13 +946,7 @@ void InputEventScreenTouch::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
}
-InputEventScreenTouch::InputEventScreenTouch() {
-
- index = 0;
- pressed = false;
-}
-
-/////////////////////////////
+///////////////////////////////////
void InputEventScreenDrag::set_index(int p_index) {
@@ -1088,11 +1027,7 @@ void InputEventScreenDrag::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "speed"), "set_speed", "get_speed");
}
-InputEventScreenDrag::InputEventScreenDrag() {
-
- index = 0;
-}
-/////////////////////////////
+///////////////////////////////////
void InputEventAction::set_action(const StringName &p_action) {
@@ -1171,11 +1106,7 @@ void InputEventAction::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "strength", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_strength", "get_strength");
}
-InputEventAction::InputEventAction() {
- pressed = false;
- strength = 1.0f;
-}
-/////////////////////////////
+///////////////////////////////////
void InputEventGesture::set_position(const Vector2 &p_pos) {
@@ -1194,7 +1125,8 @@ Vector2 InputEventGesture::get_position() const {
return pos;
}
-/////////////////////////////
+
+///////////////////////////////////
void InputEventMagnifyGesture::set_factor(real_t p_factor) {
@@ -1235,11 +1167,7 @@ void InputEventMagnifyGesture::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "factor"), "set_factor", "get_factor");
}
-InputEventMagnifyGesture::InputEventMagnifyGesture() {
-
- factor = 1.0;
-}
-/////////////////////////////
+///////////////////////////////////
void InputEventPanGesture::set_delta(const Vector2 &p_delta) {
@@ -1279,11 +1207,7 @@ void InputEventPanGesture::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "delta"), "set_delta", "get_delta");
}
-InputEventPanGesture::InputEventPanGesture() {
-
- delta = Vector2(0, 0);
-}
-/////////////////////////////
+///////////////////////////////////
void InputEventMIDI::set_channel(const int p_channel) {
@@ -1390,15 +1314,3 @@ void InputEventMIDI::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "controller_number"), "set_controller_number", "get_controller_number");
ADD_PROPERTY(PropertyInfo(Variant::INT, "controller_value"), "set_controller_value", "get_controller_value");
}
-
-InputEventMIDI::InputEventMIDI() {
-
- channel = 0;
- message = 0;
- pitch = 0;
- velocity = 0;
- instrument = 0;
- pressure = 0;
- controller_number = 0;
- controller_value = 0;
-}
diff --git a/core/input/input_event.h b/core/input/input_event.h
index 99ea2efee9..18792076f5 100644
--- a/core/input/input_event.h
+++ b/core/input/input_event.h
@@ -157,7 +157,7 @@ enum MidiMessageList {
class InputEvent : public Resource {
GDCLASS(InputEvent, Resource);
- int device;
+ int device = 0;
protected:
static void _bind_methods();
@@ -177,7 +177,6 @@ public:
// To be removed someday, since they do not make sense for all events
virtual bool is_pressed() const;
virtual bool is_echo() const;
- // ...-.
virtual String as_text() const;
@@ -188,14 +187,15 @@ public:
virtual bool is_action_type() const;
virtual bool accumulate(const Ref<InputEvent> &p_event) { return false; }
- InputEvent();
+
+ InputEvent() {}
};
class InputEventFromWindow : public InputEvent {
GDCLASS(InputEventFromWindow, InputEvent);
- int64_t window_id;
+ int64_t window_id = 0;
protected:
static void _bind_methods();
@@ -204,28 +204,27 @@ public:
void set_window_id(int64_t p_id);
int64_t get_window_id() const;
- InputEventFromWindow();
+ InputEventFromWindow() {}
};
class InputEventWithModifiers : public InputEventFromWindow {
GDCLASS(InputEventWithModifiers, InputEventFromWindow);
- bool shift;
- bool alt;
+ bool shift = false;
+ bool alt = false;
#ifdef APPLE_STYLE_KEYS
union {
bool command;
- bool meta; //< windows/mac key
+ bool meta = false; //< windows/mac key
};
- bool control;
+ bool control = false;
#else
union {
bool command; //< windows/mac key
- bool control;
+ bool control = false;
};
- bool meta; //< windows/mac key
-
+ bool meta = false; //< windows/mac key
#endif
protected:
@@ -249,20 +248,20 @@ public:
void set_modifiers_from_event(const InputEventWithModifiers *event);
- InputEventWithModifiers();
+ InputEventWithModifiers() {}
};
class InputEventKey : public InputEventWithModifiers {
GDCLASS(InputEventKey, InputEventWithModifiers);
- bool pressed; /// otherwise release
+ bool pressed = false; /// otherwise release
- uint32_t keycode; ///< check keyboard.h , KeyCode enum, without modifier masks
- uint32_t physical_keycode;
- uint32_t unicode; ///unicode
+ uint32_t keycode = 0; ///< check keyboard.h , KeyCode enum, without modifier masks
+ uint32_t physical_keycode = 0;
+ uint32_t unicode = 0; ///unicode
- bool echo; /// true if this is an echo key
+ bool echo = false; /// true if this is an echo key
protected:
static void _bind_methods();
@@ -293,14 +292,14 @@ public:
virtual String as_text() const;
- InputEventKey();
+ InputEventKey() {}
};
class InputEventMouse : public InputEventWithModifiers {
GDCLASS(InputEventMouse, InputEventWithModifiers);
- int button_mask;
+ int button_mask = 0;
Vector2 pos;
Vector2 global_pos;
@@ -318,17 +317,17 @@ public:
void set_global_position(const Vector2 &p_global_pos);
Vector2 get_global_position() const;
- InputEventMouse();
+ InputEventMouse() {}
};
class InputEventMouseButton : public InputEventMouse {
GDCLASS(InputEventMouseButton, InputEventMouse);
- float factor;
- int button_index;
- bool pressed; //otherwise released
- bool doubleclick; //last even less than doubleclick time
+ float factor = 1;
+ int button_index = 0;
+ bool pressed = false; //otherwise released
+ bool doubleclick = false; //last even less than doubleclick time
protected:
static void _bind_methods();
@@ -352,7 +351,7 @@ public:
virtual bool is_action_type() const { return true; }
virtual String as_text() const;
- InputEventMouseButton();
+ InputEventMouseButton() {}
};
class InputEventMouseMotion : public InputEventMouse {
@@ -360,7 +359,7 @@ class InputEventMouseMotion : public InputEventMouse {
GDCLASS(InputEventMouseMotion, InputEventMouse);
Vector2 tilt;
- float pressure;
+ float pressure = 0;
Vector2 relative;
Vector2 speed;
@@ -385,14 +384,14 @@ public:
virtual bool accumulate(const Ref<InputEvent> &p_event);
- InputEventMouseMotion();
+ InputEventMouseMotion() {}
};
class InputEventJoypadMotion : public InputEvent {
GDCLASS(InputEventJoypadMotion, InputEvent);
- int axis; ///< Joypad axis
- float axis_value; ///< -1 to 1
+ int axis = 0; ///< Joypad axis
+ float axis_value = 0; ///< -1 to 1
protected:
static void _bind_methods();
@@ -411,15 +410,15 @@ public:
virtual bool is_action_type() const { return true; }
virtual String as_text() const;
- InputEventJoypadMotion();
+ InputEventJoypadMotion() {}
};
class InputEventJoypadButton : public InputEvent {
GDCLASS(InputEventJoypadButton, InputEvent);
- int button_index;
- bool pressed;
- float pressure; //0 to 1
+ int button_index = 0;
+ bool pressed = false;
+ float pressure = 0; //0 to 1
protected:
static void _bind_methods();
@@ -439,14 +438,14 @@ public:
virtual bool is_action_type() const { return true; }
virtual String as_text() const;
- InputEventJoypadButton();
+ InputEventJoypadButton() {}
};
class InputEventScreenTouch : public InputEventFromWindow {
GDCLASS(InputEventScreenTouch, InputEventFromWindow);
- int index;
+ int index = 0;
Vector2 pos;
- bool pressed;
+ bool pressed = false;
protected:
static void _bind_methods();
@@ -464,13 +463,13 @@ public:
virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const;
virtual String as_text() const;
- InputEventScreenTouch();
+ InputEventScreenTouch() {}
};
class InputEventScreenDrag : public InputEventFromWindow {
GDCLASS(InputEventScreenDrag, InputEventFromWindow);
- int index;
+ int index = 0;
Vector2 pos;
Vector2 relative;
Vector2 speed;
@@ -494,7 +493,7 @@ public:
virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const;
virtual String as_text() const;
- InputEventScreenDrag();
+ InputEventScreenDrag() {}
};
class InputEventAction : public InputEvent {
@@ -502,8 +501,8 @@ class InputEventAction : public InputEvent {
GDCLASS(InputEventAction, InputEvent);
StringName action;
- bool pressed;
- float strength;
+ bool pressed = false;
+ float strength = 1.0f;
protected:
static void _bind_methods();
@@ -526,7 +525,7 @@ public:
virtual bool is_action_type() const { return true; }
virtual String as_text() const;
- InputEventAction();
+ InputEventAction() {}
};
class InputEventGesture : public InputEventWithModifiers {
@@ -546,7 +545,7 @@ public:
class InputEventMagnifyGesture : public InputEventGesture {
GDCLASS(InputEventMagnifyGesture, InputEventGesture);
- real_t factor;
+ real_t factor = 1.0;
protected:
static void _bind_methods();
@@ -558,7 +557,7 @@ public:
virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const;
virtual String as_text() const;
- InputEventMagnifyGesture();
+ InputEventMagnifyGesture() {}
};
class InputEventPanGesture : public InputEventGesture {
@@ -576,20 +575,20 @@ public:
virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const;
virtual String as_text() const;
- InputEventPanGesture();
+ InputEventPanGesture() {}
};
class InputEventMIDI : public InputEvent {
GDCLASS(InputEventMIDI, InputEvent);
- int channel;
- int message;
- int pitch;
- int velocity;
- int instrument;
- int pressure;
- int controller_number;
- int controller_value;
+ int channel = 0;
+ int message = 0;
+ int pitch = 0;
+ int velocity = 0;
+ int instrument = 0;
+ int pressure = 0;
+ int controller_number = 0;
+ int controller_value = 0;
protected:
static void _bind_methods();
@@ -621,7 +620,7 @@ public:
virtual String as_text() const;
- InputEventMIDI();
+ InputEventMIDI() {}
};
#endif // INPUT_EVENT_H