Minor refactor
This commit is contained in:
parent
3101b1b5f8
commit
eaf3f4e7a1
@ -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) {
|
||||
World* world = level->world;
|
||||
|
||||
auto chunk = std::shared_ptr<Chunk>(new Chunk(x, z));
|
||||
auto chunk = std::make_shared<Chunk>(x, z);
|
||||
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) {
|
||||
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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user