diff options
Diffstat (limited to 'main/main.cpp')
-rw-r--r-- | main/main.cpp | 151 |
1 files changed, 96 insertions, 55 deletions
diff --git a/main/main.cpp b/main/main.cpp index 7e69864e1e..fe0f5a0215 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -30,6 +30,7 @@ #include "main.h" +#include "core/crypto/crypto.h" #include "core/input_map.h" #include "core/io/file_access_network.h" #include "core/io/file_access_pack.h" @@ -37,8 +38,6 @@ #include "core/io/image_loader.h" #include "core/io/ip.h" #include "core/io/resource_loader.h" -#include "core/io/stream_peer_ssl.h" -#include "core/io/stream_peer_tcp.h" #include "core/message_queue.h" #include "core/os/dir_access.h" #include "core/os/os.h" @@ -387,6 +386,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph bool upwards = false; String debug_mode; String debug_host; + bool skip_breakpoints = false; String main_pack; bool quiet_stdout = false; int rtm = -1; @@ -444,6 +444,32 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph if (I->next()) { audio_driver = I->next()->get(); + + bool found = false; + for (int i = 0; i < OS::get_singleton()->get_audio_driver_count(); i++) { + if (audio_driver == OS::get_singleton()->get_audio_driver_name(i)) { + found = true; + } + } + + if (!found) { + OS::get_singleton()->print("Unknown audio driver '%s', aborting.\nValid options are ", audio_driver.utf8().get_data()); + + for (int i = 0; i < OS::get_singleton()->get_audio_driver_count(); i++) { + if (i == OS::get_singleton()->get_audio_driver_count() - 1) { + OS::get_singleton()->print(" and "); + } else if (i != 0) { + OS::get_singleton()->print(", "); + } + + OS::get_singleton()->print("'%s'", OS::get_singleton()->get_audio_driver_name(i)); + } + + OS::get_singleton()->print(".\n"); + + goto error; + } + N = I->next()->next(); } else { OS::get_singleton()->print("Missing audio driver argument, aborting.\n"); @@ -455,6 +481,32 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph if (I->next()) { video_driver = I->next()->get(); + + bool found = false; + for (int i = 0; i < OS::get_singleton()->get_video_driver_count(); i++) { + if (video_driver == OS::get_singleton()->get_video_driver_name(i)) { + found = true; + } + } + + if (!found) { + OS::get_singleton()->print("Unknown video driver '%s', aborting.\nValid options are ", video_driver.utf8().get_data()); + + for (int i = 0; i < OS::get_singleton()->get_video_driver_count(); i++) { + if (i == OS::get_singleton()->get_video_driver_count() - 1) { + OS::get_singleton()->print(" and "); + } else if (i != 0) { + OS::get_singleton()->print(", "); + } + + OS::get_singleton()->print("'%s'", OS::get_singleton()->get_video_driver_name(i)); + } + + OS::get_singleton()->print(".\n"); + + goto error; + } + N = I->next()->next(); } else { OS::get_singleton()->print("Missing video driver argument, aborting.\n"); @@ -599,6 +651,14 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph auto_build_solutions = true; editor = true; +#ifdef DEBUG_METHODS_ENABLED + } else if (I->get() == "--gdnative-generate-json-api") { + // Register as an editor instance to use the GLES2 fallback automatically on hardware that doesn't support the GLES3 backend + editor = true; + + // We still pass it to the main arguments since the argument handling itself is not done in this function + main_args.push_back(I->get()); +#endif } else if (I->get() == "--export" || I->get() == "--export-debug") { // Export project editor = true; @@ -730,6 +790,8 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph print_fps = true; } else if (I->get() == "--disable-crash-handler") { OS::get_singleton()->disable_crash_handler(); + } else if (I->get() == "--skip-breakpoints") { + skip_breakpoints = true; } else { main_args.push_back(I->get()); } @@ -783,8 +845,10 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph ProjectSettings::get_singleton()->set_custom_property_info("network/limits/debugger_stdout/max_chars_per_second", PropertyInfo(Variant::INT, "network/limits/debugger_stdout/max_chars_per_second", PROPERTY_HINT_RANGE, "0, 4096, 1, or_greater")); GLOBAL_DEF("network/limits/debugger_stdout/max_messages_per_frame", 10); ProjectSettings::get_singleton()->set_custom_property_info("network/limits/debugger_stdout/max_messages_per_frame", PropertyInfo(Variant::INT, "network/limits/debugger_stdout/max_messages_per_frame", PROPERTY_HINT_RANGE, "0, 20, 1, or_greater")); - GLOBAL_DEF("network/limits/debugger_stdout/max_errors_per_frame", 10); - ProjectSettings::get_singleton()->set_custom_property_info("network/limits/debugger_stdout/max_errors_per_frame", PropertyInfo(Variant::INT, "network/limits/debugger_stdout/max_errors_per_frame", PROPERTY_HINT_RANGE, "0, 20, 1, or_greater")); + GLOBAL_DEF("network/limits/debugger_stdout/max_errors_per_second", 100); + ProjectSettings::get_singleton()->set_custom_property_info("network/limits/debugger_stdout/max_errors_per_second", PropertyInfo(Variant::INT, "network/limits/debugger_stdout/max_errors_per_second", PROPERTY_HINT_RANGE, "0, 200, 1, or_greater")); + GLOBAL_DEF("network/limits/debugger_stdout/max_warnings_per_second", 100); + ProjectSettings::get_singleton()->set_custom_property_info("network/limits/debugger_stdout/max_warnings_per_second", PropertyInfo(Variant::INT, "network/limits/debugger_stdout/max_warnings_per_second", PROPERTY_HINT_RANGE, "0, 200, 1, or_greater")); if (debug_mode == "remote") { @@ -797,6 +861,8 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph } Error derr = sdr->connect_to_host(debug_host, debug_port); + sdr->set_skip_breakpoints(skip_breakpoints); + if (derr != OK) { memdelete(sdr); } else { @@ -814,10 +880,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph String bp = breakpoints[i]; int sp = bp.find_last(":"); - if (sp == -1) { - ERR_EXPLAIN("Invalid breakpoint: '" + bp + "', expected file:line format."); - ERR_CONTINUE(true); - } + ERR_CONTINUE_MSG(sp == -1, "Invalid breakpoint: '" + bp + "', expected file:line format."); script_debugger->insert_breakpoint(bp.substr(sp + 1, bp.length()).to_int(), bp.substr(0, sp)); } @@ -919,10 +982,13 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph video_mode.height = GLOBAL_GET("display/window/size/height"); if (globals->has_setting("display/window/size/test_width") && globals->has_setting("display/window/size/test_height")) { + int tw = globals->get("display/window/size/test_width"); - int th = globals->get("display/window/size/test_height"); - if (tw > 0 && th > 0) { + if (tw > 0) { video_mode.width = tw; + } + int th = globals->get("display/window/size/test_height"); + if (th > 0) { video_mode.height = th; } } @@ -938,7 +1004,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph OS::get_singleton()->_allow_hidpi = GLOBAL_DEF("display/window/dpi/allow_hidpi", false); } - video_mode.use_vsync = GLOBAL_DEF("display/window/vsync/use_vsync", true); + video_mode.use_vsync = GLOBAL_DEF_RST("display/window/vsync/use_vsync", true); OS::get_singleton()->_use_vsync = video_mode.use_vsync; OS::get_singleton()->_allow_layered = GLOBAL_DEF("display/window/per_pixel_transparency/allowed", false); @@ -978,10 +1044,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph } if (video_driver_idx < 0) { - - //OS::get_singleton()->alert("Invalid Video Driver: " + video_driver); video_driver_idx = 0; - //goto error; } if (audio_driver == "") { // specified in project.godot @@ -998,10 +1061,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph } if (audio_driver_idx < 0) { - - OS::get_singleton()->alert("Invalid Audio Driver: " + audio_driver); audio_driver_idx = 0; - //goto error; } { @@ -1171,7 +1231,7 @@ Error Main::setup2(Thread::ID p_main_tid_override) { boot_logo.instance(); Error load_err = ImageLoader::load_image(boot_logo_path, boot_logo); if (load_err) - ERR_PRINTS("Non-existing or invalid boot splash at: " + boot_logo_path + ". Loading default splash."); + ERR_PRINTS("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); @@ -1373,10 +1433,7 @@ bool Main::start() { { DirAccessRef da = DirAccess::open(doc_tool); - if (!da) { - ERR_EXPLAIN("Argument supplied to --doctool must be a base Godot build directory"); - ERR_FAIL_V(false); - } + ERR_FAIL_COND_V_MSG(!da, false, "Argument supplied to --doctool must be a base Godot build directory."); } DocData doc; doc.generate(doc_base); @@ -1449,19 +1506,17 @@ bool Main::start() { }; if (test != "") { -#ifdef DEBUG_ENABLED +#ifdef TOOLS_ENABLED main_loop = test_main(test, args); if (!main_loop) return false; - #endif } else if (script != "") { Ref<Script> script_res = ResourceLoader::load(script); - ERR_EXPLAIN("Can't load script: " + script); - ERR_FAIL_COND_V(script_res.is_null(), false); + ERR_FAIL_COND_V_MSG(script_res.is_null(), false, "Can't load script: " + script); if (check_only) { return false; @@ -1475,8 +1530,7 @@ bool Main::start() { if (!script_loop) { if (obj) memdelete(obj); - ERR_EXPLAIN("Can't load script '" + script + "', it does not inherit from a MainLoop type"); - ERR_FAIL_V(false); + ERR_FAIL_V_MSG(false, "Can't load script '" + script + "', it does not inherit from a MainLoop type."); } script_loop->set_init_script(script_res); @@ -1500,17 +1554,13 @@ bool Main::start() { } else { Object *ml = ClassDB::instance(main_loop_type); - if (!ml) { - ERR_EXPLAIN("Can't instance MainLoop type"); - ERR_FAIL_V(false); - } + ERR_FAIL_COND_V_MSG(!ml, false, "Can't instance MainLoop type."); main_loop = Object::cast_to<MainLoop>(ml); if (!main_loop) { memdelete(ml); - ERR_EXPLAIN("Invalid MainLoop type"); - ERR_FAIL_V(false); + ERR_FAIL_V_MSG(false, "Invalid MainLoop type."); } } } @@ -1573,8 +1623,7 @@ bool Main::start() { } RES res = ResourceLoader::load(path); - ERR_EXPLAIN("Can't autoload: " + path); - ERR_CONTINUE(res.is_null()); + ERR_CONTINUE_MSG(res.is_null(), "Can't autoload: " + path); Node *n = NULL; if (res->is_class("PackedScene")) { Ref<PackedScene> ps = res; @@ -1583,20 +1632,17 @@ bool Main::start() { Ref<Script> script_res = res; StringName ibt = script_res->get_instance_base_type(); bool valid_type = ClassDB::is_parent_class(ibt, "Node"); - ERR_EXPLAIN("Script does not inherit a Node: " + path); - ERR_CONTINUE(!valid_type); + ERR_CONTINUE_MSG(!valid_type, "Script does not inherit a Node: " + path); Object *obj = ClassDB::instance(ibt); - ERR_EXPLAIN("Cannot instance script for autoload, expected 'Node' inheritance, got: " + String(ibt)); - ERR_CONTINUE(obj == NULL); + ERR_CONTINUE_MSG(obj == NULL, "Cannot instance script for autoload, expected 'Node' inheritance, got: " + String(ibt)); n = Object::cast_to<Node>(obj); n->set_script(script_res.get_ref_ptr()); } - ERR_EXPLAIN("Path in autoload not a node or script: " + path); - ERR_CONTINUE(!n); + ERR_CONTINUE_MSG(!n, "Path in autoload not a node or script: " + path); n->set_name(name); //defer so references are all valid on _ready() @@ -1754,8 +1800,8 @@ bool Main::start() { if (!project_manager && !editor) { // game - // Load SSL Certificates from Project Settings (or builtin) - StreamPeerSSL::load_certs_from_memory(StreamPeerSSL::get_project_cert_array()); + // Load SSL Certificates from Project Settings (or builtin). + Crypto::load_default_certificates(GLOBAL_DEF("network/ssl/certificates", "")); if (game_path != "") { Node *scene = NULL; @@ -1763,8 +1809,7 @@ bool Main::start() { if (scenedata.is_valid()) scene = scenedata->instance(); - ERR_EXPLAIN("Failed loading scene: " + local_game_path); - ERR_FAIL_COND_V(!scene, false); + ERR_FAIL_COND_V_MSG(!scene, false, "Failed loading scene: " + local_game_path); sml->add_current_scene(scene); #ifdef OSX_ENABLED @@ -1808,16 +1853,12 @@ bool Main::start() { } if (project_manager || editor) { - // Load SSL Certificates from Editor Settings (or builtin) - String certs = EditorSettings::get_singleton()->get_setting("network/ssl/editor_ssl_certificates").operator String(); - if (certs != "") - StreamPeerSSL::load_certs_from_file(certs); - else - StreamPeerSSL::load_certs_from_memory(StreamPeerSSL::get_project_cert_array()); - - // Hide console window if requested (Windows-only) + // Hide console window if requested (Windows-only). bool hide_console = EditorSettings::get_singleton()->get_setting("interface/editor/hide_console_window"); OS::get_singleton()->set_console_visible(!hide_console); + + // Load SSL Certificates from Editor Settings (or builtin) + Crypto::load_default_certificates(EditorSettings::get_singleton()->get_setting("network/ssl/editor_ssl_certificates").operator String()); } #endif } @@ -1852,7 +1893,7 @@ bool Main::is_iterating() { return iterating > 0; } -// For performance metrics +// For performance metrics. static uint64_t physics_process_max = 0; static uint64_t idle_process_max = 0; |