diff options
author | Tiger Wang <ziwei.tiger@hotmail.co.uk> | 2015-06-27 00:24:51 +0200 |
---|---|---|
committer | Tiger Wang <ziwei.tiger@hotmail.co.uk> | 2015-12-18 14:17:38 +0100 |
commit | 5b62c4c3145c08b093521e42c565922fa85de4ad (patch) | |
tree | dca8cbfe86aa27af174da21f6835a8fbbe83d248 /src/Simulator/IncrementalRedstoneSimulator/PoweredRailHandler.h | |
parent | Merge pull request #2770 from cuberite/RemoveChunkDataCollector (diff) | |
download | cuberite-5b62c4c3145c08b093521e42c565922fa85de4ad.tar cuberite-5b62c4c3145c08b093521e42c565922fa85de4ad.tar.gz cuberite-5b62c4c3145c08b093521e42c565922fa85de4ad.tar.bz2 cuberite-5b62c4c3145c08b093521e42c565922fa85de4ad.tar.lz cuberite-5b62c4c3145c08b093521e42c565922fa85de4ad.tar.xz cuberite-5b62c4c3145c08b093521e42c565922fa85de4ad.tar.zst cuberite-5b62c4c3145c08b093521e42c565922fa85de4ad.zip |
Diffstat (limited to 'src/Simulator/IncrementalRedstoneSimulator/PoweredRailHandler.h')
-rw-r--r-- | src/Simulator/IncrementalRedstoneSimulator/PoweredRailHandler.h | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/src/Simulator/IncrementalRedstoneSimulator/PoweredRailHandler.h b/src/Simulator/IncrementalRedstoneSimulator/PoweredRailHandler.h new file mode 100644 index 000000000..c0c47a324 --- /dev/null +++ b/src/Simulator/IncrementalRedstoneSimulator/PoweredRailHandler.h @@ -0,0 +1,100 @@ + +#pragma once + +#include "RedstoneHandler.h" + + + + + +class cPoweredRailHandler : public cRedstoneHandler +{ + typedef cRedstoneHandler super; +public: + + cPoweredRailHandler(cWorld & a_World) : + super(a_World) + { + } + + static const Vector3i GetPoweredRailAdjacentXZCoordinateOffset(NIBBLETYPE a_Meta) // Not in cBlockRailHandler since specific to powered rails + { + switch (a_Meta & 0x7) + { + case E_META_RAIL_ZM_ZP: return { 0, 0, 1 }; + case E_META_RAIL_XM_XP: return { 1, 0, 0 }; + case E_META_RAIL_ASCEND_XP: return { 1, 1, 0 }; + case E_META_RAIL_ASCEND_XM: return { 1, 1, 0 }; + case E_META_RAIL_ASCEND_ZM: return { 0, 1, 1 }; + case E_META_RAIL_ASCEND_ZP: return { 0, 1, 1 }; + default: + { + ASSERT(!"Impossible rail meta! wat wat wat"); + return { 0, 0, 0 }; + } + } + } + + virtual unsigned char GetPowerDeliveredToPosition(const Vector3i & a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, const Vector3i & a_QueryPosition, BLOCKTYPE a_QueryBlockType) override + { + UNUSED(a_QueryBlockType); + + auto Offset = GetPoweredRailAdjacentXZCoordinateOffset(a_Meta); + if (((Offset + a_Position) == a_QueryPosition) || ((-Offset + a_Position) == a_QueryPosition)) + { + auto Power = GetPowerLevel(a_Position, a_BlockType, a_Meta); + return (Power <= 7) ? 0 : --Power; + } + return 0; + } + + virtual unsigned char GetPowerLevel(const Vector3i & a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta) override + { + UNUSED(a_BlockType); + UNUSED(a_Meta); + return static_cast<cIncrementalRedstoneSimulator *>(m_World.GetRedstoneSimulator())->GetChunkData()->GetCachedPowerData(a_Position).PowerLevel; + } + + virtual cVector3iArray Update(const Vector3i & a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData) override + { + LOGD("Evaluating tracky the rail (%d %d %d)", a_Position.x, a_Position.y, a_Position.z); + + switch (a_BlockType) + { + case E_BLOCK_DETECTOR_RAIL: + { + /* + if ((m_Chunk->GetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ) & 0x08) == 0x08) + { + SetAllDirsAsPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ, a_MyType); + } + */ + return {}; + } + case E_BLOCK_ACTIVATOR_RAIL: + case E_BLOCK_POWERED_RAIL: + { + auto Offset = GetPoweredRailAdjacentXZCoordinateOffset(a_Meta); + if (a_PoweringData != static_cast<cIncrementalRedstoneSimulator *>(m_World.GetRedstoneSimulator())->GetChunkData()->ExchangeUpdateOncePowerData(a_Position, a_PoweringData)) + { + m_World.SetBlockMeta(a_Position, (a_PoweringData.PowerLevel == 0) ? (a_Meta & 0x07) : (a_Meta | 0x08)); + return cVector3iArray{ { Offset + a_Position }, { -Offset + a_Position } }; + } + + return {}; + } + default: + { + ASSERT(!"Unhandled type of rail in passed to rail handler!"); + return {}; + } + } + } + + virtual cVector3iArray GetValidSourcePositions(const Vector3i & a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta) override + { + UNUSED(a_BlockType); + UNUSED(a_Meta); + return GetAdjustedRelatives(a_Position, GetRelativeAdjacents()); + } +}; |