summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorAndrii Doroshenko (Xrayez) <xrayez@gmail.com>2020-08-11 20:20:30 +0300
committerAndrii Doroshenko (Xrayez) <xrayez@gmail.com>2020-08-11 20:20:30 +0300
commit871b1d76d26ff35546fc40950aee439b6caf6366 (patch)
tree5e9387772743f228650da3e10e6f7e970233bdaa /main
parentf2149fe763a5678237b417fb9fefec5a5c74ae9d (diff)
Accept global classes for `MainLoop` type in project settings
`application/run/main_loop_type` setting can handle custom global classes (`class_name`). For instance: `MySceneTree`. The setting's default is changed from empty to `SceneTree` as to give some hint of what kind of input is accepted for the main loop type.
Diffstat (limited to 'main')
-rw-r--r--main/main.cpp22
1 files changed, 18 insertions, 4 deletions
diff --git a/main/main.cpp b/main/main.cpp
index 5f791159f9..65fd961f78 100644
--- a/main/main.cpp
+++ b/main/main.cpp
@@ -1730,7 +1730,6 @@ bool Main::start() {
}
}
- String main_loop_type;
#ifdef TOOLS_ENABLED
if (doc_tool != "") {
Engine::get_singleton()->set_editor_hint(
@@ -1825,6 +1824,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);
@@ -1855,9 +1855,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 == "") {