diff options
Diffstat (limited to 'main')
-rw-r--r-- | main/SCsub | 13 | ||||
-rw-r--r-- | main/main.cpp | 309 | ||||
-rw-r--r-- | main/splash_editor.png | bin | 37471 -> 0 bytes |
3 files changed, 206 insertions, 116 deletions
diff --git a/main/SCsub b/main/SCsub index 87d64e48f9..79dc4bff15 100644 --- a/main/SCsub +++ b/main/SCsub @@ -20,12 +20,13 @@ env_main.CommandNoCache( env.Run(main_builders.make_splash, "Building splash screen header."), ) -env_main.Depends("#main/splash_editor.gen.h", "#main/splash_editor.png") -env_main.CommandNoCache( - "#main/splash_editor.gen.h", - "#main/splash_editor.png", - env.Run(main_builders.make_splash_editor, "Building editor splash screen header."), -) +if not env_main["no_editor_splash"]: + env_main.Depends("#main/splash_editor.gen.h", "#main/splash_editor.png") + env_main.CommandNoCache( + "#main/splash_editor.gen.h", + "#main/splash_editor.png", + env.Run(main_builders.make_splash_editor, "Building editor splash screen header."), + ) env_main.Depends("#main/app_icon.gen.h", "#main/app_icon.png") env_main.CommandNoCache( diff --git a/main/main.cpp b/main/main.cpp index 7d7c9d7374..e760c930f2 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -56,8 +56,6 @@ #include "main/main_timer_sync.h" #include "main/performance.h" #include "main/splash.gen.h" -#include "main/splash_editor.gen.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" @@ -81,16 +79,19 @@ #endif #ifdef TOOLS_ENABLED - #include "editor/doc_data_class_path.gen.h" #include "editor/doc_tools.h" #include "editor/editor_node.h" #include "editor/editor_settings.h" #include "editor/progress_dialog.h" #include "editor/project_manager.h" - +#ifndef NO_EDITOR_SPLASH +#include "main/splash_editor.gen.h" +#endif #endif +#include "modules/modules_enabled.gen.h" // For mono. + /* Static members */ // Singletons @@ -128,7 +129,7 @@ static bool _start_success = false; String tablet_driver = ""; String text_driver = ""; - +String rendering_driver = ""; static int text_driver_idx = -1; static int display_driver_idx = -1; static int audio_driver_idx = -1; @@ -376,7 +377,9 @@ void Main::print_help(const char *p_binary) { OS::get_singleton()->print(" --doctool [<path>] Dump the engine API reference to the given <path> (defaults to current dir) 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"); OS::get_singleton()->print(" --build-solutions Build the scripting solutions (e.g. for C# projects). Implies --editor and requires a valid project to edit.\n"); + OS::get_singleton()->print(" --dump-extension-api Generate JSON dump of the Godot API for GDExtension bindings named 'extension_api.json' in the current folder.\n"); #ifdef DEBUG_METHODS_ENABLED + // TODO: Should be removed together with nativescript eventually. OS::get_singleton()->print(" --gdnative-generate-json-api <path> Generate JSON dump of the Godot API for GDNative bindings and save it on the file specified in <path>.\n"); OS::get_singleton()->print(" --gdnative-generate-json-builtin-api <path> Generate JSON dump of the Godot API of the builtin Variant types and utility functions for GDNative bindings and save it on the file specified in <path>.\n"); #endif @@ -407,6 +410,7 @@ Error Main::test_setup() { GLOBAL_DEF_RST("rendering/occlusion_culling/bvh_build_quality", 2); translation_server = memnew(TranslationServer); + tsman = memnew(TextServerManager); register_core_extensions(); @@ -440,6 +444,9 @@ Error Main::test_setup() { register_module_types(); register_driver_types(); + ERR_FAIL_COND_V(TextServerManager::get_singleton()->get_interface_count() == 0, ERR_CANT_CREATE); + TextServerManager::get_singleton()->set_primary_interface(TextServerManager::get_singleton()->get_interface(0)); + ClassDB::set_current_api(ClassDB::API_NONE); _start_success = true; @@ -459,6 +466,7 @@ void Main::test_cleanup() { #ifdef TOOLS_ENABLED EditorNode::unregister_editor_types(); #endif + unregister_module_types(); unregister_platform_apis(); unregister_scene_types(); @@ -469,6 +477,9 @@ void Main::test_cleanup() { if (translation_server) { memdelete(translation_server); } + if (tsman) { + memdelete(tsman); + } if (globals) { memdelete(globals); } @@ -724,7 +735,49 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph N = I->next()->next(); } else { - OS::get_singleton()->print("Missing video driver argument, aborting.\n"); + OS::get_singleton()->print("Missing display driver argument, aborting.\n"); + goto error; + } + } else if (I->get() == "--rendering-driver") { + if (I->next()) { + rendering_driver = I->next()->get(); + + // as the rendering drivers available may depend on the display driver selected, + // we can't do an exhaustive check here, but we can look through all the options in + // all the display drivers for a match + + bool found = false; + for (int i = 0; i < DisplayServer::get_create_function_count(); i++) { + Vector<String> r_drivers = DisplayServer::get_create_function_rendering_drivers(i); + + for (int d = 0; d < r_drivers.size(); d++) { + if (rendering_driver == r_drivers[d]) { + found = true; + break; + } + } + } + + if (!found) { + OS::get_singleton()->print("Unknown rendering driver '%s', aborting.\nValid options are ", + rendering_driver.utf8().get_data()); + + for (int i = 0; i < DisplayServer::get_create_function_count(); i++) { + Vector<String> r_drivers = DisplayServer::get_create_function_rendering_drivers(i); + + for (int d = 0; d < r_drivers.size(); d++) { + OS::get_singleton()->print("'%s', ", r_drivers[d].utf8().get_data()); + } + } + + OS::get_singleton()->print(".\n"); + + goto error; + } + + N = I->next()->next(); + } else { + OS::get_singleton()->print("Missing rendering driver argument, aborting.\n"); goto error; } } else if (I->get() == "-f" || I->get() == "--fullscreen") { // force fullscreen @@ -893,23 +946,27 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph auto_build_solutions = true; editor = true; cmdline_tool = true; - +#ifdef DEBUG_METHODS_ENABLED } else if (I->get() == "--gdnative-generate-json-api" || I->get() == "--gdnative-generate-json-builtin-api") { // Register as an editor instance to use low-end fallback if relevant. editor = true; cmdline_tool = true; - - // We still pass it to the main arguments since the argument handling itself is not done in this function + // We still pass it to the main arguments since the argument handling itself is not done in this function, + // it's done in nativescript init code. main_args.push_back(I->get()); +#endif } else if (I->get() == "--dump-extension-api") { // Register as an editor instance to use low-end fallback if relevant. editor = true; cmdline_tool = true; dump_extension_api = true; - print_line("dump extension?"); + print_line("Dumping Extension API"); + // Hack. Not needed but otherwise we end up detecting that this should + // run the project instead of a cmdline tool. + // Needs full refactoring to fix properly. main_args.push_back(I->get()); } else if (I->get() == "--export" || I->get() == "--export-debug" || - I->get() == "--export-pack") { // Export project + I->get() == "--export-pack") { // Export project // Actually handling is done in start(). editor = true; cmdline_tool = true; @@ -1081,7 +1138,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph FileAccess::make_default<FileAccessNetwork>(FileAccess::ACCESS_RESOURCES); } - if (globals->setup(project_path, main_pack, upwards) == OK) { + if (globals->setup(project_path, main_pack, upwards, editor) == OK) { #ifdef TOOLS_ENABLED found_project = true; #endif @@ -1217,16 +1274,30 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph OS::get_singleton()->set_cmdline(execpath, main_args); register_core_extensions(); //before display + // possibly be worth changing the default from vulkan to something lower spec, + // for the project manager, depending on how smooth the fallback is. + GLOBAL_DEF_RST("rendering/driver/driver_name", "vulkan"); - GLOBAL_DEF("rendering/driver/driver_name", "Vulkan"); + // this list is hard coded, which makes it more difficult to add new backends. + // can potentially be changed to more of a plugin system at a later date. ProjectSettings::get_singleton()->set_custom_property_info("rendering/driver/driver_name", PropertyInfo(Variant::STRING, "rendering/driver/driver_name", - PROPERTY_HINT_ENUM, "Vulkan")); - if (display_driver == "") { - display_driver = GLOBAL_GET("rendering/driver/driver_name"); + PROPERTY_HINT_ENUM, "vulkan,opengl3")); + + // if not set on the command line + if (rendering_driver == "") { + rendering_driver = GLOBAL_GET("rendering/driver/driver_name"); } + // note this is the desired rendering driver, it doesn't mean we will get it. + // TODO - make sure this is updated in the case of fallbacks, so that the user interface + // shows the correct driver string. + OS::get_singleton()->set_current_rendering_driver_name(rendering_driver); + + // always convert to lower case for consistency in the code + rendering_driver = rendering_driver.to_lower(); + GLOBAL_DEF_BASIC("display/window/size/width", 1024); ProjectSettings::get_singleton()->set_custom_property_info("display/window/size/width", PropertyInfo(Variant::INT, "display/window/size/width", @@ -1294,10 +1365,12 @@ 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); } - /* 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); -*/ + // FIXME: Restore support. +#if 0 + //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); +#endif + if (editor || project_manager) { // The editor and project manager always detect and use hiDPI if needed OS::get_singleton()->_allow_hidpi = true; @@ -1322,8 +1395,13 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph /* Determine audio and video drivers */ + // Display driver, e.g. X11, Wayland. + // print_line("requested display driver : " + display_driver); for (int i = 0; i < DisplayServer::get_create_function_count(); i++) { - if (display_driver == DisplayServer::get_create_function_name(i)) { + String name = DisplayServer::get_create_function_name(i); + // print_line("\t" + itos(i) + " : " + name); + + if (display_driver == name) { display_driver_idx = i; break; } @@ -1333,8 +1411,13 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph display_driver_idx = 0; } - if (audio_driver == "") { // specified in project.godot - audio_driver = GLOBAL_DEF_RST_NOVAL("audio/driver/driver", AudioDriverManager::get_driver(0)->get_name()); + // Store this in a globally accessible place, so we can retrieve the rendering drivers + // list from the display driver for the editor UI. + OS::get_singleton()->set_display_driver_id(display_driver_idx); + + GLOBAL_DEF_RST_NOVAL("audio/driver/driver", AudioDriverManager::get_driver(0)->get_name()); + if (audio_driver == "") { // Specified in project.godot. + audio_driver = GLOBAL_GET("audio/driver/driver"); } for (int i = 0; i < AudioDriverManager::get_driver_count(); i++) { @@ -1461,6 +1544,8 @@ error: } Error Main::setup2(Thread::ID p_main_tid_override) { + tsman = memnew(TextServerManager); + preregister_module_types(); preregister_server_types(); @@ -1479,64 +1564,6 @@ Error Main::setup2(Thread::ID p_main_tid_override) { } #endif - /* Determine text driver */ - - if (text_driver == "") { - text_driver = GLOBAL_GET("internationalization/rendering/text_driver"); - } - - if (text_driver != "") { - /* Load user selected text server. */ - for (int i = 0; i < TextServerManager::get_interface_count(); i++) { - if (text_driver == TextServerManager::get_interface_name(i)) { - text_driver_idx = i; - break; - } - } - } - - if (text_driver_idx < 0) { - /* If not selected, use one with the most features available. */ - int max_features = 0; - for (int i = 0; i < TextServerManager::get_interface_count(); i++) { - uint32_t ftrs = TextServerManager::get_interface_features(i); - int features = 0; - while (ftrs) { - features += ftrs & 1; - ftrs >>= 1; - } - if (features >= max_features) { - max_features = features; - text_driver_idx = i; - } - } - } - print_verbose("Using \"" + TextServerManager::get_interface_name(text_driver_idx) + "\" text server..."); - - /* Initialize Text Server */ - - { - tsman = memnew(TextServerManager); - Error err; - TextServer *text_server = TextServerManager::initialize(text_driver_idx, err); - if (err != OK || text_server == nullptr) { - for (int i = 0; i < TextServerManager::get_interface_count(); i++) { - if (i == text_driver_idx) { - continue; //don't try the same twice - } - text_server = TextServerManager::initialize(i, err); - if (err == OK && text_server != nullptr) { - break; - } - } - } - - if (err != OK || text_server == nullptr) { - ERR_PRINT("Unable to create TextServer, all text drivers failed."); - return err; - } - } - /* Initialize Input */ input = memnew(Input); @@ -1544,8 +1571,9 @@ Error Main::setup2(Thread::ID p_main_tid_override) { /* Initialize Display Server */ { - String rendering_driver; // temp broken + String display_driver = DisplayServer::get_create_function_name(display_driver_idx); + // rendering_driver now held in static global String in main and initialized in setup() Error err; display_server = DisplayServer::create(display_driver_idx, rendering_driver, window_mode, window_vsync_mode, window_flags, window_size, err); if (err != OK || display_server == nullptr) { @@ -1604,6 +1632,7 @@ Error Main::setup2(Thread::ID p_main_tid_override) { rendering_server = memnew(RenderingServerDefault(OS::get_singleton()->get_render_thread_mode() == OS::RENDER_SEPARATE_THREAD)); rendering_server->init(); + //rendering_server->call_set_use_vsync(OS::get_singleton()->_use_vsync); rendering_server->set_render_loop_enabled(!disable_render_loop); if (profile_gpu || (!editor && bool(GLOBAL_GET("debug/settings/stdout/print_gpu_profile")))) { @@ -1673,9 +1702,10 @@ Error Main::setup2(Thread::ID p_main_tid_override) { RenderingServer::get_singleton()->set_default_clear_color(clear); if (show_logo) { //boot logo! - String boot_logo_path = GLOBAL_DEF("application/boot_splash/image", String()); - bool boot_logo_scale = GLOBAL_DEF("application/boot_splash/fullsize", true); - bool boot_logo_filter = GLOBAL_DEF("application/boot_splash/use_filter", true); + const bool boot_logo_image = GLOBAL_DEF("application/boot_splash/show_image", true); + const String boot_logo_path = String(GLOBAL_DEF("application/boot_splash/image", String())).strip_edges(); + const bool boot_logo_scale = GLOBAL_DEF("application/boot_splash/fullsize", true); + const bool boot_logo_filter = GLOBAL_DEF("application/boot_splash/use_filter", true); ProjectSettings::get_singleton()->set_custom_property_info("application/boot_splash/image", PropertyInfo(Variant::STRING, "application/boot_splash/image", @@ -1683,14 +1713,19 @@ Error Main::setup2(Thread::ID p_main_tid_override) { Ref<Image> boot_logo; - boot_logo_path = boot_logo_path.strip_edges(); - - if (boot_logo_path != String()) { - boot_logo.instantiate(); - Error load_err = ImageLoader::load_image(boot_logo_path, boot_logo); - if (load_err) { - ERR_PRINT("Non-existing or invalid boot splash at '" + boot_logo_path + "'. Loading default splash."); + if (boot_logo_image) { + if (boot_logo_path != String()) { + boot_logo.instantiate(); + Error load_err = ImageLoader::load_image(boot_logo_path, boot_logo); + if (load_err) { + ERR_PRINT("Non-existing or invalid boot splash at '" + boot_logo_path + "'. Loading default splash."); + } } + } else { + // Create a 1×1 transparent image. This will effectively hide the splash image. + boot_logo.instantiate(); + boot_logo->create(1, 1, false, Image::FORMAT_RGBA8); + boot_logo->set_pixel(0, 0, Color(0, 0, 0, 0)); } #if defined(TOOLS_ENABLED) && !defined(NO_EDITOR_SPLASH) @@ -1781,6 +1816,57 @@ Error Main::setup2(Thread::ID p_main_tid_override) { ResourceLoader::load_path_remaps(); + MAIN_PRINT("Main: Load TextServer"); + + /* Enum text drivers */ + GLOBAL_DEF("internationalization/rendering/text_driver", ""); + String text_driver_options; + for (int i = 0; i < TextServerManager::get_singleton()->get_interface_count(); i++) { + if (i > 0) { + text_driver_options += ","; + } + text_driver_options += TextServerManager::get_singleton()->get_interface(i)->get_name(); + } + ProjectSettings::get_singleton()->set_custom_property_info("internationalization/rendering/text_driver", PropertyInfo(Variant::STRING, "internationalization/rendering/text_driver", PROPERTY_HINT_ENUM, text_driver_options)); + + /* Determine text driver */ + if (text_driver == "") { + text_driver = GLOBAL_GET("internationalization/rendering/text_driver"); + } + + if (text_driver != "") { + /* Load user selected text server. */ + for (int i = 0; i < TextServerManager::get_singleton()->get_interface_count(); i++) { + if (TextServerManager::get_singleton()->get_interface(i)->get_name() == text_driver) { + text_driver_idx = i; + break; + } + } + } + + if (text_driver_idx < 0) { + /* If not selected, use one with the most features available. */ + int max_features = 0; + for (int i = 0; i < TextServerManager::get_singleton()->get_interface_count(); i++) { + uint32_t features = TextServerManager::get_singleton()->get_interface(i)->get_features(); + int feature_number = 0; + while (features) { + feature_number += features & 1; + features >>= 1; + } + if (feature_number >= max_features) { + max_features = feature_number; + text_driver_idx = i; + } + } + } + if (text_driver_idx >= 0) { + TextServerManager::get_singleton()->set_primary_interface(TextServerManager::get_singleton()->get_interface(text_driver_idx)); + } else { + ERR_PRINT("TextServer: Unable to create TextServer interface."); + return ERR_CANT_CREATE; + } + MAIN_PRINT("Main: Load Scene Types"); register_scene_types(); @@ -1793,7 +1879,7 @@ Error Main::setup2(Thread::ID p_main_tid_override) { #endif - MAIN_PRINT("Main: Load Modules, Physics, Drivers, Scripts"); + MAIN_PRINT("Main: Load Modules"); register_platform_apis(); register_module_types(); @@ -1817,6 +1903,8 @@ Error Main::setup2(Thread::ID p_main_tid_override) { camera_server = CameraServer::create(); + MAIN_PRINT("Main: Load Physics, Drivers, Scripts"); + initialize_physics(); initialize_navigation_server(); register_server_singletons(); @@ -1969,9 +2057,7 @@ bool Main::start() { 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); - // From editor/csharp_project.cpp. - GLOBAL_DEF("mono/project/auto_update_project", true); + GLOBAL_DEF("mono/runtime/unhandled_exception_policy", 0); #endif DocTools doc; @@ -2060,6 +2146,8 @@ bool Main::start() { if (check_only) { if (!script_res->is_valid()) { OS::get_singleton()->set_exit_code(EXIT_FAILURE); + } else { + OS::get_singleton()->set_exit_code(EXIT_SUCCESS); } return false; } @@ -2132,7 +2220,7 @@ bool Main::start() { } #endif - bool embed_subwindows = GLOBAL_DEF("display/window/subwindows/embed_subwindows", false); + bool embed_subwindows = GLOBAL_DEF("display/window/subwindows/embed_subwindows", true); if (OS::get_singleton()->is_single_window() || (!project_manager && !editor && embed_subwindows)) { sml->get_root()->set_embed_subwindows_hint(true); @@ -2483,17 +2571,17 @@ bool Main::iteration() { iterating++; - uint64_t ticks = OS::get_singleton()->get_ticks_usec(); + const uint64_t ticks = OS::get_singleton()->get_ticks_usec(); Engine::get_singleton()->_frame_ticks = ticks; main_timer_sync.set_cpu_ticks_usec(ticks); main_timer_sync.set_fixed_fps(fixed_fps); - uint64_t ticks_elapsed = ticks - last_ticks; + const uint64_t ticks_elapsed = ticks - last_ticks; - int physics_ticks_per_second = Engine::get_singleton()->get_physics_ticks_per_second(); - float physics_step = 1.0 / physics_ticks_per_second; + const int physics_ticks_per_second = Engine::get_singleton()->get_physics_ticks_per_second(); + const double physics_step = 1.0 / physics_ticks_per_second; - float time_scale = Engine::get_singleton()->get_time_scale(); + const double time_scale = Engine::get_singleton()->get_time_scale(); MainFrameTime advance = main_timer_sync.advance(physics_step, physics_ticks_per_second); double process_step = advance.process_step; @@ -2517,6 +2605,9 @@ bool Main::iteration() { bool exit = false; + // process all our active interfaces + XRServer::get_singleton()->_process(); + for (int iters = 0; iters < advance.physics_steps; ++iters) { if (Input::get_singleton()->is_using_input_buffering() && agile_input_event_flushing) { Input::get_singleton()->flush_buffered_events(); @@ -2603,10 +2694,10 @@ bool Main::iteration() { if (frame > 1000000) { if (editor || project_manager) { if (print_fps) { - print_line(vformat("Editor FPS: %d (%s mspf)", frames, rtos(1000.0 / frames).pad_decimals(1))); + print_line(vformat("Editor FPS: %d (%s mspf)", frames, rtos(1000.0 / frames).pad_decimals(2))); } } else if (GLOBAL_GET("debug/settings/stdout/print_fps") || print_fps) { - print_line(vformat("Project FPS: %d (%s mspf)", frames, rtos(1000.0 / frames).pad_decimals(1))); + print_line(vformat("Project FPS: %d (%s mspf)", frames, rtos(1000.0 / frames).pad_decimals(2))); } Engine::get_singleton()->_fps = frames; @@ -2728,10 +2819,6 @@ void Main::cleanup(bool p_force) { finalize_navigation_server(); finalize_display(); - if (tsman) { - memdelete(tsman); - } - if (input) { memdelete(input); } @@ -2754,6 +2841,9 @@ void Main::cleanup(bool p_force) { if (translation_server) { memdelete(translation_server); } + if (tsman) { + memdelete(tsman); + } if (globals) { memdelete(globals); } @@ -2763,9 +2853,8 @@ void Main::cleanup(bool p_force) { if (OS::get_singleton()->is_restart_on_exit_set()) { //attempt to restart with arguments - String exec = OS::get_singleton()->get_executable_path(); List<String> args = OS::get_singleton()->get_restart_on_exit_arguments(); - OS::get_singleton()->create_process(exec, args); + OS::get_singleton()->create_instance(args); OS::get_singleton()->set_restart_on_exit(false, List<String>()); //clear list (uses memory) } diff --git a/main/splash_editor.png b/main/splash_editor.png Binary files differdeleted file mode 100644 index 49af9fde22..0000000000 --- a/main/splash_editor.png +++ /dev/null |