mirror of
https://github.com/Relintai/voxelman.git
synced 2025-04-15 21:06:06 +02:00
Add voxel structure storage to VoxelChunk aswell.
This commit is contained in:
parent
7311297906
commit
f14faead25
@ -29,6 +29,7 @@ SOFTWARE.
|
|||||||
#include "../defines.h"
|
#include "../defines.h"
|
||||||
|
|
||||||
#include "jobs/voxel_job.h"
|
#include "jobs/voxel_job.h"
|
||||||
|
#include "voxel_structure.h"
|
||||||
|
|
||||||
#if THREAD_POOL_PRESENT
|
#if THREAD_POOL_PRESENT
|
||||||
#include "../../thread_pool/thread_pool.h"
|
#include "../../thread_pool/thread_pool.h"
|
||||||
@ -566,6 +567,59 @@ _FORCE_INLINE_ int VoxelChunk::get_data_size() const {
|
|||||||
return _data_size_x * _data_size_y * _data_size_z;
|
return _data_size_x * _data_size_y * _data_size_z;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Voxel Structures
|
||||||
|
|
||||||
|
Ref<VoxelStructure> VoxelChunk::voxel_structure_get(const int index) const {
|
||||||
|
ERR_FAIL_INDEX_V(index, _voxel_structures.size(), Ref<VoxelStructure>());
|
||||||
|
|
||||||
|
return _voxel_structures.get(index);
|
||||||
|
}
|
||||||
|
void VoxelChunk::voxel_structure_add(const Ref<VoxelStructure> &structure) {
|
||||||
|
_voxel_structures.push_back(structure);
|
||||||
|
}
|
||||||
|
void VoxelChunk::voxel_structure_remove(const Ref<VoxelStructure> &structure) {
|
||||||
|
if (!structure.is_valid())
|
||||||
|
return;
|
||||||
|
|
||||||
|
int index = _voxel_structures.find(structure);
|
||||||
|
|
||||||
|
if (index != -1)
|
||||||
|
_voxel_structures.remove(index);
|
||||||
|
}
|
||||||
|
void VoxelChunk::voxel_structure_remove_index(const int index) {
|
||||||
|
ERR_FAIL_INDEX(index, _voxel_structures.size());
|
||||||
|
|
||||||
|
_voxel_structures.remove(index);
|
||||||
|
}
|
||||||
|
void VoxelChunk::voxel_structure_clear() {
|
||||||
|
_voxel_structures.clear();
|
||||||
|
}
|
||||||
|
int VoxelChunk::voxel_structure_get_count() const {
|
||||||
|
return _voxel_structures.size();
|
||||||
|
}
|
||||||
|
void VoxelChunk::voxel_structure_add_at_position(Ref<VoxelStructure> structure, const Vector3 &world_position) {
|
||||||
|
ERR_FAIL_COND(!structure.is_valid());
|
||||||
|
|
||||||
|
structure->set_position_x(static_cast<int>(world_position.x / _voxel_scale));
|
||||||
|
structure->set_position_y(static_cast<int>(world_position.y / _voxel_scale));
|
||||||
|
structure->set_position_z(static_cast<int>(world_position.z / _voxel_scale));
|
||||||
|
|
||||||
|
voxel_structure_add(structure);
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector<Variant> VoxelChunk::voxel_structures_get() {
|
||||||
|
VARIANT_ARRAY_GET(_voxel_structures);
|
||||||
|
}
|
||||||
|
void VoxelChunk::voxel_structures_set(const Vector<Variant> &structures) {
|
||||||
|
voxel_structure_clear();
|
||||||
|
|
||||||
|
for (int i = 0; i < structures.size(); ++i) {
|
||||||
|
Ref<VoxelLight> structure = Ref<VoxelLight>(structures[i]);
|
||||||
|
|
||||||
|
voxel_structure_add(structure);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void VoxelChunk::build() {
|
void VoxelChunk::build() {
|
||||||
ERR_FAIL_COND(!INSTANCE_VALIDATE(get_voxel_world()));
|
ERR_FAIL_COND(!INSTANCE_VALIDATE(get_voxel_world()));
|
||||||
ERR_FAIL_COND(!get_voxel_world()->is_inside_tree());
|
ERR_FAIL_COND(!get_voxel_world()->is_inside_tree());
|
||||||
@ -1308,6 +1362,18 @@ void VoxelChunk::_bind_methods() {
|
|||||||
ClassDB::bind_method(D_METHOD("get_data_index", "x", "y", "z"), &VoxelChunk::get_data_index);
|
ClassDB::bind_method(D_METHOD("get_data_index", "x", "y", "z"), &VoxelChunk::get_data_index);
|
||||||
ClassDB::bind_method(D_METHOD("get_data_size"), &VoxelChunk::get_data_size);
|
ClassDB::bind_method(D_METHOD("get_data_size"), &VoxelChunk::get_data_size);
|
||||||
|
|
||||||
|
ClassDB::bind_method(D_METHOD("voxel_structure_get", "index"), &VoxelChunk::voxel_structure_get);
|
||||||
|
ClassDB::bind_method(D_METHOD("voxel_structure_add", "structure"), &VoxelChunk::voxel_structure_add);
|
||||||
|
ClassDB::bind_method(D_METHOD("voxel_structure_remove", "structure"), &VoxelChunk::voxel_structure_remove);
|
||||||
|
ClassDB::bind_method(D_METHOD("voxel_structure_remove_index", "index"), &VoxelChunk::voxel_structure_remove_index);
|
||||||
|
ClassDB::bind_method(D_METHOD("voxel_structure_clear"), &VoxelChunk::voxel_structure_clear);
|
||||||
|
ClassDB::bind_method(D_METHOD("voxel_structure_get_count"), &VoxelChunk::voxel_structure_get_count);
|
||||||
|
ClassDB::bind_method(D_METHOD("voxel_structure_add_at_position", "structure", "world_position"), &VoxelChunk::voxel_structure_add_at_position);
|
||||||
|
|
||||||
|
ClassDB::bind_method(D_METHOD("voxel_structures_get"), &VoxelChunk::voxel_structures_get);
|
||||||
|
ClassDB::bind_method(D_METHOD("voxel_structures_set"), &VoxelChunk::voxel_structures_set);
|
||||||
|
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "voxel_structures", PROPERTY_HINT_NONE, "17/17:VoxelStructure", PROPERTY_USAGE_DEFAULT, "VoxelStructure"), "voxel_structures_set", "voxel_structures_get");
|
||||||
|
|
||||||
//Meshes
|
//Meshes
|
||||||
|
|
||||||
#if PROPS_PRESENT
|
#if PROPS_PRESENT
|
||||||
|
@ -62,6 +62,7 @@ include_pool_vector
|
|||||||
|
|
||||||
class VoxelJob;
|
class VoxelJob;
|
||||||
class VoxelWorld;
|
class VoxelWorld;
|
||||||
|
class VoxelStructure;
|
||||||
|
|
||||||
class VoxelChunk : public Resource {
|
class VoxelChunk : public Resource {
|
||||||
GDCLASS(VoxelChunk, Resource);
|
GDCLASS(VoxelChunk, Resource);
|
||||||
@ -185,6 +186,18 @@ public:
|
|||||||
int get_data_index(const int x, const int y, const int z) const;
|
int get_data_index(const int x, const int y, const int z) const;
|
||||||
int get_data_size() const;
|
int get_data_size() const;
|
||||||
|
|
||||||
|
//Voxel Structures
|
||||||
|
Ref<VoxelStructure> voxel_structure_get(const int index) const;
|
||||||
|
void voxel_structure_add(const Ref<VoxelStructure> &structure);
|
||||||
|
void voxel_structure_remove(const Ref<VoxelStructure> &structure);
|
||||||
|
void voxel_structure_remove_index(const int index);
|
||||||
|
void voxel_structure_clear();
|
||||||
|
int voxel_structure_get_count() const;
|
||||||
|
void voxel_structure_add_at_position(Ref<VoxelStructure> structure, const Vector3 &world_position);
|
||||||
|
|
||||||
|
Vector<Variant> voxel_structures_get();
|
||||||
|
void voxel_structures_set(const Vector<Variant> &structures);
|
||||||
|
|
||||||
//Meshing
|
//Meshing
|
||||||
void build();
|
void build();
|
||||||
void clear();
|
void clear();
|
||||||
@ -355,6 +368,8 @@ protected:
|
|||||||
|
|
||||||
Ref<VoxelmanLibrary> _library;
|
Ref<VoxelmanLibrary> _library;
|
||||||
|
|
||||||
|
Vector<Ref<VoxelStructure> > _voxel_structures;
|
||||||
|
|
||||||
#if PROPS_PRESENT
|
#if PROPS_PRESENT
|
||||||
Vector<PropDataStore> _props;
|
Vector<PropDataStore> _props;
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user