From 40eba5244ddd7045a9c3539c5f46c9921301ed90 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 8 Aug 2020 18:22:16 +0100 Subject: Remove the redstone solid block handler - Remove cSolidBlockHandler * Functionality now integrated into simulator dispatcher * Fix door double open/close issues, arisen due to the top/bottom halves getting different power + Small migration to block states for redstone wire --- .../RedstoneToggleHandler.h | 43 ++++++++++++---------- 1 file changed, 23 insertions(+), 20 deletions(-) (limited to 'src/Simulator/IncrementalRedstoneSimulator/RedstoneToggleHandler.h') diff --git a/src/Simulator/IncrementalRedstoneSimulator/RedstoneToggleHandler.h b/src/Simulator/IncrementalRedstoneSimulator/RedstoneToggleHandler.h index bf9c639b1..b66ce47fd 100644 --- a/src/Simulator/IncrementalRedstoneSimulator/RedstoneToggleHandler.h +++ b/src/Simulator/IncrementalRedstoneSimulator/RedstoneToggleHandler.h @@ -11,9 +11,7 @@ class cRedstoneToggleHandler final : public cRedstoneHandler { -public: - - inline static Vector3i GetPositionAttachedTo(Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta) + inline static Vector3i GetOffsetAttachedTo(Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta) { switch (a_BlockType) { @@ -22,13 +20,13 @@ public: switch (a_Meta & 0x7) { case 0x0: - case 0x7: return { a_Position + Vector3i(0, 1, 0) }; - case 0x1: return { a_Position + Vector3i(-1, 0, 0) }; - case 0x2: return { a_Position + Vector3i(1, 0, 0) }; - case 0x3: return { a_Position + Vector3i(0, 0, -1) }; - case 0x4: return { a_Position + Vector3i(0, 0, 1) }; + case 0x7: return { 0, 1, 0 }; + case 0x1: return { -1, 0, 0 }; + case 0x2: return { 1, 0, 0 }; + case 0x3: return { 0, 0, -1 }; + case 0x4: return { 0, 0, 1 }; case 0x5: - case 0x6: return { a_Position + Vector3i(0, -1, 0) }; + case 0x6: return { 0, -1, 0 }; default: { ASSERT(!"Unhandled lever metadata!"); @@ -41,12 +39,12 @@ public: { switch (a_Meta & 0x7) { - case 0x0: return { a_Position + Vector3i(0, 1, 0) }; - case 0x1: return { a_Position + Vector3i(-1, 0, 0) }; - case 0x2: return { a_Position + Vector3i(1, 0, 0) }; - case 0x3: return { a_Position + Vector3i(0, 0, -1) }; - case 0x4: return { a_Position + Vector3i(0, 0, 1) }; - case 0x5: return { a_Position + Vector3i(0, -1, 0) }; + case 0x0: return { 0, 1, 0 }; + case 0x1: return { -1, 0, 0 }; + case 0x2: return { 1, 0, 0 }; + case 0x3: return { 0, 0, -1 }; + case 0x4: return { 0, 0, 1 }; + case 0x5: return { 0, -1, 0 }; default: { ASSERT(!"Unhandled button metadata!"); @@ -62,14 +60,19 @@ public: } } - virtual unsigned char GetPowerDeliveredToPosition(cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType) const override + virtual unsigned char GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked) const override { UNUSED(a_QueryBlockType); - if ((GetPositionAttachedTo(a_Position, a_BlockType, a_Meta) == a_QueryPosition) || cIncrementalRedstoneSimulator::IsMechanism(a_QueryBlockType)) + + const auto Meta = a_Chunk.GetMeta(a_Position); + const auto QueryOffset = a_QueryPosition - a_Position; + + if (IsLinked && (QueryOffset != GetOffsetAttachedTo(a_Position, a_BlockType, Meta))) { - return GetPowerLevel(a_BlockType, a_Meta); + return 0; } - return 0; + + return GetPowerLevel(a_BlockType, Meta); } static unsigned char GetPowerLevel(BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta) @@ -92,7 +95,7 @@ public: // LOGD("Evaluating templatio<> the lever/button (%d %d %d)", a_Position.x, a_Position.y, a_Position.z); } - virtual void ForValidSourcePositions(cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, SourceCallback Callback) const override + virtual void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, SourceCallback Callback) const override { UNUSED(a_Chunk); UNUSED(a_Position); -- cgit v1.2.3