Skip to content

Commit 829dade

Browse files
committed
Replace default deadzone magic number with named constant
1 parent 0f5f3bc commit 829dade

File tree

5 files changed

+9
-6
lines changed

5 files changed

+9
-6
lines changed

core/config/project_settings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1408,7 +1408,7 @@ void ProjectSettings::_add_builtin_input_map() {
14081408
}
14091409

14101410
Dictionary action;
1411-
action["deadzone"] = Variant(0.2f);
1411+
action["deadzone"] = Variant(InputMap::DEFAULT_DEADZONE);
14121412
action["events"] = events;
14131413

14141414
String action_name = "input/" + E.key;

core/input/input_event.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,7 @@ JoyAxis InputEventJoypadMotion::get_axis() const {
10971097

10981098
void InputEventJoypadMotion::set_axis_value(float p_value) {
10991099
axis_value = p_value;
1100-
pressed = Math::abs(axis_value) >= 0.5f;
1100+
pressed = Math::abs(axis_value) >= InputMap::DEFAULT_DEADZONE;
11011101
emit_changed();
11021102
}
11031103

core/input/input_map.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ InputMap *InputMap::singleton = nullptr;
4242
void InputMap::_bind_methods() {
4343
ClassDB::bind_method(D_METHOD("has_action", "action"), &InputMap::has_action);
4444
ClassDB::bind_method(D_METHOD("get_actions"), &InputMap::_get_actions);
45-
ClassDB::bind_method(D_METHOD("add_action", "action", "deadzone"), &InputMap::add_action, DEFVAL(0.2f));
45+
ClassDB::bind_method(D_METHOD("add_action", "action", "deadzone"), &InputMap::add_action, DEFVAL(DEFAULT_DEADZONE));
4646
ClassDB::bind_method(D_METHOD("erase_action", "action"), &InputMap::erase_action);
4747

4848
ClassDB::bind_method(D_METHOD("action_set_deadzone", "action", "deadzone"), &InputMap::action_set_deadzone);
@@ -305,7 +305,7 @@ void InputMap::load_from_project_settings() {
305305
String name = pi.name.substr(pi.name.find("/") + 1, pi.name.length());
306306

307307
Dictionary action = GLOBAL_GET(pi.name);
308-
float deadzone = action.has("deadzone") ? (float)action["deadzone"] : 0.2f;
308+
float deadzone = action.has("deadzone") ? (float)action["deadzone"] : DEFAULT_DEADZONE;
309309
Array events = action["events"];
310310

311311
add_action(name, deadzone);

core/input/input_map.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ class InputMap : public Object {
4949
List<Ref<InputEvent>> inputs;
5050
};
5151

52+
static constexpr float DEFAULT_DEADZONE = 0.2f;
53+
5254
private:
5355
static InputMap *singleton;
5456

@@ -74,7 +76,7 @@ class InputMap : public Object {
7476

7577
bool has_action(const StringName &p_action) const;
7678
List<StringName> get_actions() const;
77-
void add_action(const StringName &p_action, float p_deadzone = 0.2);
79+
void add_action(const StringName &p_action, float p_deadzone = DEFAULT_DEADZONE);
7880
void erase_action(const StringName &p_action);
7981

8082
float action_get_deadzone(const StringName &p_action);

editor/project_settings_editor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "project_settings_editor.h"
3232

3333
#include "core/config/project_settings.h"
34+
#include "core/input/input_map.h"
3435
#include "editor/editor_inspector.h"
3536
#include "editor/editor_node.h"
3637
#include "editor/editor_settings.h"
@@ -390,7 +391,7 @@ void ProjectSettingsEditor::_action_added(const String &p_name) {
390391

391392
Dictionary action;
392393
action["events"] = Array();
393-
action["deadzone"] = 0.2f;
394+
action["deadzone"] = InputMap::DEFAULT_DEADZONE;
394395

395396
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
396397
undo_redo->create_action(TTR("Add Input Action"));

0 commit comments

Comments
 (0)