From 3143d6ce679f322ee73d3d70e2d843e9c98cc043 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 19 Aug 2020 21:14:40 +0100 Subject: Remove std::make_unique from redstone handler creation --- .../IncrementalRedstoneSimulator.cpp | 133 +-------------------- 1 file changed, 5 insertions(+), 128 deletions(-) (limited to 'src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.cpp') diff --git a/src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.cpp index 056bfb368..d9e4aa961 100644 --- a/src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.cpp +++ b/src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.cpp @@ -2,122 +2,9 @@ #include "Globals.h" #include "IncrementalRedstoneSimulator.h" +#include "RedstoneHandler.h" #include "ForEachSourceCallback.h" -#include "CommandBlockHandler.h" -#include "DoorHandler.h" -#include "RedstoneTorchHandler.h" -#include "RedstoneWireHandler.h" -#include "RedstoneRepeaterHandler.h" -#include "RedstoneToggleHandler.h" -#include "RedstoneLampHandler.h" -#include "RedstoneBlockHandler.h" -#include "PistonHandler.h" -#include "SmallGateHandler.h" -#include "NoteBlockHandler.h" -#include "ObserverHandler.h" -#include "TNTHandler.h" -#include "PoweredRailHandler.h" -#include "PressurePlateHandler.h" -#include "TripwireHookHandler.h" -#include "DropSpenserHandler.h" -#include "RedstoneComparatorHandler.h" -#include "TrappedChestHandler.h" -#include "HopperHandler.h" - - - - - -const cRedstoneHandler * cIncrementalRedstoneSimulator::GetComponentHandler(BLOCKTYPE a_BlockType) -{ - struct sComponents : - public std::array, 256> - { - sComponents() - { - for (size_t i = 0; i != 256; ++i) - { - (*this)[i] = cIncrementalRedstoneSimulator::CreateComponent(static_cast(i)); - } - } - }; - - - static sComponents Components; - return Components[a_BlockType].get(); -} - - - - - -std::unique_ptr cIncrementalRedstoneSimulator::CreateComponent(BLOCKTYPE a_BlockType) -{ - switch (a_BlockType) - { - case E_BLOCK_ACTIVATOR_RAIL: - case E_BLOCK_DETECTOR_RAIL: - case E_BLOCK_POWERED_RAIL: return std::make_unique(); - - case E_BLOCK_ACTIVE_COMPARATOR: - case E_BLOCK_INACTIVE_COMPARATOR: return std::make_unique(); - - case E_BLOCK_DISPENSER: - case E_BLOCK_DROPPER: return std::make_unique(); - - 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 std::make_unique(); - - 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 std::make_unique(); - - case E_BLOCK_REDSTONE_LAMP_OFF: - case E_BLOCK_REDSTONE_LAMP_ON: return std::make_unique(); - - case E_BLOCK_REDSTONE_REPEATER_OFF: - case E_BLOCK_REDSTONE_REPEATER_ON: return std::make_unique(); - - case E_BLOCK_REDSTONE_TORCH_OFF: - case E_BLOCK_REDSTONE_TORCH_ON: return std::make_unique(); - - case E_BLOCK_OBSERVER: return std::make_unique(); - - case E_BLOCK_PISTON: - case E_BLOCK_STICKY_PISTON: return std::make_unique(); - - case E_BLOCK_LEVER: - case E_BLOCK_STONE_BUTTON: - case E_BLOCK_WOODEN_BUTTON: return std::make_unique(); - - case E_BLOCK_BLOCK_OF_REDSTONE: return std::make_unique(); - case E_BLOCK_COMMAND_BLOCK: return std::make_unique(); - case E_BLOCK_HOPPER: return std::make_unique(); - case E_BLOCK_NOTE_BLOCK: return std::make_unique(); - case E_BLOCK_REDSTONE_WIRE: return std::make_unique(); - case E_BLOCK_TNT: return std::make_unique(); - case E_BLOCK_TRAPPED_CHEST: return std::make_unique(); - case E_BLOCK_TRIPWIRE_HOOK: return std::make_unique(); - default: - { - if (cBlockDoorHandler::IsDoorBlockType(a_BlockType)) - { - return std::make_unique(); - } - - return nullptr; - } - } -} - @@ -168,19 +55,11 @@ void cIncrementalRedstoneSimulator::ProcessWorkItem(cChunk & Chunk, cChunk & Tic NIBBLETYPE CurrentMeta; Chunk.GetBlockTypeMeta(Position, CurrentBlock, CurrentMeta); - auto CurrentHandler = GetComponentHandler(CurrentBlock); - if (CurrentHandler == nullptr) - { - // Block at Position doesn't have a corresponding redstone handler - // ErasePowerData will have been called in AddBlock - return; - } - ForEachSourceCallback Callback(Chunk, Position, CurrentBlock); - CurrentHandler->ForValidSourcePositions(Chunk, Position, CurrentBlock, CurrentMeta, Callback); + RedstoneHandler::ForValidSourcePositions(Chunk, Position, CurrentBlock, CurrentMeta, Callback); // Inform the handler to update - CurrentHandler->Update(Chunk, TickingSource, Position, CurrentBlock, CurrentMeta, Callback.Power); + RedstoneHandler::Update(Chunk, TickingSource, Position, CurrentBlock, CurrentMeta, Callback.Power); } @@ -189,14 +68,12 @@ void cIncrementalRedstoneSimulator::ProcessWorkItem(cChunk & Chunk, cChunk & Tic void cIncrementalRedstoneSimulator::AddBlock(cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_Block) { + // Never update blocks without a handler: if (!IsRedstone(a_Block)) { return; } - // Never update blocks without a handler: - ASSERT(GetComponentHandler(a_Block) != nullptr); - auto & ChunkData = *static_cast(a_Chunk.GetRedstoneSimulatorData()); if (IsAlwaysTicked(a_Block)) @@ -207,7 +84,7 @@ void cIncrementalRedstoneSimulator::AddBlock(cChunk & a_Chunk, Vector3i a_Positi // 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); + RedstoneHandler::SetWireState(a_Chunk, a_Position); } // Always update redstone devices: -- cgit v1.2.3