chunkmesher: use goto for error handling

pull/13/head
EmaMaker 2023-10-04 12:12:29 +02:00
parent d0ddf2256f
commit 1822911845
1 changed files with 9 additions and 13 deletions

View File

@ -51,28 +51,23 @@ void mesh(Chunk::Chunk* chunk)
mesh_data->index = chunk->getIndex(); mesh_data->index = chunk->getIndex();
mesh_data->position = chunk->getPosition(); mesh_data->position = chunk->getPosition();
// Abort if chunk is empty
if(chunk->getState(Chunk::CHUNK_STATE_EMPTY)){
chunk->setState(Chunk::CHUNK_STATE_MESHED, true);
renderer::getMeshDataQueue().push(mesh_data);
return;
}
// convert tree to array since it is easier to work with it // convert tree to array since it is easier to work with it
int length{0}; int length{0};
std::unique_ptr<Block[]> blocks = chunk->getBlocksArray(&length); std::unique_ptr<Block[]> blocks;
if(length == 0) {
chunk->setState(Chunk::CHUNK_STATE_MESHED, true);
renderer::getMeshDataQueue().push(mesh_data);
return;
}
int k, l, u, v, w, h, n, j, i; int k, l, u, v, w, h, n, j, i;
int x[]{0, 0, 0}; int x[]{0, 0, 0};
int q[]{0, 0, 0}; int q[]{0, 0, 0};
int du[]{0, 0, 0}; int du[]{0, 0, 0};
int dv[]{0, 0, 0}; int dv[]{0, 0, 0};
// Abort if chunk is empty
if(chunk->getState(Chunk::CHUNK_STATE_EMPTY)) goto end;
blocks = chunk->getBlocksArray(&length);
if(length == 0) goto end;
std::array<Block, CHUNK_SIZE * CHUNK_SIZE> mask; std::array<Block, CHUNK_SIZE * CHUNK_SIZE> mask;
for (bool backFace = true, b = false; b != backFace; backFace = backFace && b, b = !b) for (bool backFace = true, b = false; b != backFace; backFace = backFace && b, b = !b)
{ {
@ -227,6 +222,7 @@ void mesh(Chunk::Chunk* chunk)
} }
} }
end:
chunk->setState(Chunk::CHUNK_STATE_MESHED, true); chunk->setState(Chunk::CHUNK_STATE_MESHED, true);
renderer::getMeshDataQueue().push(mesh_data); renderer::getMeshDataQueue().push(mesh_data);
} }