summaryrefslogtreecommitdiffstats
path: root/src/Simulator/IncrementalRedstoneSimulator
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/Simulator/IncrementalRedstoneSimulator/ForEachSourceCallback.cpp4
-rw-r--r--src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.cpp4
-rw-r--r--src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.h2
-rw-r--r--src/Simulator/IncrementalRedstoneSimulator/PistonHandler.h2
-rw-r--r--src/Simulator/IncrementalRedstoneSimulator/PoweredRailHandler.h4
-rw-r--r--src/Simulator/IncrementalRedstoneSimulator/PressurePlateHandler.h4
-rw-r--r--src/Simulator/IncrementalRedstoneSimulator/RedstoneComparatorHandler.h2
-rw-r--r--src/Simulator/IncrementalRedstoneSimulator/RedstoneDataHelper.h16
-rw-r--r--src/Simulator/IncrementalRedstoneSimulator/RedstoneHandler.cpp103
-rw-r--r--src/Simulator/IncrementalRedstoneSimulator/RedstoneTorchHandler.h2
-rw-r--r--src/Simulator/IncrementalRedstoneSimulator/RedstoneWireHandler.h12
11 files changed, 85 insertions, 70 deletions
diff --git a/src/Simulator/IncrementalRedstoneSimulator/ForEachSourceCallback.cpp b/src/Simulator/IncrementalRedstoneSimulator/ForEachSourceCallback.cpp
index 4c676b405..d5433f25a 100644
--- a/src/Simulator/IncrementalRedstoneSimulator/ForEachSourceCallback.cpp
+++ b/src/Simulator/IncrementalRedstoneSimulator/ForEachSourceCallback.cpp
@@ -74,7 +74,7 @@ void ForEachSourceCallback::CheckIndirectPower()
ForEachSourceCallback QuasiQueryCallback(m_Chunk, Above, m_Chunk.GetBlock(Above));
// Manually feed the callback object all positions that may deliver power to Above:
- for (const auto QuasiPowerOffset : cSimulator::GetLinkedOffsets(OffsetYP))
+ for (const auto & QuasiPowerOffset : cSimulator::GetLinkedOffsets(OffsetYP))
{
QuasiQueryCallback(m_Position + QuasiPowerOffset);
}
@@ -116,7 +116,7 @@ PowerLevel ForEachSourceCallback::QueryLinkedPower(const cChunk & Chunk, const V
PowerLevel Power = 0;
// Loop through all linked powerable offsets in the direction requested:
- for (const auto Offset : cSimulator::GetLinkedOffsets(SolidBlockPosition - QueryPosition))
+ for (const auto & Offset : cSimulator::GetLinkedOffsets(SolidBlockPosition - QueryPosition))
{
auto SourcePosition = QueryPosition + Offset;
if (!cChunk::IsValidHeight(SourcePosition.y))
diff --git a/src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.cpp
index d9e4aa961..459cf672e 100644
--- a/src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.cpp
+++ b/src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.cpp
@@ -39,7 +39,7 @@ void cIncrementalRedstoneSimulator::SimulateChunk(std::chrono::milliseconds a_Dt
ProcessWorkItem(*NeighbourChunk, *a_Chunk, CurrentLocation);
}
- for (const auto Position : ChunkData.AlwaysTickedPositions)
+ for (const auto & Position : ChunkData.AlwaysTickedPositions)
{
ChunkData.WakeUp(Position);
}
@@ -119,7 +119,7 @@ void cIncrementalRedstoneSimulator::WakeUp(cChunk & a_Chunk, Vector3i a_Position
// The only thing to do go one block farther than this cross-coord, in the direction of Offset
// in order to notify linked-powered positions that there was a change
- for (const auto Offset : cSimulator::GetLinkedOffsets(a_Offset))
+ for (const auto & Offset : cSimulator::GetLinkedOffsets(a_Offset))
{
auto Relative = a_Position - a_Offset + Offset;
if (!cChunkDef::IsValidHeight(Relative.y))
diff --git a/src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.h b/src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.h
index dc00f73c7..cf08a672f 100644
--- a/src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.h
+++ b/src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.h
@@ -94,7 +94,7 @@ private:
}
}
- virtual void Simulate(float Dt) override {};
+ virtual void Simulate(float Dt) override {}
virtual void SimulateChunk(std::chrono::milliseconds Dt, int ChunkX, int ChunkZ, cChunk * Chunk) override;
void ProcessWorkItem(cChunk & Chunk, cChunk & TickingSource, const Vector3i Position);
diff --git a/src/Simulator/IncrementalRedstoneSimulator/PistonHandler.h b/src/Simulator/IncrementalRedstoneSimulator/PistonHandler.h
index 851b32498..e528788f7 100644
--- a/src/Simulator/IncrementalRedstoneSimulator/PistonHandler.h
+++ b/src/Simulator/IncrementalRedstoneSimulator/PistonHandler.h
@@ -53,7 +53,7 @@ namespace PistonHandler
const auto Face = cBlockPistonHandler::MetaDataToDirection(a_Meta);
const auto FrontOffset = AddFaceDirection(Vector3i(), Face);
- for (const auto Offset : RelativeAdjacents)
+ for (const auto & Offset : RelativeAdjacents)
{
if (Offset != FrontOffset)
{
diff --git a/src/Simulator/IncrementalRedstoneSimulator/PoweredRailHandler.h b/src/Simulator/IncrementalRedstoneSimulator/PoweredRailHandler.h
index b949db98b..6fa397c06 100644
--- a/src/Simulator/IncrementalRedstoneSimulator/PoweredRailHandler.h
+++ b/src/Simulator/IncrementalRedstoneSimulator/PoweredRailHandler.h
@@ -7,7 +7,9 @@
namespace PoweredRailHandler
{
- Vector3i GetPoweredRailAdjacentXZCoordinateOffset(NIBBLETYPE a_Meta) // Not in cBlockRailHandler since specific to powered rails
+ /** Get the offset along which the rail faces.
+ Not in cBlockRailHandler since specific to powered rails. */
+ inline Vector3i GetPoweredRailAdjacentXZCoordinateOffset(NIBBLETYPE a_Meta)
{
switch (a_Meta & 0x7)
{
diff --git a/src/Simulator/IncrementalRedstoneSimulator/PressurePlateHandler.h b/src/Simulator/IncrementalRedstoneSimulator/PressurePlateHandler.h
index 14d8c3017..46409b101 100644
--- a/src/Simulator/IncrementalRedstoneSimulator/PressurePlateHandler.h
+++ b/src/Simulator/IncrementalRedstoneSimulator/PressurePlateHandler.h
@@ -12,7 +12,7 @@ namespace PressurePlateHandler
{
inline unsigned char GetPowerLevel(const cChunk & Chunk, const Vector3i Position, const BLOCKTYPE BlockType)
{
- unsigned NumberOfEntities = 0;
+ Int64 NumberOfEntities = 0;
bool FoundPlayer = false;
Chunk.ForEachEntityInBox(cBoundingBox(Vector3d(0.5, 0, 0.5) + Position, 0.5, 0.5), [&](cEntity & Entity)
@@ -39,7 +39,7 @@ namespace PressurePlateHandler
}
case E_BLOCK_WOODEN_PRESSURE_PLATE:
{
- return (NumberOfEntities != 0 ? 15 : 0);
+ return (NumberOfEntities > 0 ? 15 : 0);
}
case E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE:
{
diff --git a/src/Simulator/IncrementalRedstoneSimulator/RedstoneComparatorHandler.h b/src/Simulator/IncrementalRedstoneSimulator/RedstoneComparatorHandler.h
index a1045cdbb..f62a7156f 100644
--- a/src/Simulator/IncrementalRedstoneSimulator/RedstoneComparatorHandler.h
+++ b/src/Simulator/IncrementalRedstoneSimulator/RedstoneComparatorHandler.h
@@ -113,7 +113,7 @@ namespace RedstoneComparatorHandler
const auto RearPower = GetPowerLevel(a_Chunk, a_Position, a_BlockType, a_Meta);
const auto FrontPower = GetFrontPowerLevel(a_Meta, Power, RearPower);
- const auto NewMeta = (FrontPower > 0) ? (a_Meta | 0x8) : (a_Meta & 0x7);
+ const NIBBLETYPE NewMeta = (FrontPower > 0) ? (a_Meta | 0x08u) : (a_Meta & 0x07u);
// Don't care about the previous power level so return value ignored
Data.ExchangeUpdateOncePowerData(a_Position, FrontPower);
diff --git a/src/Simulator/IncrementalRedstoneSimulator/RedstoneDataHelper.h b/src/Simulator/IncrementalRedstoneSimulator/RedstoneDataHelper.h
index 16d6924b1..2f827206f 100644
--- a/src/Simulator/IncrementalRedstoneSimulator/RedstoneDataHelper.h
+++ b/src/Simulator/IncrementalRedstoneSimulator/RedstoneDataHelper.h
@@ -12,7 +12,7 @@ inline void UpdateAdjustedRelative(const cChunk & From, const cChunk & To, const
{
DataForChunk(To).WakeUp(cIncrementalRedstoneSimulatorChunkData::RebaseRelativePosition(From, To, Position + Offset));
- for (const auto LinkedOffset : cSimulator::GetLinkedOffsets(Offset))
+ for (const auto & LinkedOffset : cSimulator::GetLinkedOffsets(Offset))
{
DataForChunk(To).WakeUp(cIncrementalRedstoneSimulatorChunkData::RebaseRelativePosition(From, To, Position + LinkedOffset));
}
@@ -21,7 +21,7 @@ inline void UpdateAdjustedRelative(const cChunk & From, const cChunk & To, const
template <typename ArrayType>
inline void UpdateAdjustedRelatives(const cChunk & From, const cChunk & To, const Vector3i Position, const ArrayType & Relative)
{
- for (const auto Offset : Relative)
+ for (const auto & Offset : Relative)
{
UpdateAdjustedRelative(From, To, Position, Offset);
}
@@ -30,12 +30,18 @@ inline void UpdateAdjustedRelatives(const cChunk & From, const cChunk & To, cons
template <typename ArrayType>
inline void InvokeForAdjustedRelatives(ForEachSourceCallback & Callback, const Vector3i Position, const ArrayType & Relative)
{
- for (const auto Offset : Relative)
+ for (const auto & Offset : Relative)
{
Callback(Position + Offset);
}
}
+// Warning shouldn't trigger for inline variables, this is fixed in clang 7
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wmissing-variable-declarations"
+#endif
+
inline constexpr Vector3i OffsetYP{ 0, 1, 0 };
inline constexpr Vector3i OffsetYM{ 0, -1, 0 };
@@ -61,3 +67,7 @@ inline constexpr std::array<Vector3i, 4> RelativeLaterals
{ 0, 0, -1 },
}
};
+
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
diff --git a/src/Simulator/IncrementalRedstoneSimulator/RedstoneHandler.cpp b/src/Simulator/IncrementalRedstoneSimulator/RedstoneHandler.cpp
index dc2c690f9..ff109c824 100644
--- a/src/Simulator/IncrementalRedstoneSimulator/RedstoneHandler.cpp
+++ b/src/Simulator/IncrementalRedstoneSimulator/RedstoneHandler.cpp
@@ -30,56 +30,59 @@
-#define INVOKE_FOR_HANDLERS(Callback) \
- switch (BlockType) \
- { \
- case E_BLOCK_ACTIVATOR_RAIL: \
- case E_BLOCK_DETECTOR_RAIL: \
- case E_BLOCK_POWERED_RAIL: return PoweredRailHandler::Callback; \
- case E_BLOCK_ACTIVE_COMPARATOR: \
- case E_BLOCK_INACTIVE_COMPARATOR: return RedstoneComparatorHandler::Callback; \
- case E_BLOCK_DISPENSER: \
- case E_BLOCK_DROPPER: return DropSpenserHandler::Callback; \
- case E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE: \
- case E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE: \
- case E_BLOCK_STONE_PRESSURE_PLATE: \
- case E_BLOCK_WOODEN_PRESSURE_PLATE: return PressurePlateHandler::Callback; \
- case E_BLOCK_ACACIA_FENCE_GATE: \
- case E_BLOCK_BIRCH_FENCE_GATE: \
- case E_BLOCK_DARK_OAK_FENCE_GATE: \
- case E_BLOCK_FENCE_GATE: \
- case E_BLOCK_IRON_TRAPDOOR: \
- case E_BLOCK_JUNGLE_FENCE_GATE: \
- case E_BLOCK_SPRUCE_FENCE_GATE: \
- case E_BLOCK_TRAPDOOR: return SmallGateHandler::Callback; \
- case E_BLOCK_REDSTONE_LAMP_OFF: \
- case E_BLOCK_REDSTONE_LAMP_ON: return RedstoneLampHandler::Callback; \
- case E_BLOCK_REDSTONE_REPEATER_OFF: \
- case E_BLOCK_REDSTONE_REPEATER_ON: return RedstoneRepeaterHandler::Callback; \
- case E_BLOCK_REDSTONE_TORCH_OFF: \
- case E_BLOCK_REDSTONE_TORCH_ON: return RedstoneTorchHandler::Callback; \
- case E_BLOCK_OBSERVER: return ObserverHandler::Callback; \
- case E_BLOCK_PISTON: \
- case E_BLOCK_STICKY_PISTON: return PistonHandler::Callback; \
- case E_BLOCK_LEVER: \
- case E_BLOCK_STONE_BUTTON: \
- case E_BLOCK_WOODEN_BUTTON: return RedstoneToggleHandler::Callback; \
- case E_BLOCK_BLOCK_OF_REDSTONE: return RedstoneBlockHandler::Callback; \
- case E_BLOCK_COMMAND_BLOCK: return CommandBlockHandler::Callback; \
- case E_BLOCK_HOPPER: return HopperHandler::Callback; \
- case E_BLOCK_NOTE_BLOCK: return NoteBlockHandler::Callback; \
- case E_BLOCK_REDSTONE_WIRE: return RedstoneWireHandler::Callback; \
- case E_BLOCK_TNT: return TNTHandler::Callback; \
- case E_BLOCK_TRAPPED_CHEST: return TrappedChestHandler::Callback; \
- case E_BLOCK_TRIPWIRE_HOOK: return TripwireHookHandler::Callback; \
- default: \
- { \
- if (cBlockDoorHandler::IsDoorBlockType(BlockType)) \
- { \
- return DoorHandler::Callback; \
- } \
- } \
- }
+#define INVOKE_FOR_HANDLERS(Callback) \
+ do \
+ { \
+ switch (BlockType) \
+ { \
+ case E_BLOCK_ACTIVATOR_RAIL: \
+ case E_BLOCK_DETECTOR_RAIL: \
+ case E_BLOCK_POWERED_RAIL: return PoweredRailHandler::Callback; \
+ case E_BLOCK_ACTIVE_COMPARATOR: \
+ case E_BLOCK_INACTIVE_COMPARATOR: return RedstoneComparatorHandler::Callback; \
+ case E_BLOCK_DISPENSER: \
+ case E_BLOCK_DROPPER: return DropSpenserHandler::Callback; \
+ case E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE: \
+ case E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE: \
+ case E_BLOCK_STONE_PRESSURE_PLATE: \
+ case E_BLOCK_WOODEN_PRESSURE_PLATE: return PressurePlateHandler::Callback; \
+ case E_BLOCK_ACACIA_FENCE_GATE: \
+ case E_BLOCK_BIRCH_FENCE_GATE: \
+ case E_BLOCK_DARK_OAK_FENCE_GATE: \
+ case E_BLOCK_FENCE_GATE: \
+ case E_BLOCK_IRON_TRAPDOOR: \
+ case E_BLOCK_JUNGLE_FENCE_GATE: \
+ case E_BLOCK_SPRUCE_FENCE_GATE: \
+ case E_BLOCK_TRAPDOOR: return SmallGateHandler::Callback; \
+ case E_BLOCK_REDSTONE_LAMP_OFF: \
+ case E_BLOCK_REDSTONE_LAMP_ON: return RedstoneLampHandler::Callback; \
+ case E_BLOCK_REDSTONE_REPEATER_OFF: \
+ case E_BLOCK_REDSTONE_REPEATER_ON: return RedstoneRepeaterHandler::Callback; \
+ case E_BLOCK_REDSTONE_TORCH_OFF: \
+ case E_BLOCK_REDSTONE_TORCH_ON: return RedstoneTorchHandler::Callback; \
+ case E_BLOCK_OBSERVER: return ObserverHandler::Callback; \
+ case E_BLOCK_PISTON: \
+ case E_BLOCK_STICKY_PISTON: return PistonHandler::Callback; \
+ case E_BLOCK_LEVER: \
+ case E_BLOCK_STONE_BUTTON: \
+ case E_BLOCK_WOODEN_BUTTON: return RedstoneToggleHandler::Callback; \
+ case E_BLOCK_BLOCK_OF_REDSTONE: return RedstoneBlockHandler::Callback; \
+ case E_BLOCK_COMMAND_BLOCK: return CommandBlockHandler::Callback; \
+ case E_BLOCK_HOPPER: return HopperHandler::Callback; \
+ case E_BLOCK_NOTE_BLOCK: return NoteBlockHandler::Callback; \
+ case E_BLOCK_REDSTONE_WIRE: return RedstoneWireHandler::Callback; \
+ case E_BLOCK_TNT: return TNTHandler::Callback; \
+ case E_BLOCK_TRAPPED_CHEST: return TrappedChestHandler::Callback; \
+ case E_BLOCK_TRIPWIRE_HOOK: return TripwireHookHandler::Callback; \
+ default: \
+ { \
+ if (cBlockDoorHandler::IsDoorBlockType(BlockType)) \
+ { \
+ return DoorHandler::Callback; \
+ } \
+ } \
+ } \
+ } while (false)
diff --git a/src/Simulator/IncrementalRedstoneSimulator/RedstoneTorchHandler.h b/src/Simulator/IncrementalRedstoneSimulator/RedstoneTorchHandler.h
index ac739d3b8..a2964ea38 100644
--- a/src/Simulator/IncrementalRedstoneSimulator/RedstoneTorchHandler.h
+++ b/src/Simulator/IncrementalRedstoneSimulator/RedstoneTorchHandler.h
@@ -75,7 +75,7 @@ namespace RedstoneTorchHandler
a_Chunk.FastSetBlock(a_Position, ShouldPowerOn ? E_BLOCK_REDSTONE_TORCH_ON : E_BLOCK_REDSTONE_TORCH_OFF, a_Meta);
Data.m_MechanismDelays.erase(a_Position);
- for (const auto Adjacent : RelativeAdjacents)
+ for (const auto & Adjacent : RelativeAdjacents)
{
// Update all adjacents (including linked power positions)
// apart from our attachment, which can't possibly need an update:
diff --git a/src/Simulator/IncrementalRedstoneSimulator/RedstoneWireHandler.h b/src/Simulator/IncrementalRedstoneSimulator/RedstoneWireHandler.h
index 0bf3d58f3..c97f37aa5 100644
--- a/src/Simulator/IncrementalRedstoneSimulator/RedstoneWireHandler.h
+++ b/src/Simulator/IncrementalRedstoneSimulator/RedstoneWireHandler.h
@@ -109,7 +109,7 @@ namespace RedstoneWireHandler
const bool IsYPTerracingBlocked = cBlockInfo::IsSolid(YPTerraceBlock) && !cBlockInfo::IsTransparent(YPTerraceBlock);
// Loop through laterals, discovering terracing connections:
- for (const auto Offset : RelativeLaterals)
+ for (const auto & Offset : RelativeLaterals)
{
auto Adjacent = Position + Offset;
auto NeighbourChunk = Chunk.GetRelNeighborChunkAdjustCoords(Adjacent);
@@ -268,7 +268,7 @@ namespace RedstoneWireHandler
a_Chunk.SetMeta(a_Position, Power);
// Notify all positions, sans YP, to update:
- for (const auto Offset : RelativeAdjacents)
+ for (const auto & Offset : RelativeAdjacents)
{
if (Offset == OffsetYP)
{
@@ -291,7 +291,7 @@ namespace RedstoneWireHandler
const auto Block = Data.WireStates.find(a_Position)->second;
// Figure out, based on our pre-computed block, where we connect to:
- for (const auto Offset : RelativeLaterals)
+ for (const auto & Offset : RelativeLaterals)
{
const auto Relative = a_Position + Offset;
Callback(Relative);
@@ -311,10 +311,10 @@ namespace RedstoneWireHandler
const auto YMDiagonalPosition = Relative + OffsetYM;
if (
- BLOCKTYPE Block;
+ BLOCKTYPE QueryBlock;
cChunkDef::IsValidHeight(YMDiagonalPosition.y) &&
- a_Chunk.UnboundedRelGetBlockType(YMDiagonalPosition, Block) &&
- (Block == E_BLOCK_REDSTONE_WIRE)
+ a_Chunk.UnboundedRelGetBlockType(YMDiagonalPosition, QueryBlock) &&
+ (QueryBlock == E_BLOCK_REDSTONE_WIRE)
)
{
Callback(YMDiagonalPosition);