From a593fdff6332e6cc2a0cb0c6ef2fe6b59ae19fa0 Mon Sep 17 00:00:00 2001 From: Relintai Date: Wed, 27 Mar 2024 07:55:04 +0100 Subject: [PATCH] Fix VertexLights2DServer's changed notification setup. --- modules/vertex_lights_2d/register_types.cpp | 2 -- .../vertex_lights_2d_server.cpp | 21 ++++++++++++++----- .../vertex_lights_2d_server.h | 8 +++---- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/modules/vertex_lights_2d/register_types.cpp b/modules/vertex_lights_2d/register_types.cpp index 544c36bd1..846b2b8a2 100644 --- a/modules/vertex_lights_2d/register_types.cpp +++ b/modules/vertex_lights_2d/register_types.cpp @@ -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(); } } } diff --git a/modules/vertex_lights_2d/vertex_lights_2d_server.cpp b/modules/vertex_lights_2d/vertex_lights_2d_server.cpp index de325f06d..beac07f5d 100644 --- a/modules/vertex_lights_2d/vertex_lights_2d_server.cpp +++ b/modules/vertex_lights_2d/vertex_lights_2d_server.cpp @@ -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()); @@ -156,7 +155,7 @@ bool VertexLights2DServer::light_get_is_enabled(RID p_light) { void VertexLights2DServer::light_set_enabled(RID p_light, const bool p_enabled) { VertexLightData2D *light = light_owner.getornull(p_light); ERR_FAIL_COND(light == NULL); - + if (light->enabled == p_enabled) { return; } @@ -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() { @@ -377,7 +387,7 @@ void VertexLights2DServer::_bind_methods() { ClassDB::bind_method(D_METHOD("map_get_quadrant_size", "map"), &VertexLights2DServer::map_get_quadrant_size); ClassDB::bind_method(D_METHOD("map_set_quadrant_size", "map", "size"), &VertexLights2DServer::map_set_quadrant_size); - + ClassDB::bind_method(D_METHOD("map_get_base_color", "map"), &VertexLights2DServer::map_get_base_color); ClassDB::bind_method(D_METHOD("map_set_base_color", "map", "base_color"), &VertexLights2DServer::map_set_base_color); @@ -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); diff --git a/modules/vertex_lights_2d/vertex_lights_2d_server.h b/modules/vertex_lights_2d/vertex_lights_2d_server.h index 1cd1b33c9..70b2f01b4 100644 --- a/modules/vertex_lights_2d/vertex_lights_2d_server.h +++ b/modules/vertex_lights_2d/vertex_lights_2d_server.h @@ -113,9 +113,8 @@ public: // Rest 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();