Added generation specific process and physics process to VoxelChunk and VoxelJob.

This commit is contained in:
Relintai 2020-10-02 16:45:08 +02:00
parent 43bb7dfa66
commit 46132202b0
5 changed files with 65 additions and 1 deletions

View File

@ -129,6 +129,15 @@ void VoxelJob::_execute_phase() {
next_job();
}
void VoxelJob::process(const float delta) {
if (has_method("_process"))
call("_process", delta);
}
void VoxelJob::physics_process(const float delta) {
if (has_method("_physics_process"))
call("_physics_process", delta);
}
//Data Management functions
void VoxelJob::generate_ao() {
ERR_FAIL_COND(!_chunk.is_valid());
@ -251,6 +260,9 @@ VoxelJob::~VoxelJob() {
}
void VoxelJob::_bind_methods() {
BIND_VMETHOD(MethodInfo("_process", PropertyInfo(Variant::REAL, "delta")));
BIND_VMETHOD(MethodInfo("_physics_process", PropertyInfo(Variant::REAL, "delta")));
ClassDB::bind_method(D_METHOD("get_build_phase_type"), &VoxelJob::get_build_phase_type);
ClassDB::bind_method(D_METHOD("set_build_phase_type", "value"), &VoxelJob::set_build_phase_type);
ADD_PROPERTY(PropertyInfo(Variant::INT, "build_phase_type", PROPERTY_HINT_ENUM, BINDING_STRING_ACTIVE_BUILD_PHASE_TYPE), "set_build_phase_type", "get_build_phase_type");

View File

@ -71,6 +71,9 @@ public:
void execute_phase();
virtual void _execute_phase();
void process(const float delta);
void physics_process(const float delta);
void generate_ao();
void generate_random_ao(int seed, int octaves, int period, float persistence, float scale_factor);

View File

@ -1012,6 +1012,34 @@ void VoxelChunk::world_light_removed(const Ref<VoxelLight> &light) {
if (has_method("_world_light_removed"))
call("_world_light_removed", light);
}
void VoxelChunk::generation_process(const float delta) {
call("_generation_process", delta);
}
void VoxelChunk::generation_physics_process(const float delta) {
call("_generation_physics_process", delta);
}
void VoxelChunk::_generation_process(const float delta) {
ERR_FAIL_INDEX(_current_job, _jobs.size());
Ref<VoxelJob> job = _jobs[_current_job];
ERR_FAIL_COND(!job.is_valid());
if (job->get_build_phase_type() == VoxelJob::BUILD_PHASE_TYPE_PROCESS) {
job->process(delta);
}
}
void VoxelChunk::_generation_physics_process(const float delta) {
ERR_FAIL_INDEX(_current_job, _jobs.size());
Ref<VoxelJob> job = _jobs[_current_job];
ERR_FAIL_COND(!job.is_valid());
if (job->get_build_phase_type() == VoxelJob::BUILD_PHASE_TYPE_PHYSICS_PROCESS) {
job->physics_process(delta);
}
}
Transform VoxelChunk::get_transform() const {
return _transform;
@ -1067,6 +1095,8 @@ VoxelChunk::VoxelChunk() {
_margin_start = 0;
_margin_end = 0;
_current_job = 0;
}
VoxelChunk::~VoxelChunk() {
@ -1178,6 +1208,9 @@ void VoxelChunk::_bind_methods() {
BIND_VMETHOD(MethodInfo("_world_light_added", PropertyInfo(Variant::OBJECT, "light", PROPERTY_HINT_RESOURCE_TYPE, "VoxelLight")));
BIND_VMETHOD(MethodInfo("_world_light_removed", PropertyInfo(Variant::OBJECT, "light", PROPERTY_HINT_RESOURCE_TYPE, "VoxelLight")));
BIND_VMETHOD(MethodInfo("_generation_process", PropertyInfo(Variant::REAL, "delta")));
BIND_VMETHOD(MethodInfo("_generation_physics_process", PropertyInfo(Variant::REAL, "delta")));
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);
@ -1187,6 +1220,9 @@ void VoxelChunk::_bind_methods() {
ClassDB::bind_method(D_METHOD("world_light_added", "light"), &VoxelChunk::world_light_added);
ClassDB::bind_method(D_METHOD("world_light_removed", "light"), &VoxelChunk::world_light_removed);
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("get_process"), &VoxelChunk::get_process);
ClassDB::bind_method(D_METHOD("set_process", "value"), &VoxelChunk::set_process);

View File

@ -274,6 +274,10 @@ public:
void visibility_changed(const bool visible);
void world_light_added(const Ref<VoxelLight> &light);
void world_light_removed(const Ref<VoxelLight> &light);
void generation_process(const float delta);
void generation_physics_process(const float delta);
void _generation_process(const float delta);
void _generation_physics_process(const float delta);
Transform get_transform() const;
void set_transform(const Transform &transform);
@ -355,6 +359,7 @@ protected:
float _voxel_scale;
int _current_job;
Vector<Ref<VoxelJob> > _jobs;
Ref<VoxelmanLibrary> _library;

View File

@ -891,7 +891,11 @@ void VoxelWorld::_notification(int p_what) {
ERR_CONTINUE(!chunk.is_valid());
if (chunk->get_process()) {
chunk->process(get_physics_process_delta_time());
chunk->process(get_process_delta_time());
}
if (chunk->get_is_generating()) {
chunk->generation_process(get_process_delta_time());
}
}
@ -941,6 +945,10 @@ void VoxelWorld::_notification(int p_what) {
if (chunk->get_process()) {
chunk->physics_process(get_physics_process_delta_time());
}
if (chunk->get_is_generating()) {
chunk->generation_physics_process(get_physics_process_delta_time());
}
}
} break;