diff options
author | Tiger Wang <ziwei.tiger@outlook.com> | 2020-08-08 19:22:16 +0200 |
---|---|---|
committer | Tiger Wang <ziwei.tiger@outlook.com> | 2020-08-08 19:22:16 +0200 |
commit | 40eba5244ddd7045a9c3539c5f46c9921301ed90 (patch) | |
tree | 9edf40e2e5033ad19ce8a0739668500e30de653e /src/Simulator/IncrementalRedstoneSimulator/RedstoneHandler.h | |
parent | const-ify some Chunk functions (diff) | |
download | cuberite-40eba5244ddd7045a9c3539c5f46c9921301ed90.tar cuberite-40eba5244ddd7045a9c3539c5f46c9921301ed90.tar.gz cuberite-40eba5244ddd7045a9c3539c5f46c9921301ed90.tar.bz2 cuberite-40eba5244ddd7045a9c3539c5f46c9921301ed90.tar.lz cuberite-40eba5244ddd7045a9c3539c5f46c9921301ed90.tar.xz cuberite-40eba5244ddd7045a9c3539c5f46c9921301ed90.tar.zst cuberite-40eba5244ddd7045a9c3539c5f46c9921301ed90.zip |
Diffstat (limited to 'src/Simulator/IncrementalRedstoneSimulator/RedstoneHandler.h')
-rw-r--r-- | src/Simulator/IncrementalRedstoneSimulator/RedstoneHandler.h | 67 |
1 files changed, 21 insertions, 46 deletions
diff --git a/src/Simulator/IncrementalRedstoneSimulator/RedstoneHandler.h b/src/Simulator/IncrementalRedstoneSimulator/RedstoneHandler.h index 79c410265..9b131ece2 100644 --- a/src/Simulator/IncrementalRedstoneSimulator/RedstoneHandler.h +++ b/src/Simulator/IncrementalRedstoneSimulator/RedstoneHandler.h @@ -2,6 +2,7 @@ #pragma once #include "../../Chunk.h" +#include "ForEachSourceCallback.h" #include "RedstoneSimulatorChunkData.h" @@ -15,71 +16,55 @@ public: cRedstoneHandler() = default; DISALLOW_COPY_AND_ASSIGN(cRedstoneHandler); - using SourceCallback = cFunctionRef<void(Vector3i)>; + using SourceCallback = ForEachSourceCallback &; - virtual unsigned char GetPowerDeliveredToPosition(cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType) const = 0; + virtual unsigned char GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked) const = 0; virtual void Update(cChunk & a_Chunk, cChunk & CurrentlyTicking, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData) const = 0; - virtual void ForValidSourcePositions(cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, SourceCallback Callback) const = 0; + virtual void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, SourceCallback Callback) const = 0; // Force a virtual destructor virtual ~cRedstoneHandler() {} protected: - template <class Container> - static Container StaticAppend(const Container & a_Lhs, const Container & a_Rhs) - { - Container ToReturn = a_Lhs; - std::copy(a_Rhs.begin(), a_Rhs.end(), std::back_inserter(ToReturn)); - return ToReturn; - } - - inline static Vector3i OffsetYP{ 0, 1, 0 }; - - inline static Vector3i OffsetYM{ 0, -1, 0 }; - - static cVector3iArray GetAdjustedRelatives(Vector3i a_Position, cVector3iArray a_Relatives) - { - for (auto & Entry : a_Relatives) - { - Entry += a_Position; - } - return a_Relatives; - } - - inline static cIncrementalRedstoneSimulatorChunkData & DataForChunk(cChunk & a_Chunk) + inline static auto & DataForChunk(const cChunk & a_Chunk) { return *static_cast<cIncrementalRedstoneSimulatorChunkData *>(a_Chunk.GetRedstoneSimulatorData()); } template <typename... ArrayTypes> - static void UpdateAdjustedRelative(cChunk & From, cChunk & To, const Vector3i Position) + static void UpdateAdjustedRelative(const cChunk & From, const cChunk & To, const Vector3i Position, const Vector3i Offset) { - DataForChunk(To).WakeUp(cIncrementalRedstoneSimulatorChunkData::RebaseRelativePosition(From, To, Position)); + 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, typename... ArrayTypes> - static void UpdateAdjustedRelatives(cChunk & From, cChunk & To, const Vector3i Position, const ArrayType & Relative, const ArrayTypes &... Relatives) + template <typename ArrayType> + static void UpdateAdjustedRelatives(const cChunk & From, const cChunk & To, const Vector3i Position, const ArrayType & Relative) { for (const auto Offset : Relative) { - DataForChunk(To).GetActiveBlocks().push(cIncrementalRedstoneSimulatorChunkData::RebaseRelativePosition(From, To, Position + Offset)); + UpdateAdjustedRelative(From, To, Position, Offset); } - - UpdateAdjustedRelatives(From, To, Position, Relatives...); } - template <typename ArrayType, typename... ArrayTypes> - static void InvokeForAdjustedRelatives(SourceCallback Callback, const Vector3i Position, const ArrayType & Relative, const ArrayTypes &... Relatives) + template <typename ArrayType> + static void InvokeForAdjustedRelatives(SourceCallback Callback, const Vector3i Position, const ArrayType & Relative) { for (const auto Offset : Relative) { Callback(Position + Offset); } - - InvokeForAdjustedRelatives(Callback, Position, Relatives...); } + inline static Vector3i OffsetYP{ 0, 1, 0 }; + + inline static Vector3i OffsetYM{ 0, -1, 0 }; + inline static std::array<Vector3i, 6> RelativeAdjacents { { @@ -101,14 +86,4 @@ protected: { 0, 0, -1 }, } }; - -private: - - static void UpdateAdjustedRelatives(cChunk &, cChunk &, const Vector3i) - { - } - - static void InvokeForAdjustedRelatives(SourceCallback, const Vector3i) - { - } }; |