summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMalcolm Anderson <malcolminyo@gmail.com>2024-11-12 09:43:29 -0800
committerMalcolm Anderson <malcolminyo@gmail.com>2024-11-12 10:11:52 -0800
commit829dade53bb3e5a23d60d0c2fc83aeef51debc56 (patch)
tree999ce2e4d135864a9659c0703abf635e27582e21
parent0f5f3bc9546b46b2029fc8896dc859697f1eab97 (diff)
downloadredot-engine-829dade53bb3e5a23d60d0c2fc83aeef51debc56.tar.gz
Replace default deadzone magic number with named constant
-rw-r--r--core/config/project_settings.cpp2
-rw-r--r--core/input/input_event.cpp2
-rw-r--r--core/input/input_map.cpp4
-rw-r--r--core/input/input_map.h4
-rw-r--r--editor/project_settings_editor.cpp3
5 files changed, 9 insertions, 6 deletions
diff --git a/core/config/project_settings.cpp b/core/config/project_settings.cpp
index 092177bc15..fa0e4037ba 100644
--- a/core/config/project_settings.cpp
+++ b/core/config/project_settings.cpp
@@ -1408,7 +1408,7 @@ void ProjectSettings::_add_builtin_input_map() {
}
Dictionary action;
- action["deadzone"] = Variant(0.2f);
+ action["deadzone"] = Variant(InputMap::DEFAULT_DEADZONE);
action["events"] = events;
String action_name = "input/" + E.key;
diff --git a/core/input/input_event.cpp b/core/input/input_event.cpp
index d125bad252..4733aaf220 100644
--- a/core/input/input_event.cpp
+++ b/core/input/input_event.cpp
@@ -1097,7 +1097,7 @@ JoyAxis InputEventJoypadMotion::get_axis() const {
void InputEventJoypadMotion::set_axis_value(float p_value) {
axis_value = p_value;
- pressed = Math::abs(axis_value) >= 0.5f;
+ pressed = Math::abs(axis_value) >= InputMap::DEFAULT_DEADZONE;
emit_changed();
}
diff --git a/core/input/input_map.cpp b/core/input/input_map.cpp
index 6378f18545..954df36f3e 100644
--- a/core/input/input_map.cpp
+++ b/core/input/input_map.cpp
@@ -42,7 +42,7 @@ InputMap *InputMap::singleton = nullptr;
void InputMap::_bind_methods() {
ClassDB::bind_method(D_METHOD("has_action", "action"), &InputMap::has_action);
ClassDB::bind_method(D_METHOD("get_actions"), &InputMap::_get_actions);
- ClassDB::bind_method(D_METHOD("add_action", "action", "deadzone"), &InputMap::add_action, DEFVAL(0.2f));
+ ClassDB::bind_method(D_METHOD("add_action", "action", "deadzone"), &InputMap::add_action, DEFVAL(DEFAULT_DEADZONE));
ClassDB::bind_method(D_METHOD("erase_action", "action"), &InputMap::erase_action);
ClassDB::bind_method(D_METHOD("action_set_deadzone", "action", "deadzone"), &InputMap::action_set_deadzone);
@@ -305,7 +305,7 @@ void InputMap::load_from_project_settings() {
String name = pi.name.substr(pi.name.find("/") + 1, pi.name.length());
Dictionary action = GLOBAL_GET(pi.name);
- float deadzone = action.has("deadzone") ? (float)action["deadzone"] : 0.2f;
+ float deadzone = action.has("deadzone") ? (float)action["deadzone"] : DEFAULT_DEADZONE;
Array events = action["events"];
add_action(name, deadzone);
diff --git a/core/input/input_map.h b/core/input/input_map.h
index 45798490f7..2b2a025332 100644
--- a/core/input/input_map.h
+++ b/core/input/input_map.h
@@ -49,6 +49,8 @@ public:
List<Ref<InputEvent>> inputs;
};
+ static constexpr float DEFAULT_DEADZONE = 0.2f;
+
private:
static InputMap *singleton;
@@ -74,7 +76,7 @@ public:
bool has_action(const StringName &p_action) const;
List<StringName> get_actions() const;
- void add_action(const StringName &p_action, float p_deadzone = 0.2);
+ void add_action(const StringName &p_action, float p_deadzone = DEFAULT_DEADZONE);
void erase_action(const StringName &p_action);
float action_get_deadzone(const StringName &p_action);
diff --git a/editor/project_settings_editor.cpp b/editor/project_settings_editor.cpp
index 89c18143dc..97f1d5d641 100644
--- a/editor/project_settings_editor.cpp
+++ b/editor/project_settings_editor.cpp
@@ -31,6 +31,7 @@
#include "project_settings_editor.h"
#include "core/config/project_settings.h"
+#include "core/input/input_map.h"
#include "editor/editor_inspector.h"
#include "editor/editor_node.h"
#include "editor/editor_settings.h"
@@ -390,7 +391,7 @@ void ProjectSettingsEditor::_action_added(const String &p_name) {
Dictionary action;
action["events"] = Array();
- action["deadzone"] = 0.2f;
+ action["deadzone"] = InputMap::DEFAULT_DEADZONE;
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
undo_redo->create_action(TTR("Add Input Action"));