diff --git a/voxel_block.cpp b/voxel_block.cpp new file mode 100644 index 00000000..1b742489 --- /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 00000000..3bec23ad --- /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 5b22a3e8..5bf2e61f 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 0c5ced03..5b0f7720 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)