diff options
Diffstat (limited to 'src/World/World.cpp')
| -rw-r--r-- | src/World/World.cpp | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/src/World/World.cpp b/src/World/World.cpp index a0b2b0d..d77ebe8 100644 --- a/src/World/World.cpp +++ b/src/World/World.cpp @@ -114,23 +114,28 @@ U64 World::timestamp() { void World::try_to_create_mesh_for_chunk(ChunkData& data) { auto index = data.index; - auto north = get({index.x, index.y - 1}); - auto east = get({index.x + 1, index.y}); - auto south = get({index.x, index.y + 1}); - auto west = get({index.x - 1, index.y}); + UInt neighbor_index = 0; + std::array<Chunk*, 8> neighbors; + for (I32 x = -1; x <= 1; x++) { + for (I32 y = -1; y <= 1; y++) { + if (x == 0 && y == 0) continue; - auto no_terrain = [](const ChunkData& d){ - return !d.chunk.has_value(); - }; + auto& neighbor_data = get({index.x + x, index.y + y}); + if (!neighbor_data.chunk.has_value()) return; // All neighbors need to be generated first. - if (no_terrain(north) || no_terrain(east) || no_terrain(south) || no_terrain(west)) { - return; + neighbors[neighbor_index++] = &neighbor_data.chunk.value(); + } } - data.mesh_data = Generation::ChunkMeshing::create_mesh_for_chunk( - data.chunk.value(), - {north.chunk.value(), east.chunk.value(), south.chunk.value(), west.chunk.value()} - ); + // Layout of neighboring chunks in `neighbors` array: + // (-1; -1) > (-1; 0) > (-1; 1) > (0; -1) + // ( 0; 1) > ( 1; -1) > ( 1; 0) > (1; 1) + Generation::ChunkMeshing::ChunkNeighbors chunk_neighbors { + neighbors[3], neighbors[6], neighbors[4], neighbors[1], + neighbors[5], neighbors[7], neighbors[2], neighbors[0], + }; + + data.mesh_data = create_mesh_for_chunk(data.chunk.value(), chunk_neighbors); data.mesh = GFX::Binder::load(data.mesh_data.value()); data.status = ChunkStatus::Done; } |
