diff options
Diffstat (limited to 'main/main.cpp')
-rw-r--r-- | main/main.cpp | 219 |
1 files changed, 117 insertions, 102 deletions
diff --git a/main/main.cpp b/main/main.cpp index 1cbd732747..e1d53e7f1b 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -60,6 +60,7 @@ #include "platform/register_platform_apis.h" #include "scene/main/scene_tree.h" #include "scene/main/window.h" +#include "scene/property_list_helper.h" #include "scene/register_scene_types.h" #include "scene/resources/packed_scene.h" #include "scene/theme/theme_db.h" @@ -793,6 +794,7 @@ void Main::test_cleanup() { ResourceLoader::remove_custom_loaders(); ResourceSaver::remove_custom_savers(); + PropertyListHelper::clear_base_helpers(); #ifdef TOOLS_ENABLED GDExtensionManager::get_singleton()->deinitialize_extensions(GDExtension::INITIALIZATION_LEVEL_EDITOR); @@ -909,13 +911,11 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph // Benchmark tracking must be done after `OS::get_singleton()->initialize()` as on some // platforms, it's used to set up the time utilities. - OS::get_singleton()->benchmark_begin_measure("Startup", "Total"); - OS::get_singleton()->benchmark_begin_measure("Startup", "Setup"); + OS::get_singleton()->benchmark_begin_measure("Startup", "Main::Setup"); engine = memnew(Engine); MAIN_PRINT("Main: Initialize CORE"); - OS::get_singleton()->benchmark_begin_measure("Startup", "Core"); register_core_types(); register_core_driver_types(); @@ -2326,12 +2326,12 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph // Make sure that headless is the last one, which it is assumed to be by design. DEV_ASSERT(NULL_DISPLAY_DRIVER == DisplayServer::get_create_function_name(DisplayServer::get_create_function_count() - 1)); - GLOBAL_DEF_RST_NOVAL("display/display_server/driver", "default"); - GLOBAL_DEF_RST_NOVAL(PropertyInfo(Variant::STRING, "display/display_server/driver.windows", PROPERTY_HINT_ENUM_SUGGESTION, "default,windows,headless"), "default"); - GLOBAL_DEF_RST_NOVAL(PropertyInfo(Variant::STRING, "display/display_server/driver.linuxbsd", PROPERTY_HINT_ENUM_SUGGESTION, "default,x11,wayland,headless"), "default"); - GLOBAL_DEF_RST_NOVAL(PropertyInfo(Variant::STRING, "display/display_server/driver.android", PROPERTY_HINT_ENUM_SUGGESTION, "default,android,headless"), "default"); - GLOBAL_DEF_RST_NOVAL(PropertyInfo(Variant::STRING, "display/display_server/driver.ios", PROPERTY_HINT_ENUM_SUGGESTION, "default,iOS,headless"), "default"); - GLOBAL_DEF_RST_NOVAL(PropertyInfo(Variant::STRING, "display/display_server/driver.macos", PROPERTY_HINT_ENUM_SUGGESTION, "default,macos,headless"), "default"); + GLOBAL_DEF_NOVAL("display/display_server/driver", "default"); + GLOBAL_DEF_NOVAL(PropertyInfo(Variant::STRING, "display/display_server/driver.windows", PROPERTY_HINT_ENUM_SUGGESTION, "default,windows,headless"), "default"); + GLOBAL_DEF_NOVAL(PropertyInfo(Variant::STRING, "display/display_server/driver.linuxbsd", PROPERTY_HINT_ENUM_SUGGESTION, "default,x11,wayland,headless"), "default"); + GLOBAL_DEF_NOVAL(PropertyInfo(Variant::STRING, "display/display_server/driver.android", PROPERTY_HINT_ENUM_SUGGESTION, "default,android,headless"), "default"); + GLOBAL_DEF_NOVAL(PropertyInfo(Variant::STRING, "display/display_server/driver.ios", PROPERTY_HINT_ENUM_SUGGESTION, "default,iOS,headless"), "default"); + GLOBAL_DEF_NOVAL(PropertyInfo(Variant::STRING, "display/display_server/driver.macos", PROPERTY_HINT_ENUM_SUGGESTION, "default,macos,headless"), "default"); GLOBAL_DEF_RST_NOVAL("audio/driver/driver", AudioDriverManager::get_driver(0)->get_name()); if (audio_driver.is_empty()) { // Specified in project.godot. @@ -2453,19 +2453,18 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph Thread::release_main_thread(); // If setup2() is called from another thread, that one will become main thread, so preventively release this one. set_current_thread_safe_for_nodes(false); - OS::get_singleton()->benchmark_end_measure("Startup", "Core"); - #if defined(STEAMAPI_ENABLED) if (editor || project_manager) { steam_tracker = memnew(SteamTracker); } #endif + OS::get_singleton()->benchmark_end_measure("Startup", "Main::Setup"); + if (p_second_phase) { return setup2(); } - OS::get_singleton()->benchmark_end_measure("Startup", "Setup"); return OK; error: @@ -2518,8 +2517,7 @@ error: memdelete(message_queue); } - OS::get_singleton()->benchmark_end_measure("Startup", "Core"); - OS::get_singleton()->benchmark_end_measure("Startup", "Setup"); + OS::get_singleton()->benchmark_end_measure("Startup", "Main::Setup"); #if defined(STEAMAPI_ENABLED) if (steam_tracker) { @@ -2552,7 +2550,9 @@ Error _parse_resource_dummy(void *p_data, VariantParser::Stream *p_stream, Ref<R return OK; } -Error Main::setup2() { +Error Main::setup2(bool p_show_boot_logo) { + OS::get_singleton()->benchmark_begin_measure("Startup", "Main::Setup2"); + Thread::make_main_thread(); // Make whatever thread call this the main thread. set_current_thread_safe_for_nodes(true); @@ -2592,6 +2592,7 @@ Error Main::setup2() { String screen_property; bool prefer_wayland_found = false; + bool prefer_wayland = false; if (editor) { screen_property = "interface/editor/editor_screen"; @@ -2624,16 +2625,17 @@ Error Main::setup2() { } if (!prefer_wayland_found && assign == "run/platforms/linuxbsd/prefer_wayland") { - if (value) { - display_driver = "wayland"; - } else { - display_driver = "default"; - } - + prefer_wayland = value; prefer_wayland_found = true; } } } + + if (prefer_wayland) { + display_driver = "wayland"; + } else { + display_driver = "default"; + } } } } @@ -2896,12 +2898,6 @@ Error Main::setup2() { MAIN_PRINT("Main: Setup Logo"); -#if !defined(TOOLS_ENABLED) && defined(WEB_ENABLED) - bool show_logo = false; -#else - bool show_logo = true; -#endif - if (init_windowed) { //do none.. } else if (init_maximized) { @@ -2913,74 +2909,16 @@ Error Main::setup2() { DisplayServer::get_singleton()->window_set_flag(DisplayServer::WINDOW_FLAG_ALWAYS_ON_TOP, true); } - MAIN_PRINT("Main: Load Boot Image"); - Color clear = GLOBAL_DEF_BASIC("rendering/environment/defaults/default_clear_color", Color(0.3, 0.3, 0.3)); RenderingServer::get_singleton()->set_default_clear_color(clear); - if (show_logo) { //boot logo! - const bool boot_logo_image = GLOBAL_DEF_BASIC("application/boot_splash/show_image", true); - const String boot_logo_path = String(GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "application/boot_splash/image", PROPERTY_HINT_FILE, "*.png"), String())).strip_edges(); - const bool boot_logo_scale = GLOBAL_DEF_BASIC("application/boot_splash/fullsize", true); - const bool boot_logo_filter = GLOBAL_DEF_BASIC("application/boot_splash/use_filter", true); - - Ref<Image> boot_logo; - - if (boot_logo_image) { - if (!boot_logo_path.is_empty()) { - 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->initialize_data(1, 1, false, Image::FORMAT_RGBA8); - boot_logo->set_pixel(0, 0, Color(0, 0, 0, 0)); - } - - Color boot_bg_color = GLOBAL_GET("application/boot_splash/bg_color"); - -#if defined(TOOLS_ENABLED) && !defined(NO_EDITOR_SPLASH) - boot_bg_color = - GLOBAL_DEF_BASIC("application/boot_splash/bg_color", - (editor || project_manager) ? boot_splash_editor_bg_color : boot_splash_bg_color); -#endif - if (boot_logo.is_valid()) { - RenderingServer::get_singleton()->set_boot_image(boot_logo, boot_bg_color, boot_logo_scale, - boot_logo_filter); - - } else { -#ifndef NO_DEFAULT_BOOT_LOGO - MAIN_PRINT("Main: Create bootsplash"); -#if defined(TOOLS_ENABLED) && !defined(NO_EDITOR_SPLASH) - Ref<Image> splash = (editor || project_manager) ? memnew(Image(boot_splash_editor_png)) : memnew(Image(boot_splash_png)); -#else - Ref<Image> splash = memnew(Image(boot_splash_png)); -#endif - - MAIN_PRINT("Main: ClearColor"); - RenderingServer::get_singleton()->set_default_clear_color(boot_bg_color); - MAIN_PRINT("Main: Image"); - RenderingServer::get_singleton()->set_boot_image(splash, boot_bg_color, false); -#endif - } - -#if defined(TOOLS_ENABLED) && defined(MACOS_ENABLED) - if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_ICON) && OS::get_singleton()->get_bundle_icon_path().is_empty()) { - Ref<Image> icon = memnew(Image(app_icon_png)); - DisplayServer::get_singleton()->set_icon(icon); - } -#endif + if (p_show_boot_logo) { + setup_boot_logo(); } MAIN_PRINT("Main: Clear Color"); DisplayServer::set_early_window_clear_color_override(false); - RenderingServer::get_singleton()->set_default_clear_color( - GLOBAL_GET("rendering/environment/defaults/default_clear_color")); GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "application/config/icon", PROPERTY_HINT_FILE, "*.png,*.webp,*.svg"), String()); GLOBAL_DEF(PropertyInfo(Variant::STRING, "application/config/macos_native_icon", PROPERTY_HINT_FILE, "*.icns"), String()); @@ -2990,7 +2928,8 @@ Error Main::setup2() { Input *id = Input::get_singleton(); if (id) { - agile_input_event_flushing = GLOBAL_DEF("input_devices/buffering/agile_event_flushing", false); + bool agile_input_event_flushing = GLOBAL_DEF("input_devices/buffering/agile_event_flushing", false); + id->set_agile_input_event_flushing(agile_input_event_flushing); if (bool(GLOBAL_DEF_BASIC("input_devices/pointing/emulate_touch_from_mouse", false)) && !(editor || project_manager)) { @@ -3211,11 +3150,78 @@ Error Main::setup2() { print_verbose("EDITOR API HASH: " + uitos(ClassDB::get_api_hash(ClassDB::API_EDITOR))); MAIN_PRINT("Main: Done"); - OS::get_singleton()->benchmark_end_measure("Startup", "Setup"); + OS::get_singleton()->benchmark_end_measure("Startup", "Main::Setup2"); return OK; } +void Main::setup_boot_logo() { + MAIN_PRINT("Main: Load Boot Image"); + +#if !defined(TOOLS_ENABLED) && defined(WEB_ENABLED) + bool show_logo = false; +#else + bool show_logo = true; +#endif + + if (show_logo) { //boot logo! + const bool boot_logo_image = GLOBAL_DEF_BASIC("application/boot_splash/show_image", true); + const String boot_logo_path = String(GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "application/boot_splash/image", PROPERTY_HINT_FILE, "*.png"), String())).strip_edges(); + const bool boot_logo_scale = GLOBAL_DEF_BASIC("application/boot_splash/fullsize", true); + const bool boot_logo_filter = GLOBAL_DEF_BASIC("application/boot_splash/use_filter", true); + + Ref<Image> boot_logo; + + if (boot_logo_image) { + if (!boot_logo_path.is_empty()) { + 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->initialize_data(1, 1, false, Image::FORMAT_RGBA8); + boot_logo->set_pixel(0, 0, Color(0, 0, 0, 0)); + } + + Color boot_bg_color = GLOBAL_GET("application/boot_splash/bg_color"); + +#if defined(TOOLS_ENABLED) && !defined(NO_EDITOR_SPLASH) + boot_bg_color = GLOBAL_DEF_BASIC("application/boot_splash/bg_color", (editor || project_manager) ? boot_splash_editor_bg_color : boot_splash_bg_color); +#endif + if (boot_logo.is_valid()) { + RenderingServer::get_singleton()->set_boot_image(boot_logo, boot_bg_color, boot_logo_scale, boot_logo_filter); + + } else { +#ifndef NO_DEFAULT_BOOT_LOGO + MAIN_PRINT("Main: Create bootsplash"); +#if defined(TOOLS_ENABLED) && !defined(NO_EDITOR_SPLASH) + Ref<Image> splash = (editor || project_manager) ? memnew(Image(boot_splash_editor_png)) : memnew(Image(boot_splash_png)); +#else + Ref<Image> splash = memnew(Image(boot_splash_png)); +#endif + + MAIN_PRINT("Main: ClearColor"); + RenderingServer::get_singleton()->set_default_clear_color(boot_bg_color); + MAIN_PRINT("Main: Image"); + RenderingServer::get_singleton()->set_boot_image(splash, boot_bg_color, false); +#endif + } + +#if defined(TOOLS_ENABLED) && defined(MACOS_ENABLED) + if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_ICON) && OS::get_singleton()->get_bundle_icon_path().is_empty()) { + Ref<Image> icon = memnew(Image(app_icon_png)); + DisplayServer::get_singleton()->set_icon(icon); + } +#endif + } + RenderingServer::get_singleton()->set_default_clear_color( + GLOBAL_GET("rendering/environment/defaults/default_clear_color")); +} + String Main::get_rendering_driver_name() { return rendering_driver; } @@ -3227,6 +3233,8 @@ static MainTimerSync main_timer_sync; // and should move on to `OS::run`, and EXIT_FAILURE otherwise for // an early exit with that error code. int Main::start() { + OS::get_singleton()->benchmark_begin_measure("Startup", "Main::Start"); + ERR_FAIL_COND_V(!_start_success, false); bool has_icon = false; @@ -3950,7 +3958,7 @@ int Main::start() { } } - OS::get_singleton()->benchmark_end_measure("Startup", "Total"); + OS::get_singleton()->benchmark_end_measure("Startup", "Main::Start"); OS::get_singleton()->benchmark_dump(); return EXIT_SUCCESS; @@ -3972,7 +3980,6 @@ uint32_t Main::hide_print_fps_attempts = 3; uint32_t Main::frame = 0; bool Main::force_redraw_requested = false; int Main::iterating = 0; -bool Main::agile_input_event_flushing = false; bool Main::is_iterating() { return iterating > 0; @@ -4033,11 +4040,12 @@ bool Main::iteration() { NavigationServer3D::get_singleton()->sync(); for (int iters = 0; iters < advance.physics_steps; ++iters) { - if (Input::get_singleton()->is_using_input_buffering() && agile_input_event_flushing) { + if (Input::get_singleton()->is_agile_input_event_flushing()) { Input::get_singleton()->flush_buffered_events(); } Engine::get_singleton()->_in_physics = true; + Engine::get_singleton()->_physics_frames++; uint64_t physics_begin = OS::get_singleton()->get_ticks_usec(); @@ -4085,12 +4093,11 @@ bool Main::iteration() { physics_process_ticks = MAX(physics_process_ticks, OS::get_singleton()->get_ticks_usec() - physics_begin); // keep the largest one for reference physics_process_max = MAX(OS::get_singleton()->get_ticks_usec() - physics_begin, physics_process_max); - Engine::get_singleton()->_physics_frames++; Engine::get_singleton()->_in_physics = false; } - if (Input::get_singleton()->is_using_input_buffering() && agile_input_event_flushing) { + if (Input::get_singleton()->is_agile_input_event_flushing()) { Input::get_singleton()->flush_buffered_events(); } @@ -4103,7 +4110,7 @@ bool Main::iteration() { RenderingServer::get_singleton()->sync(); //sync if still drawing from previous frames. - if (DisplayServer::get_singleton()->can_any_window_draw() && + if ((DisplayServer::get_singleton()->can_any_window_draw() || DisplayServer::get_singleton()->has_additional_outputs()) && RenderingServer::get_singleton()->is_render_loop_enabled()) { if ((!force_redraw_requested) && OS::get_singleton()->is_in_low_processor_usage_mode()) { if (RenderingServer::get_singleton()->has_changed()) { @@ -4162,16 +4169,17 @@ bool Main::iteration() { iterating--; - // Needed for OSs using input buffering regardless accumulation (like Android) - if (Input::get_singleton()->is_using_input_buffering() && !agile_input_event_flushing) { - Input::get_singleton()->flush_buffered_events(); - } - if (movie_writer) { movie_writer->add_frame(); } +#ifdef TOOLS_ENABLED + bool quit_after_timeout = false; +#endif if ((quit_after > 0) && (Engine::get_singleton()->_process_frames >= quit_after)) { +#ifdef TOOLS_ENABLED + quit_after_timeout = true; +#endif exit = true; } @@ -4204,6 +4212,12 @@ bool Main::iteration() { } #endif +#ifdef TOOLS_ENABLED + if (exit && quit_after_timeout && EditorNode::get_singleton()) { + EditorNode::get_singleton()->unload_editor_addons(); + } +#endif + return exit; } @@ -4218,7 +4232,7 @@ void Main::force_redraw() { * The order matters as some of those steps are linked with each other. */ void Main::cleanup(bool p_force) { - OS::get_singleton()->benchmark_begin_measure("Shutdown", "Total"); + OS::get_singleton()->benchmark_begin_measure("Shutdown", "Main::Cleanup"); if (!p_force) { ERR_FAIL_COND(!_start_success); } @@ -4241,6 +4255,7 @@ void Main::cleanup(bool p_force) { ResourceLoader::remove_custom_loaders(); ResourceSaver::remove_custom_savers(); + PropertyListHelper::clear_base_helpers(); // Flush before uninitializing the scene, but delete the MessageQueue as late as possible. message_queue->flush(); @@ -4376,7 +4391,7 @@ void Main::cleanup(bool p_force) { unregister_core_types(); - OS::get_singleton()->benchmark_end_measure("Shutdown", "Total"); + OS::get_singleton()->benchmark_end_measure("Shutdown", "Main::Cleanup"); OS::get_singleton()->benchmark_dump(); OS::get_singleton()->finalize_core(); |