From 171c59a01b07b7513cf7a281bbcb141e8182d274 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 2 Jun 2015 13:29:52 +0100 Subject: Changed appropriate containers to unordered_map Thanks to @worktycho for guidance! * Potential speed improvements --- src/Simulator/IncrementalRedstoneSimulator.h | 31 +++++++--------------------- 1 file changed, 7 insertions(+), 24 deletions(-) (limited to 'src/Simulator/IncrementalRedstoneSimulator.h') diff --git a/src/Simulator/IncrementalRedstoneSimulator.h b/src/Simulator/IncrementalRedstoneSimulator.h index 934a0eab9..c4be70e97 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.h +++ b/src/Simulator/IncrementalRedstoneSimulator.h @@ -3,7 +3,7 @@ #include "RedstoneSimulator.h" #include "BlockEntities/RedstonePoweredEntity.h" -#include +#include class cWorld; class cChunk; @@ -38,15 +38,6 @@ public: virtual bool IsAllowedBlock(BLOCKTYPE a_BlockType) override { return IsRedstone(a_BlockType); } virtual void WakeUp(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk) override; - enum eRedstoneWireDirectionBitfieldPositions - { - eWbpXP = 0, - eWbpXN = 1, - eWbpZP = 2, - eWbpZN = 3, - }; - std::bitset<4> GetWireDirection(int a_BlockX, int a_BlockY, int a_BlockZ); - private: #define MAX_POWER_LEVEL 15 @@ -66,15 +57,8 @@ private: unsigned char a_PowerLevel; }; - struct sSimulatedPlayerToggleableList // Define structure of the list containing simulate-on-update blocks (such as trapdoors that respond once to a block update, and can be toggled by a player) - { - Vector3i a_RelBlockPos; - bool WasLastStatePowered; // Was the last state powered or not? Determines whether a source update has happened and if I should resimulate - }; - struct sRepeatersDelayList // Define structure of list containing repeaters' delay states { - Vector3i a_RelBlockPos; unsigned char a_DelayTicks; // For how many ticks should the repeater delay unsigned char a_ElapsedTicks; // How much of the previous has been elapsed? bool ShouldPowerOn; // What happens when the delay time is fulfilled? @@ -85,20 +69,19 @@ private: { public: /// Per-chunk data for the simulator, specified individual chunks to simulate - cCoordWithBlockAndBoolVector m_ChunkData; - cCoordWithBlockAndBoolVector m_QueuedChunkData; + std::unordered_map, Vector3i> m_ChunkData; std::vector m_PoweredBlocks; std::vector m_LinkedBlocks; - std::vector m_SimulatedPlayerToggleableBlocks; - std::vector m_RepeatersDelayList; + std::unordered_map m_SimulatedPlayerToggleableBlocks; + std::unordered_map m_RepeatersDelayList; }; public: typedef std::vector PoweredBlocksList; typedef std::vector LinkedBlocksList; - typedef std::vector SimulatedPlayerToggleableList; - typedef std::vector RepeatersDelayList; + typedef std::unordered_map SimulatedPlayerToggleableList; + typedef std::unordered_map RepeatersDelayList; private: @@ -211,7 +194,7 @@ private: void SetAllDirsAsPowered(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ, unsigned char a_PowerLevel = MAX_POWER_LEVEL); /** Queues a repeater to be powered or unpowered and returns if the m_RepeatersDelayList iterators were invalidated */ - bool QueueRepeaterPowerChange(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ, NIBBLETYPE a_Meta, bool ShouldPowerOn); + void QueueRepeaterPowerChange(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ, NIBBLETYPE a_Meta, bool ShouldPowerOn); /** Removes a block from the Powered and LinkedPowered lists Recursively removes all blocks powered by the given one -- cgit v1.2.3