1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-09 12:50:35 +00:00

Merge pull request #70771 from kleonc/main-loop-set-after-resolved

Ensure `MainLoop` and its custom script is set right after it's resolved
This commit is contained in:
Yuri Sizov
2023-07-12 17:15:59 +02:00
3 changed files with 4 additions and 16 deletions

View File

@@ -52,15 +52,7 @@ void MainLoop::_bind_methods() {
GDVIRTUAL_BIND(_finalize); GDVIRTUAL_BIND(_finalize);
} }
void MainLoop::set_initialize_script(const Ref<Script> &p_initialize_script) {
initialize_script = p_initialize_script;
}
void MainLoop::initialize() { void MainLoop::initialize() {
if (initialize_script.is_valid()) {
set_script(initialize_script);
}
GDVIRTUAL_CALL(_initialize); GDVIRTUAL_CALL(_initialize);
} }

View File

@@ -39,8 +39,6 @@
class MainLoop : public Object { class MainLoop : public Object {
GDCLASS(MainLoop, Object); GDCLASS(MainLoop, Object);
Ref<Script> initialize_script;
protected: protected:
static void _bind_methods(); static void _bind_methods();
@@ -69,8 +67,6 @@ public:
virtual bool process(double p_time); virtual bool process(double p_time);
virtual void finalize(); virtual void finalize();
void set_initialize_script(const Ref<Script> &p_initialize_script);
MainLoop() {} MainLoop() {}
virtual ~MainLoop() {} virtual ~MainLoop() {}
}; };

View File

@@ -2917,7 +2917,7 @@ bool Main::start() {
ERR_FAIL_V_MSG(false, vformat("Can't load the script \"%s\" as it doesn't inherit from SceneTree or MainLoop.", script)); ERR_FAIL_V_MSG(false, vformat("Can't load the script \"%s\" as it doesn't inherit from SceneTree or MainLoop.", script));
} }
script_loop->set_initialize_script(script_res); script_loop->set_script(script_res);
main_loop = script_loop; main_loop = script_loop;
} else { } else {
return false; return false;
@@ -2940,7 +2940,7 @@ bool Main::start() {
OS::get_singleton()->alert("Error: Invalid MainLoop script base type: " + script_base); 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)); ERR_FAIL_V_MSG(false, vformat("The global class %s does not inherit from SceneTree or MainLoop.", main_loop_type));
} }
script_loop->set_initialize_script(script_res); script_loop->set_script(script_res);
main_loop = script_loop; main_loop = script_loop;
} }
} }
@@ -2965,6 +2965,8 @@ bool Main::start() {
} }
} }
OS::get_singleton()->set_main_loop(main_loop);
SceneTree *sml = Object::cast_to<SceneTree>(main_loop); SceneTree *sml = Object::cast_to<SceneTree>(main_loop);
if (sml) { if (sml) {
#ifdef DEBUG_ENABLED #ifdef DEBUG_ENABLED
@@ -3284,8 +3286,6 @@ bool Main::start() {
DisplayServer::get_singleton()->set_icon(icon); DisplayServer::get_singleton()->set_icon(icon);
} }
OS::get_singleton()->set_main_loop(main_loop);
if (movie_writer) { if (movie_writer) {
movie_writer->begin(DisplayServer::get_singleton()->window_get_size(), fixed_fps, Engine::get_singleton()->get_write_movie_path()); movie_writer->begin(DisplayServer::get_singleton()->window_get_size(), fixed_fps, Engine::get_singleton()->get_write_movie_path());
} }