From 4a3c9836ffcc687134eb1ea6201bd1bfc0c3442b Mon Sep 17 00:00:00 2001 From: Relintai Date: Sun, 29 Mar 2020 23:55:40 +0200 Subject: [PATCH] Made the default visibility change event overrideable in VoxelChunkDefault. --- world/voxel_chunk_default.cpp | 41 +++++++++++++++++------------------ world/voxel_chunk_default.h | 3 ++- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/world/voxel_chunk_default.cpp b/world/voxel_chunk_default.cpp index 10e6fd5..389c7fc 100644 --- a/world/voxel_chunk_default.cpp +++ b/world/voxel_chunk_default.cpp @@ -608,12 +608,22 @@ void VoxelChunkDefault::draw_debug_voxel_lights() { _debug_drawer->end(); } -void VoxelChunkDefault::set_visibility(bool visible) { - if (get_mesh_instance_rid() != RID()) - VS::get_singleton()->instance_set_visible(get_mesh_instance_rid(), is_visible_in_tree()); +void VoxelChunkDefault::visibility_changed(bool visible) { + call("visibility_changed", visible); +} - if (get_prop_mesh_instance_rid() != RID()) - VS::get_singleton()->instance_set_visible(get_prop_mesh_instance_rid(), is_visible_in_tree()); +void VoxelChunkDefault::_visibility_changed(bool visible) { + if (_mesh_instance_rid != RID()) + VS::get_singleton()->instance_set_visible(_mesh_instance_rid, visible); + + if (_prop_mesh_instance_rid != RID()) + VS::get_singleton()->instance_set_visible(_prop_mesh_instance_rid, visible); + + if (_liquid_mesh_instance_rid != RID()) + VS::get_singleton()->instance_set_visible(_liquid_mesh_instance_rid, visible); + + if (_clutter_mesh_instance_rid != RID()) + VS::get_singleton()->instance_set_visible(_clutter_mesh_instance_rid, visible); } void VoxelChunkDefault::free_chunk() { @@ -913,18 +923,6 @@ void VoxelChunkDefault::_build_phase(int phase) { } */ case BUILD_PHASE_FINALIZE: { - if (_mesh_instance_rid != RID()) - VS::get_singleton()->instance_set_visible(_mesh_instance_rid, is_visible()); - - if (_prop_mesh_instance_rid != RID()) - VS::get_singleton()->instance_set_visible(_prop_mesh_instance_rid, is_visible()); - - if (_liquid_mesh_instance_rid != RID()) - VS::get_singleton()->instance_set_visible(_liquid_mesh_instance_rid, is_visible()); - - if (_clutter_mesh_instance_rid != RID()) - VS::get_singleton()->instance_set_visible(_clutter_mesh_instance_rid, is_visible()); - update_transforms(); next_phase(); @@ -1048,9 +1046,8 @@ void VoxelChunkDefault::_build(bool immediate) { void VoxelChunkDefault::_notification(int p_what) { switch (p_what) { case NOTIFICATION_VISIBILITY_CHANGED: { - if (is_inside_tree()) { - set_visibility(is_visible_in_tree()); - } + if (is_inside_tree()) + visibility_changed(is_visible_in_tree()); } case NOTIFICATION_ENTER_TREE: { set_notify_transform(true); @@ -1261,7 +1258,9 @@ void VoxelChunkDefault::_bind_methods() { ClassDB::bind_method(D_METHOD("_create_meshers"), &VoxelChunkDefault::_create_meshers); ClassDB::bind_method(D_METHOD("_build", "immediate"), &VoxelChunkDefault::_build); - //ClassDB::bind_method(D_METHOD("set_visibility", "visible"), &VoxelChunkDefault::set_visibility); + BIND_VMETHOD(MethodInfo("_visibility_changed", PropertyInfo(Variant::BOOL, "visible"))); + ClassDB::bind_method(D_METHOD("visibility_changed", "visible"), &VoxelChunkDefault::visibility_changed); + ClassDB::bind_method(D_METHOD("_visibility_changed", "visible"), &VoxelChunkDefault::_visibility_changed); BIND_CONSTANT(BUILD_PHASE_DONE); BIND_CONSTANT(BUILD_PHASE_SETUP); diff --git a/world/voxel_chunk_default.h b/world/voxel_chunk_default.h index d6a757c..7c4cafa 100644 --- a/world/voxel_chunk_default.h +++ b/world/voxel_chunk_default.h @@ -204,7 +204,7 @@ public: void draw_debug_voxels(int max, Color color = Color(1, 1, 1)); void draw_debug_voxel_lights(); - void set_visibility(bool visible); + void visibility_changed(bool visible); //free void free_chunk(); @@ -224,6 +224,7 @@ protected: virtual void _clear_baked_lights(); virtual void _create_meshers(); virtual void _build(bool immediate); + virtual void _visibility_changed(bool visible); void wait_and_finish_thread();