summaryrefslogtreecommitdiffstats
path: root/src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.cpp
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/IncrementalRedstoneSimulator.cpp
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 'src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.cpp')
-rw-r--r--src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.cpp133
1 files changed, 5 insertions, 128 deletions
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<std::unique_ptr<cRedstoneHandler>, 256>
- {
- sComponents()
- {
- for (size_t i = 0; i != 256; ++i)
- {
- (*this)[i] = cIncrementalRedstoneSimulator::CreateComponent(static_cast<BLOCKTYPE>(i));
- }
- }
- };
-
-
- static sComponents Components;
- return Components[a_BlockType].get();
-}
-
-
-
-
-
-std::unique_ptr<cRedstoneHandler> 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<cPoweredRailHandler>();
-
- case E_BLOCK_ACTIVE_COMPARATOR:
- case E_BLOCK_INACTIVE_COMPARATOR: return std::make_unique<cRedstoneComparatorHandler>();
-
- case E_BLOCK_DISPENSER:
- case E_BLOCK_DROPPER: return std::make_unique<cDropSpenserHandler>();
-
- 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<cPressurePlateHandler>();
-
- 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<cSmallGateHandler>();
-
- case E_BLOCK_REDSTONE_LAMP_OFF:
- case E_BLOCK_REDSTONE_LAMP_ON: return std::make_unique<cRedstoneLampHandler>();
-
- case E_BLOCK_REDSTONE_REPEATER_OFF:
- case E_BLOCK_REDSTONE_REPEATER_ON: return std::make_unique<cRedstoneRepeaterHandler>();
-
- case E_BLOCK_REDSTONE_TORCH_OFF:
- case E_BLOCK_REDSTONE_TORCH_ON: return std::make_unique<cRedstoneTorchHandler>();
-
- case E_BLOCK_OBSERVER: return std::make_unique<cObserverHandler>();
-
- case E_BLOCK_PISTON:
- case E_BLOCK_STICKY_PISTON: return std::make_unique<cPistonHandler>();
-
- case E_BLOCK_LEVER:
- case E_BLOCK_STONE_BUTTON:
- case E_BLOCK_WOODEN_BUTTON: return std::make_unique<cRedstoneToggleHandler>();
-
- case E_BLOCK_BLOCK_OF_REDSTONE: return std::make_unique<cRedstoneBlockHandler>();
- case E_BLOCK_COMMAND_BLOCK: return std::make_unique<cCommandBlockHandler>();
- case E_BLOCK_HOPPER: return std::make_unique<cHopperHandler>();
- case E_BLOCK_NOTE_BLOCK: return std::make_unique<cNoteBlockHandler>();
- case E_BLOCK_REDSTONE_WIRE: return std::make_unique<cRedstoneWireHandler>();
- case E_BLOCK_TNT: return std::make_unique<cTNTHandler>();
- case E_BLOCK_TRAPPED_CHEST: return std::make_unique<cTrappedChestHandler>();
- case E_BLOCK_TRIPWIRE_HOOK: return std::make_unique<cTripwireHookHandler>();
- default:
- {
- if (cBlockDoorHandler::IsDoorBlockType(a_BlockType))
- {
- return std::make_unique<cDoorHandler>();
- }
-
- 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<cIncrementalRedstoneSimulatorChunkData *>(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<const cRedstoneWireHandler *>(GetComponentHandler(a_Block))->SetWireState(a_Chunk, a_Position);
+ RedstoneHandler::SetWireState(a_Chunk, a_Position);
}
// Always update redstone devices: