summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2019-06-27 01:05:18 +0200
committerGitHub <noreply@github.com>2019-06-27 01:05:18 +0200
commiteaaff9da3178fa515a0f051fda932c1dd04d53db (patch)
tree56173535c376e0324f89baccf4bc14b2580ead23 /main
parentd8c96461183f0dc3208c3d624674fa4544212ea5 (diff)
parent4e5310cc60dc17e5ef09e57115ca8236544679e4 (diff)
Merge pull request #29941 from qarmin/redundant_code_and_others
Remove redundant code, possible NULL pointers and others
Diffstat (limited to 'main')
-rw-r--r--main/input_default.cpp40
-rw-r--r--main/main.cpp4
-rw-r--r--main/tests/test_gdscript.cpp4
-rw-r--r--main/tests/test_physics.cpp1
-rw-r--r--main/tests/test_string.cpp6
5 files changed, 26 insertions, 29 deletions
diff --git a/main/input_default.cpp b/main/input_default.cpp
index a939d77a1e..199fcfcf66 100644
--- a/main/input_default.cpp
+++ b/main/input_default.cpp
@@ -726,14 +726,14 @@ InputDefault::InputDefault() {
if (entries[i] == "")
continue;
parse_mapping(entries[i]);
- };
- };
+ }
+ }
int i = 0;
while (DefaultControllerMappings::mappings[i]) {
parse_mapping(DefaultControllerMappings::mappings[i++]);
- };
+ }
}
void InputDefault::joy_button(int p_device, int p_button, bool p_pressed) {
@@ -748,14 +748,14 @@ void InputDefault::joy_button(int p_device, int p_button, bool p_pressed) {
if (joy.mapping == -1) {
_button_event(p_device, p_button, p_pressed);
return;
- };
+ }
const Map<int, JoyEvent>::Element *el = map_db[joy.mapping].buttons.find(p_button);
if (!el) {
//don't process un-mapped events for now, it could mess things up badly for devices with additional buttons/axis
//return _button_event(p_last_id, p_device, p_button, p_pressed);
return;
- };
+ }
JoyEvent map = el->get();
if (map.type == TYPE_BUTTON) {
@@ -767,14 +767,13 @@ void InputDefault::joy_button(int p_device, int p_button, bool p_pressed) {
}
_button_event(p_device, map.index, p_pressed);
return;
- };
+ }
if (map.type == TYPE_AXIS) {
_axis_event(p_device, map.index, p_pressed ? 1.0 : 0.0);
- };
-
- return; // no event?
-};
+ }
+ // no event?
+}
void InputDefault::joy_axis(int p_device, int p_axis, const JoyAxis &p_value) {
@@ -878,19 +877,18 @@ void InputDefault::joy_axis(int p_device, int p_axis, const JoyAxis &p_value) {
if (pressed == joy_buttons_pressed.has(_combine_device(map.index, p_device))) {
// button already pressed or released, this is an axis bounce value
return;
- };
+ }
_button_event(p_device, map.index, pressed);
return;
- };
+ }
if (map.type == TYPE_AXIS) {
_axis_event(p_device, map.index, val);
return;
- };
+ }
//printf("invalid mapping\n");
- return;
-};
+}
void InputDefault::joy_hat(int p_device, int p_val) {
@@ -909,20 +907,20 @@ void InputDefault::joy_hat(int p_device, int p_val) {
if ((p_val & HAT_MASK_UP) != (cur_val & HAT_MASK_UP)) {
_button_event(p_device, map[HAT_UP].index, p_val & HAT_MASK_UP);
- };
+ }
if ((p_val & HAT_MASK_RIGHT) != (cur_val & HAT_MASK_RIGHT)) {
_button_event(p_device, map[HAT_RIGHT].index, p_val & HAT_MASK_RIGHT);
- };
+ }
if ((p_val & HAT_MASK_DOWN) != (cur_val & HAT_MASK_DOWN)) {
_button_event(p_device, map[HAT_DOWN].index, p_val & HAT_MASK_DOWN);
- };
+ }
if ((p_val & HAT_MASK_LEFT) != (cur_val & HAT_MASK_LEFT)) {
_button_event(p_device, map[HAT_LEFT].index, p_val & HAT_MASK_LEFT);
- };
+ }
joy_names[p_device].hat_current = p_val;
-};
+}
void InputDefault::_button_event(int p_device, int p_index, bool p_pressed) {
@@ -933,7 +931,7 @@ void InputDefault::_button_event(int p_device, int p_index, bool p_pressed) {
ievent->set_pressed(p_pressed);
parse_input_event(ievent);
-};
+}
void InputDefault::_axis_event(int p_device, int p_axis, float p_value) {
diff --git a/main/main.cpp b/main/main.cpp
index c765ff9700..9183dab58c 100644
--- a/main/main.cpp
+++ b/main/main.cpp
@@ -812,7 +812,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
int sp = bp.find_last(":");
if (sp == -1) {
ERR_EXPLAIN("Invalid breakpoint: '" + bp + "', expected file:line format.");
- ERR_CONTINUE(sp == -1);
+ ERR_CONTINUE(true);
}
script_debugger->insert_breakpoint(bp.substr(sp + 1, bp.length()).to_int(), bp.substr(0, sp));
@@ -1469,7 +1469,7 @@ bool Main::start() {
if (obj)
memdelete(obj);
ERR_EXPLAIN("Can't load script '" + script + "', it does not inherit from a MainLoop type");
- ERR_FAIL_COND_V(!script_loop, false);
+ ERR_FAIL_V(false);
}
script_loop->set_init_script(script_res);
diff --git a/main/tests/test_gdscript.cpp b/main/tests/test_gdscript.cpp
index 87bd640001..e82af93293 100644
--- a/main/tests/test_gdscript.cpp
+++ b/main/tests/test_gdscript.cpp
@@ -911,7 +911,7 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
if (incr == 0) {
ERR_EXPLAIN("unhandled opcode: " + itos(code[ip]));
- ERR_BREAK(incr == 0);
+ ERR_BREAK(true);
}
ip += incr;
@@ -974,7 +974,7 @@ MainLoop *test(TestType p_type) {
if (tk.get_token() == GDScriptTokenizer::TK_IDENTIFIER)
text = "'" + tk.get_token_identifier() + "' (identifier)";
else if (tk.get_token() == GDScriptTokenizer::TK_CONSTANT) {
- Variant c = tk.get_token_constant();
+ const Variant &c = tk.get_token_constant();
if (c.get_type() == Variant::STRING)
text = "\"" + String(c) + "\"";
else
diff --git a/main/tests/test_physics.cpp b/main/tests/test_physics.cpp
index 84f504a78d..6850c4d88a 100644
--- a/main/tests/test_physics.cpp
+++ b/main/tests/test_physics.cpp
@@ -329,7 +329,6 @@ public:
make_grid(5, 5, 2.5, 1, gxf);
test_fall();
quit = false;
- return;
}
virtual bool iteration(float p_time) {
diff --git a/main/tests/test_string.cpp b/main/tests/test_string.cpp
index a107fd738f..05df888f40 100644
--- a/main/tests/test_string.cpp
+++ b/main/tests/test_string.cpp
@@ -57,7 +57,7 @@ bool test_2() {
OS::get_singleton()->print("\n\nTest 2: Assign from string (operator=)\n");
String s = "Dolly";
- String t = s;
+ const String &t = s;
OS::get_singleton()->print("\tExpected: Dolly\n");
OS::get_singleton()->print("\tResulted: %ls\n", t.c_str());
@@ -70,7 +70,7 @@ bool test_3() {
OS::get_singleton()->print("\n\nTest 3: Assign from c-string (copycon)\n");
String s("Sheep");
- String t(s);
+ const String &t(s);
OS::get_singleton()->print("\tExpected: Sheep\n");
OS::get_singleton()->print("\tResulted: %ls\n", t.c_str());
@@ -1062,7 +1062,7 @@ bool test_33() {
OS::get_singleton()->print("\n\nTest 33: parse_utf8(null, -1)\n");
String empty;
- return empty.parse_utf8(NULL, -1) == true;
+ return empty.parse_utf8(NULL, -1);
}
bool test_34() {