summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
Diffstat (limited to 'main')
-rw-r--r--main/main.cpp143
-rw-r--r--main/main_timer_sync.cpp19
-rw-r--r--main/performance.cpp3
-rw-r--r--main/tests/test_astar.cpp77
-rw-r--r--main/tests/test_gdscript.cpp105
-rw-r--r--main/tests/test_math.cpp9
-rw-r--r--main/tests/test_oa_hash_map.cpp6
-rw-r--r--main/tests/test_ordered_hash_map.cpp6
-rw-r--r--main/tests/test_physics_2d.cpp3
-rw-r--r--main/tests/test_render.cpp3
-rw-r--r--main/tests/test_shader_lang.cpp12
-rw-r--r--main/tests/test_string.cpp93
12 files changed, 309 insertions, 170 deletions
diff --git a/main/main.cpp b/main/main.cpp
index ef632e197c..f35e73cdc2 100644
--- a/main/main.cpp
+++ b/main/main.cpp
@@ -177,8 +177,9 @@ static String unescape_cmdline(const String &p_str) {
static String get_full_version_string() {
String hash = String(VERSION_HASH);
- if (hash.length() != 0)
+ if (hash.length() != 0) {
hash = "." + hash.left(9);
+ }
return String(VERSION_FULL_BUILD) + hash;
}
@@ -458,8 +459,9 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
bool use_vsync = false;
packed_data = PackedData::get_singleton();
- if (!packed_data)
+ if (!packed_data) {
packed_data = memnew(PackedData);
+ }
#ifdef MINIZIP_ENABLED
@@ -696,12 +698,13 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
} else if (I->get() == "--render-thread") { // render thread mode
if (I->next()) {
- if (I->next()->get() == "safe")
+ if (I->next()->get() == "safe") {
rtm = OS::RENDER_THREAD_SAFE;
- else if (I->next()->get() == "unsafe")
+ } else if (I->next()->get() == "unsafe") {
rtm = OS::RENDER_THREAD_UNSAFE;
- else if (I->next()->get() == "separate")
+ } else if (I->next()->get() == "separate") {
rtm = OS::RENDER_SEPARATE_THREAD;
+ }
N = I->next()->next();
} else {
@@ -754,9 +757,9 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
String path;
String file = I->get();
int sep = MAX(file.find_last("/"), file.find_last("\\"));
- if (sep == -1)
+ if (sep == -1) {
path = ".";
- else {
+ } else {
path = file.substr(0, sep);
}
if (OS::get_singleton()->set_cwd(path) == OK) {
@@ -976,8 +979,9 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
_print_error_enabled = false;
};
- if (quiet_stdout)
+ if (quiet_stdout) {
_print_line_enabled = false;
+ }
OS::get_singleton()->set_cmdline(execpath, main_args);
@@ -1116,20 +1120,21 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
{
String orientation = GLOBAL_DEF("display/window/handheld/orientation", "landscape");
- if (orientation == "portrait")
+ if (orientation == "portrait") {
window_orientation = DisplayServer::SCREEN_PORTRAIT;
- else if (orientation == "reverse_landscape")
+ } else if (orientation == "reverse_landscape") {
window_orientation = DisplayServer::SCREEN_REVERSE_LANDSCAPE;
- else if (orientation == "reverse_portrait")
+ } else if (orientation == "reverse_portrait") {
window_orientation = DisplayServer::SCREEN_REVERSE_PORTRAIT;
- else if (orientation == "sensor_landscape")
+ } else if (orientation == "sensor_landscape") {
window_orientation = DisplayServer::SCREEN_SENSOR_LANDSCAPE;
- else if (orientation == "sensor_portrait")
+ } else if (orientation == "sensor_portrait") {
window_orientation = DisplayServer::SCREEN_SENSOR_PORTRAIT;
- else if (orientation == "sensor")
+ } else if (orientation == "sensor") {
window_orientation = DisplayServer::SCREEN_SENSOR;
- else
+ } else {
window_orientation = DisplayServer::SCREEN_LANDSCAPE;
+ }
}
Engine::get_singleton()->set_iterations_per_second(GLOBAL_DEF("physics/common/physics_fps", 60));
@@ -1160,8 +1165,9 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
message_queue = memnew(MessageQueue);
- if (p_second_phase)
+ if (p_second_phase) {
return setup2();
+ }
return OK;
@@ -1174,33 +1180,42 @@ error:
args.clear();
main_args.clear();
- if (show_help)
+ if (show_help) {
print_help(execpath);
+ }
EngineDebugger::deinitialize();
- if (performance)
+ if (performance) {
memdelete(performance);
- if (input_map)
+ }
+ if (input_map) {
memdelete(input_map);
- if (translation_server)
+ }
+ if (translation_server) {
memdelete(translation_server);
- if (globals)
+ }
+ if (globals) {
memdelete(globals);
- if (engine)
+ }
+ if (engine) {
memdelete(engine);
- if (packed_data)
+ }
+ if (packed_data) {
memdelete(packed_data);
- if (file_access_network_client)
+ }
+ if (file_access_network_client) {
memdelete(file_access_network_client);
+ }
unregister_core_driver_types();
unregister_core_types();
OS::get_singleton()->_cmdline.clear();
- if (message_queue)
+ if (message_queue) {
memdelete(message_queue);
+ }
OS::get_singleton()->finalize_core();
locale = String();
@@ -1333,8 +1348,9 @@ Error Main::setup2(Thread::ID p_main_tid_override) {
if (boot_logo_path != String()) {
boot_logo.instance();
Error load_err = ImageLoader::load_image(boot_logo_path, boot_logo);
- if (load_err)
+ if (load_err) {
ERR_PRINT("Non-existing or invalid boot splash at '" + boot_logo_path + "'. Loading default splash.");
+ }
}
Color boot_bg_color = GLOBAL_DEF("application/boot_splash/bg_color", boot_splash_bg_color);
@@ -1536,8 +1552,9 @@ bool Main::start() {
#ifdef TOOLS_ENABLED
} else if (args[i] == "--doctool") {
doc_tool = args[i + 1];
- for (int j = i + 2; j < args.size(); j++)
+ for (int j = i + 2; j < args.size(); j++) {
removal_docs.push_back(args[j]);
+ }
} else if (args[i] == "--export") {
editor = true; //needs editor
_export_preset = args[i + 1];
@@ -1653,8 +1670,9 @@ bool Main::start() {
#ifdef TOOLS_ENABLED
main_loop = test_main(test, args);
- if (!main_loop)
+ if (!main_loop) {
return false;
+ }
#endif
} else if (script != "") {
@@ -1673,8 +1691,9 @@ bool Main::start() {
Object *obj = ClassDB::instance(instance_type);
MainLoop *script_loop = Object::cast_to<MainLoop>(obj);
if (!script_loop) {
- if (obj)
+ if (obj) {
memdelete(obj);
+ }
ERR_FAIL_V_MSG(false, vformat("Can't load the script \"%s\" as it doesn't inherit from SceneTree or MainLoop.", script));
}
@@ -1688,8 +1707,9 @@ bool Main::start() {
main_loop_type = GLOBAL_DEF("application/run/main_loop_type", "");
}
- if (!main_loop && main_loop_type == "")
+ if (!main_loop && main_loop_type == "") {
main_loop_type = "SceneTree";
+ }
if (!main_loop) {
if (!ClassDB::class_exists(main_loop_type)) {
@@ -1736,8 +1756,9 @@ bool Main::start() {
//first pass, add the constants so they exist before any script is loaded
for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
String s = E->get().name;
- if (!s.begins_with("autoload/"))
+ if (!s.begins_with("autoload/")) {
continue;
+ }
String name = s.get_slicec('/', 1);
String path = ProjectSettings::get_singleton()->get(s);
bool global_var = false;
@@ -1756,8 +1777,9 @@ bool Main::start() {
List<Node *> to_add;
for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
String s = E->get().name;
- if (!s.begins_with("autoload/"))
+ if (!s.begins_with("autoload/")) {
continue;
+ }
String name = s.get_slicec('/', 1);
String path = ProjectSettings::get_singleton()->get(s);
bool global_var = false;
@@ -1831,20 +1853,22 @@ bool Main::start() {
Size2i stretch_size = Size2(GLOBAL_DEF("display/window/size/width", 0), GLOBAL_DEF("display/window/size/height", 0));
Window::ContentScaleMode cs_sm = Window::CONTENT_SCALE_MODE_DISABLED;
- if (stretch_mode == "objects")
+ if (stretch_mode == "objects") {
cs_sm = Window::CONTENT_SCALE_MODE_OBJECTS;
- else if (stretch_mode == "pixels")
+ } else if (stretch_mode == "pixels") {
cs_sm = Window::CONTENT_SCALE_MODE_PIXELS;
+ }
Window::ContentScaleAspect cs_aspect = Window::CONTENT_SCALE_ASPECT_IGNORE;
- if (stretch_aspect == "keep")
+ if (stretch_aspect == "keep") {
cs_aspect = Window::CONTENT_SCALE_ASPECT_KEEP;
- else if (stretch_aspect == "keep_width")
+ } else if (stretch_aspect == "keep_width") {
cs_aspect = Window::CONTENT_SCALE_ASPECT_KEEP_WIDTH;
- else if (stretch_aspect == "keep_height")
+ } else if (stretch_aspect == "keep_height") {
cs_aspect = Window::CONTENT_SCALE_ASPECT_KEEP_HEIGHT;
- else if (stretch_aspect == "expand")
+ } else if (stretch_aspect == "expand") {
cs_aspect = Window::CONTENT_SCALE_ASPECT_EXPAND;
+ }
sml->get_root()->set_content_scale_mode(cs_sm);
sml->get_root()->set_content_scale_aspect(cs_aspect);
@@ -1938,8 +1962,9 @@ bool Main::start() {
if (game_path != GLOBAL_GET("application/run/main_scene") || !editor_node->has_scenes_in_session()) {
Error serr = editor_node->load_scene(local_game_path);
- if (serr != OK)
+ if (serr != OK) {
ERR_PRINT("Failed to load scene");
+ }
}
DisplayServer::get_singleton()->set_context(DisplayServer::CONTEXT_EDITOR);
}
@@ -1957,8 +1982,9 @@ bool Main::start() {
if (game_path != "") {
Node *scene = nullptr;
Ref<PackedScene> scenedata = ResourceLoader::load(local_game_path);
- if (scenedata.is_valid())
+ if (scenedata.is_valid()) {
scene = scenedata->instance();
+ }
ERR_FAIL_COND_V_MSG(!scene, false, "Failed loading scene: " + local_game_path);
sml->add_current_scene(scene);
@@ -2155,8 +2181,9 @@ bool Main::iteration() {
AudioServer::get_singleton()->update();
- if (EngineDebugger::is_active())
+ if (EngineDebugger::is_active()) {
EngineDebugger::get_singleton()->iteration(frame_time, idle_process_ticks, physics_process_ticks, frame_slice);
+ }
frames++;
Engine::get_singleton()->_idle_frames++;
@@ -2182,15 +2209,17 @@ bool Main::iteration() {
iterating--;
- if (fixed_fps != -1)
+ if (fixed_fps != -1) {
return exit;
+ }
- if (OS::get_singleton()->is_in_low_processor_usage_mode() || !DisplayServer::get_singleton()->can_any_window_draw())
+ if (OS::get_singleton()->is_in_low_processor_usage_mode() || !DisplayServer::get_singleton()->can_any_window_draw()) {
OS::get_singleton()->delay_usec(OS::get_singleton()->get_low_processor_usage_mode_sleep_usec()); //apply some delay to force idle time
- else {
+ } else {
uint32_t frame_delay = Engine::get_singleton()->get_frame_delay();
- if (frame_delay)
+ if (frame_delay) {
OS::get_singleton()->delay_usec(Engine::get_singleton()->get_frame_delay() * 1000);
+ }
}
int target_fps = Engine::get_singleton()->get_target_fps();
@@ -2198,8 +2227,9 @@ bool Main::iteration() {
uint64_t time_step = 1000000L / target_fps;
target_ticks += time_step;
uint64_t current_ticks = OS::get_singleton()->get_ticks_usec();
- if (current_ticks < target_ticks)
+ if (current_ticks < target_ticks) {
OS::get_singleton()->delay_usec(target_ticks - current_ticks);
+ }
current_ticks = OS::get_singleton()->get_ticks_usec();
target_ticks = MIN(MAX(target_ticks, current_ticks - time_step), current_ticks + time_step);
}
@@ -2294,20 +2324,27 @@ void Main::cleanup() {
memdelete(input);
}
- if (packed_data)
+ if (packed_data) {
memdelete(packed_data);
- if (file_access_network_client)
+ }
+ if (file_access_network_client) {
memdelete(file_access_network_client);
- if (performance)
+ }
+ if (performance) {
memdelete(performance);
- if (input_map)
+ }
+ if (input_map) {
memdelete(input_map);
- if (translation_server)
+ }
+ if (translation_server) {
memdelete(translation_server);
- if (globals)
+ }
+ if (globals) {
memdelete(globals);
- if (engine)
+ }
+ if (engine) {
memdelete(engine);
+ }
if (OS::get_singleton()->is_restart_on_exit_set()) {
//attempt to restart with arguments
diff --git a/main/main_timer_sync.cpp b/main/main_timer_sync.cpp
index 469ef6f20a..5252ea005b 100644
--- a/main/main_timer_sync.cpp
+++ b/main/main_timer_sync.cpp
@@ -56,15 +56,17 @@ int MainTimerSync::get_average_physics_steps(float &p_min, float &p_max) {
for (int i = 1; i < CONTROL_STEPS; ++i) {
const float typical_lower = typical_physics_steps[i];
const float current_min = typical_lower / (i + 1);
- if (current_min > p_max)
+ if (current_min > p_max) {
return i; // bail out of further restrictions would void the interval
- else if (current_min > p_min)
+ } else if (current_min > p_min) {
p_min = current_min;
+ }
const float current_max = (typical_lower + 1) / (i + 1);
- if (current_max < p_min)
+ if (current_max < p_min) {
return i;
- else if (current_max < p_max)
+ } else if (current_max < p_max) {
p_max = current_max;
+ }
}
return CONTROL_STEPS;
@@ -95,10 +97,12 @@ MainFrameTime MainTimerSync::advance_core(float p_frame_slice, int p_iterations_
break;
}
- if (steps_left_to_match_typical > min_typical_steps)
+ if (steps_left_to_match_typical > min_typical_steps) {
min_typical_steps = steps_left_to_match_typical;
- if (steps_left_to_match_typical + 1 < max_typical_steps)
+ }
+ if (steps_left_to_match_typical + 1 < max_typical_steps) {
max_typical_steps = steps_left_to_match_typical + 1;
+ }
}
// try to keep it consistent with previous iterations
@@ -143,8 +147,9 @@ MainFrameTime MainTimerSync::advance_core(float p_frame_slice, int p_iterations_
// calls advance_core, keeps track of deficit it adds to animaption_step, make sure the deficit sum stays close to zero
MainFrameTime MainTimerSync::advance_checked(float p_frame_slice, int p_iterations_per_second, float p_idle_step) {
- if (fixed_fps != -1)
+ if (fixed_fps != -1) {
p_idle_step = 1.0 / fixed_fps;
+ }
// compensate for last deficit
p_idle_step += time_deficit;
diff --git a/main/performance.cpp b/main/performance.cpp
index 0894d68d3c..7e6b9fca64 100644
--- a/main/performance.cpp
+++ b/main/performance.cpp
@@ -78,8 +78,9 @@ void Performance::_bind_methods() {
float Performance::_get_node_count() const {
MainLoop *ml = OS::get_singleton()->get_main_loop();
SceneTree *sml = Object::cast_to<SceneTree>(ml);
- if (!sml)
+ if (!sml) {
return 0;
+ }
return sml->get_node_count();
}
diff --git a/main/tests/test_astar.cpp b/main/tests/test_astar.cpp
index 3cc754e230..fe335589b0 100644
--- a/main/tests/test_astar.cpp
+++ b/main/tests/test_astar.cpp
@@ -173,8 +173,9 @@ bool test_add_remove() {
for (int i = 0; i < 20000; i++) {
int u = Math::rand() % 5;
int v = Math::rand() % 4;
- if (u == v)
+ if (u == v) {
v = 4;
+ }
if (Math::rand() % 2 == 1) {
// Add a (possibly existing) directed edge and confirm connectivity
a.connect_points(u, v, false);
@@ -189,19 +190,22 @@ bool test_add_remove() {
// Random tests for point removal
for (int i = 0; i < 20000; i++) {
a.clear();
- for (int j = 0; j < 5; j++)
+ for (int j = 0; j < 5; j++) {
a.add_point(j, Vector3(0, 0, 0));
+ }
// Add or remove random edges
for (int j = 0; j < 10; j++) {
int u = Math::rand() % 5;
int v = Math::rand() % 4;
- if (u == v)
+ if (u == v) {
v = 4;
- if (Math::rand() % 2 == 1)
+ }
+ if (Math::rand() % 2 == 1) {
a.connect_points(u, v, false);
- else
+ } else {
a.disconnect_points(u, v, false);
+ }
}
// Remove point 0
@@ -241,8 +245,9 @@ bool test_solutions() {
int u, v;
u = Math::rand() % N;
v = Math::rand() % (N - 1);
- if (u == v)
+ if (u == v) {
v = N - 1;
+ }
// Pick a random operation
int op = Math::rand();
@@ -256,16 +261,18 @@ bool test_solutions() {
// Add edge (u, v); possibly bidirectional
a.connect_points(u, v, op % 2);
adj[u][v] = true;
- if (op % 2)
+ if (op % 2) {
adj[v][u] = true;
+ }
break;
case 6:
case 7:
// Remove edge (u, v); possibly bidirectional
a.disconnect_points(u, v, op % 2);
adj[u][v] = false;
- if (op % 2)
+ if (op % 2) {
adj[v][u] = false;
+ }
break;
case 8:
// Remove point u and add it back; clears adjacent edges and changes coordinates
@@ -274,42 +281,55 @@ bool test_solutions() {
p[u].y = Math::rand() % 100;
p[u].z = Math::rand() % 100;
a.add_point(u, p[u]);
- for (v = 0; v < N; v++)
+ for (v = 0; v < N; v++) {
adj[u][v] = adj[v][u] = false;
+ }
break;
}
}
// Floyd-Warshall
float d[N][N];
- for (int u = 0; u < N; u++)
- for (int v = 0; v < N; v++)
+ for (int u = 0; u < N; u++) {
+ for (int v = 0; v < N; v++) {
d[u][v] = (u == v || adj[u][v]) ? p[u].distance_to(p[v]) : INFINITY;
+ }
+ }
- for (int w = 0; w < N; w++)
- for (int u = 0; u < N; u++)
- for (int v = 0; v < N; v++)
- if (d[u][v] > d[u][w] + d[w][v])
+ for (int w = 0; w < N; w++) {
+ for (int u = 0; u < N; u++) {
+ for (int v = 0; v < N; v++) {
+ if (d[u][v] > d[u][w] + d[w][v]) {
d[u][v] = d[u][w] + d[w][v];
+ }
+ }
+ }
+ }
// Display statistics
int count = 0;
- for (int u = 0; u < N; u++)
- for (int v = 0; v < N; v++)
- if (adj[u][v])
+ for (int u = 0; u < N; u++) {
+ for (int v = 0; v < N; v++) {
+ if (adj[u][v]) {
count++;
+ }
+ }
+ }
printf("Test #%4d: %3d edges, ", test + 1, count);
count = 0;
- for (int u = 0; u < N; u++)
- for (int v = 0; v < N; v++)
- if (!Math::is_inf(d[u][v]))
+ for (int u = 0; u < N; u++) {
+ for (int v = 0; v < N; v++) {
+ if (!Math::is_inf(d[u][v])) {
count++;
+ }
+ }
+ }
printf("%3d/%d pairs of reachable points\n", count - N, N * (N - 1));
// Check A*'s output
bool match = true;
- for (int u = 0; u < N; u++)
- for (int v = 0; v < N; v++)
+ for (int u = 0; u < N; u++) {
+ for (int v = 0; v < N; v++) {
if (u != v) {
Vector<int> route = a.get_id_path(u, v);
if (!Math::is_inf(d[u][v])) {
@@ -344,10 +364,13 @@ bool test_solutions() {
}
}
}
+ }
+ }
exit:
- if (!match)
+ if (!match) {
return false;
+ }
}
return true;
}
@@ -367,11 +390,13 @@ MainLoop *test() {
int passed = 0;
while (true) {
- if (!test_funcs[count])
+ if (!test_funcs[count]) {
break;
+ }
bool pass = test_funcs[count]();
- if (pass)
+ if (pass) {
passed++;
+ }
OS::get_singleton()->print("\t%s\n", pass ? "PASS" : "FAILED");
count++;
diff --git a/main/tests/test_gdscript.cpp b/main/tests/test_gdscript.cpp
index ea6fcee1c0..10586c6495 100644
--- a/main/tests/test_gdscript.cpp
+++ b/main/tests/test_gdscript.cpp
@@ -57,13 +57,15 @@ static String _parser_extends(const GDScriptParser::ClassNode *p_class) {
String txt = "extends ";
if (String(p_class->extends_file) != "") {
txt += "\"" + p_class->extends_file + "\"";
- if (p_class->extends_class.size())
+ if (p_class->extends_class.size()) {
txt += ".";
+ }
}
for (int i = 0; i < p_class->extends_class.size(); i++) {
- if (i != 0)
+ if (i != 0) {
txt += ".";
+ }
txt += p_class->extends_class[i];
}
@@ -80,10 +82,11 @@ static String _parser_expr(const GDScriptParser::Node *p_expr) {
} break;
case GDScriptParser::Node::TYPE_CONSTANT: {
const GDScriptParser::ConstantNode *c_node = static_cast<const GDScriptParser::ConstantNode *>(p_expr);
- if (c_node->value.get_type() == Variant::STRING)
+ if (c_node->value.get_type() == Variant::STRING) {
txt = "\"" + String(c_node->value) + "\"";
- else
+ } else {
txt = c_node->value;
+ }
} break;
case GDScriptParser::Node::TYPE_SELF: {
@@ -93,8 +96,9 @@ static String _parser_expr(const GDScriptParser::Node *p_expr) {
const GDScriptParser::ArrayNode *arr_node = static_cast<const GDScriptParser::ArrayNode *>(p_expr);
txt += "[";
for (int i = 0; i < arr_node->elements.size(); i++) {
- if (i > 0)
+ if (i > 0) {
txt += ", ";
+ }
txt += _parser_expr(arr_node->elements[i]);
}
txt += "]";
@@ -103,8 +107,9 @@ static String _parser_expr(const GDScriptParser::Node *p_expr) {
const GDScriptParser::DictionaryNode *dict_node = static_cast<const GDScriptParser::DictionaryNode *>(p_expr);
txt += "{";
for (int i = 0; i < dict_node->elements.size(); i++) {
- if (i > 0)
+ if (i > 0) {
txt += ", ";
+ }
const GDScriptParser::DictionaryNode::Pair &p = dict_node->elements[i];
txt += _parser_expr(p.key);
@@ -137,8 +142,9 @@ static String _parser_expr(const GDScriptParser::Node *p_expr) {
nfunc = c_node->arguments[1];
ERR_FAIL_COND_V(nfunc->type != GDScriptParser::Node::TYPE_IDENTIFIER, "");
- if (c_node->arguments[0]->type != GDScriptParser::Node::TYPE_SELF)
+ if (c_node->arguments[0]->type != GDScriptParser::Node::TYPE_SELF) {
func_name = _parser_expr(c_node->arguments[0]) + ".";
+ }
func_name += _parser_expr(nfunc);
arg_ofs = 2;
@@ -148,8 +154,9 @@ static String _parser_expr(const GDScriptParser::Node *p_expr) {
for (int i = arg_ofs; i < c_node->arguments.size(); i++) {
const GDScriptParser::Node *arg = c_node->arguments[i];
- if (i > arg_ofs)
+ if (i > arg_ofs) {
txt += ", ";
+ }
txt += _parser_expr(arg);
}
@@ -346,10 +353,11 @@ static void _parser_show_block(const GDScriptParser::BlockNode *p_block, int p_i
_print_indent(p_indent, "break");
} break;
case GDScriptParser::ControlFlowNode::CF_RETURN: {
- if (cf_node->arguments.size())
+ if (cf_node->arguments.size()) {
_print_indent(p_indent, "return " + _parser_expr(cf_node->arguments[0]));
- else
+ } else {
_print_indent(p_indent, "return ");
+ }
} break;
}
@@ -368,18 +376,21 @@ static void _parser_show_block(const GDScriptParser::BlockNode *p_block, int p_i
static void _parser_show_function(const GDScriptParser::FunctionNode *p_func, int p_indent, GDScriptParser::BlockNode *p_initializer = nullptr) {
String txt;
- if (p_func->_static)
+ if (p_func->_static) {
txt = "static ";
+ }
txt += "func ";
- if (p_func->name == "") // initializer
+ if (p_func->name == "") { // initializer
txt += "[built-in-initializer]";
- else
+ } else {
txt += String(p_func->name);
+ }
txt += "(";
for (int i = 0; i < p_func->arguments.size(); i++) {
- if (i != 0)
+ if (i != 0) {
txt += ", ";
+ }
txt += "var " + String(p_func->arguments[i]);
if (i >= (p_func->arguments.size() - p_func->default_values.size())) {
int defarg = i - (p_func->arguments.size() - p_func->default_values.size());
@@ -395,8 +406,9 @@ static void _parser_show_function(const GDScriptParser::FunctionNode *p_func, in
txt += ":";
_print_indent(p_indent, txt);
- if (p_initializer)
+ if (p_initializer) {
_parser_show_block(p_initializer, p_indent + 1);
+ }
_parser_show_block(p_func->body, p_indent + 1);
}
@@ -409,8 +421,9 @@ static void _parser_show_class(const GDScriptParser::ClassNode *p_class, int p_i
for (int i = 0; i < p_class->subclasses.size(); i++) {
const GDScriptParser::ClassNode *subclass = p_class->subclasses[i];
String line = "class " + subclass->name;
- if (String(subclass->extends_file) != "" || subclass->extends_class.size())
+ if (String(subclass->extends_file) != "" || subclass->extends_class.size()) {
line += " " + _parser_extends(subclass);
+ }
line += ":";
_print_indent(p_indent, line);
_parser_show_class(subclass, p_indent + 1, p_code);
@@ -438,8 +451,9 @@ static void _parser_show_class(const GDScriptParser::ClassNode *p_class, int p_i
for (int i = 0; i < p_class->functions.size(); i++) {
if (String(p_class->functions[i]->name) == "_init") {
_parser_show_function(p_class->functions[i], p_indent, p_class->initializer);
- } else
+ } else {
_parser_show_function(p_class->functions[i], p_indent);
+ }
print_line("\n");
}
//_parser_show_function(p_class->initializer,p_indent);
@@ -465,10 +479,11 @@ static String _disassemble_addr(const Ref<GDScript> &p_script, const GDScriptFun
case GDScriptFunction::ADDR_TYPE_LOCAL_CONSTANT: {
Variant v = func.get_constant(addr);
String txt;
- if (v.get_type() == Variant::STRING || v.get_type() == Variant::NODE_PATH)
+ if (v.get_type() == Variant::STRING || v.get_type() == Variant::NODE_PATH) {
txt = "\"" + String(v) + "\"";
- else
+ } else {
txt = v;
+ }
return "const(" + txt + ")";
} break;
case GDScriptFunction::ADDR_TYPE_STACK: {
@@ -499,8 +514,9 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
if (func.get_default_argument_count()) {
defargs = "defarg at: ";
for (int i = 0; i < func.get_default_argument_count(); i++) {
- if (i > 0)
+ if (i > 0) {
defargs += ",";
+ }
defargs += itos(func.get_default_argument_addr(i));
}
defargs += " ";
@@ -654,8 +670,9 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
txt += Variant::get_type_name(t) + "(";
for (int i = 0; i < argc; i++) {
- if (i > 0)
+ if (i > 0) {
txt += ", ";
+ }
txt += DADDR(i + 3);
}
txt += ")";
@@ -670,8 +687,9 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
txt += " = [ ";
for (int i = 0; i < argc; i++) {
- if (i > 0)
+ if (i > 0) {
txt += ", ";
+ }
txt += DADDR(2 + i);
}
@@ -687,8 +705,9 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
txt += " = { ";
for (int i = 0; i < argc; i++) {
- if (i > 0)
+ if (i > 0) {
txt += ", ";
+ }
txt += DADDR(2 + i * 2 + 0);
txt += ":";
txt += DADDR(2 + i * 2 + 1);
@@ -704,10 +723,11 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
case GDScriptFunction::OPCODE_CALL_RETURN: {
bool ret = code[ip] == GDScriptFunction::OPCODE_CALL_RETURN;
- if (ret)
+ if (ret) {
txt += " call-ret ";
- else
+ } else {
txt += " call ";
+ }
int argc = code[ip + 1];
if (ret) {
@@ -719,8 +739,9 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
txt += "(";
for (int i = 0; i < argc; i++) {
- if (i > 0)
+ if (i > 0) {
txt += ", ";
+ }
txt += DADDR(4 + i);
}
txt += ")";
@@ -738,8 +759,9 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
txt += "(";
for (int i = 0; i < argc; i++) {
- if (i > 0)
+ if (i > 0) {
txt += ", ";
+ }
txt += DADDR(3 + i);
}
txt += ")";
@@ -757,8 +779,9 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
txt += "(";
for (int i = 0; i < argc; i++) {
- if (i > 0)
+ if (i > 0) {
txt += ", ";
+ }
txt += DADDR(3 + i);
}
txt += ")";
@@ -829,10 +852,11 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
} break;
case GDScriptFunction::OPCODE_LINE: {
int line = code[ip + 1] - 1;
- if (line >= 0 && line < p_code.size())
+ if (line >= 0 && line < p_code.size()) {
txt = "\n" + itos(line + 1) + ": " + p_code[line] + "\n";
- else
+ } else {
txt = "";
+ }
incr += 2;
} break;
case GDScriptFunction::OPCODE_END: {
@@ -852,8 +876,9 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
}
ip += incr;
- if (txt != "")
+ if (txt != "") {
print_line(txt);
+ }
}
}
}
@@ -899,24 +924,26 @@ MainLoop *test(TestType p_type) {
int line = -1;
while (tk.get_token() != GDScriptTokenizer::TK_EOF) {
String text;
- if (tk.get_token() == GDScriptTokenizer::TK_IDENTIFIER)
+ if (tk.get_token() == GDScriptTokenizer::TK_IDENTIFIER) {
text = "'" + tk.get_token_identifier() + "' (identifier)";
- else if (tk.get_token() == GDScriptTokenizer::TK_CONSTANT) {
+ } else if (tk.get_token() == GDScriptTokenizer::TK_CONSTANT) {
const Variant &c = tk.get_token_constant();
- if (c.get_type() == Variant::STRING)
+ if (c.get_type() == Variant::STRING) {
text = "\"" + String(c) + "\"";
- else
+ } else {
text = c;
+ }
text = text + " (" + Variant::get_type_name(c.get_type()) + " constant)";
- } else if (tk.get_token() == GDScriptTokenizer::TK_ERROR)
+ } else if (tk.get_token() == GDScriptTokenizer::TK_ERROR) {
text = "ERROR: " + tk.get_token_error();
- else if (tk.get_token() == GDScriptTokenizer::TK_NEWLINE)
+ } else if (tk.get_token() == GDScriptTokenizer::TK_NEWLINE) {
text = "newline (" + itos(tk.get_token_line()) + ") + indent: " + itos(tk.get_token_line_indent());
- else if (tk.get_token() == GDScriptTokenizer::TK_BUILT_IN_FUNC)
+ } else if (tk.get_token() == GDScriptTokenizer::TK_BUILT_IN_FUNC) {
text = "'" + String(GDScriptFunctions::get_func_name(tk.get_token_built_in_func())) + "' (built-in function)";
- else
+ } else {
text = tk.get_token_name(tk.get_token());
+ }
if (tk.get_token_line() != line) {
int from = line + 1;
diff --git a/main/tests/test_math.cpp b/main/tests/test_math.cpp
index 14ae81ad26..11aa164709 100644
--- a/main/tests/test_math.cpp
+++ b/main/tests/test_math.cpp
@@ -213,8 +213,9 @@ class GetClassAndNamespace {
tk_string += res;
} else {
- if (code[idx] == '\n')
+ if (code[idx] == '\n') {
line++;
+ }
tk_string += code[idx];
}
idx++;
@@ -338,8 +339,9 @@ public:
tk = get_token();
}
- if (error)
+ if (error) {
return ERR_PARSE_ERROR;
+ }
return OK;
}
@@ -571,8 +573,9 @@ MainLoop *test() {
break;
}
}
- if (success)
+ if (success) {
break;
+ }
}
print_line("DONE");
diff --git a/main/tests/test_oa_hash_map.cpp b/main/tests/test_oa_hash_map.cpp
index 27792c48e6..cae143bb5d 100644
--- a/main/tests/test_oa_hash_map.cpp
+++ b/main/tests/test_oa_hash_map.cpp
@@ -70,8 +70,9 @@ MainLoop *test() {
uint32_t num_elems = 0;
for (int i = 0; i < 500; i++) {
int tmp;
- if (map.lookup(i, tmp) && tmp == i * 2)
+ if (map.lookup(i, tmp) && tmp == i * 2) {
num_elems++;
+ }
}
OS::get_singleton()->print("elements %d == %d.\n", map.get_num_elements(), num_elems);
@@ -104,8 +105,9 @@ MainLoop *test() {
keys[i] = Math::rand();
map.set(keys[i], dummy);
- if (!map.lookup(keys[i], dummy))
+ if (!map.lookup(keys[i], dummy)) {
OS::get_singleton()->print("could not find 0x%X despite it was just inserted!\n", unsigned(keys[i]));
+ }
}
// check whether the keys are still present
diff --git a/main/tests/test_ordered_hash_map.cpp b/main/tests/test_ordered_hash_map.cpp
index aba222fbba..d18a3784be 100644
--- a/main/tests/test_ordered_hash_map.cpp
+++ b/main/tests/test_ordered_hash_map.cpp
@@ -150,11 +150,13 @@ MainLoop *test() {
int passed = 0;
while (true) {
- if (!test_funcs[count])
+ if (!test_funcs[count]) {
break;
+ }
bool pass = test_funcs[count]();
- if (pass)
+ if (pass) {
passed++;
+ }
OS::get_singleton()->print("\t%s\n", pass ? "PASS" : "FAILED");
count++;
diff --git a/main/tests/test_physics_2d.cpp b/main/tests/test_physics_2d.cpp
index 9b37033354..6cb9bf7b60 100644
--- a/main/tests/test_physics_2d.cpp
+++ b/main/tests/test_physics_2d.cpp
@@ -304,8 +304,9 @@ protected:
vs->canvas_item_clear(ray);
vs->canvas_item_add_line(ray, ray_from, ray_end, p_rid.is_valid() ? Color(0, 1, 0.4) : Color(1, 0.4, 0), 2);
- if (p_rid.is_valid())
+ if (p_rid.is_valid()) {
vs->canvas_item_add_line(ray, ray_end, ray_end + p_normal * 20, p_rid.is_valid() ? Color(0, 1, 0.4) : Color(1, 0.4, 0), 2);
+ }
}
static void _bind_methods() {
diff --git a/main/tests/test_render.cpp b/main/tests/test_render.cpp
index adae0283e5..afc09374b9 100644
--- a/main/tests/test_render.cpp
+++ b/main/tests/test_render.cpp
@@ -65,8 +65,9 @@ class TestMainLoop : public MainLoop {
protected:
public:
virtual void input_event(const Ref<InputEvent> &p_event) {
- if (p_event->is_pressed())
+ if (p_event->is_pressed()) {
quit = true;
+ }
}
virtual void init() {
diff --git a/main/tests/test_shader_lang.cpp b/main/tests/test_shader_lang.cpp
index 707a25699f..34ee3e3210 100644
--- a/main/tests/test_shader_lang.cpp
+++ b/main/tests/test_shader_lang.cpp
@@ -140,8 +140,9 @@ static String dump_node_code(SL::Node *p_node, int p_level) {
"white"
};
- if (E->get().hint)
+ if (E->get().hint) {
ucode += " : " + String(hint_name[E->get().hint]);
+ }
code += ucode + "\n";
}
@@ -160,8 +161,9 @@ static String dump_node_code(SL::Node *p_node, int p_level) {
String header;
header = _typestr(fnode->return_type) + " " + fnode->name + "(";
for (int j = 0; j < fnode->arguments.size(); j++) {
- if (j > 0)
+ if (j > 0) {
header += ", ";
+ }
header += _prestr(fnode->arguments[j].precision) + _typestr(fnode->arguments[j].type) + " " + fnode->arguments[j].name;
}
@@ -252,8 +254,9 @@ static String dump_node_code(SL::Node *p_node, int p_level) {
case SL::OP_CONSTRUCT:
code = dump_node_code(onode->arguments[0], p_level) + "(";
for (int i = 1; i < onode->arguments.size(); i++) {
- if (i > 1)
+ if (i > 1) {
code += ", ";
+ }
code += dump_node_code(onode->arguments[i], p_level);
}
code += ")";
@@ -323,8 +326,9 @@ MainLoop *test() {
while (true) {
CharType c = fa->get_8();
- if (fa->eof_reached())
+ if (fa->eof_reached()) {
break;
+ }
code += c;
}
diff --git a/main/tests/test_string.cpp b/main/tests/test_string.cpp
index ca66ef1cf7..775c039282 100644
--- a/main/tests/test_string.cpp
+++ b/main/tests/test_string.cpp
@@ -108,14 +108,17 @@ bool test_6() {
OS::get_singleton()->print("\tComparing to \"Test Compare\"\n");
- if (!(s == "Test Compare"))
+ if (!(s == "Test Compare")) {
return false;
+ }
- if (!(s == L"Test Compare"))
+ if (!(s == L"Test Compare")) {
return false;
+ }
- if (!(s == String("Test Compare")))
+ if (!(s == String("Test Compare"))) {
return false;
+ }
return true;
}
@@ -127,14 +130,17 @@ bool test_7() {
OS::get_singleton()->print("\tComparing to \"Test Compare\"\n");
- if (!(s != "Peanut"))
+ if (!(s != "Peanut")) {
return false;
+ }
- if (!(s != L"Coconut"))
+ if (!(s != L"Coconut")) {
return false;
+ }
- if (!(s != String("Butter")))
+ if (!(s != String("Butter"))) {
return false;
+ }
return true;
}
@@ -146,14 +152,17 @@ bool test_8() {
OS::get_singleton()->print("\tComparing to \"Bees\"\n");
- if (!(s < "Elephant"))
+ if (!(s < "Elephant")) {
return false;
+ }
- if (s < L"Amber")
+ if (s < L"Amber") {
return false;
+ }
- if (s < String("Beatrix"))
+ if (s < String("Beatrix")) {
return false;
+ }
return true;
}
@@ -179,14 +188,17 @@ bool test_9() {
bool test_10() {
OS::get_singleton()->print("\n\nTest 10: Misc funcs (size/length/empty/etc)\n");
- if (!String("").empty())
+ if (!String("").empty()) {
return false;
+ }
- if (String("Mellon").size() != 7)
+ if (String("Mellon").size() != 7) {
return false;
+ }
- if (String("Oranges").length() != 7)
+ if (String("Oranges").length() != 7) {
return false;
+ }
return true;
}
@@ -199,11 +211,13 @@ bool test_11() {
a[0] = 'S';
a[6] = 'C';
- if (a != "Sugar Cane")
+ if (a != "Sugar Cane") {
return false;
+ }
- if (a[1] != 'u')
+ if (a[1] != 'u') {
return false;
+ }
return true;
}
@@ -213,11 +227,13 @@ bool test_12() {
String a = "MoMoNgA";
- if (a.to_upper() != "MOMONGA")
+ if (a.to_upper() != "MOMONGA") {
return false;
+ }
- if (a.nocasecmp_to("momonga") != 0)
+ if (a.nocasecmp_to("momonga") != 0) {
return false;
+ }
return true;
}
@@ -265,11 +281,13 @@ bool test_16() {
OS::get_singleton()->print("\t\"tty\" is at %i pos.\n", s.find("tty"));
OS::get_singleton()->print("\t\"Revenge of the Monster Truck\" is at %i pos.\n", s.find("Revenge of the Monster Truck"));
- if (s.find("tty") != 3)
+ if (s.find("tty") != 3) {
return false;
+ }
- if (s.find("Revenge of the Monster Truck") != -1)
+ if (s.find("Revenge of the Monster Truck") != -1) {
return false;
+ }
return true;
}
@@ -282,11 +300,13 @@ bool test_17() {
OS::get_singleton()->print("\t\"WHA\" is at %i pos.\n", s.findn("WHA"));
OS::get_singleton()->print("\t\"Revenge of the Monster SawFish\" is at %i pos.\n", s.findn("Revenge of the Monster Truck"));
- if (s.findn("WHA") != 7)
+ if (s.findn("WHA") != 7) {
return false;
+ }
- if (s.findn("Revenge of the Monster SawFish") != -1)
+ if (s.findn("Revenge of the Monster SawFish") != -1) {
return false;
+ }
return true;
}
@@ -299,11 +319,13 @@ bool test_18() {
OS::get_singleton()->print("\t\"WHA\" is at %i pos.\n", s.findn("WHA"));
OS::get_singleton()->print("\t\"Revenge of the Monster SawFish\" is at %i pos.\n", s.findn("Revenge of the Monster Truck"));
- if (s.findn("WHA") != 7)
+ if (s.findn("WHA") != 7) {
return false;
+ }
- if (s.findn("Revenge of the Monster SawFish") != -1)
+ if (s.findn("Revenge of the Monster SawFish") != -1) {
return false;
+ }
return true;
}
@@ -350,8 +372,9 @@ bool test_22() {
for (int i = 0; i < 4; i++) {
OS::get_singleton()->print("\tString: \"%s\" as Int is %i\n", nums[i], String(nums[i]).to_int());
- if (String(nums[i]).to_int() != num[i])
+ if (String(nums[i]).to_int() != num[i]) {
return false;
+ }
}
return true;
@@ -366,8 +389,9 @@ bool test_23() {
for (int i = 0; i < 4; i++) {
OS::get_singleton()->print("\tString: \"%s\" as Float is %f\n", nums[i], String(nums[i]).to_double());
- if (ABS(String(nums[i]).to_double() - num[i]) > 0.00001)
+ if (ABS(String(nums[i]).to_double() - num[i]) > 0.00001) {
return false;
+ }
}
return true;
@@ -385,8 +409,9 @@ bool test_24() {
for (int i = 0; i < s.get_slice_count(","); i++) {
OS::get_singleton()->print("\t\t%i- %ls\n", i + 1, s.get_slice(",", i).c_str());
- if (s.get_slice(",", i) != slices[i])
+ if (s.get_slice(",", i) != slices[i]) {
return false;
+ }
}
return true;
@@ -942,26 +967,30 @@ bool test_31() {
String a = "";
success = a[0] == 0;
OS::get_singleton()->print("Is 0 String[0]:, %s\n", success ? "OK" : "FAIL");
- if (!success)
+ if (!success) {
state = false;
+ }
String b = "Godot";
success = b[b.size()] == 0;
OS::get_singleton()->print("Is 0 String[size()]:, %s\n", success ? "OK" : "FAIL");
- if (!success)
+ if (!success) {
state = false;
+ }
const String c = "";
success = c[0] == 0;
OS::get_singleton()->print("Is 0 const String[0]:, %s\n", success ? "OK" : "FAIL");
- if (!success)
+ if (!success) {
state = false;
+ }
const String d = "Godot";
success = d[d.size()] == 0;
OS::get_singleton()->print("Is 0 const String[size()]:, %s\n", success ? "OK" : "FAIL");
- if (!success)
+ if (!success) {
state = false;
+ }
return state;
};
@@ -1150,11 +1179,13 @@ MainLoop *test() {
int passed = 0;
while (true) {
- if (!test_funcs[count])
+ if (!test_funcs[count]) {
break;
+ }
bool pass = test_funcs[count]();
- if (pass)
+ if (pass) {
passed++;
+ }
OS::get_singleton()->print("\t%s\n", pass ? "PASS" : "FAILED");
count++;