diff options
Diffstat (limited to 'main')
-rw-r--r-- | main/SCsub | 132 | ||||
-rw-r--r-- | main/input_default.cpp | 6 | ||||
-rw-r--r-- | main/main.cpp | 6 | ||||
-rw-r--r-- | main/main_builders.py | 130 | ||||
-rw-r--r-- | main/tests/test_gdscript.cpp | 4 | ||||
-rw-r--r-- | main/tests/test_io.cpp | 2 | ||||
-rw-r--r-- | main/tests/test_math.cpp | 4 | ||||
-rw-r--r-- | main/tests/test_physics.cpp | 4 |
8 files changed, 149 insertions, 139 deletions
diff --git a/main/SCsub b/main/SCsub index 0692175799..9af102600e 100644 --- a/main/SCsub +++ b/main/SCsub @@ -1,128 +1,8 @@ #!/usr/bin/env python Import('env') -from compat import byte_to_str -from collections import OrderedDict - -def make_splash(target, source, env): - - src = source[0].srcnode().abspath - dst = target[0].srcnode().abspath - - with open(src, "rb") as f: - buf = f.read() - - with open(dst, "w") as g: - g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n") - g.write("#ifndef BOOT_SPLASH_H\n") - g.write("#define BOOT_SPLASH_H\n") - g.write('static const Color boot_splash_bg_color = Color::html("#232323");\n') - g.write("static const unsigned char boot_splash_png[] = {\n") - for i in range(len(buf)): - g.write(byte_to_str(buf[i]) + ",\n") - g.write("};\n") - g.write("#endif") - - -def make_splash_editor(target, source, env): - - src = source[0].srcnode().abspath - dst = target[0].srcnode().abspath - - with open(src, "rb") as f: - buf = f.read() - - with open(dst, "w") as g: - g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n") - g.write("#ifndef BOOT_SPLASH_EDITOR_H\n") - g.write("#define BOOT_SPLASH_EDITOR_H\n") - g.write('static const Color boot_splash_editor_bg_color = Color::html("#232323");\n') - g.write("static const unsigned char boot_splash_editor_png[] = {\n") - for i in range(len(buf)): - g.write(byte_to_str(buf[i]) + ",\n") - g.write("};\n") - g.write("#endif") - - -def make_app_icon(target, source, env): - - src = source[0].srcnode().abspath - dst = target[0].srcnode().abspath - - with open(src, "rb") as f: - buf = f.read() - - with open(dst, "w") as g: - g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n") - g.write("#ifndef APP_ICON_H\n") - g.write("#define APP_ICON_H\n") - g.write("static const unsigned char app_icon_png[] = {\n") - for i in range(len(buf)): - g.write(byte_to_str(buf[i]) + ",\n") - g.write("};\n") - g.write("#endif") - -def make_default_controller_mappings(target, source, env): - dst = target[0].srcnode().abspath - g = open(dst, "w") - - g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n") - g.write("#include \"default_controller_mappings.h\"\n") - g.write("#include \"typedefs.h\"\n") - - # ensure mappings have a consistent order - platform_mappings = OrderedDict() - for src in source: - src_path = src.srcnode().abspath - with open(src_path, "r") as f: - # read mapping file and skip header - mapping_file_lines = f.readlines()[2:] - - current_platform = None - for line in mapping_file_lines: - if not line: - continue - line = line.strip() - if len(line) == 0: - continue - if line[0] == "#": - current_platform = line[1:].strip() - if current_platform not in platform_mappings: - platform_mappings[current_platform] = {} - elif current_platform: - line_parts = line.split(",") - guid = line_parts[0] - if guid in platform_mappings[current_platform]: - g.write("// WARNING - DATABASE {} OVERWROTE PRIOR MAPPING: {} {}\n".format(src_path, current_platform, platform_mappings[current_platform][guid])) - valid_mapping = True - for input_map in line_parts[2:]: - if "+" in input_map or "-" in input_map or "~" in input_map: - g.write("// WARNING - DISCARDED UNSUPPORTED MAPPING TYPE FROM DATABASE {}: {} {}\n".format(src_path, current_platform, line)) - valid_mapping = False - break - if valid_mapping: - platform_mappings[current_platform][guid] = line - - platform_variables = { - "Linux": "#if X11_ENABLED", - "Windows": "#ifdef WINDOWS_ENABLED", - "Mac OS X": "#ifdef OSX_ENABLED", - "Android": "#if defined(__ANDROID__)", - "iOS": "#ifdef IPHONE_ENABLED", - "Javascript": "#ifdef JAVASCRIPT_ENABLED", - "UWP": "#ifdef UWP_ENABLED", - } - - g.write("const char* DefaultControllerMappings::mappings[] = {\n") - for platform, mappings in platform_mappings.items(): - variable = platform_variables[platform] - g.write("{}\n".format(variable)) - for mapping in mappings.values(): - g.write("\t\"{}\",\n".format(mapping)) - g.write("#endif\n") - - g.write("\tNULL\n};\n") - g.close() +from platform_methods import run_in_subprocess +import main_builders env.main_sources = [] env.add_source_files(env.main_sources, "*.cpp") @@ -131,20 +11,20 @@ env.add_source_files(env.main_sources, "*.cpp") controller_databases = ["#main/gamecontrollerdb.txt", "#main/gamecontrollerdb_205.txt", "#main/gamecontrollerdb_204.txt", "#main/godotcontrollerdb.txt"] env.Depends("#main/default_controller_mappings.gen.cpp", controller_databases) -env.CommandNoCache("#main/default_controller_mappings.gen.cpp", controller_databases, make_default_controller_mappings) +env.CommandNoCache("#main/default_controller_mappings.gen.cpp", controller_databases, run_in_subprocess(main_builders.make_default_controller_mappings)) env.main_sources.append("#main/default_controller_mappings.gen.cpp") Export('env') env.Depends("#main/splash.gen.h", "#main/splash.png") -env.CommandNoCache("#main/splash.gen.h", "#main/splash.png", make_splash) +env.CommandNoCache("#main/splash.gen.h", "#main/splash.png", run_in_subprocess(main_builders.make_splash)) env.Depends("#main/splash_editor.gen.h", "#main/splash_editor.png") -env.CommandNoCache("#main/splash_editor.gen.h", "#main/splash_editor.png", make_splash_editor) +env.CommandNoCache("#main/splash_editor.gen.h", "#main/splash_editor.png", run_in_subprocess(main_builders.make_splash_editor)) env.Depends("#main/app_icon.gen.h", "#main/app_icon.png") -env.CommandNoCache("#main/app_icon.gen.h", "#main/app_icon.png", make_app_icon) +env.CommandNoCache("#main/app_icon.gen.h", "#main/app_icon.png", run_in_subprocess(main_builders.make_app_icon)) SConscript('tests/SCsub') diff --git a/main/input_default.cpp b/main/input_default.cpp index 29d30110e3..4363fc1c88 100644 --- a/main/input_default.cpp +++ b/main/input_default.cpp @@ -684,7 +684,7 @@ void InputDefault::joy_button(int p_device, int p_button, bool p_pressed) { return; }; - Map<int, JoyEvent>::Element *el = map_db[joy.mapping].buttons.find(p_button); + 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); @@ -755,7 +755,7 @@ void InputDefault::joy_axis(int p_device, int p_axis, const JoyAxis &p_value) { return; }; - Map<int, JoyEvent>::Element *el = map_db[joy.mapping].axis.find(p_axis); + const Map<int, JoyEvent>::Element *el = map_db[joy.mapping].axis.find(p_axis); if (!el) { //return _axis_event(p_last_id, p_device, p_axis, p_value); return; @@ -831,7 +831,7 @@ void InputDefault::joy_hat(int p_device, int p_val) { _THREAD_SAFE_METHOD_; const Joypad &joy = joy_names[p_device]; - JoyEvent *map; + const JoyEvent *map; if (joy.mapping == -1) { map = hat_map_default; diff --git a/main/main.cpp b/main/main.cpp index 5beeb95a11..2fd9cfa734 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -265,7 +265,7 @@ void Main::print_help(const char *p_binary) { OS::get_singleton()->print(" -s, --script <script> Run a script.\n"); OS::get_singleton()->print(" --check-only Only parse for errors and quit (use with --script).\n"); #ifdef TOOLS_ENABLED - OS::get_singleton()->print(" --export <target> Export the project using the given export target. Export only main pack if path ends with .pck or .zip'.\n"); + OS::get_singleton()->print(" --export <target> Export the project using the given export target. Export only main pack if path ends with .pck or .zip.\n"); OS::get_singleton()->print(" --export-debug <target> Like --export, but use debug template.\n"); OS::get_singleton()->print(" --doctool <path> Dump the engine API reference to the given <path> in XML format, merging if existing files are found.\n"); OS::get_singleton()->print(" --no-docbase Disallow dumping the base types (used with --doctool).\n"); @@ -1257,14 +1257,14 @@ bool Main::start() { #endif } else if (args[i].length() && args[i][0] != '-' && game_path == "") { game_path = args[i]; + } else if (args[i] == "--check-only") { + check_only = true; } //parameters that have an argument to the right else if (i < (args.size() - 1)) { bool parsed_pair = true; if (args[i] == "-s" || args[i] == "--script") { script = args[i + 1]; - } else if (args[i] == "--check-only") { - check_only = true; } else if (args[i] == "--test") { test = args[i + 1]; #ifdef TOOLS_ENABLED diff --git a/main/main_builders.py b/main/main_builders.py new file mode 100644 index 0000000000..6d45768493 --- /dev/null +++ b/main/main_builders.py @@ -0,0 +1,130 @@ +"""Functions used to generate source files during build time + +All such functions are invoked in a subprocess on Windows to prevent build flakiness. + +""" +from platform_methods import subprocess_main +from compat import byte_to_str +from collections import OrderedDict + + +def make_splash(target, source, env): + src = source[0] + dst = target[0] + + with open(src, "rb") as f: + buf = f.read() + + with open(dst, "w") as g: + g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n") + g.write("#ifndef BOOT_SPLASH_H\n") + g.write("#define BOOT_SPLASH_H\n") + g.write('static const Color boot_splash_bg_color = Color::html("#232323");\n') + g.write("static const unsigned char boot_splash_png[] = {\n") + for i in range(len(buf)): + g.write(byte_to_str(buf[i]) + ",\n") + g.write("};\n") + g.write("#endif") + + +def make_splash_editor(target, source, env): + src = source[0] + dst = target[0] + + with open(src, "rb") as f: + buf = f.read() + + with open(dst, "w") as g: + g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n") + g.write("#ifndef BOOT_SPLASH_EDITOR_H\n") + g.write("#define BOOT_SPLASH_EDITOR_H\n") + g.write('static const Color boot_splash_editor_bg_color = Color::html("#232323");\n') + g.write("static const unsigned char boot_splash_editor_png[] = {\n") + for i in range(len(buf)): + g.write(byte_to_str(buf[i]) + ",\n") + g.write("};\n") + g.write("#endif") + + +def make_app_icon(target, source, env): + src = source[0] + dst = target[0] + + with open(src, "rb") as f: + buf = f.read() + + with open(dst, "w") as g: + g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n") + g.write("#ifndef APP_ICON_H\n") + g.write("#define APP_ICON_H\n") + g.write("static const unsigned char app_icon_png[] = {\n") + for i in range(len(buf)): + g.write(byte_to_str(buf[i]) + ",\n") + g.write("};\n") + g.write("#endif") + + +def make_default_controller_mappings(target, source, env): + dst = target[0] + g = open(dst, "w") + + g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n") + g.write("#include \"default_controller_mappings.h\"\n") + g.write("#include \"typedefs.h\"\n") + + # ensure mappings have a consistent order + platform_mappings = OrderedDict() + for src_path in source: + with open(src_path, "r") as f: + # read mapping file and skip header + mapping_file_lines = f.readlines()[2:] + + current_platform = None + for line in mapping_file_lines: + if not line: + continue + line = line.strip() + if len(line) == 0: + continue + if line[0] == "#": + current_platform = line[1:].strip() + if current_platform not in platform_mappings: + platform_mappings[current_platform] = {} + elif current_platform: + line_parts = line.split(",") + guid = line_parts[0] + if guid in platform_mappings[current_platform]: + g.write("// WARNING - DATABASE {} OVERWROTE PRIOR MAPPING: {} {}\n".format(src_path, current_platform, platform_mappings[current_platform][guid])) + valid_mapping = True + for input_map in line_parts[2:]: + if "+" in input_map or "-" in input_map or "~" in input_map: + g.write("// WARNING - DISCARDED UNSUPPORTED MAPPING TYPE FROM DATABASE {}: {} {}\n".format(src_path, current_platform, line)) + valid_mapping = False + break + if valid_mapping: + platform_mappings[current_platform][guid] = line + + platform_variables = { + "Linux": "#if X11_ENABLED", + "Windows": "#ifdef WINDOWS_ENABLED", + "Mac OS X": "#ifdef OSX_ENABLED", + "Android": "#if defined(__ANDROID__)", + "iOS": "#ifdef IPHONE_ENABLED", + "Javascript": "#ifdef JAVASCRIPT_ENABLED", + "UWP": "#ifdef UWP_ENABLED", + } + + g.write("const char* DefaultControllerMappings::mappings[] = {\n") + for platform, mappings in platform_mappings.items(): + variable = platform_variables[platform] + g.write("{}\n".format(variable)) + for mapping in mappings.values(): + g.write("\t\"{}\",\n".format(mapping)) + g.write("#endif\n") + + g.write("\tNULL\n};\n") + g.close() + + +if __name__ == '__main__': + subprocess_main(globals()) diff --git a/main/tests/test_gdscript.cpp b/main/tests/test_gdscript.cpp index 5f3a2c1dc8..0a9d03c1b7 100644 --- a/main/tests/test_gdscript.cpp +++ b/main/tests/test_gdscript.cpp @@ -924,8 +924,8 @@ MainLoop *test(TestType p_type) { Vector<uint8_t> buf; int flen = fa->get_len(); buf.resize(fa->get_len() + 1); - fa->get_buffer(&buf[0], flen); - buf[flen] = 0; + fa->get_buffer(buf.ptrw(), flen); + buf.write[flen] = 0; String code; code.parse_utf8((const char *)&buf[0]); diff --git a/main/tests/test_io.cpp b/main/tests/test_io.cpp index 08dc374ed1..4f98955995 100644 --- a/main/tests/test_io.cpp +++ b/main/tests/test_io.cpp @@ -103,7 +103,7 @@ MainLoop *test() { int len = z->get_len(); Vector<uint8_t> zip; zip.resize(len); - z->get_buffer(&zip[0], len); + z->get_buffer(zip.ptrw(), len); z->close(); memdelete(z); diff --git a/main/tests/test_math.cpp b/main/tests/test_math.cpp index 8b71c5dc70..1a72416d6a 100644 --- a/main/tests/test_math.cpp +++ b/main/tests/test_math.cpp @@ -503,8 +503,8 @@ MainLoop *test() { Vector<uint8_t> buf; int flen = fa->get_len(); buf.resize(fa->get_len() + 1); - fa->get_buffer(&buf[0], flen); - buf[flen] = 0; + fa->get_buffer(buf.ptrw(), flen); + buf.write[flen] = 0; String code; code.parse_utf8((const char *)&buf[0]); diff --git a/main/tests/test_physics.cpp b/main/tests/test_physics.cpp index 475663dabe..99c8fce70e 100644 --- a/main/tests/test_physics.cpp +++ b/main/tests/test_physics.cpp @@ -228,11 +228,11 @@ protected: for (int i = 0; i < p_width; i++) { - grid[i].resize(p_height); + grid.write[i].resize(p_height); for (int j = 0; j < p_height; j++) { - grid[i][j] = 1.0 + Math::random(-p_cellheight, p_cellheight); + grid.write[i].write[j] = 1.0 + Math::random(-p_cellheight, p_cellheight); } } |