Added chunk states, and dirty flag to Chunk.

This commit is contained in:
Relintai 2019-11-10 03:10:42 +01:00
parent f82076e9c2
commit c674a8c045
3 changed files with 67 additions and 16 deletions

View File

@ -73,7 +73,7 @@ void VoxelSurface::_bind_methods() {
ClassDB::bind_method(D_METHOD("is_transparent"), &VoxelSurface::is_transparent);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "transparent"), "set_transparent", "is_transparent");
ClassDB::bind_method(D_METHOD("get_clutter", "transparent"), &VoxelSurface::get_clutter);
ClassDB::bind_method(D_METHOD("get_clutter"), &VoxelSurface::get_clutter);
ClassDB::bind_method(D_METHOD("set_clutter"), &VoxelSurface::set_clutter);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "clutter", PROPERTY_HINT_RESOURCE_TYPE, "GroundClutter"), "set_clutter", "get_clutter");

View File

@ -2,6 +2,20 @@
#include "voxel_world.h"
bool VoxelChunk::get_dirty() const {
return _dirty;
}
void VoxelChunk::set_dirty(bool value) {
_dirty = value;
}
int VoxelChunk::get_state() const {
return _state;
}
void VoxelChunk::set_state(int value) {
_state = value;
}
int VoxelChunk::get_chunk_position_x() {
return _chunk_position.x;
}
@ -708,6 +722,9 @@ void VoxelChunk::free_chunk() {
}
VoxelChunk::VoxelChunk() {
_dirty = false;
_state = VOXEL_CHUNK_STATE_OK;
_build_mesh = true;
_create_collider = true;
_bake_lights = true;
@ -754,6 +771,14 @@ void VoxelChunk::_bind_methods() {
ClassDB::bind_method(D_METHOD("_create_mesher"), &VoxelChunk::_create_mesher);
ClassDB::bind_method(D_METHOD("get_dirty"), &VoxelChunk::get_dirty);
ClassDB::bind_method(D_METHOD("set_dirty", "value"), &VoxelChunk::set_dirty);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "dirty"), "set_dirty", "get_dirty");
ClassDB::bind_method(D_METHOD("get_state"), &VoxelChunk::get_state);
ClassDB::bind_method(D_METHOD("set_state", "value"), &VoxelChunk::set_state);
ADD_PROPERTY(PropertyInfo(Variant::INT, "state"), "set_state", "get_state");
ClassDB::bind_method(D_METHOD("get_chunk_position_x"), &VoxelChunk::get_chunk_position_x);
ClassDB::bind_method(D_METHOD("set_chunk_position_x", "value"), &VoxelChunk::set_chunk_position_x);
ADD_PROPERTY(PropertyInfo(Variant::INT, "chunk_position_x"), "set_chunk_position_x", "get_chunk_position_x");
@ -906,4 +931,11 @@ void VoxelChunk::_bind_methods() {
BIND_CONSTANT(BUILD_PHASE_PROP_MESH);
BIND_CONSTANT(BUILD_PHASE_PROP_COLLIDER);
BIND_CONSTANT(BUILD_PHASE_MAX);
BIND_CONSTANT(VOXEL_CHUNK_STATE_OK);
BIND_CONSTANT(VOXEL_CHUNK_STATE_GENERATION_QUEUED);
BIND_CONSTANT(VOXEL_CHUNK_STATE_GENERATION);
BIND_CONSTANT(VOXEL_CHUNK_STATE_MESH_GENERATION_QUEUED);
BIND_CONSTANT(VOXEL_CHUNK_STATE_MESH_GENERATION);
BIND_CONSTANT(VOXEL_CHUNK_STATE_MAX);
}

View File

@ -39,6 +39,36 @@ class VoxelChunk : public Spatial {
GDCLASS(VoxelChunk, Spatial);
public:
enum {
VOXEL_CHUNK_STATE_OK = 0,
VOXEL_CHUNK_STATE_GENERATION_QUEUED = 1,
VOXEL_CHUNK_STATE_GENERATION = 2,
VOXEL_CHUNK_STATE_MESH_GENERATION_QUEUED = 3,
VOXEL_CHUNK_STATE_MESH_GENERATION = 4,
VOXEL_CHUNK_STATE_MAX = 5,
};
enum {
BUILD_PHASE_DONE = 0,
BUILD_PHASE_SETUP = 1,
BUILD_PHASE_TERRARIN_MESH_SETUP = 2,
BUILD_PHASE_TERRARIN_MESH_COLLIDER = 3,
BUILD_PHASE_LIGHTS = 4,
BUILD_PHASE_TERRARIN_MESH = 5,
BUILD_PHASE_PROP_MESH = 6,
BUILD_PHASE_PROP_COLLIDER = 7,
BUILD_PHASE_LIQUID = 8,
BUILD_PHASE_CLUTTER = 9,
BUILD_PHASE_MAX = 10
};
public:
bool get_dirty() const;
void set_dirty(bool value);
int get_state() const;
void set_state(int value);
//Properties
int get_chunk_position_x();
void set_chunk_position_x(int value);
@ -170,23 +200,12 @@ public:
VoxelChunk();
~VoxelChunk();
public:
enum {
BUILD_PHASE_DONE = 0,
BUILD_PHASE_SETUP = 1,
BUILD_PHASE_TERRARIN_MESH_SETUP = 2,
BUILD_PHASE_TERRARIN_MESH_COLLIDER = 3,
BUILD_PHASE_LIGHTS = 4,
BUILD_PHASE_TERRARIN_MESH = 5,
BUILD_PHASE_PROP_MESH = 6,
BUILD_PHASE_PROP_COLLIDER = 7,
BUILD_PHASE_LIQUID = 8,
BUILD_PHASE_CLUTTER = 9,
BUILD_PHASE_MAX = 10
};
protected:
static void _bind_methods();
bool _dirty;
int _state;
int _current_build_phase;
bool _enabled;