From 3add3daef4c4f90a435ffff68a5714c3921634f5 Mon Sep 17 00:00:00 2001 From: Relintai Date: Tue, 6 Oct 2020 19:24:58 +0200 Subject: [PATCH] VoxelPropJob now works. --- world/jobs/voxel_prop_job.cpp | 52 ++++++++++++++++++++++++------- world/jobs/voxel_prop_job.h | 5 +-- world/jobs/voxel_terrarin_job.cpp | 3 -- 3 files changed, 43 insertions(+), 17 deletions(-) diff --git a/world/jobs/voxel_prop_job.cpp b/world/jobs/voxel_prop_job.cpp index f578acd..415acaa 100644 --- a/world/jobs/voxel_prop_job.cpp +++ b/world/jobs/voxel_prop_job.cpp @@ -43,13 +43,6 @@ void VoxelPropJob::set_prop_mesher(const Ref &mesher) { _prop_mesher = mesher; } -void VoxelPropJob::phase_reset() { - if (get_prop_mesher().is_valid()) { - get_prop_mesher()->reset(); - get_prop_mesher()->set_library(_chunk->get_library()); - } -} - void VoxelPropJob::phase_physics_process() { Ref chunk = _chunk; @@ -320,24 +313,57 @@ void VoxelPropJob::phase_prop() { } } - //next_phase() #endif + set_complete(true); //So threadpool knows it's done next_job(); } -void VoxelPropJob::_execute() { +void VoxelPropJob::_physics_process(float delta) { + if (_phase == 0) + phase_physics_process(); +} + +void VoxelPropJob::_execute_phase() { ERR_FAIL_COND(!_chunk.is_valid()); Ref library = _chunk->get_library(); ERR_FAIL_COND(!library.is_valid()); - next_job(); + Ref chunk = _chunk; - //phase_prop(); + if (!chunk.is_valid() + //#ifdef MESH_DATA_RESOURCE_PRESENT + || chunk->get_mesh_data_resource_count() == 0 + //#endif + ) { + set_complete(true); + next_job(); + return; + } - //finish + if (_phase == 1) { + phase_prop(); + } else if (_phase > 1) { + set_complete(true); //So threadpool knows it's done + next_job(); + ERR_FAIL_MSG("VoxelPropJob: _phase is too high!"); + } +} + +void VoxelPropJob::_reset() { + VoxelJob::_reset(); + + _build_done = false; + _phase = 0; + + if (get_prop_mesher().is_valid()) { + get_prop_mesher()->reset(); + get_prop_mesher()->set_library(_chunk->get_library()); + } + + set_build_phase_type(BUILD_PHASE_TYPE_PHYSICS_PROCESS); } VoxelPropJob::VoxelPropJob() { @@ -350,4 +376,6 @@ void VoxelPropJob::_bind_methods() { ClassDB::bind_method(D_METHOD("get_prop_mesher"), &VoxelPropJob::get_prop_mesher); ClassDB::bind_method(D_METHOD("set_prop_mesher", "mesher"), &VoxelPropJob::set_prop_mesher); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "prop_mesher", PROPERTY_HINT_RESOURCE_TYPE, "VoxelMesher", 0), "set_prop_mesher", "get_prop_mesher"); + + ClassDB::bind_method(D_METHOD("_physics_process", "delta"), &VoxelPropJob::_physics_process); } diff --git a/world/jobs/voxel_prop_job.h b/world/jobs/voxel_prop_job.h index dde1449..9fc68eb 100644 --- a/world/jobs/voxel_prop_job.h +++ b/world/jobs/voxel_prop_job.h @@ -34,11 +34,12 @@ public: Ref get_prop_mesher() const; void set_prop_mesher(const Ref &mesher); - void phase_reset(); void phase_physics_process(); void phase_prop(); - void _execute(); + void _physics_process(float delta); + void _execute_phase(); + void _reset(); VoxelPropJob(); ~VoxelPropJob(); diff --git a/world/jobs/voxel_terrarin_job.cpp b/world/jobs/voxel_terrarin_job.cpp index 2013b05..57c343d 100644 --- a/world/jobs/voxel_terrarin_job.cpp +++ b/world/jobs/voxel_terrarin_job.cpp @@ -568,10 +568,7 @@ void VoxelTerrarinJob::phase_terrarin_mesh() { } void VoxelTerrarinJob::phase_finalize() { - //add vs meshes to chunk - set_complete(true); //So threadpool knows it's done - //set_build_phase_type(BUILD_PHASE_TYPE_PHYSICS_PROCESS); next_job(); }