From 469927cc3bf0a1a3cfd1369b74862c415c1ba4c2 Mon Sep 17 00:00:00 2001 From: Relintai Date: Tue, 4 Aug 2020 14:53:10 +0200 Subject: [PATCH] Now BUILD_PHASE_COLLIDER, and BUILD_PHASE_LIGHTS can both distribute their work onto multiple frames. --- world/default/voxel_chunk_default.cpp | 53 +++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/world/default/voxel_chunk_default.cpp b/world/default/voxel_chunk_default.cpp index f70e912..e002916 100644 --- a/world/default/voxel_chunk_default.cpp +++ b/world/default/voxel_chunk_default.cpp @@ -1234,7 +1234,18 @@ void VoxelChunkDefault::_build_phase(int phase) { return; } - for (int i = 0; i < _meshers.size(); ++i) { + int starti = 0; + + if (_job->has_meta("bpc_aa")) { + starti = _job->get_meta("bpc_aa"); + } + + for (int i = starti; i < _meshers.size(); ++i) { + if (_job->should_return()) { + _job->set_meta("bpc_aa", i); + return; + } + Ref mesher = _meshers.get(i); ERR_CONTINUE(!mesher.is_valid()); @@ -1254,7 +1265,19 @@ void VoxelChunkDefault::_build_phase(int phase) { */ if (Engine::get_singleton()->is_editor_hint()) { + + starti = 0; + + if (_job->has_meta("bpc_laa")) { + starti = _job->get_meta("bpc_laa"); + } + for (int i = 0; i < _liquid_meshers.size(); ++i) { + if (_job->should_return()) { + _job->set_meta("bpc_laa", i); + return; + } + Ref mesher = _liquid_meshers.get(i); ERR_CONTINUE(!mesher.is_valid()); @@ -1274,6 +1297,14 @@ void VoxelChunkDefault::_build_phase(int phase) { */ } + if (_job->has_meta("bpc_aa")) { + _job->remove_meta("bpc_aa"); + } + + if (_job->has_meta("bpc_laa")) { + _job->remove_meta("bpc_laa"); + } + if (temp_arr_collider.size() == 0 && temp_arr_collider_liquid.size() == 0 #ifdef MESH_DATA_RESOURCE_PRESENT && get_mesh_data_resource_count() == 0 @@ -1296,15 +1327,29 @@ void VoxelChunkDefault::_build_phase(int phase) { bool bl = (_build_flags & BUILD_FLAG_BAKE_LIGHTS) != 0; - if (bl) + if (bl && _job->should_do()) { clear_baked_lights(); - if (gr) + if (_job->should_return()) + return; + } + + if (gr && _job->should_do()) { generate_random_ao(_voxel_world->get_current_seed()); - if (bl) + if (_job->should_return()) + return; + } + + if (bl && _job->should_do()) { bake_lights(); + if (_job->should_return()) + return; + } + + _job->reset_stages(); + next_phase(); return;