From dc4f0c5cd1d9d7c1b9006d1c4d33e16c3ec068e9 Mon Sep 17 00:00:00 2001 From: Marc Gilleron Date: Sun, 20 Aug 2017 15:48:55 +0200 Subject: [PATCH] Moved VoxelBlock to its own file --- voxel_block.cpp | 29 +++++++++++++++++++++++++++++ voxel_block.h | 25 +++++++++++++++++++++++++ voxel_map.cpp | 34 ---------------------------------- voxel_map.h | 19 ++----------------- 4 files changed, 56 insertions(+), 51 deletions(-) create mode 100644 voxel_block.cpp create mode 100644 voxel_block.h diff --git a/voxel_block.cpp b/voxel_block.cpp new file mode 100644 index 0000000..1b74248 --- /dev/null +++ b/voxel_block.cpp @@ -0,0 +1,29 @@ +#include "voxel_block.h" + +MeshInstance *VoxelBlock::get_mesh_instance(const Node &root) { + if (mesh_instance_path.is_empty()) + return NULL; + Node *n = root.get_node(mesh_instance_path); + if (n == NULL) + return NULL; + return n->cast_to(); +} + +// Helper +VoxelBlock *VoxelBlock::create(Vector3i bpos, Ref buffer, unsigned int size) { + const int bs = size; + ERR_FAIL_COND_V(buffer.is_null(), NULL); + ERR_FAIL_COND_V(buffer->get_size() != Vector3i(bs, bs, bs), NULL); + + VoxelBlock *block = memnew(VoxelBlock); + block->pos = bpos; + + block->voxels = buffer; + //block->map = ↦ + return block; +} + +VoxelBlock::VoxelBlock() + : voxels(NULL) { +} + diff --git a/voxel_block.h b/voxel_block.h new file mode 100644 index 0000000..3bec23a --- /dev/null +++ b/voxel_block.h @@ -0,0 +1,25 @@ +#ifndef VOXEL_BLOCK_H +#define VOXEL_BLOCK_H + +#include "voxel_buffer.h" + +#include +#include + +// Internal structure holding a reference to mesh visuals, physics and a block of voxel data. +// TODO Voxel data should be separated from this +class VoxelBlock { +public: + Ref voxels; // SIZE*SIZE*SIZE voxels + Vector3i pos; + NodePath mesh_instance_path; + + static VoxelBlock *create(Vector3i bpos, Ref buffer, unsigned int size); + + MeshInstance *get_mesh_instance(const Node &root); + +private: + VoxelBlock(); +}; + +#endif // VOXEL_BLOCK_H diff --git a/voxel_map.cpp b/voxel_map.cpp index 5b22a3e..5bf2e61 100644 --- a/voxel_map.cpp +++ b/voxel_map.cpp @@ -2,40 +2,6 @@ #include "core/os/os.h" #include "cube_tables.h" -//---------------------------------------------------------------------------- -// VoxelBlock -//---------------------------------------------------------------------------- - -MeshInstance *VoxelBlock::get_mesh_instance(const Node &root) { - if (mesh_instance_path.is_empty()) - return NULL; - Node *n = root.get_node(mesh_instance_path); - if (n == NULL) - return NULL; - return n->cast_to(); -} - -// Helper -VoxelBlock *VoxelBlock::create(Vector3i bpos, Ref buffer, unsigned int size) { - const int bs = size; - ERR_FAIL_COND_V(buffer.is_null(), NULL); - ERR_FAIL_COND_V(buffer->get_size() != Vector3i(bs, bs, bs), NULL); - - VoxelBlock *block = memnew(VoxelBlock); - block->pos = bpos; - - block->voxels = buffer; - //block->map = ↦ - return block; -} - -VoxelBlock::VoxelBlock() - : voxels(NULL) { -} - -//---------------------------------------------------------------------------- -// VoxelMap -//---------------------------------------------------------------------------- VoxelMap::VoxelMap() : _last_accessed_block(NULL) { diff --git a/voxel_map.h b/voxel_map.h index 0c5ced0..5b0f772 100644 --- a/voxel_map.h +++ b/voxel_map.h @@ -2,26 +2,11 @@ #define VOXEL_MAP_H #include "voxel_buffer.h" +#include "voxel_block.h" + #include -#include -#include #include -// Fixed-size voxel container used in VoxelMap. Used internally. -class VoxelBlock { -public: - Ref voxels; // SIZE*SIZE*SIZE voxels - Vector3i pos; - NodePath mesh_instance_path; - - static VoxelBlock *create(Vector3i bpos, Ref buffer, unsigned int size); - - MeshInstance *get_mesh_instance(const Node &root); - -private: - VoxelBlock(); -}; - // Infinite voxel storage by means of octants like Gridmap class VoxelMap : public Reference { GDCLASS(VoxelMap, Reference)