More work on the logic, and api fixes.

This commit is contained in:
Relintai 2020-10-03 17:18:43 +02:00
parent 235943f7ca
commit eb1d55f05b
5 changed files with 50 additions and 30 deletions

View File

@ -833,16 +833,7 @@ void VoxelChunkDefault::free_chunk() {
free_rids();
}
void VoxelChunkDefault::build() {
if (get_is_generating()) {
_queued_generation = true;
return;
}
next_job();
}
void VoxelChunkDefault::finalize_build() {
void VoxelChunkDefault::_finalize_build() {
ERR_FAIL_COND(!_library.is_valid());
#if TOOLS_ENABLED
@ -858,7 +849,6 @@ void VoxelChunkDefault::finalize_build() {
VoxelChunkDefault::VoxelChunkDefault() {
_abort_build = false;
_queued_generation = false;
_enabled = true;
@ -978,7 +968,7 @@ void VoxelChunkDefault::_bind_methods() {
ClassDB::bind_method(D_METHOD("_world_light_added", "light"), &VoxelChunkDefault::_world_light_added);
ClassDB::bind_method(D_METHOD("_world_light_removed", "light"), &VoxelChunkDefault::_world_light_removed);
//ClassDB::bind_method(D_METHOD("get_job"), &VoxelChunkDefault::get_job);
ClassDB::bind_method(D_METHOD("_finalize_build"), &VoxelChunkDefault::_finalize_build);
BIND_ENUM_CONSTANT(DEFAULT_CHANNEL_TYPE);
BIND_ENUM_CONSTANT(DEFAULT_CHANNEL_ISOLEVEL);

View File

@ -174,8 +174,7 @@ public:
bool get_build_step_in_progress() const;
void set_build_step_in_progress(const bool value);
void build();
void finalize_build();
void _finalize_build();
VoxelChunkDefault();
~VoxelChunkDefault();
@ -200,8 +199,6 @@ protected:
int _build_flags;
bool _queued_generation;
bool _enabled;
bool _lights_dirty;

View File

@ -216,12 +216,12 @@ void VoxelChunk::set_voxel_world_bind(Node *world) {
_voxel_world = Object::cast_to<VoxelWorld>(world);
}
Ref<VoxelMesher> VoxelChunk::get_job(int index) const {
ERR_FAIL_INDEX_V(index, _jobs.size(), Ref<VoxelMesher>());
Ref<VoxelJob> VoxelChunk::get_job(int index) const {
ERR_FAIL_INDEX_V(index, _jobs.size(), Ref<VoxelJob>());
return _jobs.get(index);
}
void VoxelChunk::set_job(int index, const Ref<VoxelMesher> &job) {
void VoxelChunk::set_job(int index, const Ref<VoxelJob> &job) {
ERR_FAIL_INDEX(index, _jobs.size());
_jobs.set(index, job);
@ -231,7 +231,7 @@ void VoxelChunk::remove_job(const int index) {
_jobs.remove(index);
}
void VoxelChunk::add_job(const Ref<VoxelMesher> &job) {
void VoxelChunk::add_job(const Ref<VoxelJob> &job) {
_jobs.push_back(job);
}
int VoxelChunk::get_job_count() const {
@ -257,11 +257,12 @@ void VoxelChunk::next_job() {
next_job();
}
if (j->get_build_phase_type() == VoxelJob::BUILD_PHASE_TYPE_NORMAL) {
j->set_complete(false);
j->set_complete(false);
if (j->get_build_phase_type() == VoxelJob::BUILD_PHASE_TYPE_NORMAL) {
#if THREAD_POOL_PRESENT
ThreadPool::get_singleton()->add_job(j);
//ThreadPool::get_singleton()->add_job(j);
j->execute();
#else
j->execute();
#endif
@ -566,13 +567,23 @@ void VoxelChunk::create_meshers() {
call("_create_meshers");
}
void VoxelChunk::build(const bool immediate) {
void VoxelChunk::build() {
ERR_FAIL_COND(!INSTANCE_VALIDATE(get_voxel_world()));
ERR_FAIL_COND(!get_voxel_world()->is_inside_tree());
ERR_FAIL_COND(!is_in_tree());
ERR_FAIL_COND_MSG(!has_method("_build"), "VoxelChunk: _build(immediate : bool) is missing! Please implement it!");
call("_build", immediate);
call("_build");
}
void VoxelChunk::_build() {
if (get_is_generating()) {
_queued_generation = true;
return;
}
_is_generating = true;
next_job();
}
void VoxelChunk::clear() {
@ -581,6 +592,12 @@ void VoxelChunk::clear() {
call("_clear");
}
void VoxelChunk::finalize_build() {
if (has_method("_finalize_build")) {
call("_finalize_build");
}
}
void VoxelChunk::bake_lights() {
if (has_method("_bake_lights"))
call("_bake_lights");
@ -952,6 +969,8 @@ VoxelChunk::VoxelChunk() {
_margin_end = 0;
_current_job = 0;
_queued_generation = false;
}
VoxelChunk::~VoxelChunk() {
@ -1115,6 +1134,8 @@ void VoxelChunk::_bind_methods() {
BIND_VMETHOD(MethodInfo("_generation_process", PropertyInfo(Variant::REAL, "delta")));
BIND_VMETHOD(MethodInfo("_generation_physics_process", PropertyInfo(Variant::REAL, "delta")));
BIND_VMETHOD(MethodInfo("_finalize_build"));
ClassDB::bind_method(D_METHOD("enter_tree"), &VoxelChunk::enter_tree);
ClassDB::bind_method(D_METHOD("exit_tree"), &VoxelChunk::exit_tree);
ClassDB::bind_method(D_METHOD("process", "delta"), &VoxelChunk::process);
@ -1127,6 +1148,8 @@ void VoxelChunk::_bind_methods() {
ClassDB::bind_method(D_METHOD("generation_process", "delta"), &VoxelChunk::generation_process);
ClassDB::bind_method(D_METHOD("generation_physics_process", "delta"), &VoxelChunk::generation_physics_process);
ClassDB::bind_method(D_METHOD("finalize_build"), &VoxelChunk::finalize_build);
ClassDB::bind_method(D_METHOD("get_process"), &VoxelChunk::get_process);
ClassDB::bind_method(D_METHOD("set_process", "value"), &VoxelChunk::set_process);
@ -1317,6 +1340,10 @@ void VoxelChunk::_bind_methods() {
ClassDB::bind_method(D_METHOD("create_meshers"), &VoxelChunk::create_meshers);
BIND_VMETHOD(MethodInfo("_build"));
ClassDB::bind_method(D_METHOD("build"), &VoxelChunk::build);
ClassDB::bind_method(D_METHOD("_build"), &VoxelChunk::_build);
ClassDB::bind_method(D_METHOD("get_global_transform"), &VoxelChunk::get_global_transform);
ClassDB::bind_method(D_METHOD("to_local", "global"), &VoxelChunk::to_local);
ClassDB::bind_method(D_METHOD("to_global", "local"), &VoxelChunk::to_global);

View File

@ -141,10 +141,10 @@ public:
void set_voxel_world_bind(Node *world);
//Jobs
Ref<VoxelMesher> get_job(const int index) const;
void set_job(const int index, const Ref<VoxelMesher> &job);
Ref<VoxelJob> get_job(const int index) const;
void set_job(const int index, const Ref<VoxelJob> &job);
void remove_job(const int index);
void add_job(const Ref<VoxelMesher> &job);
void add_job(const Ref<VoxelJob> &job);
int get_job_count() const;
int get_current_job_index();
@ -185,8 +185,11 @@ public:
//Meshing
void create_meshers();
void build(const bool immediate = false);
void build();
void clear();
void finalize_build();
void _build();
//light Baking
void bake_lights();
@ -364,6 +367,7 @@ protected:
Transform _transform;
bool _abort_build;
bool _queued_generation;
};
#endif

View File

@ -420,6 +420,8 @@ Ref<VoxelChunk> VoxelWorld::_create_chunk(const int x, const int y, const int z,
chunk->set_size(_chunk_size_x, _chunk_size_y, _chunk_size_z, _data_margin_start, _data_margin_end);
//chunk->set_translation(Vector3(x * _chunk_size_x * _voxel_scale, y * _chunk_size_y * _voxel_scale, z * _chunk_size_z * _voxel_scale));
chunk->create_meshers();
add_chunk(chunk, x, y, z);
add_to_generation_queue(chunk);