chunkmesher: use goto for error handling
parent
d0ddf2256f
commit
1822911845
|
@ -51,21 +51,10 @@ 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};
|
||||||
|
@ -73,6 +62,12 @@ void mesh(Chunk::Chunk* chunk)
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue