diff options
| author | Mel <einebeere@gmail.com> | 2023-07-09 20:51:30 +0200 |
|---|---|---|
| committer | Mel <einebeere@gmail.com> | 2023-07-09 20:51:30 +0200 |
| commit | 680d9d5b7a61ac955fcec8a5622faa5cf4165c11 (patch) | |
| tree | 385ada2ac5e666ff4e89e073850c9e1a9b29c99e /src/World/World.cpp | |
| parent | fe2baedc760c2f29e2c720f6b1132a2de33c5430 (diff) | |
| download | meowcraft-680d9d5b7a61ac955fcec8a5622faa5cf4165c11.tar.zst meowcraft-680d9d5b7a61ac955fcec8a5622faa5cf4165c11.zip | |
Ambient occlusion (without corners)
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; } |
