diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2020-05-14 16:41:43 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2020-05-14 21:57:34 +0200 |
commit | 0ee0fa42e6639b6fa474b7cf6afc6b1a78142185 (patch) | |
tree | 198d4ff7665d89307f6ca2469fa38620a9eb1672 /core/input | |
parent | 07bc4e2f96f8f47991339654ff4ab16acc19d44f (diff) |
Style: Enforce braces around if blocks and loops
Using clang-tidy's `readability-braces-around-statements`.
https://clang.llvm.org/extra/clang-tidy/checks/readability-braces-around-statements.html
Diffstat (limited to 'core/input')
-rw-r--r-- | core/input/input.cpp | 63 | ||||
-rw-r--r-- | core/input/input_event.cpp | 81 | ||||
-rw-r--r-- | core/input/input_map.cpp | 30 |
3 files changed, 115 insertions, 59 deletions
diff --git a/core/input/input.cpp b/core/input/input.cpp index e81dfcf30f..dc1c207524 100644 --- a/core/input/input.cpp +++ b/core/input/input.cpp @@ -222,8 +222,9 @@ void Input::get_argument_options(const StringName &p_function, int p_idx, List<S for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { const PropertyInfo &pi = E->get(); - if (!pi.name.begins_with("input/")) + if (!pi.name.begins_with("input/")) { continue; + } String name = pi.name.substr(pi.name.find("/") + 1, pi.name.length()); r_options->push_back(quote_style + name + quote_style); @@ -241,8 +242,9 @@ void Input::SpeedTrack::update(const Vector2 &p_delta_p) { accum += p_delta_p; accum_t += delta_t; - if (accum_t > max_ref_frame * 10) + if (accum_t > max_ref_frame * 10) { accum_t = max_ref_frame * 10; + } while (accum_t >= min_ref_frame) { float slice_t = min_ref_frame / accum_t; @@ -291,8 +293,9 @@ bool Input::is_action_pressed(const StringName &p_action) const { bool Input::is_action_just_pressed(const StringName &p_action) const { const Map<StringName, Action>::Element *E = action_state.find(p_action); - if (!E) + if (!E) { return false; + } if (Engine::get_singleton()->is_in_physics_frame()) { return E->get().pressed && E->get().physics_frame == Engine::get_singleton()->get_physics_frames(); @@ -303,8 +306,9 @@ bool Input::is_action_just_pressed(const StringName &p_action) const { bool Input::is_action_just_released(const StringName &p_action) const { const Map<StringName, Action>::Element *E = action_state.find(p_action); - if (!E) + if (!E) { return false; + } if (Engine::get_singleton()->is_in_physics_frame()) { return !E->get().pressed && E->get().physics_frame == Engine::get_singleton()->get_physics_frames(); @@ -315,8 +319,9 @@ bool Input::is_action_just_released(const StringName &p_action) const { float Input::get_action_strength(const StringName &p_action) const { const Map<StringName, Action>::Element *E = action_state.find(p_action); - if (!E) + if (!E) { return 0.0f; + } return E->get().strength; } @@ -446,10 +451,11 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em Ref<InputEventKey> k = p_event; if (k.is_valid() && !k->is_echo() && k->get_keycode() != 0) { - if (k->is_pressed()) + if (k->is_pressed()) { keys_pressed.insert(k->get_keycode()); - else + } else { keys_pressed.erase(k->get_keycode()); + } } Ref<InputEventMouseButton> mb = p_event; @@ -568,10 +574,11 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em if (jb.is_valid()) { int c = _combine_device(jb->get_button_index(), jb->get_device()); - if (jb->is_pressed()) + if (jb->is_pressed()) { joy_buttons_pressed.insert(c); - else + } else { joy_buttons_pressed.erase(c); + } } Ref<InputEventJoypadMotion> jm = p_event; @@ -603,8 +610,9 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em } } - if (event_dispatch_function) + if (event_dispatch_function) { event_dispatch_function(p_event); + } } void Input::set_joy_axis(int p_device, int p_axis, float p_value) { @@ -776,8 +784,9 @@ Input::CursorShape Input::get_default_cursor_shape() const { } void Input::set_default_cursor_shape(CursorShape p_shape) { - if (default_shape == p_shape) + if (default_shape == p_shape) { return; + } default_shape = p_shape; // The default shape is set in Viewport::_gui_input_event. To instantly @@ -794,8 +803,9 @@ Input::CursorShape Input::get_current_cursor_shape() const { } void Input::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) { - if (Engine::get_singleton()->is_editor_hint()) + if (Engine::get_singleton()->is_editor_hint()) { return; + } set_custom_mouse_cursor_func(p_cursor, p_shape, p_hotspot); } @@ -833,8 +843,9 @@ void Input::release_pressed_events() { _joy_axis.clear(); for (Map<StringName, Input::Action>::Element *E = action_state.front(); E; E = E->next()) { - if (E->get().pressed) + if (E->get().pressed) { action_release(E->key()); + } } } @@ -1064,8 +1075,9 @@ Input::JoyEvent Input::_get_mapped_axis_event(const JoyDeviceMapping &mapping, i const JoyBinding binding = mapping.bindings[i]; if (binding.inputType == TYPE_AXIS && binding.input.axis.axis == p_axis) { float value = p_value.value; - if (binding.input.axis.invert) + if (binding.input.axis.invert) { value = -value; + } if (binding.input.axis.range == FULL_AXIS || (binding.input.axis.range == POSITIVE_HALF_AXIS && value > 0) || (binding.input.axis.range == NEGATIVE_HALF_AXIS && value < 0)) { @@ -1152,16 +1164,18 @@ void Input::_get_mapped_hat_events(const JoyDeviceMapping &mapping, int p_hat, J JoyButtonList Input::_get_output_button(String output) { for (int i = 0; _joy_buttons[i]; i++) { - if (output == _joy_buttons[i]) + if (output == _joy_buttons[i]) { return JoyButtonList(i); + } } return JoyButtonList::JOY_INVALID_BUTTON; } JoyAxisList Input::_get_output_axis(String output) { for (int i = 0; _joy_axes[i]; i++) { - if (output == _joy_axes[i]) + if (output == _joy_axes[i]) { return JoyAxisList(i); + } } return JoyAxisList::JOY_INVALID_AXIS; } @@ -1183,25 +1197,28 @@ void Input::parse_mapping(String p_mapping) { int idx = 1; while (++idx < entry.size()) { - if (entry[idx] == "") + if (entry[idx] == "") { continue; + } String output = entry[idx].get_slice(":", 0).replace(" ", ""); String input = entry[idx].get_slice(":", 1).replace(" ", ""); ERR_CONTINUE_MSG(output.length() < 1 || input.length() < 2, String(entry[idx] + "\nInvalid device mapping entry: " + entry[idx])); - if (output == "platform") + if (output == "platform") { continue; + } JoyAxisRange output_range = FULL_AXIS; if (output[0] == '+' || output[0] == '-') { ERR_CONTINUE_MSG(output.length() < 2, String(entry[idx] + "\nInvalid output: " + entry[idx])); output = output.right(1); - if (output[0] == '+') + if (output[0] == '+') { output_range = POSITIVE_HALF_AXIS; - else if (output[0] == '-') + } else if (output[0] == '-') { output_range = NEGATIVE_HALF_AXIS; + } } JoyAxisRange input_range = FULL_AXIS; @@ -1213,8 +1230,9 @@ void Input::parse_mapping(String p_mapping) { input = input.right(1); } bool invert_axis = false; - if (input[input.length() - 1] == '~') + if (input[input.length() - 1] == '~') { invert_axis = true; + } JoyButtonList output_button = _get_output_button(output); JoyAxisList output_axis = _get_output_axis(output); @@ -1372,8 +1390,9 @@ Input::Input() { if (env_mapping != "") { Vector<String> entries = env_mapping.split("\n"); for (int i = 0; i < entries.size(); i++) { - if (entries[i] == "") + if (entries[i] == "") { continue; + } parse_mapping(entries[i]); } } diff --git a/core/input/input_event.cpp b/core/input/input_event.cpp index 497ce79038..6ba082f86f 100644 --- a/core/input/input_event.cpp +++ b/core/input/input_event.cpp @@ -252,36 +252,45 @@ bool InputEventKey::is_echo() const { uint32_t InputEventKey::get_keycode_with_modifiers() const { uint32_t sc = keycode; - if (get_control()) + if (get_control()) { sc |= KEY_MASK_CTRL; - if (get_alt()) + } + if (get_alt()) { sc |= KEY_MASK_ALT; - if (get_shift()) + } + if (get_shift()) { sc |= KEY_MASK_SHIFT; - if (get_metakey()) + } + if (get_metakey()) { sc |= KEY_MASK_META; + } return sc; } uint32_t InputEventKey::get_physical_keycode_with_modifiers() const { uint32_t sc = physical_keycode; - if (get_control()) + if (get_control()) { sc |= KEY_MASK_CTRL; - if (get_alt()) + } + if (get_alt()) { sc |= KEY_MASK_ALT; - if (get_shift()) + } + if (get_shift()) { sc |= KEY_MASK_SHIFT; - if (get_metakey()) + } + if (get_metakey()) { sc |= KEY_MASK_META; + } return sc; } String InputEventKey::as_text() const { String kc = keycode_get_string(keycode); - if (kc == String()) + if (kc == String()) { return kc; + } if (get_metakey()) { kc = find_keycode_name(KEY_META) + ("+" + kc); @@ -300,8 +309,9 @@ String InputEventKey::as_text() const { bool InputEventKey::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const { Ref<InputEventKey> key = p_event; - if (key.is_null()) + if (key.is_null()) { return false; + } bool match = false; if (get_keycode() == 0) { @@ -316,18 +326,21 @@ bool InputEventKey::action_match(const Ref<InputEvent> &p_event, bool *p_pressed match = get_keycode() == key->get_keycode() && (!key->is_pressed() || (code & event_code) == code); } if (match) { - if (p_pressed != nullptr) + if (p_pressed != nullptr) { *p_pressed = key->is_pressed(); - if (p_strength != nullptr) + } + if (p_strength != nullptr) { *p_strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f; + } } return match; } bool InputEventKey::shortcut_match(const Ref<InputEvent> &p_event) const { Ref<InputEventKey> key = p_event; - if (key.is_null()) + if (key.is_null()) { return false; + } uint32_t code = get_keycode_with_modifiers(); uint32_t event_code = key->get_keycode_with_modifiers(); @@ -459,15 +472,18 @@ Ref<InputEvent> InputEventMouseButton::xformed_by(const Transform2D &p_xform, co bool InputEventMouseButton::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const { Ref<InputEventMouseButton> mb = p_event; - if (mb.is_null()) + if (mb.is_null()) { return false; + } bool match = mb->button_index == button_index; if (match) { - if (p_pressed != nullptr) + if (p_pressed != nullptr) { *p_pressed = mb->is_pressed(); - if (p_strength != nullptr) + } + if (p_strength != nullptr) { *p_strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f; + } } return match; @@ -616,8 +632,9 @@ String InputEventMouseMotion::as_text() const { bool InputEventMouseMotion::accumulate(const Ref<InputEvent> &p_event) { Ref<InputEventMouseMotion> motion = p_event; - if (motion.is_null()) + if (motion.is_null()) { return false; + } if (get_window_id() != motion->get_window_id()) { return false; @@ -698,15 +715,17 @@ bool InputEventJoypadMotion::is_pressed() const { bool InputEventJoypadMotion::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const { Ref<InputEventJoypadMotion> jm = p_event; - if (jm.is_null()) + if (jm.is_null()) { return false; + } bool match = (axis == jm->axis); // Matches even if not in the same direction, but returns a "not pressed" event. if (match) { bool same_direction = (((axis_value < 0) == (jm->axis_value < 0)) || jm->axis_value == 0); bool pressed = same_direction ? Math::abs(jm->get_axis_value()) >= p_deadzone : false; - if (p_pressed != nullptr) + if (p_pressed != nullptr) { *p_pressed = pressed; + } if (p_strength != nullptr) { if (pressed) { if (p_deadzone == 1.0f) { @@ -765,15 +784,18 @@ float InputEventJoypadButton::get_pressure() const { bool InputEventJoypadButton::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const { Ref<InputEventJoypadButton> jb = p_event; - if (jb.is_null()) + if (jb.is_null()) { return false; + } bool match = button_index == jb->button_index; if (match) { - if (p_pressed != nullptr) + if (p_pressed != nullptr) { *p_pressed = jb->is_pressed(); - if (p_strength != nullptr) + } + if (p_strength != nullptr) { *p_strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f; + } } return match; @@ -781,8 +803,9 @@ bool InputEventJoypadButton::action_match(const Ref<InputEvent> &p_event, bool * bool InputEventJoypadButton::shortcut_match(const Ref<InputEvent> &p_event) const { Ref<InputEventJoypadButton> button = p_event; - if (button.is_null()) + if (button.is_null()) { return false; + } return button_index == button->button_index; } @@ -963,8 +986,9 @@ float InputEventAction::get_strength() const { } bool InputEventAction::shortcut_match(const Ref<InputEvent> &p_event) const { - if (p_event.is_null()) + if (p_event.is_null()) { return false; + } return p_event->is_action(action); } @@ -975,15 +999,18 @@ bool InputEventAction::is_action(const StringName &p_action) const { bool InputEventAction::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const { Ref<InputEventAction> act = p_event; - if (act.is_null()) + if (act.is_null()) { return false; + } bool match = action == act->action; if (match) { - if (p_pressed != nullptr) + if (p_pressed != nullptr) { *p_pressed = act->pressed; - if (p_strength != nullptr) + } + if (p_strength != nullptr) { *p_strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f; + } } return match; } diff --git a/core/input/input_map.cpp b/core/input/input_map.cpp index d341b5ba4c..3cb4b43a26 100644 --- a/core/input/input_map.cpp +++ b/core/input/input_map.cpp @@ -70,8 +70,9 @@ void InputMap::erase_action(const StringName &p_action) { Array InputMap::_get_actions() { Array ret; List<StringName> actions = get_actions(); - if (actions.empty()) + if (actions.empty()) { return ret; + } for (const List<StringName>::Element *E = actions.front(); E; E = E->next()) { ret.push_back(E->get()); @@ -124,8 +125,9 @@ void InputMap::action_set_deadzone(const StringName &p_action, float p_deadzone) void InputMap::action_add_event(const StringName &p_action, const Ref<InputEvent> &p_event) { ERR_FAIL_COND_MSG(p_event.is_null(), "It's not a reference to a valid InputEvent object."); ERR_FAIL_COND_MSG(!input_map.has(p_action), "Request for nonexistent InputMap action '" + String(p_action) + "'."); - if (_find_event(input_map[p_action], p_event)) + if (_find_event(input_map[p_action], p_event)) { return; //already gots + } input_map[p_action].inputs.push_back(p_event); } @@ -139,8 +141,9 @@ void InputMap::action_erase_event(const StringName &p_action, const Ref<InputEve ERR_FAIL_COND_MSG(!input_map.has(p_action), "Request for nonexistent InputMap action '" + String(p_action) + "'."); List<Ref<InputEvent>>::Element *E = _find_event(input_map[p_action], p_event); - if (E) + if (E) { input_map[p_action].inputs.erase(E); + } } void InputMap::action_erase_events(const StringName &p_action) { @@ -163,8 +166,9 @@ Array InputMap::_get_action_list(const StringName &p_action) { const List<Ref<InputEvent>> *InputMap::get_action_list(const StringName &p_action) { const Map<StringName, Action>::Element *E = input_map.find(p_action); - if (!E) + if (!E) { return nullptr; + } return &E->get().inputs; } @@ -179,10 +183,12 @@ bool InputMap::event_get_action_status(const Ref<InputEvent> &p_event, const Str Ref<InputEventAction> input_event_action = p_event; if (input_event_action.is_valid()) { - if (p_pressed != nullptr) + if (p_pressed != nullptr) { *p_pressed = input_event_action->is_pressed(); - if (p_strength != nullptr) + } + if (p_strength != nullptr) { *p_strength = (p_pressed != nullptr && *p_pressed) ? input_event_action->get_strength() : 0.0f; + } return input_event_action->get_action() == p_action; } @@ -190,10 +196,12 @@ bool InputMap::event_get_action_status(const Ref<InputEvent> &p_event, const Str float strength; List<Ref<InputEvent>>::Element *event = _find_event(E->get(), p_event, &pressed, &strength); if (event != nullptr) { - if (p_pressed != nullptr) + if (p_pressed != nullptr) { *p_pressed = pressed; - if (p_strength != nullptr) + } + if (p_strength != nullptr) { *p_strength = strength; + } return true; } else { return false; @@ -213,8 +221,9 @@ void InputMap::load_from_globals() { for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { const PropertyInfo &pi = E->get(); - if (!pi.name.begins_with("input/")) + if (!pi.name.begins_with("input/")) { continue; + } String name = pi.name.substr(pi.name.find("/") + 1, pi.name.length()); @@ -225,8 +234,9 @@ void InputMap::load_from_globals() { add_action(name, deadzone); for (int i = 0; i < events.size(); i++) { Ref<InputEvent> event = events[i]; - if (event.is_null()) + if (event.is_null()) { continue; + } action_add_event(name, event); } } |