summary refs log tree commit diff
path: root/src/World/Chunk.cpp
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2024-04-09 03:34:50 +0200
committerMel <einebeere@gmail.com>2024-04-09 03:34:50 +0200
commit22f3bad59de14b62c6680d10aff2cea5ac5b11dc (patch)
tree038add33df7ead1759bdd2ca9e2087fd55b1512f /src/World/Chunk.cpp
parent2ab9e650f814d47e78fc95500605b4561922893d (diff)
downloadmeowcraft-22f3bad59de14b62c6680d10aff2cea5ac5b11dc.tar.zst
meowcraft-22f3bad59de14b62c6680d10aff2cea5ac5b11dc.zip
Traverse all chunk blocks in a unified (and cache-friendly) way
Diffstat (limited to 'src/World/Chunk.cpp')
-rw-r--r--src/World/Chunk.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/World/Chunk.cpp b/src/World/Chunk.cpp
index b4a9ece..eeaefa0 100644
--- a/src/World/Chunk.cpp
+++ b/src/World/Chunk.cpp
@@ -39,10 +39,18 @@ Bool Chunk::is_valid_position(Position::BlockLocal pos) {
     return pos.x() < Width && pos.y() < Height && pos.z() < Width;
 }
 
-U64 Chunk::pos(U32 x, U32 y, U32 z) {
+U64 Chunk::pos(U32 const x, U32 const y, U32 const z) {
     return x + Width * y + Width * Height * z;
 }
 
+Position::BlockLocal Chunk::pos(U64 const i) {
+    return {
+        i % Width,
+        i / Width % Height,
+        i / (Width * Height)
+    };
+}
+
 AABB Chunk::block_bounds(Position::BlockLocal pos) {
     return {
         {pos.x(), pos.y(), pos.z()},