Minor refactor

This commit is contained in:
MihailRis
2024-01-05 14:59:53 +03:00
parent 3101b1b5f8
commit eaf3f4e7a1
+14 -13
View File
@@ -39,19 +39,7 @@ void ChunksStorage::remove(int x, int z) {
} }
} }
std::shared_ptr<Chunk> ChunksStorage::create(int x, int z) { void verifyLoadedChunk(ContentIndices* indices, Chunk* chunk) {
World* world = level->world;
auto chunk = std::shared_ptr<Chunk>(new Chunk(x, z));
store(chunk);
std::unique_ptr<ubyte> 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++) { for (size_t i = 0; i < CHUNK_VOL; i++) {
blockid_t id = chunk->voxels[i].id; blockid_t id = chunk->voxels[i].id;
if (indices->getBlockDef(id) == nullptr) { if (indices->getBlockDef(id) == nullptr) {
@@ -61,6 +49,19 @@ std::shared_ptr<Chunk> ChunksStorage::create(int x, int z) {
chunk->voxels[i].id = 11; chunk->voxels[i].id = 11;
} }
} }
}
std::shared_ptr<Chunk> ChunksStorage::create(int x, int z) {
World* world = level->world;
auto chunk = std::make_shared<Chunk>(x, z);
store(chunk);
std::unique_ptr<ubyte[]> data(world->wfile->getChunk(chunk->x, chunk->z));
if (data) {
chunk->decode(data.get());
chunk->setLoaded(true);
verifyLoadedChunk(level->content->indices, chunk.get());
}
light_t* lights = world->wfile->getLights(chunk->x, chunk->z); light_t* lights = world->wfile->getLights(chunk->x, chunk->z);
if (lights) { if (lights) {