mirror of
https://github.com/Relintai/voxelman.git
synced 2025-01-12 15:01:09 +01:00
Chunks that are stored inside worlds in scenes will properly generate their meshes now on load. Had to change _create_chunk a bit, now it will be called for all chunks, and it needs to check whether it has to init jobs or not.
This commit is contained in:
parent
4ecc424b84
commit
7311297906
@ -123,11 +123,16 @@ Since properly initializing a chunk usually takes quite a few steps that you pro
|
||||
parameter was added. This means you can just call the super `_create_chunk` methods, and you won't need to worry about your chunk
|
||||
getting overridden. Like:
|
||||
|
||||
Note that `_create_chunk` is also responsible for initializing chunks if you have them stored inside a scene.
|
||||
This is done by `setup_chunk(shunk)` in `VoxelWorld`.
|
||||
|
||||
```
|
||||
func _create_chunk(x : int, y : int, z : int, chunk : VoxelChunk) -> VoxelChunk:
|
||||
if !chunk:
|
||||
chunk = MyChunk.new()
|
||||
|
||||
# We need to check whether or not we need to initialize jobs
|
||||
if chunk.get_job_count() == 0:
|
||||
# Setup a blocky (minecratf like) mesher job
|
||||
var tj : VoxelTerrarinJob = VoxelTerrarinJob.new()
|
||||
|
||||
|
@ -34,7 +34,9 @@ Ref<VoxelChunk> VoxelWorldBlocky::_create_chunk(int x, int y, int z, Ref<VoxelCh
|
||||
|
||||
if (!chunk.is_valid()) {
|
||||
chunk = Ref<VoxelChunk>(memnew(VoxelChunkBlocky));
|
||||
}
|
||||
|
||||
if (chunk->get_job_count() == 0) {
|
||||
Ref<VoxelTerrarinJob> tj;
|
||||
tj.instance();
|
||||
|
||||
|
@ -33,7 +33,9 @@ Ref<VoxelChunk> VoxelWorldCubic::_create_chunk(int x, int y, int z, Ref<VoxelChu
|
||||
|
||||
if (!chunk.is_valid()) {
|
||||
chunk = Ref<VoxelChunk>(memnew(VoxelChunkCubic));
|
||||
}
|
||||
|
||||
if (chunk->get_job_count() == 0) {
|
||||
Ref<VoxelTerrarinJob> tj;
|
||||
tj.instance();
|
||||
|
||||
|
@ -175,7 +175,9 @@ void VoxelWorldDefault::_update_lods() {
|
||||
Ref<VoxelChunk> VoxelWorldDefault::_create_chunk(int x, int y, int z, Ref<VoxelChunk> chunk) {
|
||||
if (!chunk.is_valid()) {
|
||||
chunk = Ref<VoxelChunk>(memnew(VoxelChunkDefault));
|
||||
}
|
||||
|
||||
if (chunk->get_job_count() == 0) {
|
||||
Ref<VoxelTerrarinJob> tj;
|
||||
tj.instance();
|
||||
|
||||
|
@ -32,7 +32,9 @@ SOFTWARE.
|
||||
Ref<VoxelChunk> VoxelWorldMarchingCubes::_create_chunk(int x, int y, int z, Ref<VoxelChunk> chunk) {
|
||||
if (!chunk.is_valid()) {
|
||||
chunk = Ref<VoxelChunk>(memnew(VoxelChunkMarchingCubes));
|
||||
}
|
||||
|
||||
if (chunk->get_job_count() == 0) {
|
||||
Ref<VoxelTerrarinJob> tj;
|
||||
tj.instance();
|
||||
|
||||
|
@ -262,14 +262,17 @@ void VoxelWorld::add_chunk(Ref<VoxelChunk> chunk, const int x, const int y, cons
|
||||
|
||||
IntPos pos(x, y, z);
|
||||
|
||||
ERR_FAIL_COND(_chunks.has(pos));
|
||||
//ERR_FAIL_COND(_chunks.has(pos));
|
||||
|
||||
chunk->set_voxel_world(this);
|
||||
chunk->set_position(x, y, z);
|
||||
chunk->world_transform_changed();
|
||||
|
||||
_chunks.set(pos, chunk);
|
||||
_chunks_vector.push_back(chunk);
|
||||
if (!_chunks.has(pos))
|
||||
_chunks.set(pos, chunk);
|
||||
|
||||
if (_chunks_vector.find(chunk) == -1)
|
||||
_chunks_vector.push_back(chunk);
|
||||
|
||||
if (is_inside_tree())
|
||||
chunk->enter_tree();
|
||||
@ -397,15 +400,24 @@ Ref<VoxelChunk> VoxelWorld::get_or_create_chunk(int x, int y, int z) {
|
||||
Ref<VoxelChunk> VoxelWorld::create_chunk(const int x, const int y, const int z) {
|
||||
Ref<VoxelChunk> c = call("_create_chunk", x, y, z, Ref<VoxelChunk>());
|
||||
|
||||
add_to_generation_queue(c);
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
void VoxelWorld::setup_chunk(Ref<VoxelChunk> chunk) {
|
||||
ERR_FAIL_COND(!chunk.is_valid());
|
||||
|
||||
call("_create_chunk", chunk->get_position_x(), chunk->get_position_y(), chunk->get_position_z(), chunk);
|
||||
}
|
||||
|
||||
Ref<VoxelChunk> VoxelWorld::_create_chunk(const int x, const int y, const int z, Ref<VoxelChunk> chunk) {
|
||||
if (!chunk.is_valid()) {
|
||||
chunk.instance();
|
||||
|
||||
//no meshers here
|
||||
}
|
||||
|
||||
//no meshers here
|
||||
|
||||
ERR_FAIL_COND_V(!chunk.is_valid(), NULL);
|
||||
|
||||
chunk->set_name("Chunk[" + String::num(x) + "," + String::num(y) + "," + String::num(z) + "]");
|
||||
@ -424,8 +436,6 @@ Ref<VoxelChunk> VoxelWorld::_create_chunk(const int x, const int y, const int z,
|
||||
|
||||
add_chunk(chunk, x, y, z);
|
||||
|
||||
add_to_generation_queue(chunk);
|
||||
|
||||
return chunk;
|
||||
}
|
||||
|
||||
@ -907,14 +917,9 @@ void VoxelWorld::_notification(int p_what) {
|
||||
Ref<VoxelChunk> chunk = _chunks_vector[i];
|
||||
|
||||
if (chunk.is_valid()) {
|
||||
IntPos pos(chunk->get_position_x(), chunk->get_position_y(), chunk->get_position_z());
|
||||
setup_chunk(chunk);
|
||||
|
||||
chunk->set_voxel_world(this);
|
||||
chunk->world_transform_changed();
|
||||
|
||||
_chunks.set(pos, chunk);
|
||||
|
||||
chunk->enter_tree();
|
||||
chunk->build();
|
||||
}
|
||||
}
|
||||
} break;
|
||||
@ -1136,6 +1141,7 @@ void VoxelWorld::_bind_methods() {
|
||||
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);
|
||||
ClassDB::bind_method(D_METHOD("setup_chunk", "chunk"), &VoxelWorld::setup_chunk);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("_generate_chunk", "chunk"), &VoxelWorld::_generate_chunk);
|
||||
|
||||
|
@ -149,6 +149,7 @@ public:
|
||||
|
||||
Ref<VoxelChunk> get_or_create_chunk(const int x, const int y, const int z);
|
||||
Ref<VoxelChunk> create_chunk(const int x, const int y, const int z);
|
||||
void setup_chunk(Ref<VoxelChunk> chunk);
|
||||
|
||||
void generate_chunk(Ref<VoxelChunk> chunk);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user