From 9103db635f7e3065ad7cedbddf7c24624d2e18f5 Mon Sep 17 00:00:00 2001 From: Relintai Date: Mon, 18 Nov 2019 21:53:33 +0100 Subject: [PATCH] More work on compile. --- data/voxel_light.cpp | 11 +- meshers/cubic_mesher/voxel_cube_points.cpp | 215 ++++++++++----------- meshers/voxel_mesher.cpp | 24 +-- utility_old/marching_cubes_voxel_query.cpp | 149 -------------- utility_old/marching_cubes_voxel_query.h | 75 ------- world/voxel_chunk.cpp | 121 +++++------- world/voxel_chunk.h | 13 +- world/voxel_structure.cpp | 98 +++++----- world/voxel_structure.h | 41 ++-- world/voxel_world.h | 33 +++- 10 files changed, 273 insertions(+), 507 deletions(-) delete mode 100644 utility_old/marching_cubes_voxel_query.cpp delete mode 100644 utility_old/marching_cubes_voxel_query.h diff --git a/data/voxel_light.cpp b/data/voxel_light.cpp index 836f770..90fe52c 100644 --- a/data/voxel_light.cpp +++ b/data/voxel_light.cpp @@ -1,12 +1,12 @@ #include "voxel_light.h" -int VoxelLight::get_world_position_x() const { +_FORCE_INLINE_ int VoxelLight::get_world_position_x() const { return _world_position_x; } -int VoxelLight::get_world_position_y() const { +_FORCE_INLINE_ int VoxelLight::get_world_position_y() const { return _world_position_y; } -int VoxelLight::get_world_position_z() const { +_FORCE_INLINE_ int VoxelLight::get_world_position_z() const { return _world_position_z; } Vector3 VoxelLight::get_world_position() { @@ -19,7 +19,7 @@ void VoxelLight::set_world_position(const int x, const int y, const int z) { _world_position_z = z; } -Color VoxelLight::get_color() const { +_FORCE_INLINE_ Color VoxelLight::get_color() const { return _color; } @@ -28,9 +28,8 @@ void VoxelLight::set_color(Color color) { } -float VoxelLight::get_size() const { +_FORCE_INLINE_ float VoxelLight::get_size() const { return _size; - } void VoxelLight::set_size(const float size) { _size = size; diff --git a/meshers/cubic_mesher/voxel_cube_points.cpp b/meshers/cubic_mesher/voxel_cube_points.cpp index 2db3162..7aaf784 100644 --- a/meshers/cubic_mesher/voxel_cube_points.cpp +++ b/meshers/cubic_mesher/voxel_cube_points.cpp @@ -168,7 +168,7 @@ void VoxelCubePoints::recalculate_point(int point) { _points[point] = dynamic_offset; } -void VoxelCubePoints::refresh_neighbours(const VoxelChunk *buffer) { +void VoxelCubePoints::refresh_neighbours(const VoxelChunk *chunk) { int neighbours = 0; int x = _x; @@ -176,25 +176,25 @@ void VoxelCubePoints::refresh_neighbours(const VoxelChunk *buffer) { int z = _z; //000 - if (buffer->get_voxel(x - 1, y, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x - 1, y, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_LEFT; - if (buffer->get_voxel(x, y - 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x, y - 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM; - if (buffer->get_voxel(x, y, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x, y, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_FRONT; /* - if (buffer->get_voxel(x - 1, y, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x - 1, y, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_LEFT_FRONT; - if (buffer->get_voxel(x - 1, y - 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x - 1, y - 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_LEFT; - if (buffer->get_voxel(x, y - 1, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x, y - 1, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_FRONT; - if (buffer->get_voxel(x - 1, y - 1, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x - 1, y - 1, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_LEFT_FRONT;*/ _point_neighbours[P000] = neighbours; @@ -205,25 +205,25 @@ void VoxelCubePoints::refresh_neighbours(const VoxelChunk *buffer) { z = _z; //100 - if (buffer->get_voxel(x + 1, y, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x + 1, y, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_RIGHT; - if (buffer->get_voxel(x, y - 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x, y - 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM; - if (buffer->get_voxel(x, y, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x, y, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_FRONT; /* - if (buffer->get_voxel(x + 1, y, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x + 1, y, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_RIGHT_FRONT; - if (buffer->get_voxel(x + 1, y - 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x + 1, y - 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_RIGHT; - if (buffer->get_voxel(x, y - 1, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x, y - 1, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_FRONT; - if (buffer->get_voxel(x + 1, y - 1, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x + 1, y - 1, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_RIGHT_FRONT;*/ _point_neighbours[P100] = neighbours; @@ -234,25 +234,25 @@ void VoxelCubePoints::refresh_neighbours(const VoxelChunk *buffer) { z = _z; //010 - if (buffer->get_voxel(x - 1, y, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x - 1, y, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_LEFT; - if (buffer->get_voxel(x, y + 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x, y + 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_TOP; - if (buffer->get_voxel(x, y, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x, y, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_FRONT; /* - if (buffer->get_voxel(x - 1, y, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x - 1, y, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_LEFT_FRONT; - if (buffer->get_voxel(x - 1, y + 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x - 1, y + 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_LEFT; - if (buffer->get_voxel(x, y + 1, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x, y + 1, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_FRONT; - if (buffer->get_voxel(x - 1, y + 1, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x - 1, y + 1, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_LEFT_FRONT;*/ _point_neighbours[P010] = neighbours; @@ -263,25 +263,25 @@ void VoxelCubePoints::refresh_neighbours(const VoxelChunk *buffer) { z = _z; //110 - if (buffer->get_voxel(x + 1, y, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x + 1, y, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_RIGHT; - if (buffer->get_voxel(x, y + 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x, y + 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_TOP; - if (buffer->get_voxel(x, y, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x, y, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_FRONT; /* - if (buffer->get_voxel(x + 1, y, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x + 1, y, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_RIGHT_FRONT; - if (buffer->get_voxel(x + 1, y + 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x + 1, y + 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_RIGHT; - if (buffer->get_voxel(x, y + 1, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x, y + 1, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_FRONT; - if (buffer->get_voxel(x + 1, y + 1, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x + 1, y + 1, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_RIGHT_FRONT;*/ _point_neighbours[P110] = neighbours; @@ -292,25 +292,25 @@ void VoxelCubePoints::refresh_neighbours(const VoxelChunk *buffer) { z = _z + 1; //001 - if (buffer->get_voxel(x - 1, y, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x - 1, y, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_LEFT; - if (buffer->get_voxel(x, y - 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x, y - 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM; - if (buffer->get_voxel(x, y, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x, y, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_BACK; /* - if (buffer->get_voxel(x - 1, y, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x - 1, y, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_LEFT_BACK; - if (buffer->get_voxel(x - 1, y - 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x - 1, y - 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_LEFT; - if (buffer->get_voxel(x, y - 1, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x, y - 1, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_BACK; - if (buffer->get_voxel(x - 1, y - 1, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x - 1, y - 1, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_LEFT_BACK;*/ _point_neighbours[P001] = neighbours; @@ -322,25 +322,25 @@ void VoxelCubePoints::refresh_neighbours(const VoxelChunk *buffer) { z = _z + 1; //101 - if (buffer->get_voxel(x + 1, y, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x + 1, y, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_RIGHT; - if (buffer->get_voxel(x, y - 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x, y - 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM; - if (buffer->get_voxel(x, y, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x, y, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_BACK; /* - if (buffer->get_voxel(x + 1, y, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x + 1, y, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_RIGHT_BACK; - if (buffer->get_voxel(x + 1, y - 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x + 1, y - 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_RIGHT; - if (buffer->get_voxel(x, y - 1, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x, y - 1, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_BACK; - if (buffer->get_voxel(x + 1, y - 1, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x + 1, y - 1, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_RIGHT_BACK;*/ _point_neighbours[P101] = neighbours; @@ -351,25 +351,25 @@ void VoxelCubePoints::refresh_neighbours(const VoxelChunk *buffer) { z = _z + 1; //011 - if (buffer->get_voxel(x - 1, y, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x - 1, y, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_LEFT; - if (buffer->get_voxel(x, y + 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x, y + 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_TOP; - if (buffer->get_voxel(x, y, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x, y, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_BACK; /* - if (buffer->get_voxel(x - 1, y, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x - 1, y, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_LEFT_BACK; - if (buffer->get_voxel(x - 1, y + 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x - 1, y + 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_LEFT; - if (buffer->get_voxel(x, y + 1, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x, y + 1, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_BACK; - if (buffer->get_voxel(x - 1, y + 1, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x - 1, y + 1, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_LEFT_BACK;*/ _point_neighbours[P011] = neighbours; @@ -381,33 +381,33 @@ void VoxelCubePoints::refresh_neighbours(const VoxelChunk *buffer) { z = _z + 1; //111 - if (buffer->get_voxel(x + 1, y, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x + 1, y, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_RIGHT; - if (buffer->get_voxel(x, y + 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x, y + 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_TOP; - if (buffer->get_voxel(x, y, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x, y, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_BACK; /* - if (buffer->get_voxel(x + 1, y, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x + 1, y, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_RIGHT_BACK; - if (buffer->get_voxel(x + 1, y + 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x + 1, y + 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_RIGHT; - if (buffer->get_voxel(x, y + 1, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x, y + 1, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_BACK; - if (buffer->get_voxel(x + 1, y + 1, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) + if (chunk->get_voxel(x + 1, y + 1, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0) neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_RIGHT_BACK;*/ _point_neighbours[P111] = neighbours; } -void VoxelCubePoints::setup(const VoxelChunk *buffer, int x, int y, int z, int size) { +void VoxelCubePoints::setup(const VoxelChunk *chunk, int x, int y, int z, int size) { ERR_FAIL_COND(size <= 0); - ERR_FAIL_COND(!buffer->validate_pos(x + size, y + size, z + size) || !buffer->validate_pos(x, y, z)); + ERR_FAIL_COND(!chunk->validate_channel_position(x + size, y + size, z + size) || !chunk->validate_channel_position(x, y, z)); reset(); @@ -416,46 +416,46 @@ void VoxelCubePoints::setup(const VoxelChunk *buffer, int x, int y, int z, int s _z = z; _size = size; - _point_types[P000] = buffer->get_voxel(x, y, z, VoxelChunk::DEFAULT_CHANNEL_TYPE); - _point_types[P100] = buffer->get_voxel(x + size, y, z, VoxelChunk::DEFAULT_CHANNEL_TYPE); - _point_types[P010] = buffer->get_voxel(x, y + size, z, VoxelChunk::DEFAULT_CHANNEL_TYPE); - _point_types[P001] = buffer->get_voxel(x, y, z + size, VoxelChunk::DEFAULT_CHANNEL_TYPE); - _point_types[P110] = buffer->get_voxel(x + size, y + size, z, VoxelChunk::DEFAULT_CHANNEL_TYPE); - _point_types[P011] = buffer->get_voxel(x, y + size, z + size, VoxelChunk::DEFAULT_CHANNEL_TYPE); - _point_types[P101] = buffer->get_voxel(x + size, y, z + size, VoxelChunk::DEFAULT_CHANNEL_TYPE); - _point_types[P111] = buffer->get_voxel(x + size, y + size, z + size, VoxelChunk::DEFAULT_CHANNEL_TYPE); + _point_types[P000] = chunk->get_voxel(x, y, z, VoxelChunk::DEFAULT_CHANNEL_TYPE); + _point_types[P100] = chunk->get_voxel(x + size, y, z, VoxelChunk::DEFAULT_CHANNEL_TYPE); + _point_types[P010] = chunk->get_voxel(x, y + size, z, VoxelChunk::DEFAULT_CHANNEL_TYPE); + _point_types[P001] = chunk->get_voxel(x, y, z + size, VoxelChunk::DEFAULT_CHANNEL_TYPE); + _point_types[P110] = chunk->get_voxel(x + size, y + size, z, VoxelChunk::DEFAULT_CHANNEL_TYPE); + _point_types[P011] = chunk->get_voxel(x, y + size, z + size, VoxelChunk::DEFAULT_CHANNEL_TYPE); + _point_types[P101] = chunk->get_voxel(x + size, y, z + size, VoxelChunk::DEFAULT_CHANNEL_TYPE); + _point_types[P111] = chunk->get_voxel(x + size, y + size, z + size, VoxelChunk::DEFAULT_CHANNEL_TYPE); if (!has_points()) return; - _point_fills[P000] = buffer->get_voxel(x, y, z, VoxelChunk::DEFAULT_CHANNEL_ISOLEVEL); - _point_fills[P100] = buffer->get_voxel(x + size, y, z, VoxelChunk::DEFAULT_CHANNEL_ISOLEVEL); - _point_fills[P010] = buffer->get_voxel(x, y + size, z, VoxelChunk::DEFAULT_CHANNEL_ISOLEVEL); - _point_fills[P001] = buffer->get_voxel(x, y, z + size, VoxelChunk::DEFAULT_CHANNEL_ISOLEVEL); - _point_fills[P110] = buffer->get_voxel(x + size, y + size, z, VoxelChunk::DEFAULT_CHANNEL_ISOLEVEL); - _point_fills[P011] = buffer->get_voxel(x, y + size, z + size, VoxelChunk::DEFAULT_CHANNEL_ISOLEVEL); - _point_fills[P101] = buffer->get_voxel(x + size, y, z + size, VoxelChunk::DEFAULT_CHANNEL_ISOLEVEL); - _point_fills[P111] = buffer->get_voxel(x + size, y + size, z + size, VoxelChunk::DEFAULT_CHANNEL_ISOLEVEL); + _point_fills[P000] = chunk->get_voxel(x, y, z, VoxelChunk::DEFAULT_CHANNEL_ISOLEVEL); + _point_fills[P100] = chunk->get_voxel(x + size, y, z, VoxelChunk::DEFAULT_CHANNEL_ISOLEVEL); + _point_fills[P010] = chunk->get_voxel(x, y + size, z, VoxelChunk::DEFAULT_CHANNEL_ISOLEVEL); + _point_fills[P001] = chunk->get_voxel(x, y, z + size, VoxelChunk::DEFAULT_CHANNEL_ISOLEVEL); + _point_fills[P110] = chunk->get_voxel(x + size, y + size, z, VoxelChunk::DEFAULT_CHANNEL_ISOLEVEL); + _point_fills[P011] = chunk->get_voxel(x, y + size, z + size, VoxelChunk::DEFAULT_CHANNEL_ISOLEVEL); + _point_fills[P101] = chunk->get_voxel(x + size, y, z + size, VoxelChunk::DEFAULT_CHANNEL_ISOLEVEL); + _point_fills[P111] = chunk->get_voxel(x + size, y + size, z + size, VoxelChunk::DEFAULT_CHANNEL_ISOLEVEL); - _point_aos[P000] = buffer->get_voxel(x, y, z, VoxelChunk::DEFAULT_CHANNEL_AO); - _point_aos[P100] = buffer->get_voxel(x + size, y, z, VoxelChunk::DEFAULT_CHANNEL_AO); - _point_aos[P010] = buffer->get_voxel(x, y + size, z, VoxelChunk::DEFAULT_CHANNEL_AO); - _point_aos[P001] = buffer->get_voxel(x, y, z + size, VoxelChunk::DEFAULT_CHANNEL_AO); - _point_aos[P110] = buffer->get_voxel(x + size, y + size, z, VoxelChunk::DEFAULT_CHANNEL_AO); - _point_aos[P011] = buffer->get_voxel(x, y + size, z + size, VoxelChunk::DEFAULT_CHANNEL_AO); - _point_aos[P101] = buffer->get_voxel(x + size, y, z + size, VoxelChunk::DEFAULT_CHANNEL_AO); - _point_aos[P111] = buffer->get_voxel(x + size, y + size, z + size, VoxelChunk::DEFAULT_CHANNEL_AO); + _point_aos[P000] = chunk->get_voxel(x, y, z, VoxelChunk::DEFAULT_CHANNEL_AO); + _point_aos[P100] = chunk->get_voxel(x + size, y, z, VoxelChunk::DEFAULT_CHANNEL_AO); + _point_aos[P010] = chunk->get_voxel(x, y + size, z, VoxelChunk::DEFAULT_CHANNEL_AO); + _point_aos[P001] = chunk->get_voxel(x, y, z + size, VoxelChunk::DEFAULT_CHANNEL_AO); + _point_aos[P110] = chunk->get_voxel(x + size, y + size, z, VoxelChunk::DEFAULT_CHANNEL_AO); + _point_aos[P011] = chunk->get_voxel(x, y + size, z + size, VoxelChunk::DEFAULT_CHANNEL_AO); + _point_aos[P101] = chunk->get_voxel(x + size, y, z + size, VoxelChunk::DEFAULT_CHANNEL_AO); + _point_aos[P111] = chunk->get_voxel(x + size, y + size, z + size, VoxelChunk::DEFAULT_CHANNEL_AO); - _point_colors[P000] = Color(buffer->get_voxel(x, y, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_R) / 255.0, buffer->get_voxel(x, y, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0, buffer->get_voxel(x, y, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0); - _point_colors[P100] = Color(buffer->get_voxel(x + size, y, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_R) / 255.0, buffer->get_voxel(x + size, y, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0, buffer->get_voxel(x + size, y, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0); - _point_colors[P010] = Color(buffer->get_voxel(x, y + size, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_R) / 255.0, buffer->get_voxel(x, y + size, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0, buffer->get_voxel(x, y + size, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0); - _point_colors[P001] = Color(buffer->get_voxel(x, y, z + size, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_R) / 255.0, buffer->get_voxel(x, y, z + size, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0, buffer->get_voxel(x, y, z + size, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0); - _point_colors[P110] = Color(buffer->get_voxel(x + size, y + size, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_R) / 255.0, buffer->get_voxel(x + size, y + size, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0, buffer->get_voxel(x + size, y + size, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0); - _point_colors[P011] = Color(buffer->get_voxel(x, y + size, z + size, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_R) / 255.0, buffer->get_voxel(x, y + size, z + size, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0, buffer->get_voxel(x, y + size, z + size, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0); - _point_colors[P101] = Color(buffer->get_voxel(x + size, y, z + size, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_R) / 255.0, buffer->get_voxel(x + size, y, z + size, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0, buffer->get_voxel(x + size, y, z + size, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0); - _point_colors[P111] = Color(buffer->get_voxel(x + size, y + size, z + size, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_R) / 255.0, buffer->get_voxel(x + size, y + size, z + size, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0, buffer->get_voxel(x + size, y + size, z + size, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0); + _point_colors[P000] = Color(chunk->get_voxel(x, y, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_R) / 255.0, chunk->get_voxel(x, y, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0, chunk->get_voxel(x, y, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0); + _point_colors[P100] = Color(chunk->get_voxel(x + size, y, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_R) / 255.0, chunk->get_voxel(x + size, y, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0, chunk->get_voxel(x + size, y, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0); + _point_colors[P010] = Color(chunk->get_voxel(x, y + size, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_R) / 255.0, chunk->get_voxel(x, y + size, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0, chunk->get_voxel(x, y + size, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0); + _point_colors[P001] = Color(chunk->get_voxel(x, y, z + size, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_R) / 255.0, chunk->get_voxel(x, y, z + size, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0, chunk->get_voxel(x, y, z + size, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0); + _point_colors[P110] = Color(chunk->get_voxel(x + size, y + size, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_R) / 255.0, chunk->get_voxel(x + size, y + size, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0, chunk->get_voxel(x + size, y + size, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0); + _point_colors[P011] = Color(chunk->get_voxel(x, y + size, z + size, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_R) / 255.0, chunk->get_voxel(x, y + size, z + size, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0, chunk->get_voxel(x, y + size, z + size, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0); + _point_colors[P101] = Color(chunk->get_voxel(x + size, y, z + size, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_R) / 255.0, chunk->get_voxel(x + size, y, z + size, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0, chunk->get_voxel(x + size, y, z + size, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0); + _point_colors[P111] = Color(chunk->get_voxel(x + size, y + size, z + size, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_R) / 255.0, chunk->get_voxel(x + size, y + size, z + size, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0, chunk->get_voxel(x + size, y + size, z + size, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0); - refresh_neighbours(buffer); + refresh_neighbours(chunk); refresh_points(); } @@ -508,16 +508,6 @@ bool VoxelCubePoints::is_face_visible(int face) { return false; } - -bool VoxelCubePoints::is_sub_voxel_point_vec(Vector3 point) { - for (int i = 0; i < POINT_COUNT; i += 1) { - if (get_point(i) == (point)) { - return true; - } - } - return false; -} - bool VoxelCubePoints::is_sub_voxel_point(int x, int y, int z) { for (int i = 0; i < POINT_COUNT; i += 1) { if (get_point(i) == Vector3(x, y, z)) { @@ -531,21 +521,12 @@ void VoxelCubePoints::set_point(int point, int x, int y, int z) { _points[point] = Vector3(x, y, z); } -int VoxelCubePoints::get_point_id_vec(Vector3 point) { - for (int i = 0; i < POINT_COUNT; ++i) { - if (get_point(i) == point) { - return i; - } - } - return 0; -} - int VoxelCubePoints::get_point_id(int x, int y, int z) { - for (int i = 0; i < POINT_COUNT; ++i) { - if (get_point(i) == Vector3i(x, y, z)) { - return i; - } - } + //for (int i = 0; i < POINT_COUNT; ++i) { + // if (get_point(i) == Vector3i(x, y, z)) { + // return i; + // } + //} return 0; } @@ -776,7 +757,7 @@ void VoxelCubePoints::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "size"), "set_size", "get_size"); ClassDB::bind_method(D_METHOD("refresh_points"), &VoxelCubePoints::refresh_points); - ClassDB::bind_method(D_METHOD("setup", "buffer", "x", "y", "z", "size"), &VoxelCubePoints::setup, DEFVAL(1)); + ClassDB::bind_method(D_METHOD("setup", "chunk", "x", "y", "z", "size"), &VoxelCubePoints::setup, DEFVAL(1)); ClassDB::bind_method(D_METHOD("get_point_index", "face", "index"), &VoxelCubePoints::get_point_index); ClassDB::bind_method(D_METHOD("get_point_uv_direction", "face", "index"), &VoxelCubePoints::get_point_uv_direction); diff --git a/meshers/voxel_mesher.cpp b/meshers/voxel_mesher.cpp index 696e827..1c04178 100644 --- a/meshers/voxel_mesher.cpp +++ b/meshers/voxel_mesher.cpp @@ -301,14 +301,14 @@ void VoxelMesher::_bake_colors(VoxelChunk *chunk) { unsigned int y = (unsigned int)(vert.y / _voxel_scale); unsigned int z = (unsigned int)(vert.z / _voxel_scale); - if (chunk->validate_pos(x, y, z)) { + if (chunk->validate_channel_position(x, y, z)) { Color light = Color( - chunk->get_voxel(x, y, z, VoxelChunk::CHANNEL_LIGHT_COLOR_R) / 255.0, - chunk->get_voxel(x, y, z, VoxelChunk::CHANNEL_LIGHT_COLOR_G) / 255.0, - chunk->get_voxel(x, y, z, VoxelChunk::CHANNEL_LIGHT_COLOR_B) / 255.0); + chunk->get_voxel(x, y, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_R) / 255.0, + chunk->get_voxel(x, y, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0, + chunk->get_voxel(x, y, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0); - float ao = (chunk->get_voxel(x, y, z, VoxelChunk::CHANNEL_AO) / 255.0) * _ao_strength; - float rao = chunk->get_voxel(x, y, z, VoxelChunk::CHANNEL_RANDOM_AO) / 255.0; + float ao = (chunk->get_voxel(x, y, z, VoxelChunk::DEFAULT_CHANNEL_AO) / 255.0) * _ao_strength; + float rao = chunk->get_voxel(x, y, z, VoxelChunk::DEFAULT_CHANNEL_RANDOM_AO) / 255.0; ao += rao; light.r += _base_light_value; @@ -367,14 +367,14 @@ void VoxelMesher::_bake_liquid_colors(VoxelChunk *chunk) { unsigned int y = (unsigned int)(vert.y / _voxel_scale); unsigned int z = (unsigned int)(vert.z / _voxel_scale); - if (chunk->validate_pos(x, y, z)) { + if (chunk->validate_channel_position(x, y, z)) { Color light = Color( - chunk->get_voxel(x, y, z, VoxelChunk::CHANNEL_LIGHT_COLOR_R) / 255.0, - chunk->get_voxel(x, y, z, VoxelChunk::CHANNEL_LIGHT_COLOR_G) / 255.0, - chunk->get_voxel(x, y, z, VoxelChunk::CHANNEL_LIGHT_COLOR_B) / 255.0); + chunk->get_voxel(x, y, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_R) / 255.0, + chunk->get_voxel(x, y, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0, + chunk->get_voxel(x, y, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0); - float ao = (chunk->get_voxel(x, y, z, VoxelChunk::CHANNEL_AO) / 255.0) * _ao_strength; - float rao = chunk->get_voxel(x, y, z, VoxelChunk::CHANNEL_RANDOM_AO) / 255.0; + float ao = (chunk->get_voxel(x, y, z, VoxelChunk::DEFAULT_CHANNEL_AO) / 255.0) * _ao_strength; + float rao = chunk->get_voxel(x, y, z, VoxelChunk::DEFAULT_CHANNEL_RANDOM_AO) / 255.0; ao += rao; light.r += _base_light_value; diff --git a/utility_old/marching_cubes_voxel_query.cpp b/utility_old/marching_cubes_voxel_query.cpp deleted file mode 100644 index 92865cd..0000000 --- a/utility_old/marching_cubes_voxel_query.cpp +++ /dev/null @@ -1,149 +0,0 @@ -#include "marching_cubes_voxel_query.h" - -const String MarchingCubesVoxelQuery::BINDING_STRING_VOXEL_ENTRY_INDICES = "Index_000, Index_100, Index_010, Index_110, Index_001, Index_101, Index_011, Index_111"; -const String MarchingCubesVoxelQuery::BINDING_STRING_VOXEL_ENTRY_MASK = "Index_000, Index_100, Index_010, Index_110, Index_001, Index_101, Index_011, Index_111"; - -Ref MarchingCubesVoxelQuery::get_entry(int index) { - return _voxels[index]; -} -void MarchingCubesVoxelQuery::set_entry(int index, Ref voxel) { - _voxels[index] = voxel; -} - -int MarchingCubesVoxelQuery::get_size() { - return _size; -} -void MarchingCubesVoxelQuery::set_size(int size) { - _size = size; -} - -Vector3i MarchingCubesVoxelQuery::get_position() { - return _position; -} -void MarchingCubesVoxelQuery::set_position(Vector3i position) { - _position = position; -} - -Vector3 MarchingCubesVoxelQuery::get_position_bind() { - return _position.to_vec3(); -} -void MarchingCubesVoxelQuery::set_position_bind(Vector3 position) { - _position = position; -} - -int MarchingCubesVoxelQuery::get_case_code() { - return _case_code; -} - -void MarchingCubesVoxelQuery::update_case_code() { - int entry_mask = 0; - - if (_voxels[VOXEL_ENTRY_INDEX_000].is_valid()) { - entry_mask = entry_mask | VOXEL_ENTRY_MASK_000; - } - - if (_voxels[VOXEL_ENTRY_INDEX_100].is_valid()) { - entry_mask = entry_mask | VOXEL_ENTRY_MASK_100; - } - - if (_voxels[VOXEL_ENTRY_INDEX_010].is_valid()) { - entry_mask = entry_mask | VOXEL_ENTRY_MASK_010; - } - - if (_voxels[VOXEL_ENTRY_INDEX_110].is_valid()) { - entry_mask = entry_mask | VOXEL_ENTRY_MASK_110; - } - - if (_voxels[VOXEL_ENTRY_INDEX_001].is_valid()) { - entry_mask = entry_mask | VOXEL_ENTRY_MASK_001; - } - - if (_voxels[VOXEL_ENTRY_INDEX_101].is_valid()) { - entry_mask = entry_mask | VOXEL_ENTRY_MASK_101; - } - - if (_voxels[VOXEL_ENTRY_INDEX_011].is_valid()) { - entry_mask = entry_mask | VOXEL_ENTRY_MASK_011; - } - - if (_voxels[VOXEL_ENTRY_INDEX_111].is_valid()) { - entry_mask = entry_mask | VOXEL_ENTRY_MASK_111; - } - - _case_code = entry_mask; -} - -bool MarchingCubesVoxelQuery::is_triangulation_trivial() { - int corner = 0; - - if (_voxels[VOXEL_ENTRY_INDEX_111].is_valid()) { - corner = 0xFF; - } - - if ((_case_code ^ corner) != 0) { - // Cell has a nontrivial triangulation. - return false; - } - - return true; -} - -void MarchingCubesVoxelQuery::set_entries(Ref voxel000, Ref voxel100, Ref voxel010, Ref voxel110, Ref voxel001, - Ref voxel101, Ref voxel011, Ref voxel111) { - _voxels[VOXEL_ENTRY_INDEX_000] = voxel000; - _voxels[VOXEL_ENTRY_INDEX_100] = voxel100; - _voxels[VOXEL_ENTRY_INDEX_010] = voxel010; - _voxels[VOXEL_ENTRY_INDEX_110] = voxel110; - _voxels[VOXEL_ENTRY_INDEX_001] = voxel001; - _voxels[VOXEL_ENTRY_INDEX_101] = voxel101; - _voxels[VOXEL_ENTRY_INDEX_011] = voxel011; - _voxels[VOXEL_ENTRY_INDEX_111] = voxel111; - - update_case_code(); -} - -MarchingCubesVoxelQuery::MarchingCubesVoxelQuery() { - _size = 1; -} - -MarchingCubesVoxelQuery::~MarchingCubesVoxelQuery() { - -} - -void MarchingCubesVoxelQuery::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_entry", "index"), &MarchingCubesVoxelQuery::get_entry); - ClassDB::bind_method(D_METHOD("set_entry", "index", "voxel"), &MarchingCubesVoxelQuery::set_entry); - - ClassDB::bind_method(D_METHOD("get_size"), &MarchingCubesVoxelQuery::get_size); - ClassDB::bind_method(D_METHOD("set_size", "size"), &MarchingCubesVoxelQuery::set_size); - ADD_PROPERTY(PropertyInfo(Variant::INT, "size"), "set_size", "get_size"); - - ClassDB::bind_method(D_METHOD("get_position"), &MarchingCubesVoxelQuery::get_position_bind); - ClassDB::bind_method(D_METHOD("set_position", "spositionize"), &MarchingCubesVoxelQuery::set_position_bind); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "position"), "set_position", "get_position"); - - ClassDB::bind_method(D_METHOD("get_case_code"), &MarchingCubesVoxelQuery::get_case_code); - ClassDB::bind_method(D_METHOD("update_case_code"), &MarchingCubesVoxelQuery::update_case_code); - ClassDB::bind_method(D_METHOD("is_triangulation_trivial"), &MarchingCubesVoxelQuery::is_triangulation_trivial); - - BIND_ENUM_CONSTANT(VOXEL_ENTRY_INDEX_000); - BIND_ENUM_CONSTANT(VOXEL_ENTRY_INDEX_100); - BIND_ENUM_CONSTANT(VOXEL_ENTRY_INDEX_010); - BIND_ENUM_CONSTANT(VOXEL_ENTRY_INDEX_110); - BIND_ENUM_CONSTANT(VOXEL_ENTRY_INDEX_001); - BIND_ENUM_CONSTANT(VOXEL_ENTRY_INDEX_101); - BIND_ENUM_CONSTANT(VOXEL_ENTRY_INDEX_011); - BIND_ENUM_CONSTANT(VOXEL_ENTRY_INDEX_111); - - BIND_ENUM_CONSTANT(VOXEL_ENTRIES_SIZE); - - BIND_ENUM_CONSTANT(VOXEL_ENTRY_MASK_000); - BIND_ENUM_CONSTANT(VOXEL_ENTRY_MASK_100); - BIND_ENUM_CONSTANT(VOXEL_ENTRY_MASK_010); - BIND_ENUM_CONSTANT(VOXEL_ENTRY_MASK_110); - BIND_ENUM_CONSTANT(VOXEL_ENTRY_MASK_001); - BIND_ENUM_CONSTANT(VOXEL_ENTRY_MASK_101); - BIND_ENUM_CONSTANT(VOXEL_ENTRY_MASK_011); - BIND_ENUM_CONSTANT(VOXEL_ENTRY_MASK_111); - -} diff --git a/utility_old/marching_cubes_voxel_query.h b/utility_old/marching_cubes_voxel_query.h deleted file mode 100644 index 5118b77..0000000 --- a/utility_old/marching_cubes_voxel_query.h +++ /dev/null @@ -1,75 +0,0 @@ -#ifndef MARCHING_CUBES_VOXEL_QUERY_H -#define MARCHING_CUBES_VOXEL_QUERY_H - -#include "core/reference.h" - -#include "../data/voxel.h" - -class MarchingCubesVoxelQuery : public Reference { - GDCLASS(MarchingCubesVoxelQuery, Reference); - -public: - static const String BINDING_STRING_VOXEL_ENTRY_INDICES; - static const String BINDING_STRING_VOXEL_ENTRY_MASK; - - enum VoxelEntryIndices { - VOXEL_ENTRY_INDEX_000 = 0, - VOXEL_ENTRY_INDEX_100 = 1, - VOXEL_ENTRY_INDEX_001 = 2, - VOXEL_ENTRY_INDEX_101 = 3, - - VOXEL_ENTRY_INDEX_010 = 4, - VOXEL_ENTRY_INDEX_110 = 5, - VOXEL_ENTRY_INDEX_011 = 6, - VOXEL_ENTRY_INDEX_111 = 7, - - VOXEL_ENTRIES_SIZE = 8, - }; - - enum VoxelEntryMask { - VOXEL_ENTRY_MASK_000 = 1 << 0, - VOXEL_ENTRY_MASK_100 = 1 << 1, - VOXEL_ENTRY_MASK_001 = 1 << 2, - VOXEL_ENTRY_MASK_101 = 1 << 3, - - VOXEL_ENTRY_MASK_010 = 1 << 4, - VOXEL_ENTRY_MASK_110 = 1 << 5, - VOXEL_ENTRY_MASK_011 = 1 << 6, - VOXEL_ENTRY_MASK_111 = 1 << 7, - }; - - Ref get_entry(int index); - void set_entry(int index, Ref voxel); - - int get_size(); - void set_size(int size); - - Vector3i get_position(); - void set_position(Vector3i position); - - Vector3 get_position_bind(); - void set_position_bind(Vector3 position); - - int get_case_code(); - void update_case_code(); - bool is_triangulation_trivial(); - - void set_entries(Ref voxel000, Ref voxel100, Ref voxel010, Ref voxel110, Ref voxel001, Ref voxel101, Ref voxel011, Ref voxel111); - - MarchingCubesVoxelQuery(); - ~MarchingCubesVoxelQuery(); - -protected: - static void _bind_methods(); - -private: - int _case_code; - int _size; - Vector3i _position; - Ref _voxels[VOXEL_ENTRIES_SIZE]; -}; - -VARIANT_ENUM_CAST(MarchingCubesVoxelQuery::VoxelEntryIndices); -VARIANT_ENUM_CAST(MarchingCubesVoxelQuery::VoxelEntryMask); - -#endif diff --git a/world/voxel_chunk.cpp b/world/voxel_chunk.cpp index 92d30b2..7f86cab 100644 --- a/world/voxel_chunk.cpp +++ b/world/voxel_chunk.cpp @@ -181,17 +181,15 @@ RID VoxelChunk::get_clutter_mesh_instance_rid() { void VoxelChunk::set_size(int size_x, int size_y, int siye_z, int margin_start = 0, int margin_end = 0) { } -void VoxelChunk::set_channel_count(int value) { -} -void VoxelChunk::validate_channel_index(int x, int y, int z, int channel_index) { +_FORCE_INLINE_ bool VoxelChunk::validate_channel_position(int x, int y, int z) const { } -uint8_t VoxelChunk::get_voxel(int x, int y, int z, int channel_index) { +_FORCE_INLINE_ uint8_t VoxelChunk::get_voxel(int x, int y, int z, int channel_index) const { } -void VoxelChunk::set_voxel(uint8_t value, int x, int y, int z, int channel_index) { +_FORCE_INLINE_ void VoxelChunk::set_voxel(uint8_t value, int x, int y, int z, int channel_index) { } @@ -201,7 +199,7 @@ void VoxelChunk::set_channel_count(int count) { void VoxelChunk::allocate_channel(int channel_index, uint8_t value = 0) { } -void VoxelChunk::fill_channel(int channel_index) { +void VoxelChunk::fill_channel(uint8_t value, int channel_index) { } void VoxelChunk::dealloc_channel(int channel_index) { @@ -217,23 +215,23 @@ uint8_t *VoxelChunk::get_valid_channel(int channel_index) { //Data Management functions void VoxelChunk::generate_ao() { - unsigned int size_x = _actual_size_x; - unsigned int size_y = _actual_size_y; - unsigned int size_z = _actual_size_z; + unsigned int size_x = _data_size_x; + unsigned int size_y = _data_size_y; + unsigned int size_z = _data_size_z; ERR_FAIL_COND(size_x == 0 || size_y == 0 || size_z == 0); for (unsigned int y = 1; y < size_y - 1; ++y) { for (unsigned int z = 1; z < size_z - 1; ++z) { for (unsigned int x = 1; x < size_x - 1; ++x) { - int current = get_voxel(x, y, z, CHANNEL_ISOLEVEL); + int current = get_voxel(x, y, z, DEFAULT_CHANNEL_ISOLEVEL); - int sum = get_voxel(x + 1, y, z, CHANNEL_ISOLEVEL); - sum += get_voxel(x - 1, y, z, CHANNEL_ISOLEVEL); - sum += get_voxel(x, y + 1, z, CHANNEL_ISOLEVEL); - sum += get_voxel(x, y - 1, z, CHANNEL_ISOLEVEL); - sum += get_voxel(x, y, z + 1, CHANNEL_ISOLEVEL); - sum += get_voxel(x, y, z - 1, CHANNEL_ISOLEVEL); + int sum = get_voxel(x + 1, y, z, DEFAULT_CHANNEL_ISOLEVEL); + sum += get_voxel(x - 1, y, z, DEFAULT_CHANNEL_ISOLEVEL); + sum += get_voxel(x, y + 1, z, DEFAULT_CHANNEL_ISOLEVEL); + sum += get_voxel(x, y - 1, z, DEFAULT_CHANNEL_ISOLEVEL); + sum += get_voxel(x, y, z + 1, DEFAULT_CHANNEL_ISOLEVEL); + sum += get_voxel(x, y, z - 1, DEFAULT_CHANNEL_ISOLEVEL); sum /= 6; @@ -242,7 +240,7 @@ void VoxelChunk::generate_ao() { if (sum < 0) sum = 0; - set_voxel(sum, x, y, z, CHANNEL_AO); + set_voxel(sum, x, y, z, DEFAULT_CHANNEL_AO); } } } @@ -251,25 +249,21 @@ void VoxelChunk::generate_ao() { void VoxelChunk::add_light(int local_x, int local_y, int local_z, int size, Color color) { ERR_FAIL_COND(size < 0); - int size_x = _actual_size_actual_size_xx; - int size_y = _actual_size_actual_size_xy; - int size_z = _actual_size_actual_size_xz; - float sizef = static_cast(size); //float rf = (color.r / sizef); //float gf = (color.g / sizef); //float bf = (color.b / sizef); for (int y = local_y - size; y <= local_y + size; ++y) { - if (y < 0 || y >= size_y) + if (y < 0 || y >= _data_size_y) continue; for (int z = local_z - size; z <= local_z + size; ++z) { - if (z < 0 || z >= size_z) + if (z < 0 || z >= _data_size_z) continue; for (int x = local_x - size; x <= local_x + size; ++x) { - if (x < 0 || x >= size_x) + if (x < 0 || x >= _data_size_x) continue; int lx = x - local_x; @@ -286,9 +280,9 @@ void VoxelChunk::add_light(int local_x, int local_y, int local_z, int size, Colo int g = color.g * str * 255.0; int b = color.b * str * 255.0; - r += get_voxel(x, y, z, CHANNEL_LIGHT_COLOR_R); - g += get_voxel(x, y, z, CHANNEL_LIGHT_COLOR_G); - b += get_voxel(x, y, z, CHANNEL_LIGHT_COLOR_B); + r += get_voxel(x, y, z, DEFAULT_CHANNEL_LIGHT_COLOR_R); + g += get_voxel(x, y, z, DEFAULT_CHANNEL_LIGHT_COLOR_G); + b += get_voxel(x, y, z, DEFAULT_CHANNEL_LIGHT_COLOR_B); if (r > 255) r = 255; @@ -299,17 +293,17 @@ void VoxelChunk::add_light(int local_x, int local_y, int local_z, int size, Colo if (b > 255) b = 255; - set_voxel(r, x, y, z, CHANNEL_LIGHT_COLOR_R); - set_voxel(g, x, y, z, CHANNEL_LIGHT_COLOR_G); - set_voxel(b, x, y, z, CHANNEL_LIGHT_COLOR_B); + set_voxel(r, x, y, z, DEFAULT_CHANNEL_LIGHT_COLOR_R); + set_voxel(g, x, y, z, DEFAULT_CHANNEL_LIGHT_COLOR_G); + set_voxel(b, x, y, z, DEFAULT_CHANNEL_LIGHT_COLOR_B); } } } } -void VoxelChunk::clear_lights() { - fill_channel(0, CHANNEL_LIGHT_COLOR_R); - fill_channel(0, CHANNEL_LIGHT_COLOR_G); - fill_channel(0, CHANNEL_LIGHT_COLOR_B); +void VoxelChunk::clear_baked_lights() { + fill_channel(0, DEFAULT_CHANNEL_LIGHT_COLOR_R); + fill_channel(0, DEFAULT_CHANNEL_LIGHT_COLOR_G); + fill_channel(0, DEFAULT_CHANNEL_LIGHT_COLOR_B); } void VoxelChunk::create_mesher() { @@ -368,7 +362,7 @@ void VoxelChunk::_build_phase(int phase) { if (has_method("_create_mesh")) { call("_create_mesh"); } else { - _mesher->add_buffer(_buffer); + _mesher->add_chunk(this); } //finalize_mesh(); @@ -387,7 +381,7 @@ void VoxelChunk::_build_phase(int phase) { return; } case BUILD_PHASE_TERRARIN_MESH: { - _mesher->bake_colors(_buffer); + _mesher->bake_colors(this); finalize_mesh(); @@ -495,10 +489,7 @@ void VoxelChunk::create_voxel_light(const Color color, const int size, const int Ref light; light.instance(); - Vector3i pos = get_position(); - Vector3i csize = get_size(); - - light->set_world_position(pos.x * csize.x + x, pos.y * csize.y + y, pos.z * csize.z + z); + light->set_world_position(_position_x * _size_x + x, _position_y * _size_y + y, _position_z * _size_z + z); light->set_color(color); light->set_size(size); @@ -565,21 +556,15 @@ void VoxelChunk::bake_lights() { void VoxelChunk::bake_light(Ref light) { ERR_FAIL_COND(!light.is_valid()); - Vector3i wp = light->get_world_position(); - - int wpx = wp.x - (_position_x * _size_x); - int wpy = wp.y - (_position_y * _size_y); - int wpz = wp.z - (_position_z * _size_z); + int wpx = light->get_world_position_x() - (_position_x * _size_x); + int wpy = light->get_world_position_y() - (_position_y * _size_y); + int wpz = light->get_world_position_z() - (_position_z * _size_z); //int wpx = (int)(wp.x / _size.x) - _position.x; //int wpy = (int)(wp.y / _size.y) - _position.y; //int wpz = (int)(wp.z / _size.z) - _position.z; - _buffer->add_light(wpx, wpy, wpz, light->get_size(), light->get_color()); -} - -void VoxelChunk::clear_baked_lights() { - _buffer->clear_lights(); + add_light(wpx, wpy, wpz, light->get_size(), light->get_color()); } void VoxelChunk::add_prop_light(Ref light) { @@ -614,7 +599,7 @@ void VoxelChunk::process_props() { call("_process_props"); - _mesher->bake_colors(_buffer); + _mesher->bake_colors(this); _mesher->build_mesh(_prop_mesh_rid); } @@ -624,7 +609,7 @@ void VoxelChunk::build_prop_meshes() { allocate_prop_mesh(); } - _mesher->bake_colors(_buffer); + _mesher->bake_colors(this); _mesher->build_mesh(_prop_mesh_rid); } @@ -898,11 +883,9 @@ void VoxelChunk::draw_debug_voxel_lights() { for (int i = 0; i < _voxel_lights.size(); ++i) { Ref v = _voxel_lights[i]; - Vector3i pos = v->get_world_position(); - - int pos_x = pos.x - (_size_x * _position_x); - int pos_y = pos.y - (_size_y * _position_y); - int pos_z = pos.z - (_size_z * _position_z); + int pos_x = v->get_world_position_x() - (_size_x * _position_x); + int pos_y = v->get_world_position_y() - (_size_y * _position_y); + int pos_z = v->get_world_position_z() - (_size_z * _position_z); draw_cross_voxels_fill(Vector3(pos_x, pos_y, pos_z), 1.0); } @@ -935,8 +918,6 @@ VoxelChunk::VoxelChunk() { _voxel_scale = 1; _lod_size = 1; - _buffer.instance(); - _debug_drawer = NULL; _voxel_world = NULL; @@ -959,8 +940,6 @@ VoxelChunk::~VoxelChunk() { _mesher.unref(); } - _buffer.unref(); - if (_library.is_valid()) { _library.unref(); } @@ -987,30 +966,22 @@ void VoxelChunk::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "state"), "set_state", "get_state"); ClassDB::bind_method(D_METHOD("get_position_x"), &VoxelChunk::get_position_x); - ClassDB::bind_method(D_METHOD("set_position_x", "value"), &VoxelChunk::set_position_x); - ADD_PROPERTY(PropertyInfo(Variant::INT, "chunk_position_x"), "set_position_x", "get_position_x"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "position_x"), "", "get_position_x"); ClassDB::bind_method(D_METHOD("get_position_y"), &VoxelChunk::get_position_y); - ClassDB::bind_method(D_METHOD("set_position_y", "value"), &VoxelChunk::set_position_y); - ADD_PROPERTY(PropertyInfo(Variant::INT, "chunk_position_y"), "set_position_y", "get_position_y"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "position_y"), "", "get_position_y"); ClassDB::bind_method(D_METHOD("get_position_z"), &VoxelChunk::get_position_z); - ClassDB::bind_method(D_METHOD("set_position_z", "value"), &VoxelChunk::set_position_z); - ADD_PROPERTY(PropertyInfo(Variant::INT, "chunk_position_z"), "set_position_x", "get_position_z"); - - ClassDB::bind_method(D_METHOD("set_position", "x", "y", "z"), &VoxelChunk::set_position); + ADD_PROPERTY(PropertyInfo(Variant::INT, "position_z"), "", "get_position_z"); ClassDB::bind_method(D_METHOD("get_size_x"), &VoxelChunk::get_size_x); - ClassDB::bind_method(D_METHOD("set_size_x", "value"), &VoxelChunk::set_size_x); - ADD_PROPERTY(PropertyInfo(Variant::INT, "chunk_size_x"), "set_size_x", "get_size_x"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "size_x"), "", "get_size_x"); ClassDB::bind_method(D_METHOD("get_size_y"), &VoxelChunk::get_size_y); - ClassDB::bind_method(D_METHOD("set_size_y", "value"), &VoxelChunk::set_size_y); - ADD_PROPERTY(PropertyInfo(Variant::INT, "chunk_size_y"), "set_size_y", "get_size_y"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "size_y"), "", "get_size_y"); ClassDB::bind_method(D_METHOD("get_size_z"), &VoxelChunk::get_size_z); - ClassDB::bind_method(D_METHOD("set_size_z", "value"), &VoxelChunk::set_size_z); - ADD_PROPERTY(PropertyInfo(Variant::INT, "chunk_size_z"), "set_size_x", "get_size_z"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "size_z"), "", "get_size_z"); ClassDB::bind_method(D_METHOD("set_size", "x", "y", "z"), &VoxelChunk::set_size); diff --git a/world/voxel_chunk.h b/world/voxel_chunk.h index fc4160c..b801587 100644 --- a/world/voxel_chunk.h +++ b/world/voxel_chunk.h @@ -141,17 +141,17 @@ public: RID get_clutter_mesh_rid(); RID get_clutter_mesh_instance_rid(); - //Voxel Data + //Voxel Data` void set_size(int size_x, int size_y, int siye_z, int margin_start = 0, int margin_end = 0); - void set_channel_count(int value); - void validate_channel_index(int x, int y, int z, int channel_index); - uint8_t get_voxel(int x, int y, int z, int channel_index); + bool validate_channel_position(int x, int y, int z) const; + + uint8_t get_voxel(int x, int y, int z, int channel_index) const; void set_voxel(uint8_t value, int x, int y, int z, int channel_index); void set_channel_count(int count); void allocate_channel(int channel_index, uint8_t value = 0); - void fill_channel(int channel_index); + void fill_channel(uint8_t value, int channel_index); void dealloc_channel(int channel_index); uint8_t *get_channel(int channel_index); @@ -161,7 +161,7 @@ public: void generate_ao(); void add_light(int local_x, int local_y, int local_z, int size, Color color); - void clear_lights(); + void clear_baked_lights(); //Meshing void create_mesher(); @@ -194,7 +194,6 @@ public: void bake_lights(); void bake_light(Ref light); - void clear_baked_lights(); void add_prop_light(Ref light); diff --git a/world/voxel_structure.cpp b/world/voxel_structure.cpp index eae1934..9acdc0f 100644 --- a/world/voxel_structure.cpp +++ b/world/voxel_structure.cpp @@ -1,116 +1,114 @@ #include "voxel_structure.h" int VoxelStructure::get_chunk_size_x() const { - return _chunk_size.x; + return _chunk_size_x; } void VoxelStructure::set_chunk_size_x(const int value) { - _chunk_size.x = value; + _chunk_size_x = value; } int VoxelStructure::get_chunk_size_y() const { - return _chunk_size.y; + return _chunk_size_y; } void VoxelStructure::set_chunk_size_y(const int value) { - _chunk_size.y = value; + _chunk_size_y = value; } int VoxelStructure::get_chunk_size_z() const { - return _chunk_size.z; + return _chunk_size_z; } void VoxelStructure::set_chunk_size_z(const int value) { - _chunk_size.z = value; + _chunk_size_z = value; } int VoxelStructure::get_world_position_x() const { - return _world_position.x; + return _world_position_x; } void VoxelStructure::set_world_position_x(const int value) { - _world_position.x = value; + _world_position_x = value; } int VoxelStructure::get_world_position_y() const { - return _world_position.y; + return _world_position_y; } void VoxelStructure::set_world_position_y(const int value) { - _world_position.y = value; + _world_position_y = value; } int VoxelStructure::get_world_position_z() const { - return _world_position.z; + return _world_position_z; } void VoxelStructure::set_world_position_z(const int value) { - _world_position.z = value; + _world_position_z = value; } -Ref VoxelStructure::get_chunk_voxel_pos(int x, int y, int z) { - - Ref b = get_chunk(x / _chunk_size.x, y / _chunk_size.y, z / _chunk_size.z); +VoxelChunk *VoxelStructure::get_chunk_voxel_pos(int x, int y, int z) { + VoxelChunk *b = get_chunk(x / _chunk_size_x, y / _chunk_size_y, z / _chunk_size_z); +/* if (!b.is_valid()) { b.instance(); - add_chunk(b, x / _chunk_size.x, y / _chunk_size.y, z / _chunk_size.z); + add_chunk(b, x / _chunk_size_x, y / _chunk_size_y, z / _chunk_size_z); } - +*/ return b; } int VoxelStructure::get_voxel(int x, int y, int z, unsigned int channel_index) { - Ref b = get_chunk_voxel_pos(x, y, z); + VoxelChunk *b = get_chunk_voxel_pos(x, y, z); - ERR_FAIL_COND_V(!b.is_valid(), 0); + //ERR_FAIL_COND_V(!b.is_valid(), 0); return b->get_voxel(x, y, z, channel_index); } void VoxelStructure::set_voxel(int value, int x, int y, int z, unsigned int channel_index) { - Ref b = get_chunk_voxel_pos(x, y, z); + VoxelChunk *b = get_chunk_voxel_pos(x, y, z); - ERR_FAIL_COND(!b.is_valid()); + //ERR_FAIL_COND(!b.is_valid()); return b->set_voxel(value, x, y, z, channel_index); } -void VoxelStructure::set_voxel_v(int value, Vector3 pos, unsigned int channel_index) { - Ref b = get_chunk_voxel_pos(pos.x, pos.y, pos.z); - ERR_FAIL_COND(!b.is_valid()); +void VoxelStructure::add_chunk(VoxelChunk *chunk, const int x, const int y, const int z) { + //_chunks.set(Vector3i(x, y, z), chunk); - return b->set_voxel_v(value, pos, channel_index); + //VoxelStructureChunk c; + //c.chunk = chunk; + //c.position = Vector3i(x, y, z); + + //_chunks_vector.push_back(c); } +VoxelChunk *VoxelStructure::get_chunk(const int x, const int y, const int z) { + //const VoxelChunk **chunk = _chunks.getptr(Vector3i(x, y, z)); -void VoxelStructure::add_chunk(Ref chunk, const int x, const int y, const int z) { - _chunks.set(Vector3i(x, y, z), chunk); + //return Ref(chunk); - VoxelStructureChunk c; - c.buffer = chunk; - c.position = Vector3i(x, y, z); - - _chunks_vector.push_back(c); + return NULL; } -Ref VoxelStructure::get_chunk(const int x, const int y, const int z) { - const Ref *chunk = _chunks.getptr(Vector3i(x, y, z)); +VoxelChunk *VoxelStructure::remove_chunk(const int x, const int y, const int z) { + /* + VoxelChunk **chunk = _chunks.getptr(Vector3i(x, y, z)); - return Ref(chunk); -} -Ref VoxelStructure::remove_chunk(const int x, const int y, const int z) { - Ref *chunk = _chunks.getptr(Vector3i(x, y, z)); - - Ref c(chunk); + VoxelChunk *c(chunk); if (c.is_valid()) { for (int i = 0; i < _chunks_vector.size(); ++i) { - if (_chunks_vector.get(i).buffer == c) { + if (_chunks_vector.get(i).chunk == c) { _chunks_vector.remove(i); break; } } } - return c; + return c;*/ + + return NULL; } -Ref VoxelStructure::get_chunk_index(const int index) { - return _chunks_vector.get(index).buffer; +VoxelChunk *VoxelStructure::get_chunk_index(const int index) { + //return _chunks_vector.get(index).chunk; } int VoxelStructure::get_chunk_count() const { return _chunks_vector.size(); @@ -118,22 +116,22 @@ int VoxelStructure::get_chunk_count() const { void VoxelStructure::clear_chunks() { for (int i = 0; i < _chunks_vector.size(); ++i) { - _chunks_vector.get(i).buffer.unref(); + //_chunks_vector.get(i).chunk.unref(); } - _chunks_vector.clear(); + //_chunks_vector.clear(); - _chunks.clear(); + //_chunks.clear(); } VoxelStructure::VoxelStructure() { - _chunk_size = Vector3i(16, 16, 16); - _world_position = Vector3i(0, 0, 0); + //_chunk_size = Vector3i(16, 16, 16); + //_world_position = Vector3i(0, 0, 0); } VoxelStructure::~VoxelStructure() { for (int i = 0; i < _chunks_vector.size(); ++i) { - _chunks_vector.get(i).buffer.unref(); + //_chunks_vector.get(i).chunk.unref(); } _chunks.clear(); diff --git a/world/voxel_structure.h b/world/voxel_structure.h index 60fca1a..9aeff9c 100644 --- a/world/voxel_structure.h +++ b/world/voxel_structure.h @@ -4,8 +4,7 @@ #include "core/reference.h" #include "core/hash_map.h" -#include "../math/vector3i.h" -#include "voxel_buffer.h" +#include "voxel_chunk.h" class VoxelStructure : public Reference { GDCLASS(VoxelStructure, Reference); @@ -30,17 +29,17 @@ public: int get_world_position_z() const; void set_world_position_z(const int value); - Ref get_chunk_voxel_pos(int x, int y, int z); + VoxelChunk *get_chunk_voxel_pos(int x, int y, int z); int get_voxel(int x, int y, int z, unsigned int channel_index = 0); void set_voxel(int value, int x, int y, int z, unsigned int channel_index = 0); void set_voxel_v(int value, Vector3 pos, unsigned int channel_index = 0); - void add_chunk(Ref chunk, const int x, const int y, const int z); - Ref get_chunk(const int x, const int y, const int z); - Ref remove_chunk(const int x, const int y, const int z); + void add_chunk(VoxelChunk *chunk, const int x, const int y, const int z); + VoxelChunk *get_chunk(const int x, const int y, const int z); + VoxelChunk *remove_chunk(const int x, const int y, const int z); - Ref get_chunk_index(const int index); + VoxelChunk *get_chunk_index(const int index); int get_chunk_count() const; void clear_chunks(); @@ -51,17 +50,31 @@ public: protected: static void _bind_methods(); - struct VoxelStructureChunk { - Vector3i position; - Ref buffer; + struct IntPos { + int x; + int y; + int z; + }; + + struct IntPosHasher { + static _FORCE_INLINE_ uint32_t hash(const IntPos &v) { + uint32_t hash = hash_djb2_one_32(v.x); + hash = hash_djb2_one_32(v.y, hash); + return hash_djb2_one_32(v.z, hash); + } }; private: - Vector3i _chunk_size; - Vector3i _world_position; + int _chunk_size_x; + int _chunk_size_y; + int _chunk_size_z; - HashMap, Vector3iHasher> _chunks; - Vector _chunks_vector; + int _world_position_x; + int _world_position_y; + int _world_position_z; + + HashMap _chunks; + Vector _chunks_vector; }; #endif diff --git a/world/voxel_world.h b/world/voxel_world.h index d607187..c70a4db 100644 --- a/world/voxel_world.h +++ b/world/voxel_world.h @@ -64,14 +64,43 @@ public: protected: static void _bind_methods(); + struct IntPos { + int x; + int y; + int z; + + IntPos() { + x = 0; + y = 0; + z = 0; + } + + IntPos(int p_x, int p_y, int p_z) { + x = p_x; + y = p_y; + z = p_z; + } + }; + + struct IntPosHasher { + static _FORCE_INLINE_ uint32_t hash(const IntPos &v) { + uint32_t hash = hash_djb2_one_32(v.x); + hash = hash_djb2_one_32(v.y, hash); + return hash_djb2_one_32(v.z, hash); + } + }; + private: - Vector3i _chunk_size; + int _chunk_size_x; + int _chunk_size_y; + int _chunk_size_z; + Ref _library; Ref _level_generator; float _voxel_scale; int _chunk_spawn_range; - HashMap _chunks; + HashMap _chunks; Vector _chunks_vector; Vector > _world_areas;