Fix set_chunks, and enter_tree.

This commit is contained in:
Relintai 2020-04-06 00:51:25 +02:00
parent b046db78ed
commit d717c9886b
2 changed files with 25 additions and 3 deletions

View File

@ -364,14 +364,27 @@ Vector<Variant> VoxelWorld::get_chunks() {
}
void VoxelWorld::set_chunks(const Vector<Variant> &chunks) {
clear();
for (int i = 0; i < chunks.size(); i++) {
for (int i = 0; i < _chunks_vector.size(); ++i) {
Ref<VoxelChunk> chunk = Ref<VoxelChunk>(_chunks_vector[i]);
if (chunks.find(chunk) == -1) {
remove_chunk_index(i);
_generation_queue.erase(chunk);
_generating.erase(chunk);
--i;
}
}
for (int i = 0; i < chunks.size(); ++i) {
Ref<VoxelChunk> chunk = Ref<VoxelChunk>(chunks[i]);
if (!chunk.is_valid())
continue;
if (_chunks_vector.find(chunk) != -1)
continue;
add_chunk(chunk, chunk->get_position_x(), chunk->get_position_y(), chunk->get_position_z());
}
}
@ -434,7 +447,16 @@ 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());
chunk->set_voxel_world(this);
chunk->world_transform_changed();
_chunks.set(pos, chunk);
chunk->enter_tree();
chunk->build();
}
}
} break;

View File

@ -35,7 +35,7 @@ SOFTWARE.
#include "voxel_chunk.h"
bool VoxelWorldEditor::forward_spatial_input_event(Camera *p_camera, const Ref<InputEvent> &p_event) {
if (!_world && !_world->get_editable()) {
if (!_world || !_world->get_editable()) {
return false;
}