Minor refactor
This commit is contained in:
@@ -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<Chunk> ChunksStorage::create(int x, int z) {
|
std::shared_ptr<Chunk> ChunksStorage::create(int x, int z) {
|
||||||
World* world = level->world;
|
World* world = level->world;
|
||||||
|
|
||||||
auto chunk = std::shared_ptr<Chunk>(new Chunk(x, z));
|
auto chunk = std::make_shared<Chunk>(x, z);
|
||||||
store(chunk);
|
store(chunk);
|
||||||
std::unique_ptr<ubyte> data(world->wfile->getChunk(chunk->x, chunk->z));
|
std::unique_ptr<ubyte[]> data(world->wfile->getChunk(chunk->x, chunk->z));
|
||||||
if (data) {
|
if (data) {
|
||||||
chunk->decode(data.get());
|
chunk->decode(data.get());
|
||||||
chunk->setLoaded(true);
|
chunk->setLoaded(true);
|
||||||
}
|
verifyLoadedChunk(level->content->indices, chunk.get());
|
||||||
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
light_t* lights = world->wfile->getLights(chunk->x, chunk->z);
|
light_t* lights = world->wfile->getLights(chunk->x, chunk->z);
|
||||||
|
|||||||
Reference in New Issue
Block a user