diff options
Diffstat (limited to '')
-rw-r--r-- | src/Chunk.cpp | 1 | ||||
-rw-r--r-- | src/Chunk.h | 4 | ||||
-rw-r--r-- | src/Simulator/IncrementalRedstoneSimulator/ForEachSourceCallback.cpp | 1 | ||||
-rw-r--r-- | src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.cpp | 129 | ||||
-rw-r--r-- | src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.h | 90 | ||||
-rw-r--r-- | src/Simulator/NoopFluidSimulator.h | 2 | ||||
-rw-r--r-- | src/Simulator/RedstoneSimulator.h | 2 | ||||
-rw-r--r-- | src/Simulator/VaporizeFluidSimulator.h | 2 |
8 files changed, 125 insertions, 106 deletions
diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 5d54f3c16..b16646d5a 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -21,6 +21,7 @@ #include "Bindings/PluginManager.h" #include "Blocks/BlockHandler.h" #include "Simulator/FluidSimulator.h" +#include "Simulator/RedstoneSimulator.h" #include "MobCensus.h" #include "MobSpawner.h" #include "BlockInServerPluginInterface.h" diff --git a/src/Chunk.h b/src/Chunk.h index 405f5253e..b8c9b75ae 100644 --- a/src/Chunk.h +++ b/src/Chunk.h @@ -6,7 +6,6 @@ #include "Simulator/FireSimulator.h" #include "Simulator/SandSimulator.h" -#include "Simulator/RedstoneSimulator.h" #include "ChunkMap.h" @@ -25,10 +24,11 @@ class cBlockArea; class cFluidSimulatorData; class cMobCensus; class cMobSpawner; +class cRedstoneSimulatorChunkData; struct SetChunkData; -typedef std::list<cClientHandle *> cClientHandleList; +typedef std::list<cClientHandle *> cClientHandleList; // A convenience macro for calling GetChunkAndRelByAbsolute. #define PREPARE_REL_AND_CHUNK(Position, OriginalChunk) cChunk * Chunk; Vector3i Rel; bool RelSuccess = (OriginalChunk).GetChunkAndRelByAbsolute(Position, &Chunk, Rel) diff --git a/src/Simulator/IncrementalRedstoneSimulator/ForEachSourceCallback.cpp b/src/Simulator/IncrementalRedstoneSimulator/ForEachSourceCallback.cpp index 3afa42532..9505b12da 100644 --- a/src/Simulator/IncrementalRedstoneSimulator/ForEachSourceCallback.cpp +++ b/src/Simulator/IncrementalRedstoneSimulator/ForEachSourceCallback.cpp @@ -2,6 +2,7 @@ #include "Globals.h" #include "ForEachSourceCallback.h" +#include "BlockType.h" #include "../../BlockInfo.h" #include "../../Chunk.h" #include "IncrementalRedstoneSimulator.h" diff --git a/src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.cpp index 459cf672e..c27f6d04d 100644 --- a/src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.cpp +++ b/src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.cpp @@ -2,13 +2,116 @@ #include "Globals.h" #include "IncrementalRedstoneSimulator.h" +#include "BlockType.h" #include "RedstoneHandler.h" +#include "RedstoneSimulatorChunkData.h" #include "ForEachSourceCallback.h" +bool cIncrementalRedstoneSimulator::IsAlwaysTicked(BLOCKTYPE a_Block) +{ + switch (a_Block) // Call the appropriate simulator for the entry's block type + { + case E_BLOCK_DAYLIGHT_SENSOR: + case E_BLOCK_INVERTED_DAYLIGHT_SENSOR: + case E_BLOCK_TRIPWIRE_HOOK: + case E_BLOCK_WOODEN_PRESSURE_PLATE: + case E_BLOCK_STONE_PRESSURE_PLATE: + case E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE: + case E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE: return true; + default: return false; + } +} + + + + + +bool cIncrementalRedstoneSimulator::IsRedstone(BLOCKTYPE a_Block) + +{ + switch (a_Block) + { + // All redstone devices, please alpha sort + case E_BLOCK_ACACIA_DOOR: + case E_BLOCK_ACACIA_FENCE_GATE: + case E_BLOCK_ACTIVATOR_RAIL: + case E_BLOCK_ACTIVE_COMPARATOR: + case E_BLOCK_BIRCH_DOOR: + case E_BLOCK_BIRCH_FENCE_GATE: + case E_BLOCK_BLOCK_OF_REDSTONE: + case E_BLOCK_COMMAND_BLOCK: + case E_BLOCK_DARK_OAK_DOOR: + case E_BLOCK_DARK_OAK_FENCE_GATE: + case E_BLOCK_DAYLIGHT_SENSOR: + case E_BLOCK_DETECTOR_RAIL: + case E_BLOCK_DISPENSER: + case E_BLOCK_DROPPER: + case E_BLOCK_FENCE_GATE: + case E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE: + case E_BLOCK_HOPPER: + case E_BLOCK_INACTIVE_COMPARATOR: + case E_BLOCK_INVERTED_DAYLIGHT_SENSOR: + case E_BLOCK_IRON_DOOR: + case E_BLOCK_IRON_TRAPDOOR: + case E_BLOCK_JUNGLE_DOOR: + case E_BLOCK_JUNGLE_FENCE_GATE: + case E_BLOCK_LEVER: + case E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE: + case E_BLOCK_NOTE_BLOCK: + case E_BLOCK_OBSERVER: + case E_BLOCK_POWERED_RAIL: + case E_BLOCK_REDSTONE_LAMP_OFF: + case E_BLOCK_REDSTONE_LAMP_ON: + case E_BLOCK_REDSTONE_REPEATER_OFF: + case E_BLOCK_REDSTONE_REPEATER_ON: + case E_BLOCK_REDSTONE_TORCH_OFF: + case E_BLOCK_REDSTONE_TORCH_ON: + case E_BLOCK_REDSTONE_WIRE: + case E_BLOCK_SPRUCE_DOOR: + case E_BLOCK_SPRUCE_FENCE_GATE: + case E_BLOCK_STICKY_PISTON: + case E_BLOCK_STONE_BUTTON: + case E_BLOCK_STONE_PRESSURE_PLATE: + case E_BLOCK_TNT: + case E_BLOCK_TRAPDOOR: + case E_BLOCK_TRAPPED_CHEST: + case E_BLOCK_TRIPWIRE_HOOK: + case E_BLOCK_WOODEN_BUTTON: + case E_BLOCK_WOODEN_DOOR: + case E_BLOCK_WOODEN_PRESSURE_PLATE: + case E_BLOCK_PISTON: + { + return true; + } + default: return false; + } +} + + + + + +void cIncrementalRedstoneSimulator::ProcessWorkItem(cChunk & Chunk, cChunk & TickingSource, const Vector3i Position) +{ + BLOCKTYPE CurrentBlock; + NIBBLETYPE CurrentMeta; + Chunk.GetBlockTypeMeta(Position, CurrentBlock, CurrentMeta); + + ForEachSourceCallback Callback(Chunk, Position, CurrentBlock); + RedstoneHandler::ForValidSourcePositions(Chunk, Position, CurrentBlock, CurrentMeta, Callback); + + // Inform the handler to update + RedstoneHandler::Update(Chunk, TickingSource, Position, CurrentBlock, CurrentMeta, Callback.Power); +} + + + + + void cIncrementalRedstoneSimulator::SimulateChunk(std::chrono::milliseconds a_Dt, int a_ChunkX, int a_ChunkZ, cChunk * a_Chunk) { auto & ChunkData = *static_cast<cIncrementalRedstoneSimulatorChunkData *>(a_Chunk->GetRedstoneSimulatorData()); @@ -49,23 +152,6 @@ void cIncrementalRedstoneSimulator::SimulateChunk(std::chrono::milliseconds a_Dt -void cIncrementalRedstoneSimulator::ProcessWorkItem(cChunk & Chunk, cChunk & TickingSource, const Vector3i Position) -{ - BLOCKTYPE CurrentBlock; - NIBBLETYPE CurrentMeta; - Chunk.GetBlockTypeMeta(Position, CurrentBlock, CurrentMeta); - - ForEachSourceCallback Callback(Chunk, Position, CurrentBlock); - RedstoneHandler::ForValidSourcePositions(Chunk, Position, CurrentBlock, CurrentMeta, Callback); - - // Inform the handler to update - RedstoneHandler::Update(Chunk, TickingSource, Position, CurrentBlock, CurrentMeta, Callback.Power); -} - - - - - void cIncrementalRedstoneSimulator::AddBlock(cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_Block) { // Never update blocks without a handler: @@ -95,6 +181,15 @@ void cIncrementalRedstoneSimulator::AddBlock(cChunk & a_Chunk, Vector3i a_Positi +cRedstoneSimulatorChunkData * cIncrementalRedstoneSimulator::CreateChunkData() +{ + return new cIncrementalRedstoneSimulatorChunkData; +} + + + + + void cIncrementalRedstoneSimulator::WakeUp(cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_Block) { // Having WakeUp called on us directly means someone called SetBlock (or WakeUp) diff --git a/src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.h b/src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.h index b13d1f6f5..7f08c50af 100644 --- a/src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.h +++ b/src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.h @@ -1,9 +1,7 @@ #pragma once -#include "BlockType.h" #include "../RedstoneSimulator.h" -#include "RedstoneSimulatorChunkData.h" @@ -16,98 +14,22 @@ class cIncrementalRedstoneSimulator final : public: - using Super::cRedstoneSimulator; + using Super::Super; private: /** Returns if a redstone device is always ticked due to influence by its environment */ - inline static bool IsAlwaysTicked(BLOCKTYPE a_Block) - { - switch (a_Block) // Call the appropriate simulator for the entry's block type - { - case E_BLOCK_DAYLIGHT_SENSOR: - case E_BLOCK_INVERTED_DAYLIGHT_SENSOR: - case E_BLOCK_TRIPWIRE_HOOK: - case E_BLOCK_WOODEN_PRESSURE_PLATE: - case E_BLOCK_STONE_PRESSURE_PLATE: - case E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE: - case E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE: return true; - default: return false; - } - } + static bool IsAlwaysTicked(BLOCKTYPE a_Block); /** Returns if a block is any sort of redstone device */ - inline static bool IsRedstone(BLOCKTYPE a_Block) - { - switch (a_Block) - { - // All redstone devices, please alpha sort - case E_BLOCK_ACACIA_DOOR: - case E_BLOCK_ACACIA_FENCE_GATE: - case E_BLOCK_ACTIVATOR_RAIL: - case E_BLOCK_ACTIVE_COMPARATOR: - case E_BLOCK_BIRCH_DOOR: - case E_BLOCK_BIRCH_FENCE_GATE: - case E_BLOCK_BLOCK_OF_REDSTONE: - case E_BLOCK_COMMAND_BLOCK: - case E_BLOCK_DARK_OAK_DOOR: - case E_BLOCK_DARK_OAK_FENCE_GATE: - case E_BLOCK_DAYLIGHT_SENSOR: - case E_BLOCK_DETECTOR_RAIL: - case E_BLOCK_DISPENSER: - case E_BLOCK_DROPPER: - case E_BLOCK_FENCE_GATE: - case E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE: - case E_BLOCK_HOPPER: - case E_BLOCK_INACTIVE_COMPARATOR: - case E_BLOCK_INVERTED_DAYLIGHT_SENSOR: - case E_BLOCK_IRON_DOOR: - case E_BLOCK_IRON_TRAPDOOR: - case E_BLOCK_JUNGLE_DOOR: - case E_BLOCK_JUNGLE_FENCE_GATE: - case E_BLOCK_LEVER: - case E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE: - case E_BLOCK_NOTE_BLOCK: - case E_BLOCK_OBSERVER: - case E_BLOCK_POWERED_RAIL: - case E_BLOCK_REDSTONE_LAMP_OFF: - case E_BLOCK_REDSTONE_LAMP_ON: - case E_BLOCK_REDSTONE_REPEATER_OFF: - case E_BLOCK_REDSTONE_REPEATER_ON: - case E_BLOCK_REDSTONE_TORCH_OFF: - case E_BLOCK_REDSTONE_TORCH_ON: - case E_BLOCK_REDSTONE_WIRE: - case E_BLOCK_SPRUCE_DOOR: - case E_BLOCK_SPRUCE_FENCE_GATE: - case E_BLOCK_STICKY_PISTON: - case E_BLOCK_STONE_BUTTON: - case E_BLOCK_STONE_PRESSURE_PLATE: - case E_BLOCK_TNT: - case E_BLOCK_TRAPDOOR: - case E_BLOCK_TRAPPED_CHEST: - case E_BLOCK_TRIPWIRE_HOOK: - case E_BLOCK_WOODEN_BUTTON: - case E_BLOCK_WOODEN_DOOR: - case E_BLOCK_WOODEN_PRESSURE_PLATE: - case E_BLOCK_PISTON: - { - return true; - } - default: return false; - } - } - - virtual void Simulate(float Dt) override {} - virtual void SimulateChunk(std::chrono::milliseconds Dt, int ChunkX, int ChunkZ, cChunk * Chunk) override; + static bool IsRedstone(BLOCKTYPE a_Block); void ProcessWorkItem(cChunk & Chunk, cChunk & TickingSource, const Vector3i Position); - virtual cIncrementalRedstoneSimulatorChunkData * CreateChunkData() override - { - return new cIncrementalRedstoneSimulatorChunkData; - } - + virtual void Simulate(float Dt) override {} + virtual void SimulateChunk(std::chrono::milliseconds Dt, int ChunkX, int ChunkZ, cChunk * Chunk) override; virtual void AddBlock(cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_Block) override; + virtual cRedstoneSimulatorChunkData * CreateChunkData() override; virtual void WakeUp(cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_Block) override; virtual void WakeUp(cChunk & a_Chunk, Vector3i a_Position, Vector3i a_Offset, BLOCKTYPE a_Block) override; } ; diff --git a/src/Simulator/NoopFluidSimulator.h b/src/Simulator/NoopFluidSimulator.h index 2be4f86a9..1b963f569 100644 --- a/src/Simulator/NoopFluidSimulator.h +++ b/src/Simulator/NoopFluidSimulator.h @@ -22,7 +22,7 @@ class cNoopFluidSimulator: public: - using Super::cFluidSimulator; + using Super::Super; private: diff --git a/src/Simulator/RedstoneSimulator.h b/src/Simulator/RedstoneSimulator.h index 0ef0dd6af..86b5b84b3 100644 --- a/src/Simulator/RedstoneSimulator.h +++ b/src/Simulator/RedstoneSimulator.h @@ -27,7 +27,7 @@ class cRedstoneSimulator: public: - using Super::cSimulator; + using Super::Super; virtual cRedstoneSimulatorChunkData * CreateChunkData() = 0; }; diff --git a/src/Simulator/VaporizeFluidSimulator.h b/src/Simulator/VaporizeFluidSimulator.h index ef61c9a84..963cc7bc3 100644 --- a/src/Simulator/VaporizeFluidSimulator.h +++ b/src/Simulator/VaporizeFluidSimulator.h @@ -23,7 +23,7 @@ class cVaporizeFluidSimulator: public: - using Super::cFluidSimulator; + using Super::Super; private: |