mirror of
https://github.com/Relintai/voxelman.git
synced 2024-11-14 10:17:20 +01:00
Started reworking VoxelStructure's api.
This commit is contained in:
parent
6c39845387
commit
f25dac92ea
@ -64,103 +64,37 @@ void VoxelStructure::set_world_position_z(const int value) {
|
||||
_world_position_z = value;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
*/
|
||||
return b;
|
||||
}
|
||||
|
||||
int VoxelStructure::get_voxel(int x, int y, int z, unsigned int channel_index) {
|
||||
VoxelChunk *b = get_chunk_voxel_pos(x, y, z);
|
||||
|
||||
//ERR_FAIL_COND_V(!b.is_valid(), 0);
|
||||
|
||||
return b->get_voxel(x, y, z, channel_index);
|
||||
return 0;
|
||||
}
|
||||
void VoxelStructure::set_voxel(int value, int x, int y, int z, unsigned int channel_index) {
|
||||
VoxelChunk *b = get_chunk_voxel_pos(x, y, z);
|
||||
|
||||
//ERR_FAIL_COND(!b.is_valid());
|
||||
|
||||
return b->set_voxel(value, x, y, z, channel_index);
|
||||
}
|
||||
|
||||
void add_chunk_bind(Node *chunk, const int x, const int y, const int z) {
|
||||
void VoxelStructure::add_from_chunk_bind(Node *chunk) {
|
||||
VoxelChunk *c = Object::cast_to<VoxelChunk>(chunk);
|
||||
|
||||
ERR_FAIL_COND(!ObjectDB::instance_validate(c));
|
||||
|
||||
add_from_chunk(c);
|
||||
}
|
||||
void VoxelStructure::add_chunk(VoxelChunk *chunk, const int x, const int y, const int z) {
|
||||
//_chunks.set(Vector3i(x, y, z), chunk);
|
||||
|
||||
//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));
|
||||
|
||||
//return Ref<VoxelBuffer>(chunk);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
VoxelChunk *VoxelStructure::remove_chunk(const int x, const int y, const int z) {
|
||||
/*
|
||||
VoxelChunk **chunk = _chunks.getptr(Vector3i(x, y, z));
|
||||
|
||||
VoxelChunk *c(chunk);
|
||||
|
||||
if (c.is_valid()) {
|
||||
|
||||
for (int i = 0; i < _chunks_vector.size(); ++i) {
|
||||
if (_chunks_vector.get(i).chunk == c) {
|
||||
_chunks_vector.remove(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return c;*/
|
||||
|
||||
return NULL;
|
||||
void VoxelStructure::add_from_chunk(VoxelChunk *chunk) {
|
||||
}
|
||||
|
||||
VoxelChunk *VoxelStructure::get_chunk_index(const int index) {
|
||||
//return _chunks_vector.get(index).chunk;
|
||||
return NULL;
|
||||
void VoxelStructure::write_to_chunk_bind(Node *chunk) {
|
||||
VoxelChunk *c = Object::cast_to<VoxelChunk>(chunk);
|
||||
|
||||
ERR_FAIL_COND(!ObjectDB::instance_validate(c));
|
||||
|
||||
add_from_chunk(c);
|
||||
}
|
||||
int VoxelStructure::get_chunk_count() const {
|
||||
return _chunks_vector.size();
|
||||
}
|
||||
|
||||
void VoxelStructure::clear_chunks() {
|
||||
for (int i = 0; i < _chunks_vector.size(); ++i) {
|
||||
//_chunks_vector.get(i).chunk.unref();
|
||||
}
|
||||
|
||||
//_chunks_vector.clear();
|
||||
|
||||
//_chunks.clear();
|
||||
void VoxelStructure::write_to_chunk(VoxelChunk *chunk) {
|
||||
}
|
||||
|
||||
VoxelStructure::VoxelStructure() {
|
||||
//_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).chunk.unref();
|
||||
}
|
||||
|
||||
_chunks.clear();
|
||||
_chunks_vector.clear();
|
||||
_data.clear();
|
||||
}
|
||||
|
||||
void VoxelStructure::_bind_methods() {
|
||||
@ -188,18 +122,9 @@ void VoxelStructure::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_world_position_z", "value"), &VoxelStructure::set_world_position_z);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "world_position_z"), "set_world_position_z", "get_world_position_z");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_chunk_voxel_pos", "x", "y", "z"), &VoxelStructure::get_chunk_voxel_pos);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_voxel", "x", "y", "z", "channel_index"), &VoxelStructure::get_voxel, DEFVAL(0));
|
||||
ClassDB::bind_method(D_METHOD("set_voxel", "value", "x", "y", "z", "channel_index"), &VoxelStructure::set_voxel, DEFVAL(0));
|
||||
//ClassDB::bind_method(D_METHOD("set_voxel_v", "value", "pos", "channel_index"), &VoxelStructure::set_voxel_v, DEFVAL(0));
|
||||
|
||||
//ClassDB::bind_method(D_METHOD("add_chunk", "chunk", "x", "y", "z"), &VoxelStructure::add_chunk_bind);
|
||||
ClassDB::bind_method(D_METHOD("get_chunk", "x", "y", "z"), &VoxelStructure::get_chunk);
|
||||
ClassDB::bind_method(D_METHOD("remove_chunk", "x", "y", "z"), &VoxelStructure::remove_chunk);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_chunk_index", "index"), &VoxelStructure::get_chunk_index);
|
||||
ClassDB::bind_method(D_METHOD("get_chunk_count"), &VoxelStructure::get_chunk_count);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("clear_chunks"), &VoxelStructure::clear_chunks);
|
||||
ClassDB::bind_method(D_METHOD("add_from_chunk", "chunk"), &VoxelStructure::add_from_chunk_bind);
|
||||
ClassDB::bind_method(D_METHOD("write_to_chunk", "chunk"), &VoxelStructure::write_to_chunk_bind);
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ SOFTWARE.
|
||||
#include "core/reference.h"
|
||||
|
||||
#include "core/hash_map.h"
|
||||
#include "core/pool_vector.h"
|
||||
#include "voxel_chunk.h"
|
||||
|
||||
class VoxelStructure : public Reference {
|
||||
@ -50,21 +51,15 @@ public:
|
||||
int get_world_position_z() const;
|
||||
void set_world_position_z(const int value);
|
||||
|
||||
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_bind(Node *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);
|
||||
void add_from_chunk_bind(Node *chunk);
|
||||
void add_from_chunk(VoxelChunk *chunk);
|
||||
|
||||
VoxelChunk *get_chunk_index(const int index);
|
||||
int get_chunk_count() const;
|
||||
|
||||
void clear_chunks();
|
||||
void write_to_chunk_bind(Node *chunk);
|
||||
void write_to_chunk(VoxelChunk *chunk);
|
||||
|
||||
VoxelStructure();
|
||||
~VoxelStructure();
|
||||
@ -95,8 +90,7 @@ private:
|
||||
int _world_position_y;
|
||||
int _world_position_z;
|
||||
|
||||
HashMap<IntPos, VoxelChunk *, IntPosHasher> _chunks;
|
||||
Vector<VoxelChunk *> _chunks_vector;
|
||||
HashMap<IntPos, PoolByteArray, IntPosHasher> _data;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user