Chunk is invisible until being surrounded by chunks in every direction
This commit is contained in:
@@ -17,6 +17,7 @@ public:
|
|||||||
bool modified = true;
|
bool modified = true;
|
||||||
bool ready = false;
|
bool ready = false;
|
||||||
bool loaded = false;
|
bool loaded = false;
|
||||||
|
int surrounding = 0;
|
||||||
int references = 1;
|
int references = 1;
|
||||||
Chunk(int x, int y, int z);
|
Chunk(int x, int y, int z);
|
||||||
~Chunk();
|
~Chunk();
|
||||||
|
|||||||
@@ -13,6 +13,8 @@
|
|||||||
|
|
||||||
ChunksController::ChunksController(Chunks* chunks, Lighting* lighting) : chunks(chunks), lighting(lighting){
|
ChunksController::ChunksController(Chunks* chunks, Lighting* lighting) : chunks(chunks), lighting(lighting){
|
||||||
loadersCount = std::thread::hardware_concurrency() - 1;
|
loadersCount = std::thread::hardware_concurrency() - 1;
|
||||||
|
if (loadersCount <= 0)
|
||||||
|
loadersCount = 1;
|
||||||
loaders = new ChunksLoader*[loadersCount];
|
loaders = new ChunksLoader*[loadersCount];
|
||||||
for (int i = 0; i < loadersCount; i++){
|
for (int i = 0; i < loadersCount; i++){
|
||||||
loaders[i] = new ChunksLoader();
|
loaders[i] = new ChunksLoader();
|
||||||
@@ -54,8 +56,17 @@ bool ChunksController::loadVisible(WorldFiles* worldFiles){
|
|||||||
for (int x = 2; x < w-2; x++){
|
for (int x = 2; x < w-2; x++){
|
||||||
int index = (y * d + z) * w + x;
|
int index = (y * d + z) * w + x;
|
||||||
Chunk* chunk = chunks->chunks[index];
|
Chunk* chunk = chunks->chunks[index];
|
||||||
if (chunk != nullptr)
|
if (chunk != nullptr){
|
||||||
|
int surrounding = 0;
|
||||||
|
for (int oz = -1; oz <= 1; oz++){
|
||||||
|
for (int ox = -1; ox <= 1; ox++){
|
||||||
|
Chunk* other = chunks->getChunk(chunk->x+ox, chunk->y, chunk->z+oz);
|
||||||
|
if (other != nullptr) surrounding++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
chunk->surrounding = surrounding;
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
int lx = x - w / 2;
|
int lx = x - w / 2;
|
||||||
int ly = y - h / 2;
|
int ly = y - h / 2;
|
||||||
int lz = z - d / 2;
|
int lz = z - d / 2;
|
||||||
@@ -138,7 +149,7 @@ bool ChunksController::_buildMeshes(VoxelRenderer* renderer, int tick) {
|
|||||||
Mesh* mesh = chunks->meshes[index];
|
Mesh* mesh = chunks->meshes[index];
|
||||||
if (mesh != nullptr && !chunk->modified)
|
if (mesh != nullptr && !chunk->modified)
|
||||||
continue;
|
continue;
|
||||||
if (!chunk->ready){
|
if (!chunk->ready || chunk->surrounding < 9){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
int lx = x - w / 2;
|
int lx = x - w / 2;
|
||||||
|
|||||||
Reference in New Issue
Block a user