From 9cca71355f29289e25133811cd772bee8b5efc9e Mon Sep 17 00:00:00 2001 From: Relintai Date: Thu, 1 Oct 2020 21:44:59 +0200 Subject: [PATCH] Added VoxelLightJob. --- SCsub | 1 + config.py | 1 + register_types.cpp | 2 + world/jobs/voxel_light_job.cpp | 87 ++++++++++++++++++++++++++++++++++ world/jobs/voxel_light_job.h | 45 ++++++++++++++++++ 5 files changed, 136 insertions(+) create mode 100644 world/jobs/voxel_light_job.cpp create mode 100644 world/jobs/voxel_light_job.h diff --git a/SCsub b/SCsub index 02fa590..898fa5a 100644 --- a/SCsub +++ b/SCsub @@ -74,6 +74,7 @@ sources = [ "world/jobs/voxel_job.cpp", "world/jobs/voxel_terrarin_job.cpp", + "world/jobs/voxel_light_job.cpp", ] if has_texture_packer: diff --git a/config.py b/config.py index 76b6075..f7298a2 100644 --- a/config.py +++ b/config.py @@ -58,6 +58,7 @@ def get_doc_classes(): "VoxelJob", "VoxelTerrarinJob", + "VoxelLightJob", ] diff --git a/register_types.cpp b/register_types.cpp index 72f57d7..2a6fd07 100644 --- a/register_types.cpp +++ b/register_types.cpp @@ -73,6 +73,7 @@ SOFTWARE. #include "nodes/voxelman_light.h" #include "world/jobs/voxel_job.h" +#include "world/jobs/voxel_light_job.h" #include "world/jobs/voxel_terrarin_job.h" void register_voxelman_types() { @@ -126,6 +127,7 @@ void register_voxelman_types() { ClassDB::register_class(); ClassDB::register_class(); + ClassDB::register_class(); #ifdef TOOLS_ENABLED EditorPlugins::add_by_type(); diff --git a/world/jobs/voxel_light_job.cpp b/world/jobs/voxel_light_job.cpp new file mode 100644 index 0000000..6d2f7b5 --- /dev/null +++ b/world/jobs/voxel_light_job.cpp @@ -0,0 +1,87 @@ +/* +Copyright (c) 2019-2020 Péter Magyar + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#include "voxel_light_job.h" + +#include "../../defines.h" + +#include "../../library/voxel_surface.h" +#include "../../library/voxelman_library.h" + +#include "../../meshers/voxel_mesher.h" +#include "../default/voxel_chunk_default.h" + +void VoxelLightJob::phase_light() { + Ref chunk = _chunk; + + bool gr = (chunk->get_build_flags() & VoxelChunkDefault::BUILD_FLAG_AUTO_GENERATE_RAO) != 0; + + if (!gr && (chunk->get_build_flags() & VoxelChunkDefault::BUILD_FLAG_USE_LIGHTING) == 0) { + return; + } + + bool bl = (chunk->get_build_flags() & VoxelChunkDefault::BUILD_FLAG_BAKE_LIGHTS) != 0; + + if (bl && should_do()) { + chunk->clear_baked_lights(); + + if (should_return()) + return; + } + + if (gr && should_do()) { + chunk->generate_random_ao(chunk->get_voxel_world()->get_current_seed()); + + if (should_return()) + return; + } + + if (bl && should_do()) { + chunk->bake_lights(); + + if (should_return()) + return; + } + + reset_stages(); +} + +void VoxelLightJob::_execute() { + ERR_FAIL_COND(!_chunk.is_valid()); + + Ref library = _chunk->get_library(); + + ERR_FAIL_COND(!library.is_valid()); + + phase_light(); + + //finish +} + +VoxelLightJob::VoxelLightJob() { +} + +VoxelLightJob::~VoxelLightJob() { +} + +void VoxelLightJob::_bind_methods() { +} diff --git a/world/jobs/voxel_light_job.h b/world/jobs/voxel_light_job.h new file mode 100644 index 0000000..cd8c92e --- /dev/null +++ b/world/jobs/voxel_light_job.h @@ -0,0 +1,45 @@ +/* +Copyright (c) 2019-2020 Péter Magyar + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#ifndef VOXEL_LIGHT_JOB_H +#define VOXEL_LIGHT_JOB_H + +#include "voxel_job.h" + +class VoxelMesher; + +class VoxelLightJob : public VoxelJob { + GDCLASS(VoxelLightJob, VoxelJob); + +public: + void phase_light(); + + void _execute(); + + VoxelLightJob(); + ~VoxelLightJob(); + +protected: + static void _bind_methods(); +}; + +#endif