From eaf3f4e7a1468ef36605ebec67c40e08eefe9cd8 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Fri, 5 Jan 2024 14:59:53 +0300 Subject: [PATCH] Minor refactor --- src/voxels/ChunksStorage.cpp | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/voxels/ChunksStorage.cpp b/src/voxels/ChunksStorage.cpp index 082a17e5..57ba0400 100644 --- a/src/voxels/ChunksStorage.cpp +++ b/src/voxels/ChunksStorage.cpp @@ -39,27 +39,28 @@ void ChunksStorage::remove(int x, int z) { } } +void verifyLoadedChunk(ContentIndices* indices, Chunk* chunk) { + for (size_t i = 0; i < CHUNK_VOL; i++) { + blockid_t id = chunk->voxels[i].id; + if (indices->getBlockDef(id) == nullptr) { + std::cout << "corruped block detected at " << i << " of chunk "; + std::cout << chunk->x << "x" << chunk->z; + std::cout << " -> " << (int)id << std::endl; + chunk->voxels[i].id = 11; + } + } +} + std::shared_ptr ChunksStorage::create(int x, int z) { World* world = level->world; - auto chunk = std::shared_ptr(new Chunk(x, z)); + auto chunk = std::make_shared(x, z); store(chunk); - std::unique_ptr data(world->wfile->getChunk(chunk->x, chunk->z)); + std::unique_ptr data(world->wfile->getChunk(chunk->x, chunk->z)); if (data) { chunk->decode(data.get()); chunk->setLoaded(true); - } - - // Verifying and converting data - ContentIndices* indices = level->content->indices; - for (size_t i = 0; i < CHUNK_VOL; i++) { - blockid_t id = chunk->voxels[i].id; - if (indices->getBlockDef(id) == nullptr) { - std::cout << "corruped block detected at " << i << " of chunk "; - std::cout << chunk->x << "x" << chunk->z; - std::cout << " -> " << (int)id << std::endl; - chunk->voxels[i].id = 11; - } + verifyLoadedChunk(level->content->indices, chunk.get()); } light_t* lights = world->wfile->getLights(chunk->x, chunk->z);