Merge pull request #52438 from tommyZZM/main-loop-type-class-3.x

This commit is contained in:
Rémi Verschelde 2021-09-17 16:20:41 +02:00 committed by GitHub
commit a72724023c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1590,7 +1590,6 @@ bool Main::start() {
} }
} }
String main_loop_type;
#ifdef TOOLS_ENABLED #ifdef TOOLS_ENABLED
if (doc_tool_path != "") { if (doc_tool_path != "") {
Engine::get_singleton()->set_editor_hint(true); // Needed to instance editor-only classes for their default values Engine::get_singleton()->set_editor_hint(true); // Needed to instance editor-only classes for their default values
@ -1661,6 +1660,7 @@ bool Main::start() {
if (editor) { if (editor) {
main_loop = memnew(SceneTree); main_loop = memnew(SceneTree);
}; };
String main_loop_type = GLOBAL_DEF("application/run/main_loop_type", "SceneTree");
if (test != "") { if (test != "") {
#ifdef TOOLS_ENABLED #ifdef TOOLS_ENABLED
@ -1699,8 +1699,23 @@ bool Main::start() {
return false; return false;
} }
} else { } else { // Not based on script path.
main_loop_type = GLOBAL_DEF("application/run/main_loop_type", ""); 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, "Script", true);
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);
}
OS::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 == "") { if (!main_loop && main_loop_type == "") {