Fix VertexLights2DServer's changed notification setup.

This commit is contained in:
Relintai 2024-03-27 07:55:04 +01:00
parent 59a4fcfc70
commit a593fdff63
3 changed files with 19 additions and 12 deletions

View File

@ -56,8 +56,6 @@ void unregister_vertex_lights_2d_types(ModuleRegistrationLevel p_level) {
if (p_level == MODULE_REGISTRATION_LEVEL_SINGLETON) {
if (vertex_lights_2d_server) {
memdelete(vertex_lights_2d_server);
} else if (p_level == MODULE_REGISTRATION_LEVEL_FINALIZE) {
vertex_lights_2d_server->finalize();
}
}
}

View File

@ -83,7 +83,6 @@ void VertexLights2DServer::map_set_base_color(RID p_map, const Color &p_base_col
_map_changed(map);
}
Array VertexLights2DServer::map_get_lights(RID p_map) const {
VertexLightMap2D *map = map_owner.getornull(p_map);
ERR_FAIL_COND_V(map == NULL, Array());
@ -336,12 +335,23 @@ void VertexLights2DServer::free(RID p_rid) {
}
void VertexLights2DServer::init() {
call_deferred("_register_update");
}
void VertexLights2DServer::register_update() {
if (SceneTree::get_singleton()) {
SceneTree::get_singleton()->add_idle_callback(VertexLights2DServer::_scene_tree_idle_callback);
if (!SceneTree::get_singleton()->is_connected("idle_frame", this, "flush_notifications")) {
SceneTree::get_singleton()->connect("idle_frame", this, "flush_notifications");
}
}
}
void VertexLights2DServer::finalize() {
void VertexLights2DServer::unregister_update() {
if (SceneTree::get_singleton()) {
if (SceneTree::get_singleton()->is_connected("idle_frame", this, "flush_notifications")) {
SceneTree::get_singleton()->disconnect("idle_frame", this, "flush_notifications");
}
}
}
void VertexLights2DServer::flush_notifications() {
@ -427,6 +437,7 @@ void VertexLights2DServer::_bind_methods() {
ClassDB::bind_method(D_METHOD("free", "rid"), &VertexLights2DServer::free);
ClassDB::bind_method(D_METHOD("_register_update"), &VertexLights2DServer::register_update);
ClassDB::bind_method(D_METHOD("flush_notifications"), &VertexLights2DServer::flush_notifications);
BIND_ENUM_CONSTANT(VERTEX_LIGHT_2D_MODE_ADD);

View File

@ -115,7 +115,6 @@ public:
void free(RID p_rid);
void init();
void finalize();
void flush_notifications();
_FORCE_INLINE_ static VertexLights2DServer *get_singleton() {
@ -126,9 +125,8 @@ public:
~VertexLights2DServer();
protected:
static void _scene_tree_idle_callback() {
VertexLights2DServer::get_singleton()->flush_notifications();
}
void register_update();
void unregister_update();
static void _bind_methods();