From 07b7e083dd7bfe292ff024ef49e2eaedb03c42e9 Mon Sep 17 00:00:00 2001 From: Marc Gilleron Date: Mon, 28 Aug 2017 15:42:54 +0200 Subject: [PATCH] VoxelProvider now receives an offset in voxels instead of blocks --- voxel_provider.cpp | 16 ++++++++-------- voxel_provider.h | 8 ++++---- voxel_provider_test.cpp | 13 ++++++------- voxel_provider_test.h | 6 +++--- voxel_terrain.cpp | 3 +-- 5 files changed, 22 insertions(+), 24 deletions(-) diff --git a/voxel_provider.cpp b/voxel_provider.cpp index 9ede5e6..5db8333 100644 --- a/voxel_provider.cpp +++ b/voxel_provider.cpp @@ -1,38 +1,38 @@ #include "voxel_provider.h" #include "voxel_map.h" -void VoxelProvider::emerge_block(Ref out_buffer, Vector3i block_pos) { +void VoxelProvider::emerge_block(Ref out_buffer, Vector3i origin_in_voxels) { ERR_FAIL_COND(out_buffer.is_null()); ScriptInstance *script = get_script_instance(); if (script) { // Call script to generate buffer Variant arg1 = out_buffer; - Variant arg2 = block_pos.to_vec3(); + Variant arg2 = origin_in_voxels.to_vec3(); const Variant *args[2] = { &arg1, &arg2 }; //Variant::CallError err; // wut script->call_multilevel("emerge_block", args, 2); } } -void VoxelProvider::immerge_block(Ref buffer, Vector3i block_pos) { +void VoxelProvider::immerge_block(Ref buffer, Vector3i origin_in_voxels) { ERR_FAIL_COND(buffer.is_null()); ScriptInstance *script = get_script_instance(); if (script) { // Call script to save buffer Variant arg1 = buffer; - Variant arg2 = block_pos.to_vec3(); + Variant arg2 = origin_in_voxels.to_vec3(); const Variant *args[2] = { &arg1, &arg2 }; //Variant::CallError err; // wut script->call_multilevel("immerge_block", args, 2); } } -void VoxelProvider::_emerge_block(Ref out_buffer, Vector3 block_pos) { - emerge_block(out_buffer, Vector3i(block_pos)); +void VoxelProvider::_emerge_block(Ref out_buffer, Vector3 origin_in_voxels) { + emerge_block(out_buffer, Vector3i(origin_in_voxels)); } -void VoxelProvider::_immerge_block(Ref buffer, Vector3 block_pos) { - immerge_block(buffer, Vector3i(block_pos)); +void VoxelProvider::_immerge_block(Ref buffer, Vector3 origin_in_voxels) { + immerge_block(buffer, Vector3i(origin_in_voxels)); } void VoxelProvider::_bind_methods() { diff --git a/voxel_provider.h b/voxel_provider.h index afa23d4..58a7aae 100644 --- a/voxel_provider.h +++ b/voxel_provider.h @@ -7,14 +7,14 @@ class VoxelProvider : public Resource { GDCLASS(VoxelProvider, Resource) public: - virtual void emerge_block(Ref out_buffer, Vector3i block_pos); - virtual void immerge_block(Ref buffer, Vector3i block_pos); + virtual void emerge_block(Ref out_buffer, Vector3i origin_in_voxels); + virtual void immerge_block(Ref buffer, Vector3i origin_in_voxels); protected: static void _bind_methods(); - void _emerge_block(Ref out_buffer, Vector3 block_pos); - void _immerge_block(Ref buffer, Vector3 block_pos); + void _emerge_block(Ref out_buffer, Vector3 origin_in_voxels); + void _immerge_block(Ref buffer, Vector3 origin_in_voxels); }; #endif // VOXEL_PROVIDER_H diff --git a/voxel_provider_test.cpp b/voxel_provider_test.cpp index bd87cac..3f258e0 100644 --- a/voxel_provider_test.cpp +++ b/voxel_provider_test.cpp @@ -30,26 +30,25 @@ void VoxelProviderTest::set_pattern_offset(Vector3i offset) { _pattern_offset = offset; } -void VoxelProviderTest::emerge_block(Ref out_buffer, Vector3i block_pos) { +void VoxelProviderTest::emerge_block(Ref out_buffer, Vector3i origin) { ERR_FAIL_COND(out_buffer.is_null()); switch (_mode) { case MODE_FLAT: - generate_block_flat(**out_buffer, block_pos); + generate_block_flat(**out_buffer, origin); break; case MODE_WAVES: - generate_block_waves(**out_buffer, block_pos); + generate_block_waves(**out_buffer, origin); break; } } -void VoxelProviderTest::generate_block_flat(VoxelBuffer &out_buffer, Vector3i block_pos) { +void VoxelProviderTest::generate_block_flat(VoxelBuffer &out_buffer, Vector3i origin) { // TODO Don't expect a block pos, but a voxel pos! Vector3i size = out_buffer.get_size(); - Vector3i origin = size * block_pos; int rh = _pattern_offset.y - origin.y; if (rh > size.y) @@ -64,11 +63,11 @@ void VoxelProviderTest::generate_block_flat(VoxelBuffer &out_buffer, Vector3i bl } } -void VoxelProviderTest::generate_block_waves(VoxelBuffer &out_buffer, Vector3i block_pos) { +void VoxelProviderTest::generate_block_waves(VoxelBuffer &out_buffer, Vector3i origin) { // TODO Don't expect a block pos, but a voxel pos! Vector3i size = out_buffer.get_size(); - Vector3i origin = size * block_pos + _pattern_offset; + //origin += _pattern_offset; float amplitude = static_cast(_pattern_size.y); float period_x = 1.f / static_cast(_pattern_size.x); diff --git a/voxel_provider_test.h b/voxel_provider_test.h index 9a2487d..9a48e76 100644 --- a/voxel_provider_test.h +++ b/voxel_provider_test.h @@ -14,7 +14,7 @@ public: VoxelProviderTest(); - virtual void emerge_block(Ref out_buffer, Vector3i block_pos); + virtual void emerge_block(Ref out_buffer, Vector3i origin); void set_mode(Mode mode); Mode get_mode() const { return _mode; } @@ -29,8 +29,8 @@ public: void set_pattern_offset(Vector3i offset); protected: - void generate_block_flat(VoxelBuffer &out_buffer, Vector3i block_pos); - void generate_block_waves(VoxelBuffer &out_buffer, Vector3i block_pos); + void generate_block_flat(VoxelBuffer &out_buffer, Vector3i origin); + void generate_block_waves(VoxelBuffer &out_buffer, Vector3i origin); static void _bind_methods(); diff --git a/voxel_terrain.cpp b/voxel_terrain.cpp index 6f4eab7..3c878a5 100644 --- a/voxel_terrain.cpp +++ b/voxel_terrain.cpp @@ -458,7 +458,6 @@ void VoxelTerrain::update_blocks() { //printf("Remaining: %i\n", _block_update_queue.size()); // TODO Move this to a thread - // TODO Have VoxelTerrainGenerator in C++ // Get request Vector3i block_pos = _block_update_queue[_block_update_queue.size() - 1]; @@ -479,7 +478,7 @@ void VoxelTerrain::update_blocks() { VOXEL_PROFILE_BEGIN("block_generation") // Query voxel provider - _provider->emerge_block(buffer_ref, block_pos); + _provider->emerge_block(buffer_ref, _map->block_to_voxel(block_pos)); // Check script return // TODO Shouldn't halt execution though, as it can bring the map in an invalid state!