summary refs log tree commit diff
path: root/src/World/Position.hpp
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2023-07-22 17:35:00 +0200
committerMel <einebeere@gmail.com>2023-07-22 17:35:00 +0200
commit2eef7cf49b7a15559ee7bb6719411bcf67386213 (patch)
tree11eb7a4f437da7bfdde620c10a043960fd423cfb /src/World/Position.hpp
parent23d88e5f1c8f0c8652a07050fcfa8ff126e85d4a (diff)
downloadmeowcraft-2eef7cf49b7a15559ee7bb6719411bcf67386213.tar.zst
meowcraft-2eef7cf49b7a15559ee7bb6719411bcf67386213.zip
Propagation in lighting system
Diffstat (limited to 'src/World/Position.hpp')
-rw-r--r--src/World/Position.hpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/World/Position.hpp b/src/World/Position.hpp
new file mode 100644
index 0000000..49cbbb6
--- /dev/null
+++ b/src/World/Position.hpp
@@ -0,0 +1,45 @@
+#pragma once
+
+#include "array"
+#include "../Math/Vector.hpp"
+
+namespace MC::World::Position {
+
+// Position within entire world.
+using World = Vector<3>;
+
+// Offset between block positions within single chunk.
+class OffsetBlock : public Vector<3, I8> {
+public:
+    OffsetBlock(I8 x, I8 y, I8 z) : Vector(x, y, z) {}
+    Bool fits_within_chunk() const {
+        using namespace ChunkDimensions;
+        return x() >= 0 && x() < Width && y() >= 0 && y() < Height && z() >= 0 && z() < Width;
+    }
+};
+
+// Position of a block within entire world.
+class BlockWorld : public Vector<3, I64> {
+public:
+    BlockWorld(I64 x, I64 y, I64 z) : Vector(x, y, z) {}
+};
+
+// Position of a block within single chunk.
+class BlockLocal : public Vector<3, U8> {
+public:
+    BlockLocal(U8 x, U8 y, U8 z) : Vector(x, y, z) {}
+    BlockLocal(OffsetBlock offset) : BlockLocal(offset.x(), offset.y(), offset.z()) {}
+    OffsetBlock offset(OffsetBlock by) {
+        return {
+            static_cast<I8>(x() + by.x()),
+            static_cast<I8>(y() + by.y()),
+            static_cast<I8>(z() + by.z())
+        };
+    }
+};
+
+const std::array<OffsetBlock, 6> axis_directions = {{
+    {1, 0, 0}, {-1, 0, 0}, {0, 1, 0}, {0, -1, 0}, {0, 0, 1}, {0, 0, -1},
+}};
+
+}