Made the default visibility change event overrideable in VoxelChunkDefault.

This commit is contained in:
Relintai 2020-03-29 23:55:40 +02:00
parent 541abb954d
commit 4a3c9836ff
2 changed files with 22 additions and 22 deletions

View File

@ -608,12 +608,22 @@ void VoxelChunkDefault::draw_debug_voxel_lights() {
_debug_drawer->end(); _debug_drawer->end();
} }
void VoxelChunkDefault::set_visibility(bool visible) { void VoxelChunkDefault::visibility_changed(bool visible) {
if (get_mesh_instance_rid() != RID()) call("visibility_changed", visible);
VS::get_singleton()->instance_set_visible(get_mesh_instance_rid(), is_visible_in_tree()); }
if (get_prop_mesh_instance_rid() != RID()) void VoxelChunkDefault::_visibility_changed(bool visible) {
VS::get_singleton()->instance_set_visible(get_prop_mesh_instance_rid(), is_visible_in_tree()); 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() { void VoxelChunkDefault::free_chunk() {
@ -913,18 +923,6 @@ void VoxelChunkDefault::_build_phase(int phase) {
} }
*/ */
case BUILD_PHASE_FINALIZE: { 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(); update_transforms();
next_phase(); next_phase();
@ -1048,9 +1046,8 @@ void VoxelChunkDefault::_build(bool immediate) {
void VoxelChunkDefault::_notification(int p_what) { void VoxelChunkDefault::_notification(int p_what) {
switch (p_what) { switch (p_what) {
case NOTIFICATION_VISIBILITY_CHANGED: { case NOTIFICATION_VISIBILITY_CHANGED: {
if (is_inside_tree()) { if (is_inside_tree())
set_visibility(is_visible_in_tree()); visibility_changed(is_visible_in_tree());
}
} }
case NOTIFICATION_ENTER_TREE: { case NOTIFICATION_ENTER_TREE: {
set_notify_transform(true); 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("_create_meshers"), &VoxelChunkDefault::_create_meshers);
ClassDB::bind_method(D_METHOD("_build", "immediate"), &VoxelChunkDefault::_build); 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_DONE);
BIND_CONSTANT(BUILD_PHASE_SETUP); BIND_CONSTANT(BUILD_PHASE_SETUP);

View File

@ -204,7 +204,7 @@ public:
void draw_debug_voxels(int max, Color color = Color(1, 1, 1)); void draw_debug_voxels(int max, Color color = Color(1, 1, 1));
void draw_debug_voxel_lights(); void draw_debug_voxel_lights();
void set_visibility(bool visible); void visibility_changed(bool visible);
//free //free
void free_chunk(); void free_chunk();
@ -224,6 +224,7 @@ protected:
virtual void _clear_baked_lights(); virtual void _clear_baked_lights();
virtual void _create_meshers(); virtual void _create_meshers();
virtual void _build(bool immediate); virtual void _build(bool immediate);
virtual void _visibility_changed(bool visible);
void wait_and_finish_thread(); void wait_and_finish_thread();