From 5b62c4c3145c08b093521e42c565922fa85de4ad Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 26 Jun 2015 17:24:51 -0500 Subject: Reorganised the redstone simulator -> Many thanks to @worktycho for the idea, and @Haxi52 for the implementation plan! * Uses classes and inheritance now * Speed should be improved --- .../RedstoneSimulatorChunkData.h | 70 ++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 src/Simulator/IncrementalRedstoneSimulator/RedstoneSimulatorChunkData.h (limited to 'src/Simulator/IncrementalRedstoneSimulator/RedstoneSimulatorChunkData.h') diff --git a/src/Simulator/IncrementalRedstoneSimulator/RedstoneSimulatorChunkData.h b/src/Simulator/IncrementalRedstoneSimulator/RedstoneSimulatorChunkData.h new file mode 100644 index 000000000..8e025d154 --- /dev/null +++ b/src/Simulator/IncrementalRedstoneSimulator/RedstoneSimulatorChunkData.h @@ -0,0 +1,70 @@ + +#pragma once + +#include "Vector3.h" +#include "RedstoneHandler.h" +#include "../RedstoneSimulator.h" +#include + + + + + +class cIncrementalRedstoneSimulatorChunkData : public cRedstoneSimulatorChunkData +{ + +public: + void WakeUp(const Vector3i & a_Position) + { + m_ActiveBlocks.push_back(a_Position); + } + + cVector3iArray & GetActiveBlocks() + { + return m_ActiveBlocks; + } + + const cRedstoneHandler::PoweringData GetCachedPowerData(const Vector3i & a_Position) const + { + auto Result = m_CachedPowerLevels.find(a_Position); + return (Result == m_CachedPowerLevels.end()) ? cRedstoneHandler::PoweringData() : Result->second; + } + + void SetCachedPowerData(const Vector3i & a_Position, cRedstoneHandler::PoweringData a_PoweringData) + { + m_CachedPowerLevels[a_Position] = a_PoweringData; + } + + std::pair * GetMechanismDelayInfo(const Vector3i & a_Position) + { + auto Result = m_MechanismDelays.find(a_Position); + return (Result == m_MechanismDelays.end()) ? nullptr : &Result->second; + } + + cRedstoneHandler::PoweringData ExchangeUpdateOncePowerData(const Vector3i & a_Position, cRedstoneHandler::PoweringData a_PoweringData) + { + auto Result = m_CachedPowerLevels.find(a_Position); + if (Result == m_CachedPowerLevels.end()) + { + m_CachedPowerLevels[a_Position] = a_PoweringData; + return cRedstoneHandler::PoweringData(); + } + std::swap(Result->second, a_PoweringData); + return a_PoweringData; + } + + /** Structure storing position of mechanism + it's delay ticks (countdown) & if to power on */ + std::unordered_map, VectorHasher> m_MechanismDelays; + std::unordered_map> m_UpdateOncePositions; + +private: + + cVector3iArray m_ActiveBlocks; + + // TODO: map -> Position of torch + it's heat level + + std::unordered_map> m_CachedPowerLevels; + + friend class cRedstoneHandlerFactory; + +}; -- cgit v1.2.3