diff options
Diffstat (limited to 'src/Simulator/IncrementalRedstoneSimulator/RedstoneToggleHandler.h')
-rw-r--r-- | src/Simulator/IncrementalRedstoneSimulator/RedstoneToggleHandler.h | 158 |
1 files changed, 89 insertions, 69 deletions
diff --git a/src/Simulator/IncrementalRedstoneSimulator/RedstoneToggleHandler.h b/src/Simulator/IncrementalRedstoneSimulator/RedstoneToggleHandler.h index 45682406d..cd8a4d45c 100644 --- a/src/Simulator/IncrementalRedstoneSimulator/RedstoneToggleHandler.h +++ b/src/Simulator/IncrementalRedstoneSimulator/RedstoneToggleHandler.h @@ -10,96 +10,116 @@ namespace RedstoneToggleHandler { - static Vector3i GetOffsetAttachedTo(Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta) +static Vector3i GetOffsetAttachedTo(Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta) +{ + switch (a_BlockType) { - switch (a_BlockType) + case E_BLOCK_LEVER: { - case E_BLOCK_LEVER: + switch (a_Meta & 0x7) { - switch (a_Meta & 0x7) + case 0x0: + 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 {0, -1, 0}; + default: { - case 0x0: - 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 { 0, -1, 0 }; - default: - { - ASSERT(!"Unhandled lever metadata!"); - return { 0, 0, 0 }; - } + ASSERT(!"Unhandled lever metadata!"); + return {0, 0, 0}; } } - case E_BLOCK_STONE_BUTTON: - case E_BLOCK_WOODEN_BUTTON: + } + case E_BLOCK_STONE_BUTTON: + case E_BLOCK_WOODEN_BUTTON: + { + switch (a_Meta & 0x7) { - switch (a_Meta & 0x7) + 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: { - 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!"); - return { 0, 0, 0 }; - } + ASSERT(!"Unhandled button metadata!"); + return {0, 0, 0}; } } - default: - { - ASSERT(!"Unexpected block passed to button/lever handler"); - return { 0, 0, 0 }; - } } - } - - static unsigned char GetPowerLevel(BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta) - { - switch (a_BlockType) + default: { - case E_BLOCK_LEVER: return cBlockLeverHandler::IsLeverOn(a_Meta) ? 15 : 0; - case E_BLOCK_STONE_BUTTON: - case E_BLOCK_WOODEN_BUTTON: return cBlockButtonHandler::IsButtonOn(a_Meta) ? 15 : 0; - default: - { - ASSERT(!"Unexpected block passed to button/lever handler"); - return 0; - } + ASSERT(!"Unexpected block passed to button/lever handler"); + return {0, 0, 0}; } } +} - static PowerLevel GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked) +static unsigned char GetPowerLevel(BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta) +{ + switch (a_BlockType) { - UNUSED(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))) + case E_BLOCK_LEVER: return cBlockLeverHandler::IsLeverOn(a_Meta) ? 15 : 0; + case E_BLOCK_STONE_BUTTON: + case E_BLOCK_WOODEN_BUTTON: return cBlockButtonHandler::IsButtonOn(a_Meta) ? 15 : 0; + default: { + ASSERT(!"Unexpected block passed to button/lever handler"); return 0; } - - return GetPowerLevel(a_BlockType, Meta); } +} - static void Update(cChunk & a_Chunk, cChunk & CurrentlyTicking, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, const PowerLevel Power) - { - // LOGD("Evaluating templatio<> the lever/button (%d %d %d)", a_Position.x, a_Position.y, a_Position.z); - } +static PowerLevel GetPowerDeliveredToPosition( + const cChunk & a_Chunk, + Vector3i a_Position, + BLOCKTYPE a_BlockType, + Vector3i a_QueryPosition, + BLOCKTYPE a_QueryBlockType, + bool IsLinked +) +{ + UNUSED(a_QueryBlockType); + + const auto Meta = a_Chunk.GetMeta(a_Position); + const auto QueryOffset = a_QueryPosition - a_Position; - static void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, ForEachSourceCallback & Callback) + if (IsLinked && (QueryOffset != GetOffsetAttachedTo(a_Position, a_BlockType, Meta))) { - UNUSED(a_Chunk); - UNUSED(a_Position); - UNUSED(a_BlockType); - UNUSED(a_Meta); - UNUSED(Callback); + return 0; } -}; + + return GetPowerLevel(a_BlockType, Meta); +} + +static void Update( + cChunk & a_Chunk, + cChunk & CurrentlyTicking, + Vector3i a_Position, + BLOCKTYPE a_BlockType, + NIBBLETYPE a_Meta, + const PowerLevel Power +) +{ + // LOGD("Evaluating templatio<> the lever/button (%d %d %d)", a_Position.x, a_Position.y, a_Position.z); +} + +static void ForValidSourcePositions( + const cChunk & a_Chunk, + Vector3i a_Position, + BLOCKTYPE a_BlockType, + NIBBLETYPE a_Meta, + ForEachSourceCallback & Callback +) +{ + UNUSED(a_Chunk); + UNUSED(a_Position); + UNUSED(a_BlockType); + UNUSED(a_Meta); + UNUSED(Callback); +} +}; // namespace RedstoneToggleHandler |