From 40eba5244ddd7045a9c3539c5f46c9921301ed90 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 8 Aug 2020 18:22:16 +0100 Subject: Remove the redstone solid block handler - Remove cSolidBlockHandler * Functionality now integrated into simulator dispatcher * Fix door double open/close issues, arisen due to the top/bottom halves getting different power + Small migration to block states for redstone wire --- .../IncrementalRedstoneSimulator.cpp | 69 +++++++++------------- 1 file changed, 27 insertions(+), 42 deletions(-) (limited to 'src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.cpp') diff --git a/src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.cpp index e3177e420..056bfb368 100644 --- a/src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.cpp +++ b/src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.cpp @@ -1,9 +1,8 @@ - #include "Globals.h" #include "IncrementalRedstoneSimulator.h" -#include "../../Chunk.h" +#include "ForEachSourceCallback.h" #include "CommandBlockHandler.h" #include "DoorHandler.h" @@ -11,7 +10,6 @@ #include "RedstoneWireHandler.h" #include "RedstoneRepeaterHandler.h" #include "RedstoneToggleHandler.h" -#include "SolidBlockHandler.h" #include "RedstoneLampHandler.h" #include "RedstoneBlockHandler.h" #include "PistonHandler.h" @@ -115,10 +113,6 @@ std::unique_ptr cIncrementalRedstoneSimulator::CreateComponent return std::make_unique(); } - if (cBlockInfo::FullyOccupiesVoxel(a_BlockType)) - { - return std::make_unique(); - } return nullptr; } } @@ -182,42 +176,11 @@ void cIncrementalRedstoneSimulator::ProcessWorkItem(cChunk & Chunk, cChunk & Tic return; } - PoweringData Power; - CurrentHandler->ForValidSourcePositions(Chunk, Position, CurrentBlock, CurrentMeta, [&Chunk, Position, CurrentBlock, &Power](Vector3i Location) - { - if (!cChunk::IsValidHeight(Location.y)) - { - return; - } - - const auto NeighbourChunk = Chunk.GetRelNeighborChunkAdjustCoords(Location); - if ((NeighbourChunk == nullptr) || !NeighbourChunk->IsValid()) - { - return; - } - - BLOCKTYPE PotentialBlock; - NIBBLETYPE PotentialMeta; - NeighbourChunk->GetBlockTypeMeta(Location, PotentialBlock, PotentialMeta); - - auto PotentialSourceHandler = GetComponentHandler(PotentialBlock); - if (PotentialSourceHandler == nullptr) - { - return; - } - - const PoweringData PotentialPower( - PotentialBlock, - PotentialSourceHandler->GetPowerDeliveredToPosition( - *NeighbourChunk, Location, PotentialBlock, PotentialMeta, - cIncrementalRedstoneSimulatorChunkData::RebaseRelativePosition(Chunk, *NeighbourChunk, Position), CurrentBlock - ) - ); - Power = std::max(Power, PotentialPower); - }); + ForEachSourceCallback Callback(Chunk, Position, CurrentBlock); + CurrentHandler->ForValidSourcePositions(Chunk, Position, CurrentBlock, CurrentMeta, Callback); // Inform the handler to update - CurrentHandler->Update(Chunk, TickingSource, Position, CurrentBlock, CurrentMeta, Power); + CurrentHandler->Update(Chunk, TickingSource, Position, CurrentBlock, CurrentMeta, Callback.Power); } @@ -241,6 +204,12 @@ void cIncrementalRedstoneSimulator::AddBlock(cChunk & a_Chunk, Vector3i a_Positi ChunkData.AlwaysTickedPositions.emplace(a_Position); } + // Temporary: in the absence of block state support calculate our own: + if (a_Block == E_BLOCK_REDSTONE_WIRE) + { + static_cast(GetComponentHandler(a_Block))->SetWireState(a_Chunk, a_Position); + } + // Always update redstone devices: ChunkData.WakeUp(a_Position); } @@ -273,5 +242,21 @@ 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 - // TODO: use a_Offset, exclude a_Position and a_Position - a_Offset + for (const auto Offset : cSimulator::GetLinkedOffsets(a_Offset)) + { + auto Relative = a_Position - a_Offset + Offset; + if (!cChunkDef::IsValidHeight(Relative.y)) + { + continue; + } + + auto Chunk = a_Chunk.GetRelNeighborChunkAdjustCoords(Relative); + if ((Chunk == nullptr) || !Chunk->IsValid()) + { + continue; + } + + const auto Block = Chunk->GetBlock(Relative); + AddBlock(*Chunk, Relative, Block); + } } -- cgit v1.2.3