summary refs log tree commit diff
path: root/src/World
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2023-12-07 02:14:47 +0100
committerMel <einebeere@gmail.com>2023-12-07 02:14:47 +0100
commitefd17623627607a26f33dac8f7ef1a1ddc931907 (patch)
tree76cf0389ae927bfc697c830155d926843178030e /src/World
parent581f50e0bd45a19282d7958975997d376512b195 (diff)
downloadmeowcraft-efd17623627607a26f33dac8f7ef1a1ddc931907.tar.zst
meowcraft-efd17623627607a26f33dac8f7ef1a1ddc931907.zip
Gather all possibly colliding blocks in the player move domain for collision detection
Diffstat (limited to 'src/World')
-rw-r--r--src/World/Chunk.hpp12
-rw-r--r--src/World/ChunkIndex.hpp4
2 files changed, 16 insertions, 0 deletions
diff --git a/src/World/Chunk.hpp b/src/World/Chunk.hpp
index ed3220d..9a29284 100644
--- a/src/World/Chunk.hpp
+++ b/src/World/Chunk.hpp
@@ -48,6 +48,18 @@ public:
     void set_details(const Details& details) { m_details = details; }
     Details& details(){ return m_details; }
 
+    template <typename F>
+    void for_each(F f) {
+        for (U32 x = 0; x < Width; ++x) {
+            for (U32 y = 0; y < Height; ++y) {
+                for (U32 z = 0; z < Width; ++z) {
+                    Position::BlockLocal pos{x, y, z};
+                    f(pos, at(x, y, z));
+                }
+            }
+        }
+    }
+
     ChunkIndex index() const;
     Vector<3> position() const;
 
diff --git a/src/World/ChunkIndex.hpp b/src/World/ChunkIndex.hpp
index 2e4fa67..bc61f3d 100644
--- a/src/World/ChunkIndex.hpp
+++ b/src/World/ChunkIndex.hpp
@@ -21,6 +21,10 @@ struct ChunkIndex {
         return {x * Width + local.x(), local.y(), y * Width + local.z()};
     }
 
+    Position::BlockWorld world_position() const {
+        return local_to_world_position({0, 0, 0});
+    }
+
     static ChunkIndex from_position(Position::BlockWorld pos) {
         I32 chunk_x = std::floor((Real)pos.x() / ChunkDimensions::Width);
         I32 chunk_y = std::floor((Real)pos.z() / ChunkDimensions::Width);