summaryrefslogtreecommitdiffstats
path: root/src/Simulator/IncrementalRedstoneSimulator/ObserverHandler.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/Simulator/IncrementalRedstoneSimulator/ObserverHandler.h')
-rw-r--r--src/Simulator/IncrementalRedstoneSimulator/ObserverHandler.h44
1 files changed, 19 insertions, 25 deletions
diff --git a/src/Simulator/IncrementalRedstoneSimulator/ObserverHandler.h b/src/Simulator/IncrementalRedstoneSimulator/ObserverHandler.h
index b4af66aff..a3c055844 100644
--- a/src/Simulator/IncrementalRedstoneSimulator/ObserverHandler.h
+++ b/src/Simulator/IncrementalRedstoneSimulator/ObserverHandler.h
@@ -8,7 +8,7 @@
-class cObserverHandler : public cRedstoneHandler
+class cObserverHandler final : public cRedstoneHandler
{
public:
@@ -17,24 +17,24 @@ public:
return (a_Meta & 0x8) == 0x8;
}
- static bool ShouldPowerOn(cWorld & a_World, const Vector3i a_Position, NIBBLETYPE a_Meta, cIncrementalRedstoneSimulatorChunkData * a_Data)
+ static bool ShouldPowerOn(cChunk & Chunk, const Vector3i a_Position, NIBBLETYPE a_Meta, cIncrementalRedstoneSimulatorChunkData & a_Data)
{
BLOCKTYPE BlockType;
NIBBLETYPE BlockMeta;
- if (!a_World.GetBlockTypeMeta(a_Position + cBlockObserverHandler::GetObservingFaceOffset(a_Meta), BlockType, BlockMeta))
+ if (!Chunk.UnboundedRelGetBlock(a_Position + cBlockObserverHandler::GetObservingFaceOffset(a_Meta), BlockType, BlockMeta))
{
return false;
}
// Cache the last seen block type and meta in the power data for this position
auto Observed = PoweringData(BlockType, BlockMeta);
- auto Previous = a_Data->ExchangeUpdateOncePowerData(a_Position, Observed);
+ auto Previous = a_Data.ExchangeUpdateOncePowerData(a_Position, Observed);
// Determine if to signal an update based on the block previously observed changed
return (Previous.PoweringBlock != Observed.PoweringBlock) || (Previous.PowerLevel != Observed.PowerLevel);
}
- virtual unsigned char GetPowerDeliveredToPosition(cWorld & a_World, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType) const override
+ virtual unsigned char GetPowerDeliveredToPosition(cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType) const override
{
if (IsOn(a_Meta) && (a_QueryPosition == (a_Position + cBlockObserverHandler::GetSignalOutputOffset(a_Meta))))
{
@@ -44,30 +44,25 @@ public:
return 0;
}
- virtual unsigned char GetPowerLevel(cWorld & a_World, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta) const override
- {
- return IsOn(a_BlockType) ? 15 : 0;
- }
-
- virtual cVector3iArray Update(cWorld & a_World, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData) const override
+ virtual void Update(cChunk & a_Chunk, cChunk & CurrentlyTicking, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData) const override
{
// LOGD("Evaluating Lenny the observer (%i %i %i)", a_Position.x, a_Position.y, a_Position.z);
- auto Data = static_cast<cIncrementalRedstoneSimulator *>(a_World.GetRedstoneSimulator())->GetChunkData();
- auto DelayInfo = Data->GetMechanismDelayInfo(a_Position);
+ auto & Data = DataForChunk(a_Chunk);
+ auto DelayInfo = Data.GetMechanismDelayInfo(a_Position);
if (DelayInfo == nullptr)
{
- if (!ShouldPowerOn(a_World, a_Position, a_Meta, Data))
+ if (!ShouldPowerOn(a_Chunk, a_Position, a_Meta, Data))
{
- return {};
+ return;
}
// From rest, we've determined there was a block update
// Schedule power-on 1 tick in the future
- Data->m_MechanismDelays[a_Position] = std::make_pair(1, true);
+ Data.m_MechanismDelays[a_Position] = std::make_pair(1, true);
- return {};
+ return;
}
int DelayTicks;
@@ -76,31 +71,30 @@ public:
if (DelayTicks != 0)
{
- return {};
+ return;
}
if (ShouldPowerOn)
{
// Remain on for 1 tick before resetting
*DelayInfo = std::make_pair(1, false);
- a_World.SetBlockMeta(a_Position, a_Meta | 0x8);
+ a_Chunk.SetMeta(a_Position, a_Meta | 0x8);
}
else
{
// We've reset. Erase delay data in preparation for detecting further updates
- Data->m_MechanismDelays.erase(a_Position);
- a_World.SetBlockMeta(a_Position, a_Meta & ~0x8);
+ Data.m_MechanismDelays.erase(a_Position);
+ a_Chunk.SetMeta(a_Position, a_Meta & ~0x8);
}
- return { a_Position + cBlockObserverHandler::GetSignalOutputOffset(a_Meta) };
+ UpdateAdjustedRelatives(a_Chunk, CurrentlyTicking, a_Position + cBlockObserverHandler::GetSignalOutputOffset(a_Meta));
}
- virtual cVector3iArray GetValidSourcePositions(cWorld & a_World, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta) const override
+ virtual void ForValidSourcePositions(cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, SourceCallback Callback) const override
{
- UNUSED(a_World);
+ UNUSED(a_Chunk);
UNUSED(a_Position);
UNUSED(a_BlockType);
UNUSED(a_BlockType);
- return {};
}
};