From 9518a273570e8d38438c2a29aa10f987e7d44ce1 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 21 Dec 2020 13:54:04 +0000 Subject: Prepare for 1.15+ (#4856) + Add type-safe container for states * Split registry Blocks into BlockTypes, BlockStates so the block types enumeration can be #included without too much penalty * Ensure Registry uses type-safe container --- .../IncrementalRedstoneSimulator/RedstoneSimulatorChunkData.h | 7 ++++--- src/Simulator/IncrementalRedstoneSimulator/RedstoneWireHandler.h | 8 ++++---- 2 files changed, 8 insertions(+), 7 deletions(-) (limited to 'src/Simulator/IncrementalRedstoneSimulator') diff --git a/src/Simulator/IncrementalRedstoneSimulator/RedstoneSimulatorChunkData.h b/src/Simulator/IncrementalRedstoneSimulator/RedstoneSimulatorChunkData.h index 02da327a1..f9545d997 100644 --- a/src/Simulator/IncrementalRedstoneSimulator/RedstoneSimulatorChunkData.h +++ b/src/Simulator/IncrementalRedstoneSimulator/RedstoneSimulatorChunkData.h @@ -3,8 +3,9 @@ #include -#include "../RedstoneSimulator.h" -#include "../../Chunk.h" +#include "Chunk.h" +#include "BlockState.h" +#include "Simulator/RedstoneSimulator.h" @@ -82,7 +83,7 @@ public: } /** Temporary, should be chunk data: wire block store, to avoid recomputing states every time. */ - std::unordered_map> WireStates; + std::unordered_map> WireStates; std::unordered_set> AlwaysTickedPositions; diff --git a/src/Simulator/IncrementalRedstoneSimulator/RedstoneWireHandler.h b/src/Simulator/IncrementalRedstoneSimulator/RedstoneWireHandler.h index c97f37aa5..66709293a 100644 --- a/src/Simulator/IncrementalRedstoneSimulator/RedstoneWireHandler.h +++ b/src/Simulator/IncrementalRedstoneSimulator/RedstoneWireHandler.h @@ -2,7 +2,7 @@ #pragma once #include "RedstoneHandler.h" -#include "../../Registries/Blocks.h" +#include "Registries/BlockStates.h" @@ -20,7 +20,7 @@ namespace RedstoneWireHandler /** Invokes Callback with the wire's left, front, and right direction state corresponding to Offset. Returns a new block constructed from the directions that the callback may have modified. */ template - inline short DoWithDirectionState(const Vector3i Offset, short Block, OffsetCallback Callback) + inline BlockState DoWithDirectionState(const Vector3i Offset, BlockState Block, OffsetCallback Callback) { auto North = Block::RedstoneWire::North(Block); auto South = Block::RedstoneWire::South(Block); @@ -49,7 +49,7 @@ namespace RedstoneWireHandler } /** Adjusts a given wire block so that the direction represented by Offset has state Direction. */ - inline void SetDirectionState(const Vector3i Offset, short & Block, TemporaryDirection Direction) + inline void SetDirectionState(const Vector3i Offset, BlockState & Block, TemporaryDirection Direction) { Block = DoWithDirectionState(Offset, Block, [Direction](auto, auto & Front, auto) { @@ -189,7 +189,7 @@ namespace RedstoneWireHandler return; } - DataForChunk(Chunk).WireStates[Position] = Block; + DataForChunk(Chunk).WireStates.emplace(Position, Block); } inline PowerLevel GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked) -- cgit v1.2.3