diff options
Diffstat (limited to 'main')
-rw-r--r-- | main/SCsub | 8 | ||||
-rw-r--r-- | main/main.cpp | 123 | ||||
-rw-r--r-- | main/main.h | 6 | ||||
-rw-r--r-- | main/main_builders.py | 1 | ||||
-rw-r--r-- | main/performance.h | 2 | ||||
-rw-r--r-- | main/splash_editor.png | bin | 28059 -> 25801 bytes |
6 files changed, 125 insertions, 15 deletions
diff --git a/main/SCsub b/main/SCsub index ebadefd450..87d64e48f9 100644 --- a/main/SCsub +++ b/main/SCsub @@ -15,7 +15,9 @@ if env["tests"]: env_main.Depends("#main/splash.gen.h", "#main/splash.png") env_main.CommandNoCache( - "#main/splash.gen.h", "#main/splash.png", env.Run(main_builders.make_splash, "Building splash screen header."), + "#main/splash.gen.h", + "#main/splash.png", + env.Run(main_builders.make_splash, "Building splash screen header."), ) env_main.Depends("#main/splash_editor.gen.h", "#main/splash_editor.png") @@ -27,7 +29,9 @@ env_main.CommandNoCache( env_main.Depends("#main/app_icon.gen.h", "#main/app_icon.png") env_main.CommandNoCache( - "#main/app_icon.gen.h", "#main/app_icon.png", env.Run(main_builders.make_app_icon, "Building application icon."), + "#main/app_icon.gen.h", + "#main/app_icon.png", + env.Run(main_builders.make_app_icon, "Building application icon."), ) lib = env_main.add_library("main", env.main_sources) diff --git a/main/main.cpp b/main/main.cpp index e371bef25f..5ebd0138d3 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -369,16 +369,94 @@ void Main::print_help(const char *p_binary) { #endif } +#ifdef TESTS_ENABLED +// The order is the same as in `Main::setup()`, only core and some editor types +// are initialized here. This also combines `Main::setup2()` initialization. +Error Main::test_setup() { + OS::get_singleton()->initialize(); + + engine = memnew(Engine); + + ClassDB::init(); + + register_core_types(); + register_core_driver_types(); + + globals = memnew(ProjectSettings); + + GLOBAL_DEF("debug/settings/crash_handler/message", + String("Please include this when reporting the bug on https://github.com/godotengine/godot/issues")); + + // From `Main::setup2()`. + preregister_module_types(); + preregister_server_types(); + + register_core_singletons(); + + register_server_types(); + register_scene_types(); + +#ifdef TOOLS_ENABLED + ClassDB::set_current_api(ClassDB::API_EDITOR); + EditorNode::register_editor_types(); + + ClassDB::set_current_api(ClassDB::API_CORE); +#endif + register_platform_apis(); + + register_module_types(); + register_driver_types(); + + ClassDB::set_current_api(ClassDB::API_NONE); + + _start_success = true; + + return OK; +} +// The order is the same as in `Main::cleanup()`. +void Main::test_cleanup() { + ERR_FAIL_COND(!_start_success); + + EngineDebugger::deinitialize(); + + ResourceLoader::remove_custom_loaders(); + ResourceSaver::remove_custom_savers(); + +#ifdef TOOLS_ENABLED + EditorNode::unregister_editor_types(); +#endif + unregister_driver_types(); + unregister_module_types(); + unregister_platform_apis(); + unregister_scene_types(); + unregister_server_types(); + + OS::get_singleton()->finalize(); + + if (globals) { + memdelete(globals); + } + if (engine) { + memdelete(engine); + } + + unregister_core_driver_types(); + unregister_core_types(); + + OS::get_singleton()->finalize_core(); +} +#endif + int Main::test_entrypoint(int argc, char *argv[], bool &tests_need_run) { #ifdef TESTS_ENABLED for (int x = 0; x < argc; x++) { if ((strncmp(argv[x], "--test", 6) == 0) && (strlen(argv[x]) == 6)) { tests_need_run = true; - OS::get_singleton()->initialize(); - StringName::setup(); + // TODO: need to come up with different test contexts. + // Not every test requires high-level functionality like `ClassDB`. + test_setup(); int status = test_main(argc, argv); - StringName::cleanup(); - // TODO: fix OS::singleton cleanup + test_cleanup(); return status; } } @@ -1140,7 +1218,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph } if (bool(GLOBAL_GET("display/window/size/always_on_top"))) { - window_flags |= DisplayServer::WINDOW_FLAG_ALWAYS_ON_TOP; + window_flags |= DisplayServer::WINDOW_FLAG_ALWAYS_ON_TOP_BIT; } } @@ -1196,9 +1274,13 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph } if (rtm >= 0 && rtm < 3) { +#ifdef NO_THREADS + rtm = OS::RENDER_THREAD_UNSAFE; // No threads available on this platform. +#else if (editor) { rtm = OS::RENDER_THREAD_SAFE; } +#endif OS::get_singleton()->_render_thread_mode = OS::RenderThreadMode(rtm); } @@ -1287,6 +1369,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph "0,33200,1,or_greater")); // No negative numbers GLOBAL_DEF("display/window/ios/hide_home_indicator", true); + GLOBAL_DEF("input_devices/pointing/ios/touch_delay", 0.150); Engine::get_singleton()->set_frame_delay(frame_delay); @@ -1487,7 +1570,6 @@ Error Main::setup2(Thread::ID p_main_tid_override) { Color boot_bg_color = GLOBAL_DEF("application/boot_splash/bg_color", boot_splash_bg_color); if (boot_logo.is_valid()) { - OS::get_singleton()->_msec_splash = OS::get_singleton()->get_ticks_msec(); RenderingServer::get_singleton()->set_boot_image(boot_logo, boot_bg_color, boot_logo_scale, boot_logo_filter); @@ -1727,7 +1809,6 @@ bool Main::start() { } } - String main_loop_type; #ifdef TOOLS_ENABLED if (doc_tool != "") { Engine::get_singleton()->set_editor_hint( @@ -1822,6 +1903,7 @@ bool Main::start() { if (editor) { main_loop = memnew(SceneTree); }; + String main_loop_type = GLOBAL_DEF("application/run/main_loop_type", "SceneTree"); if (script != "") { Ref<Script> script_res = ResourceLoader::load(script); @@ -1852,9 +1934,23 @@ bool Main::start() { } else { return false; } - - } else { - main_loop_type = GLOBAL_DEF("application/run/main_loop_type", ""); + } else { // Not based on script path. + if (!editor && !ClassDB::class_exists(main_loop_type) && ScriptServer::is_global_class(main_loop_type)) { + String script_path = ScriptServer::get_global_class_path(main_loop_type); + Ref<Script> script_res = ResourceLoader::load(script_path); + StringName script_base = ScriptServer::get_global_class_native_base(main_loop_type); + Object *obj = ClassDB::instance(script_base); + MainLoop *script_loop = Object::cast_to<MainLoop>(obj); + if (!script_loop) { + if (obj) { + memdelete(obj); + } + DisplayServer::get_singleton()->alert("Error: Invalid MainLoop script base type: " + script_base); + ERR_FAIL_V_MSG(false, vformat("The global class %s does not inherit from SceneTree or MainLoop.", main_loop_type)); + } + script_loop->set_init_script(script_res); + main_loop = script_loop; + } } if (!main_loop && main_loop_type == "") { @@ -2200,6 +2296,13 @@ bool Main::start() { } if (project_manager || editor) { + 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") diff --git a/main/main.h b/main/main.h index 20c0bebefa..75a1c0d8cd 100644 --- a/main/main.h +++ b/main/main.h @@ -48,6 +48,10 @@ public: static int test_entrypoint(int argc, char *argv[], bool &tests_need_run); static Error setup(const char *execpath, int argc, char *argv[], bool p_second_phase = true); static Error setup2(Thread::ID p_main_tid_override = 0); +#ifdef TESTS_ENABLED + static Error test_setup(); + static void test_cleanup(); +#endif static bool start(); static bool iteration(); @@ -58,7 +62,7 @@ public: static void cleanup(); }; -// Test main override is for the testing behaviour +// Test main override is for the testing behaviour. #define TEST_MAIN_OVERRIDE \ bool run_test = false; \ int return_code = Main::test_entrypoint(argc, argv, run_test); \ diff --git a/main/main_builders.py b/main/main_builders.py index 2ea774e3b4..aa91201c3e 100644 --- a/main/main_builders.py +++ b/main/main_builders.py @@ -4,7 +4,6 @@ All such functions are invoked in a subprocess on Windows to prevent build flaki """ from platform_methods import subprocess_main -from collections import OrderedDict def make_splash(target, source, env): diff --git a/main/performance.h b/main/performance.h index 5f88a24c0f..f406433cf2 100644 --- a/main/performance.h +++ b/main/performance.h @@ -31,7 +31,7 @@ #ifndef PERFORMANCE_H #define PERFORMANCE_H -#include "core/object.h" +#include "core/class_db.h" #include "core/ordered_hash_map.h" #define PERF_WARN_OFFLINE_FUNCTION diff --git a/main/splash_editor.png b/main/splash_editor.png Binary files differindex 29931a71db..855646b346 100644 --- a/main/splash_editor.png +++ b/main/splash_editor.png |