summaryrefslogtreecommitdiffstats
path: root/src/Simulator/IncrementalRedstoneSimulator/RedstoneWireHandler.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/RedstoneWireHandler.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 '')
-rw-r--r--src/Simulator/IncrementalRedstoneSimulator/RedstoneWireHandler.h112
1 files changed, 54 insertions, 58 deletions
diff --git a/src/Simulator/IncrementalRedstoneSimulator/RedstoneWireHandler.h b/src/Simulator/IncrementalRedstoneSimulator/RedstoneWireHandler.h
index 2772441bd..bbc1c212d 100644
--- a/src/Simulator/IncrementalRedstoneSimulator/RedstoneWireHandler.h
+++ b/src/Simulator/IncrementalRedstoneSimulator/RedstoneWireHandler.h
@@ -8,7 +8,7 @@
-class cRedstoneWireHandler final : public cRedstoneHandler
+namespace RedstoneWireHandler
{
/** A unified representation of wire direction. */
enum class TemporaryDirection
@@ -17,32 +17,10 @@ class cRedstoneWireHandler final : public cRedstoneHandler
Side
};
- /** Adjusts a given wire block so that the direction represented by Offset has state Direction. */
- inline static void SetDirectionState(const Vector3i Offset, short & Block, TemporaryDirection Direction)
- {
- Block = DoWithDirectionState(Offset, Block, [Direction](auto, auto & Front, auto)
- {
- using FrontState = std::remove_reference_t<decltype(Front)>;
- switch (Direction)
- {
- case TemporaryDirection::Up:
- {
- Front = FrontState::Up;
- return;
- }
- case TemporaryDirection::Side:
- {
- Front = FrontState::Side;
- return;
- }
- }
- });
- }
-
/** Invokes Callback with the wire's left, front, and right direction state corresponding to Offset.
Returns a new block constructed from the directions that the callback may have modified. */
template <class OffsetCallback>
- inline static short DoWithDirectionState(const Vector3i Offset, short Block, OffsetCallback Callback)
+ inline short DoWithDirectionState(const Vector3i Offset, short Block, OffsetCallback Callback)
{
auto North = Block::RedstoneWire::North(Block);
auto South = Block::RedstoneWire::South(Block);
@@ -70,11 +48,58 @@ class cRedstoneWireHandler final : public cRedstoneHandler
return Block::RedstoneWire::RedstoneWire(East, North, 0, South, West);
}
-public:
+ /** Adjusts a given wire block so that the direction represented by Offset has state Direction. */
+ inline void SetDirectionState(const Vector3i Offset, short & Block, TemporaryDirection Direction)
+ {
+ Block = DoWithDirectionState(Offset, Block, [Direction](auto, auto & Front, auto)
+ {
+ using FrontState = std::remove_reference_t<decltype(Front)>;
+ switch (Direction)
+ {
+ case TemporaryDirection::Up:
+ {
+ Front = FrontState::Up;
+ return;
+ }
+ case TemporaryDirection::Side:
+ {
+ Front = FrontState::Side;
+ return;
+ }
+ }
+ });
+ }
+
+ inline bool IsDirectlyConnectingMechanism(BLOCKTYPE a_Block, NIBBLETYPE a_BlockMeta, const Vector3i a_Offset)
+ {
+ switch (a_Block)
+ {
+ case E_BLOCK_REDSTONE_REPEATER_ON:
+ case E_BLOCK_REDSTONE_REPEATER_OFF:
+ {
+ a_BlockMeta &= E_META_REDSTONE_REPEATER_FACING_MASK;
+ if ((a_BlockMeta == E_META_REDSTONE_REPEATER_FACING_XP) || (a_BlockMeta == E_META_REDSTONE_REPEATER_FACING_XM))
+ {
+ // Wire connects to repeater if repeater is aligned along X
+ // and wire is in front or behind it (#4639)
+ return a_Offset.x != 0;
+ }
+
+ return a_Offset.z != 0;
+ }
+ case E_BLOCK_ACTIVE_COMPARATOR:
+ case E_BLOCK_INACTIVE_COMPARATOR:
+ case E_BLOCK_BLOCK_OF_REDSTONE:
+ case E_BLOCK_REDSTONE_TORCH_OFF:
+ case E_BLOCK_REDSTONE_TORCH_ON:
+ case E_BLOCK_REDSTONE_WIRE: return true;
+ default: return false;
+ }
+ }
/** Temporary. Discovers a wire's connection state, including terracing, storing the block inside redstone chunk data.
TODO: once the server supports block states this should go in the block handler, with data saved in the world. */
- void SetWireState(const cChunk & Chunk, const Vector3i Position) const
+ inline void SetWireState(const cChunk & Chunk, const Vector3i Position)
{
auto Block = Block::RedstoneWire::RedstoneWire();
const auto YPTerraceBlock = Chunk.GetBlock(Position + OffsetYP);
@@ -164,36 +189,7 @@ public:
DataForChunk(Chunk).WireStates[Position] = Block;
}
-private:
-
- inline static bool IsDirectlyConnectingMechanism(BLOCKTYPE a_Block, NIBBLETYPE a_BlockMeta, const Vector3i a_Offset)
- {
- switch (a_Block)
- {
- case E_BLOCK_REDSTONE_REPEATER_ON:
- case E_BLOCK_REDSTONE_REPEATER_OFF:
- {
- a_BlockMeta &= E_META_REDSTONE_REPEATER_FACING_MASK;
- if ((a_BlockMeta == E_META_REDSTONE_REPEATER_FACING_XP) || (a_BlockMeta == E_META_REDSTONE_REPEATER_FACING_XM))
- {
- // Wire connects to repeater if repeater is aligned along X
- // and wire is in front or behind it (#4639)
- return a_Offset.x != 0;
- }
-
- return a_Offset.z != 0;
- }
- case E_BLOCK_ACTIVE_COMPARATOR:
- case E_BLOCK_INACTIVE_COMPARATOR:
- case E_BLOCK_BLOCK_OF_REDSTONE:
- case E_BLOCK_REDSTONE_TORCH_OFF:
- case E_BLOCK_REDSTONE_TORCH_ON:
- case E_BLOCK_REDSTONE_WIRE: return true;
- default: return false;
- }
- }
-
- virtual unsigned char GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked) const override
+ inline unsigned char GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked)
{
// Starts off as the wire's meta value, modified appropriately and returned
auto Power = a_Chunk.GetMeta(a_Position);
@@ -257,7 +253,7 @@ private:
return Power;
}
- virtual void Update(cChunk & a_Chunk, cChunk & CurrentlyTicking, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData) const override
+ inline void Update(cChunk & a_Chunk, cChunk & CurrentlyTicking, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData)
{
// LOGD("Evaluating dusty the wire (%d %d %d) %i", a_Position.x, a_Position.y, a_Position.z, a_PoweringData.PowerLevel);
@@ -280,7 +276,7 @@ private:
}
}
- virtual void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, SourceCallback Callback) const override
+ inline void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, ForEachSourceCallback & Callback)
{
UNUSED(a_BlockType);
UNUSED(a_Meta);