summary refs log tree commit diff
path: root/src/World/Generation/ChunkNeighbors.cpp
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2023-07-29 03:31:42 +0200
committerMel <einebeere@gmail.com>2023-07-29 03:31:42 +0200
commit6b69d4b5b648253f894707723af0e2eae9f71445 (patch)
tree0cd0b6c7b18c30abbb2618f553f144d1d06dacba /src/World/Generation/ChunkNeighbors.cpp
parent2eef7cf49b7a15559ee7bb6719411bcf67386213 (diff)
downloadmeowcraft-6b69d4b5b648253f894707723af0e2eae9f71445.tar.zst
meowcraft-6b69d4b5b648253f894707723af0e2eae9f71445.zip
Move chunk reification to worker threads and set stage for chunk-unbound lighting
Diffstat (limited to 'src/World/Generation/ChunkNeighbors.cpp')
-rw-r--r--src/World/Generation/ChunkNeighbors.cpp26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/World/Generation/ChunkNeighbors.cpp b/src/World/Generation/ChunkNeighbors.cpp
index f34466e..c3ae5cb 100644
--- a/src/World/Generation/ChunkNeighbors.cpp
+++ b/src/World/Generation/ChunkNeighbors.cpp
@@ -2,7 +2,28 @@
 
 namespace MC::World::Generation {
 
-Chunk::BlockData get_block_wrapping(const Chunk& chunk, const ChunkNeighbors& neighbors, Vector<3, I32> pos) {
+ChunkNeighbors find_chunk_neighbors(ChunkIndex chunk, ChunkRegistry& chunks) {
+    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& neighbor_data = chunks.get({chunk.x + x, chunk.y + y});
+            if (neighbor_data.chunk.has_value()) neighbors[neighbor_index++] = &neighbor_data.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)
+    return {
+        neighbors[3], neighbors[6], neighbors[4], neighbors[1],
+        neighbors[5], neighbors[7], neighbors[2], neighbors[0],
+    };
+}
+
+GetBlockWrappingResult get_block_wrapping(const Chunk& chunk, const ChunkNeighbors& neighbors, Vector<3, I32> pos) {
     const Chunk* chunk_to_ask;
 
     auto overflow = [](I32& c, I32 max) -> I8 {
@@ -28,7 +49,8 @@ Chunk::BlockData get_block_wrapping(const Chunk& chunk, const ChunkNeighbors& ne
     else if (zo == -1) { chunk_to_ask = neighbors.north; }
     else { chunk_to_ask = &chunk; }
 
-    return chunk_to_ask->at(pos.x(), pos.y(), pos.z());
+    if (!chunk_to_ask) return {false};
+    return {true, chunk_to_ask->at(pos.x(), pos.y(), pos.z())};
 }
 
 }
\ No newline at end of file