Moved VoxelBlock to its own file

This commit is contained in:
Marc Gilleron 2017-08-20 15:48:55 +02:00
parent aa4d04d1a0
commit dc4f0c5cd1
4 changed files with 56 additions and 51 deletions

29
voxel_block.cpp Normal file
View File

@ -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<MeshInstance>();
}
// Helper
VoxelBlock *VoxelBlock::create(Vector3i bpos, Ref<VoxelBuffer> 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 = &map;
return block;
}
VoxelBlock::VoxelBlock()
: voxels(NULL) {
}

25
voxel_block.h Normal file
View File

@ -0,0 +1,25 @@
#ifndef VOXEL_BLOCK_H
#define VOXEL_BLOCK_H
#include "voxel_buffer.h"
#include <scene/3d/mesh_instance.h>
#include <scene/3d/physics_body.h>
// 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<VoxelBuffer> voxels; // SIZE*SIZE*SIZE voxels
Vector3i pos;
NodePath mesh_instance_path;
static VoxelBlock *create(Vector3i bpos, Ref<VoxelBuffer> buffer, unsigned int size);
MeshInstance *get_mesh_instance(const Node &root);
private:
VoxelBlock();
};
#endif // VOXEL_BLOCK_H

View File

@ -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<MeshInstance>();
}
// Helper
VoxelBlock *VoxelBlock::create(Vector3i bpos, Ref<VoxelBuffer> 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 = &map;
return block;
}
VoxelBlock::VoxelBlock()
: voxels(NULL) {
}
//----------------------------------------------------------------------------
// VoxelMap
//----------------------------------------------------------------------------
VoxelMap::VoxelMap()
: _last_accessed_block(NULL) {

View File

@ -2,26 +2,11 @@
#define VOXEL_MAP_H
#include "voxel_buffer.h"
#include "voxel_block.h"
#include <core/hash_map.h>
#include <scene/3d/mesh_instance.h>
#include <scene/3d/physics_body.h>
#include <scene/main/node.h>
// Fixed-size voxel container used in VoxelMap. Used internally.
class VoxelBlock {
public:
Ref<VoxelBuffer> voxels; // SIZE*SIZE*SIZE voxels
Vector3i pos;
NodePath mesh_instance_path;
static VoxelBlock *create(Vector3i bpos, Ref<VoxelBuffer> 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)