Added get_or_create_chunk to VoxelWorld.

This commit is contained in:
Relintai 2020-04-10 13:39:11 +02:00
parent f6ed4505e7
commit 03f9041eb8
2 changed files with 15 additions and 3 deletions

View File

@ -292,6 +292,16 @@ void VoxelWorld::clear() {
_generating.clear();
}
Ref<VoxelChunk> VoxelWorld::get_or_create_chunk(int x, int y, int z) {
Ref<VoxelChunk> chunk = get_chunk(x, y, z);
if (!chunk.is_valid()) {
chunk = create_chunk(x, y, z);
}
return chunk;
}
Ref<VoxelChunk> VoxelWorld::create_chunk(int x, int y, int z) {
Ref<VoxelChunk> c = call("_create_chunk", x, y, z, Ref<VoxelChunk>());
@ -666,6 +676,7 @@ void VoxelWorld::_bind_methods() {
BIND_VMETHOD(MethodInfo("_prepare_chunk_for_generation", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "VoxelChunk")));
BIND_VMETHOD(MethodInfo("_generate_chunk", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "VoxelChunk")));
ClassDB::bind_method(D_METHOD("get_or_create_chunk", "x", "y", "z"), &VoxelWorld::get_or_create_chunk);
ClassDB::bind_method(D_METHOD("create_chunk", "x", "y", "z"), &VoxelWorld::create_chunk);
ClassDB::bind_method(D_METHOD("_create_chunk", "x", "y", "z", "chunk"), &VoxelWorld::_create_chunk);

View File

@ -127,6 +127,7 @@ public:
void clear();
Ref<VoxelChunk> get_or_create_chunk(int x, int y, int z);
Ref<VoxelChunk> create_chunk(int x, int y, int z);
void generate_chunk(Ref<VoxelChunk> chunk);