diff options
Diffstat (limited to 'main/main.cpp')
-rw-r--r-- | main/main.cpp | 410 |
1 files changed, 243 insertions, 167 deletions
diff --git a/main/main.cpp b/main/main.cpp index 89c8832731..94dd895a26 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -32,7 +32,7 @@ #include "core/crypto/crypto.h" #include "core/debugger/engine_debugger.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/input/input_map.h" #include "core/io/file_access_network.h" #include "core/io/file_access_pack.h" @@ -55,13 +55,13 @@ #include "main/splash.gen.h" #include "main/splash_editor.gen.h" #include "main/tests/test_main.h" +#include "modules/modules_enabled.gen.h" #include "modules/register_module_types.h" #include "platform/register_platform_apis.h" #include "scene/main/scene_tree.h" #include "scene/main/window.h" #include "scene/register_scene_types.h" #include "scene/resources/packed_scene.h" -#include "servers/arvr_server.h" #include "servers/audio_server.h" #include "servers/camera_server.h" #include "servers/display_server.h" @@ -72,6 +72,7 @@ #include "servers/register_server_types.h" #include "servers/rendering/rendering_server_raster.h" #include "servers/rendering/rendering_server_wrap_mt.h" +#include "servers/xr_server.h" #ifdef TOOLS_ENABLED #include "editor/doc_data.h" @@ -87,29 +88,29 @@ // Singletons // Initialized in setup() -static Engine *engine = NULL; -static ProjectSettings *globals = NULL; -static InputFilter *input = NULL; -static InputMap *input_map = NULL; -static TranslationServer *translation_server = NULL; -static Performance *performance = NULL; -static PackedData *packed_data = NULL; +static Engine *engine = nullptr; +static ProjectSettings *globals = nullptr; +static Input *input = nullptr; +static InputMap *input_map = nullptr; +static TranslationServer *translation_server = nullptr; +static Performance *performance = nullptr; +static PackedData *packed_data = nullptr; #ifdef MINIZIP_ENABLED -static ZipArchive *zip_packed_data = NULL; +static ZipArchive *zip_packed_data = nullptr; #endif -static FileAccessNetworkClient *file_access_network_client = NULL; -static MessageQueue *message_queue = NULL; +static FileAccessNetworkClient *file_access_network_client = nullptr; +static MessageQueue *message_queue = nullptr; // Initialized in setup2() -static AudioServer *audio_server = NULL; -static DisplayServer *display_server = NULL; -static RenderingServer *rendering_server = NULL; -static CameraServer *camera_server = NULL; -static ARVRServer *arvr_server = NULL; -static PhysicsServer3D *physics_server = NULL; -static PhysicsServer2D *physics_2d_server = NULL; -static NavigationServer3D *navigation_server = NULL; -static NavigationServer2D *navigation_2d_server = NULL; +static AudioServer *audio_server = nullptr; +static DisplayServer *display_server = nullptr; +static RenderingServer *rendering_server = nullptr; +static CameraServer *camera_server = nullptr; +static XRServer *xr_server = nullptr; +static PhysicsServer3D *physics_server = nullptr; +static PhysicsServer2D *physics_2d_server = nullptr; +static NavigationServer3D *navigation_server = nullptr; +static NavigationServer2D *navigation_2d_server = nullptr; // We error out if setup2() doesn't turn this true static bool _start_success = false; @@ -175,8 +176,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; } @@ -203,7 +205,6 @@ void initialize_physics() { } void finalize_physics() { - physics_server->finish(); memdelete(physics_server); @@ -212,7 +213,6 @@ void finalize_physics() { } void finalize_display() { - rendering_server->finish(); memdelete(rendering_server); @@ -220,7 +220,7 @@ void finalize_display() { } void initialize_navigation_server() { - ERR_FAIL_COND(navigation_server != NULL); + ERR_FAIL_COND(navigation_server != nullptr); navigation_server = NavigationServer3DManager::new_default_server(); navigation_2d_server = memnew(NavigationServer2D); @@ -228,10 +228,10 @@ void initialize_navigation_server() { void finalize_navigation_server() { memdelete(navigation_server); - navigation_server = NULL; + navigation_server = nullptr; memdelete(navigation_2d_server); - navigation_2d_server = NULL; + navigation_2d_server = nullptr; } //#define DEBUG_INIT @@ -242,7 +242,6 @@ void finalize_navigation_server() { #endif void Main::print_help(const char *p_binary) { - print_line(String(VERSION_NAME) + " v" + get_full_version_string() + " - " + String(VERSION_WEBSITE)); OS::get_singleton()->print("Free and open source software under the terms of the MIT license.\n"); OS::get_singleton()->print("(c) 2007-2020 Juan Linietsky, Ariel Manzur.\n"); @@ -313,6 +312,13 @@ void Main::print_help(const char *p_binary) { OS::get_singleton()->print(" --enable-vsync-via-compositor When vsync is enabled, vsync via the OS' window compositor (Windows only).\n"); OS::get_singleton()->print(" --disable-vsync-via-compositor Disable vsync via the OS' window compositor (Windows only).\n"); OS::get_singleton()->print(" --single-window Use a single window (no separate subwindows).\n"); + OS::get_singleton()->print(" --tablet-driver Tablet input driver ("); + for (int i = 0; i < OS::get_singleton()->get_tablet_driver_count(); i++) { + if (i != 0) + OS::get_singleton()->print(", "); + OS::get_singleton()->print("'%s'", OS::get_singleton()->get_tablet_driver_name(i).utf8().get_data()); + } + OS::get_singleton()->print(") (Windows only).\n"); OS::get_singleton()->print("\n"); #endif @@ -321,7 +327,7 @@ void Main::print_help(const char *p_binary) { OS::get_singleton()->print(" -b, --breakpoints Breakpoint list as source::line comma-separated pairs, no spaces (use %%20 instead).\n"); OS::get_singleton()->print(" --profiling Enable profiling in the script debugger.\n"); OS::get_singleton()->print(" --gpu-abort Abort on GPU errors (usually validation layer errors), may help see the problem if your system freezes.\n"); - OS::get_singleton()->print(" --remote-debug <address> Remote debug (<host/IP>:<port> address).\n"); + OS::get_singleton()->print(" --remote-debug <uri> Remote debug (<protocol>://<host/IP>[:<port>], e.g. tcp://127.0.0.1:6007).\n"); #if defined(DEBUG_ENABLED) && !defined(SERVER_ENABLED) OS::get_singleton()->print(" --debug-collisions Show collision shapes when running the scene.\n"); OS::get_singleton()->print(" --debug-navigation Show navigation polygons when running the scene.\n"); @@ -387,7 +393,6 @@ void Main::print_help(const char *p_binary) { */ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_phase) { - OS::get_singleton()->initialize(); engine = memnew(Engine); @@ -422,7 +427,6 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph List<String> main_args; for (int i = 0; i < argc; i++) { - args.push_back(String::utf8(argv[i])); } @@ -431,7 +435,6 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph I = args.front(); while (I) { - I->get() = unescape_cmdline(I->get().strip_edges()); I = I->next(); } @@ -440,6 +443,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph String display_driver = ""; String audio_driver = ""; + String tablet_driver = ""; String project_path = "."; bool upwards = false; String debug_uri = ""; @@ -461,8 +465,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 @@ -478,6 +483,14 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph I = args.front(); while (I) { +#ifdef OSX_ENABLED + // Ignore the process serial number argument passed by macOS Gatekeeper. + // Otherwise, Godot would try to open a non-existent project on the first start and abort. + if (I->get().begins_with("-psn_")) { + I = I->next(); + continue; + } +#endif List<String>::Element *N = I->next(); @@ -487,7 +500,6 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph goto error; } else if (I->get() == "--version") { - print_line(get_full_version_string()); goto error; @@ -501,7 +513,6 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph } else if (I->get() == "--audio-driver") { // audio driver if (I->next()) { - audio_driver = I->next()->get(); bool found = false; @@ -538,7 +549,6 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph } else if (I->get() == "--display-driver") { // force video driver if (I->next()) { - display_driver = I->next()->get(); bool found = false; @@ -586,6 +596,26 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph } else if (I->get() == "--gpu-abort") { // force windowed window Engine::singleton->abort_on_gpu_errors = true; + } else if (I->get() == "--tablet-driver") { + if (I->next()) { + tablet_driver = I->next()->get(); + bool found = false; + for (int i = 0; i < OS::get_singleton()->get_tablet_driver_count(); i++) { + if (tablet_driver == OS::get_singleton()->get_tablet_driver_name(i)) { + found = true; + } + } + + if (!found) { + OS::get_singleton()->print("Unknown tablet driver '%s', aborting.\n", tablet_driver.utf8().get_data()); + goto error; + } + + N = I->next()->next(); + } else { + OS::get_singleton()->print("Missing tablet driver argument, aborting.\n"); + goto error; + } } else if (I->get() == "--single-window") { // force single window single_window = true; @@ -595,7 +625,6 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph } else if (I->get() == "--resolution") { // force resolution if (I->next()) { - String vm = I->next()->get(); if (vm.find("x") == -1) { // invalid parameter format @@ -608,7 +637,6 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph int h = vm.get_slice("x", 1).to_int(); if (w <= 0 || h <= 0) { - OS::get_singleton()->print("Invalid resolution '%s', width and height must be above 0.\n", vm.utf8().get_data()); goto error; } @@ -626,7 +654,6 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph } else if (I->get() == "--position") { // set window position if (I->next()) { - String vm = I->next()->get(); if (vm.find(",") == -1) { // invalid parameter format @@ -654,11 +681,9 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph OS::get_singleton()->set_no_window_mode(true); } else if (I->get() == "--enable-vsync-via-compositor") { - window_vsync_via_compositor = true; saw_vsync_via_compositor_override = true; } else if (I->get() == "--disable-vsync-via-compositor") { - window_vsync_via_compositor = false; saw_vsync_via_compositor_override = true; #endif @@ -669,7 +694,6 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph } else if (I->get() == "-l" || I->get() == "--language") { // language if (I->next()) { - locale = I->next()->get(); N = I->next()->next(); } else { @@ -680,7 +704,6 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph } else if (I->get() == "--remote-fs") { // remote filesystem if (I->next()) { - remotefs = I->next()->get(); N = I->next()->next(); } else { @@ -690,7 +713,6 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph } else if (I->get() == "--remote-fs-password") { // remote filesystem password if (I->next()) { - remotefs_pass = I->next()->get(); N = I->next()->next(); } else { @@ -700,13 +722,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 { @@ -740,7 +762,6 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph } else if (I->get() == "--path") { // set path of project to start or edit if (I->next()) { - String p = I->next()->get(); if (OS::get_singleton()->set_cwd(p) == OK) { //nothing @@ -760,9 +781,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) { @@ -776,7 +797,6 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph } else if (I->get() == "-b" || I->get() == "--breakpoints") { // add breakpoints if (I->next()) { - String bplist = I->next()->get(); breakpoints = bplist.split(","); N = I->next()->next(); @@ -788,7 +808,6 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph } else if (I->get() == "--frame-delay") { // force frame delay if (I->next()) { - frame_delay = I->next()->get().to_int(); N = I->next()->next(); } else { @@ -799,7 +818,6 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph } else if (I->get() == "--time-scale") { // force time scale if (I->next()) { - Engine::get_singleton()->set_time_scale(I->next()->get().to_double()); N = I->next()->next(); } else { @@ -808,9 +826,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph } } else if (I->get() == "--main-pack") { - if (I->next()) { - main_pack = I->next()->get(); N = I->next()->next(); } else { @@ -828,13 +844,11 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph #endif } else if (I->get() == "--remote-debug") { if (I->next()) { - debug_uri = I->next()->get(); - if (debug_uri.find(":") == -1) { // wrong address - OS::get_singleton()->print("Invalid debug host address, it should be of the form <host/IP>:<port>.\n"); + if (debug_uri.find("://") == -1) { // wrong address + OS::get_singleton()->print("Invalid debug host address, it should be of the form <protocol>://<host/IP>:<port>.\n"); goto error; } - debug_uri = "tcp://" + debug_uri; // will support multiple protocols eventually. N = I->next()->next(); } else { OS::get_singleton()->print("Missing remote debug host address, aborting.\n"); @@ -842,7 +856,6 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph } } else if (I->get() == "--allow_focus_steal_pid") { // not exposed to user if (I->next()) { - allow_focus_steal_pid = I->next()->get().to_int64(); N = I->next()->next(); } else { @@ -883,7 +896,6 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph // 'project.godot' file which will only be available through the network if this is enabled FileAccessNetwork::configure(); if (remotefs != "") { - file_access_network_client = memnew(FileAccessNetworkClient); int port; if (remotefs.find(":") != -1) { @@ -907,7 +919,6 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph found_project = true; #endif } else { - #ifdef TOOLS_ENABLED editor = false; #else @@ -992,8 +1003,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); @@ -1020,13 +1032,11 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph ProjectSettings::get_singleton()->set_custom_property_info("display/window/size/test_height", PropertyInfo(Variant::INT, "display/window/size/test_height", PROPERTY_HINT_RANGE, "0,4320,or_greater")); // 8K resolution if (use_custom_res) { - if (!force_res) { window_size.width = GLOBAL_GET("display/window/size/width"); window_size.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"); if (tw > 0) { window_size.width = tw; @@ -1070,6 +1080,21 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph OS::get_singleton()->_vsync_via_compositor = window_vsync_via_compositor; + if (tablet_driver == "") { // specified in project.godot + tablet_driver = GLOBAL_DEF_RST("display/window/tablet_driver", OS::get_singleton()->get_tablet_driver_name(0)); + } + + for (int i = 0; i < OS::get_singleton()->get_tablet_driver_count(); i++) { + if (tablet_driver == OS::get_singleton()->get_tablet_driver_name(i)) { + OS::get_singleton()->set_current_tablet_driver(OS::get_singleton()->get_tablet_driver_name(i)); + break; + } + } + + if (tablet_driver == "") { + OS::get_singleton()->set_current_tablet_driver(OS::get_singleton()->get_tablet_driver_name(0)); + } + /* todo restore OS::get_singleton()->_allow_layered = GLOBAL_DEF("display/window/per_pixel_transparency/allowed", false); video_mode.layered = GLOBAL_DEF("display/window/per_pixel_transparency/enabled", false); @@ -1099,9 +1124,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph /* Determine audio and video drivers */ for (int i = 0; i < DisplayServer::get_create_function_count(); i++) { - if (display_driver == DisplayServer::get_create_function_name(i)) { - display_driver_idx = i; break; } @@ -1116,9 +1139,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph } for (int i = 0; i < AudioDriverManager::get_driver_count(); i++) { - if (audio_driver == AudioDriverManager::get_driver(i)->get_name()) { - audio_driver_idx = i; break; } @@ -1131,20 +1152,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)); @@ -1154,9 +1176,11 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph ProjectSettings::get_singleton()->set_custom_property_info("debug/settings/fps/force_fps", PropertyInfo(Variant::INT, "debug/settings/fps/force_fps", PROPERTY_HINT_RANGE, "0,120,1,or_greater")); GLOBAL_DEF("debug/settings/stdout/print_fps", false); + GLOBAL_DEF("debug/settings/stdout/verbose_stdout", false); - if (!OS::get_singleton()->_verbose_stdout) //overridden - OS::get_singleton()->_verbose_stdout = GLOBAL_DEF("debug/settings/stdout/verbose_stdout", false); + if (!OS::get_singleton()->_verbose_stdout) { // Not manually overridden. + OS::get_singleton()->_verbose_stdout = GLOBAL_GET("debug/settings/stdout/verbose_stdout"); + } if (frame_delay == 0) { frame_delay = GLOBAL_DEF("application/run/frame_delay_msec", 0); @@ -1173,8 +1197,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; @@ -1182,38 +1207,48 @@ error: display_driver = ""; audio_driver = ""; + tablet_driver = ""; project_path = ""; 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(); @@ -1221,7 +1256,6 @@ error: } Error Main::setup2(Thread::ID p_main_tid_override) { - preregister_module_types(); preregister_server_types(); @@ -1238,12 +1272,11 @@ Error Main::setup2(Thread::ID p_main_tid_override) { /* Initialize Input */ - input = memnew(InputFilter); + input = memnew(Input); /* Iniitalize Display Server */ { - String rendering_driver; // temp broken Error err; @@ -1297,8 +1330,8 @@ Error Main::setup2(Thread::ID p_main_tid_override) { audio_server = memnew(AudioServer); audio_server->init(); - // also init our arvr_server from here - arvr_server = memnew(ARVRServer); + // also init our xr_server from here + xr_server = memnew(XRServer); register_core_singletons(); @@ -1348,8 +1381,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); @@ -1392,10 +1426,9 @@ Error Main::setup2(Thread::ID p_main_tid_override) { GLOBAL_DEF("application/config/windows_native_icon", String()); ProjectSettings::get_singleton()->set_custom_property_info("application/config/windows_native_icon", PropertyInfo(Variant::STRING, "application/config/windows_native_icon", PROPERTY_HINT_FILE, "*.ico")); - InputFilter *id = InputFilter::get_singleton(); + Input *id = Input::get_singleton(); if (id) { if (bool(GLOBAL_DEF("input_devices/pointing/emulate_touch_from_mouse", false)) && !(editor || project_manager)) { - bool found_touchscreen = false; for (int i = 0; i < DisplayServer::get_singleton()->get_screen_count(); i++) { if (DisplayServer::get_singleton()->screen_is_touchscreen(i)) { @@ -1423,11 +1456,10 @@ Error Main::setup2(Thread::ID p_main_tid_override) { ProjectSettings::get_singleton()->set_custom_property_info("display/mouse_cursor/custom_image", PropertyInfo(Variant::STRING, "display/mouse_cursor/custom_image", PROPERTY_HINT_FILE, "*.png,*.webp")); if (String(ProjectSettings::get_singleton()->get("display/mouse_cursor/custom_image")) != String()) { - Ref<Texture2D> cursor = ResourceLoader::load(ProjectSettings::get_singleton()->get("display/mouse_cursor/custom_image")); if (cursor.is_valid()) { Vector2 hotspot = ProjectSettings::get_singleton()->get("display/mouse_cursor/custom_image_hotspot"); - InputFilter::get_singleton()->set_custom_mouse_cursor(cursor, InputFilter::CURSOR_ARROW, hotspot); + Input::get_singleton()->set_custom_mouse_cursor(cursor, Input::CURSOR_ARROW, hotspot); } } #ifdef TOOLS_ENABLED @@ -1458,7 +1490,6 @@ Error Main::setup2(Thread::ID p_main_tid_override) { translation_server->setup(); //register translations, load them, etc. if (locale != "") { - translation_server->set_locale(locale); } translation_server->load_translations(); @@ -1473,6 +1504,15 @@ Error Main::setup2(Thread::ID p_main_tid_override) { // We could add more, and make the CLI arg require a comma-separated list of profilers. EngineDebugger::get_singleton()->profiler_enable("scripts", true); } + + if (!project_manager) { + // If not running the project manager, and now that the engine is + // able to load resources, load the global shader variables. + // If running on editor, dont load the textures because the editor + // may want to import them first. Editor will reload those later. + rendering_server->global_variables_load_settings(!editor); + } + _start_success = true; locale = String(); @@ -1489,7 +1529,6 @@ Error Main::setup2(Thread::ID p_main_tid_override) { static MainTimerSync main_timer_sync; bool Main::start() { - ERR_FAIL_COND_V(!_start_success, false); bool hasicon = false; @@ -1526,7 +1565,11 @@ bool Main::start() { } else if (args[i].length() && args[i][0] != '-' && positional_arg == "") { positional_arg = args[i]; - if (args[i].ends_with(".scn") || args[i].ends_with(".tscn") || args[i].ends_with(".escn")) { + if (args[i].ends_with(".scn") || + args[i].ends_with(".tscn") || + args[i].ends_with(".escn") || + args[i].ends_with(".res") || + args[i].ends_with(".tres")) { // Only consider the positional argument to be a scene path if it ends with // a file extension associated with Godot scenes. This makes it possible // for projects to parse command-line arguments for custom CLI arguments @@ -1546,8 +1589,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]; @@ -1573,13 +1617,25 @@ bool Main::start() { String main_loop_type; #ifdef TOOLS_ENABLED if (doc_tool != "") { - Engine::get_singleton()->set_editor_hint(true); // Needed to instance editor-only classes for their default values { DirAccessRef da = DirAccess::open(doc_tool); ERR_FAIL_COND_V_MSG(!da, false, "Argument supplied to --doctool must be a base Godot build directory."); } + +#ifndef MODULE_MONO_ENABLED + // Hack to define Mono-specific project settings even on non-Mono builds, + // so that we don't lose their descriptions and default values in DocData. + // Default values should be synced with mono_gd/gd_mono.cpp. + GLOBAL_DEF("mono/debugger_agent/port", 23685); + GLOBAL_DEF("mono/debugger_agent/wait_for_debugger", false); + GLOBAL_DEF("mono/debugger_agent/wait_timeout", 3000); + GLOBAL_DEF("mono/profiler/args", "log:calls,alloc,sample,output=output.mlpd"); + GLOBAL_DEF("mono/profiler/enabled", false); + GLOBAL_DEF("mono/unhandled_exception_policy", 0); +#endif + DocData doc; doc.generate(doc_base); @@ -1589,7 +1645,11 @@ bool Main::start() { print_line("Loading docs..."); for (int i = 0; i < _doc_data_class_path_count; i++) { - String path = doc_tool.plus_file(_doc_data_class_paths[i].path); + // Custom modules are always located by absolute path. + String path = _doc_data_class_paths[i].path; + if (path.is_rel_path()) { + path = doc_tool.plus_file(path); + } String name = _doc_data_class_paths[i].name; doc_data_classes[name] = path; if (!checked_paths.has(path)) { @@ -1642,7 +1702,7 @@ bool Main::start() { game_path = GLOBAL_DEF("application/run/main_scene", ""); } - MainLoop *main_loop = NULL; + MainLoop *main_loop = nullptr; if (editor) { main_loop = memnew(SceneTree); }; @@ -1651,12 +1711,12 @@ bool Main::start() { #ifdef TOOLS_ENABLED main_loop = test_main(test, args); - if (!main_loop) + if (!main_loop) { return false; + } #endif } else if (script != "") { - Ref<Script> script_res = ResourceLoader::load(script); ERR_FAIL_COND_V_MSG(script_res.is_null(), false, "Can't load script: " + script); @@ -1667,21 +1727,20 @@ bool Main::start() { return false; } - if (script_res->can_instance() /*&& script_res->inherits_from("SceneTreeScripted")*/) { - + if (script_res->can_instance()) { StringName instance_type = script_res->get_instance_base_type(); 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, "Can't load script '" + script + "', it does not inherit from a MainLoop type."); + } + ERR_FAIL_V_MSG(false, vformat("Can't load the script \"%s\" as it doesn't inherit from SceneTree or MainLoop.", script)); } script_loop->set_init_script(script_res); main_loop = script_loop; } else { - return false; } @@ -1689,21 +1748,20 @@ 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)) { DisplayServer::get_singleton()->alert("Error: MainLoop type doesn't exist: " + main_loop_type); return false; } else { - Object *ml = ClassDB::instance(main_loop_type); 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_FAIL_V_MSG(false, "Invalid MainLoop type."); } @@ -1711,7 +1769,6 @@ bool Main::start() { } if (main_loop->is_class("SceneTree")) { - SceneTree *sml = Object::cast_to<SceneTree>(main_loop); #ifdef DEBUG_ENABLED @@ -1723,7 +1780,9 @@ bool Main::start() { } #endif - if (single_window) { + bool embed_subwindows = GLOBAL_DEF("display/window/subwindows/embed_subwindows", false); + + if (single_window || (!project_manager && !editor && embed_subwindows)) { sml->get_root()->set_embed_subwindows_hint(true); } ResourceLoader::add_custom_loaders(); @@ -1737,10 +1796,10 @@ 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; @@ -1758,10 +1817,10 @@ bool Main::start() { //second pass, load into global constants 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; @@ -1772,7 +1831,7 @@ bool Main::start() { RES res = ResourceLoader::load(path); ERR_CONTINUE_MSG(res.is_null(), "Can't autoload: " + path); - Node *n = NULL; + Node *n = nullptr; if (res->is_class("PackedScene")) { Ref<PackedScene> ps = res; n = ps->instance(); @@ -1784,7 +1843,7 @@ bool Main::start() { Object *obj = ClassDB::instance(ibt); - ERR_CONTINUE_MSG(obj == NULL, "Cannot instance script for autoload, expected 'Node' inheritance, got: " + String(ibt)); + ERR_CONTINUE_MSG(obj == nullptr, "Cannot instance script for autoload, expected 'Node' inheritance, got: " + String(ibt)); n = Object::cast_to<Node>(obj); n->set_script(script_res); @@ -1804,14 +1863,13 @@ bool Main::start() { } for (List<Node *>::Element *E = to_add.front(); E; E = E->next()) { - sml->get_root()->add_child(E->get()); } } } #ifdef TOOLS_ENABLED - EditorNode *editor_node = NULL; + EditorNode *editor_node = nullptr; if (editor) { editor_node = memnew(EditorNode); sml->get_root()->add_child(editor_node); @@ -1824,7 +1882,6 @@ bool Main::start() { #endif { - int directional_atlas_size = GLOBAL_GET("rendering/quality/directional_shadow/size"); RenderingServer::get_singleton()->directional_shadow_atlas_set_size(directional_atlas_size); } @@ -1837,20 +1894,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); @@ -1886,7 +1945,6 @@ bool Main::start() { sml->get_root()->set_default_canvas_item_texture_repeat(Viewport::DefaultCanvasItemTextureRepeat(texture_repeat)); } else { - GLOBAL_DEF("display/window/stretch/mode", "disabled"); ProjectSettings::get_singleton()->set_custom_property_info("display/window/stretch/mode", PropertyInfo(Variant::STRING, "display/window/stretch/mode", PROPERTY_HINT_ENUM, "disabled,2d,viewport")); GLOBAL_DEF("display/window/stretch/aspect", "ignore"); @@ -1904,18 +1962,25 @@ bool Main::start() { ProjectSettings::get_singleton()->set_custom_property_info("rendering/canvas_textures/default_texture_repeat", PropertyInfo(Variant::INT, "rendering/canvas_textures/default_texture_repeat", PROPERTY_HINT_ENUM, "Disable,Enable,Mirror")); } +#ifdef TOOLS_ENABLED + if (editor) { + bool editor_embed_subwindows = EditorSettings::get_singleton()->get_setting("interface/editor/single_window_mode"); + + if (editor_embed_subwindows) { + sml->get_root()->set_embed_subwindows_hint(true); + } + } +#endif + String local_game_path; if (game_path != "" && !project_manager) { - local_game_path = game_path.replace("\\", "/"); if (!local_game_path.begins_with("res://")) { bool absolute = (local_game_path.size() > 1) && (local_game_path[0] == '/' || local_game_path[1] == ':'); if (!absolute) { - if (ProjectSettings::get_singleton()->is_using_datapack()) { - local_game_path = "res://" + local_game_path; } else { @@ -1926,7 +1991,6 @@ bool Main::start() { local_game_path = da->get_current_dir().plus_file(local_game_path); memdelete(da); } else { - DirAccess *da = DirAccess::open(local_game_path.substr(0, sep)); if (da) { local_game_path = da->get_current_dir().plus_file(local_game_path.substr(sep + 1, local_game_path.length())); @@ -1941,11 +2005,11 @@ bool Main::start() { #ifdef TOOLS_ENABLED if (editor) { - 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); } @@ -1958,13 +2022,14 @@ bool Main::start() { if (!project_manager && !editor) { // game // Load SSL Certificates from Project Settings (or builtin). - Crypto::load_default_certificates(GLOBAL_DEF("network/ssl/certificates", "")); + Crypto::load_default_certificates(GLOBAL_DEF("network/ssl/certificate_bundle_override", "")); if (game_path != "") { - Node *scene = NULL; + 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); @@ -1999,7 +2064,6 @@ bool Main::start() { #ifdef TOOLS_ENABLED if (project_manager || (script == "" && test == "" && game_path == "" && !editor)) { - Engine::get_singleton()->set_editor_hint(true); ProjectManager *pmanager = memnew(ProjectManager); ProgressDialog *progress_dialog = memnew(ProgressDialog); @@ -2010,9 +2074,11 @@ bool Main::start() { } if (project_manager || editor) { - // Hide console window if requested (Windows-only). - bool hide_console = EditorSettings::get_singleton()->get_setting("interface/editor/hide_console_window"); - DisplayServer::get_singleton()->console_set_visible(!hide_console); + if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_CONSOLE_WINDOW)) { + // Hide console window if requested (Windows-only). + bool hide_console = EditorSettings::get_singleton()->get_setting("interface/editor/hide_console_window"); + DisplayServer::get_singleton()->console_set_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()); @@ -2055,7 +2121,6 @@ static uint64_t physics_process_max = 0; static uint64_t idle_process_max = 0; bool Main::iteration() { - //for now do not error on this //ERR_FAIL_COND_V(iterating, false); @@ -2098,7 +2163,6 @@ bool Main::iteration() { Engine::get_singleton()->_in_physics = true; for (int iters = 0; iters < advance.physics_steps; ++iters) { - uint64_t physics_begin = OS::get_singleton()->get_ticks_usec(); PhysicsServer3D::get_singleton()->sync(); @@ -2140,7 +2204,6 @@ bool Main::iteration() { RenderingServer::get_singleton()->sync(); //sync if still drawing from previous frames. if (DisplayServer::get_singleton()->can_any_window_draw() && !disable_render_loop) { - if ((!force_redraw_requested) && OS::get_singleton()->is_in_low_processor_usage_mode()) { if (RenderingServer::get_singleton()->has_changed()) { RenderingServer::get_singleton()->draw(true, scaled_step); // flush visual commands @@ -2163,14 +2226,14 @@ 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++; if (frame > 1000000) { - if (editor || project_manager) { if (print_fps) { print_line("Editor FPS: " + itos(frames)); @@ -2191,15 +2254,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(); @@ -2207,7 +2272,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) OS::get_singleton()->delay_usec(target_ticks - current_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); } @@ -2239,7 +2306,6 @@ void Main::force_redraw() { * The order matters as some of those steps are linked with each other. */ void Main::cleanup() { - ERR_FAIL_COND(!_start_success); EngineDebugger::deinitialize(); @@ -2264,13 +2330,16 @@ void Main::cleanup() { // Sync pending commands that may have been queued from a different thread during ScriptServer finalization RenderingServer::get_singleton()->sync(); + //clear global shader variables before scene and other graphics stuff is deinitialized. + rendering_server->global_variables_clear(); + #ifdef TOOLS_ENABLED EditorNode::unregister_editor_types(); #endif - if (arvr_server) { + if (xr_server) { // cleanup now before we pull the rug from underneath... - memdelete(arvr_server); + memdelete(xr_server); } ImageLoader::cleanup(); @@ -2300,20 +2369,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 |