summaryrefslogtreecommitdiffstats
path: root/src/Simulator/IncrementalRedstoneSimulator/RedstoneDataHelper.h
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@outlook.com>2020-08-19 22:14:40 +0200
committerTiger Wang <ziwei.tiger@outlook.com>2020-08-21 01:50:09 +0200
commit3143d6ce679f322ee73d3d70e2d843e9c98cc043 (patch)
tree8ccc3b6d2a22a848e0c01c667aa10b25c3a5684e /src/Simulator/IncrementalRedstoneSimulator/RedstoneDataHelper.h
parentMinor typo fixes (diff)
downloadcuberite-3143d6ce679f322ee73d3d70e2d843e9c98cc043.tar
cuberite-3143d6ce679f322ee73d3d70e2d843e9c98cc043.tar.gz
cuberite-3143d6ce679f322ee73d3d70e2d843e9c98cc043.tar.bz2
cuberite-3143d6ce679f322ee73d3d70e2d843e9c98cc043.tar.lz
cuberite-3143d6ce679f322ee73d3d70e2d843e9c98cc043.tar.xz
cuberite-3143d6ce679f322ee73d3d70e2d843e9c98cc043.tar.zst
cuberite-3143d6ce679f322ee73d3d70e2d843e9c98cc043.zip
Diffstat (limited to 'src/Simulator/IncrementalRedstoneSimulator/RedstoneDataHelper.h')
-rw-r--r--src/Simulator/IncrementalRedstoneSimulator/RedstoneDataHelper.h63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/Simulator/IncrementalRedstoneSimulator/RedstoneDataHelper.h b/src/Simulator/IncrementalRedstoneSimulator/RedstoneDataHelper.h
new file mode 100644
index 000000000..16d6924b1
--- /dev/null
+++ b/src/Simulator/IncrementalRedstoneSimulator/RedstoneDataHelper.h
@@ -0,0 +1,63 @@
+#pragma once
+
+#include "../../Chunk.h"
+
+inline auto & DataForChunk(const cChunk & a_Chunk)
+{
+ return *static_cast<cIncrementalRedstoneSimulatorChunkData *>(a_Chunk.GetRedstoneSimulatorData());
+}
+
+template <typename... ArrayTypes>
+inline void UpdateAdjustedRelative(const cChunk & From, const cChunk & To, const Vector3i Position, const Vector3i Offset)
+{
+ DataForChunk(To).WakeUp(cIncrementalRedstoneSimulatorChunkData::RebaseRelativePosition(From, To, Position + Offset));
+
+ for (const auto LinkedOffset : cSimulator::GetLinkedOffsets(Offset))
+ {
+ DataForChunk(To).WakeUp(cIncrementalRedstoneSimulatorChunkData::RebaseRelativePosition(From, To, Position + LinkedOffset));
+ }
+}
+
+template <typename ArrayType>
+inline void UpdateAdjustedRelatives(const cChunk & From, const cChunk & To, const Vector3i Position, const ArrayType & Relative)
+{
+ for (const auto Offset : Relative)
+ {
+ UpdateAdjustedRelative(From, To, Position, Offset);
+ }
+}
+
+template <typename ArrayType>
+inline void InvokeForAdjustedRelatives(ForEachSourceCallback & Callback, const Vector3i Position, const ArrayType & Relative)
+{
+ for (const auto Offset : Relative)
+ {
+ Callback(Position + Offset);
+ }
+}
+
+inline constexpr Vector3i OffsetYP{ 0, 1, 0 };
+
+inline constexpr Vector3i OffsetYM{ 0, -1, 0 };
+
+inline constexpr std::array<Vector3i, 6> RelativeAdjacents
+{
+ {
+ { 1, 0, 0 },
+ { -1, 0, 0 },
+ { 0, 1, 0 },
+ { 0, -1, 0 },
+ { 0, 0, 1 },
+ { 0, 0, -1 },
+ }
+};
+
+inline constexpr std::array<Vector3i, 4> RelativeLaterals
+{
+ {
+ { 1, 0, 0 },
+ { -1, 0, 0 },
+ { 0, 0, 1 },
+ { 0, 0, -1 },
+ }
+};