summaryrefslogtreecommitdiffstats
path: root/src/Simulator/IncrementalRedstoneSimulator/RedstoneSimulatorChunkData.h
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@outlook.com>2015-12-19 22:20:56 +0100
committerTiger Wang <ziwei.tiger@outlook.com>2015-12-19 22:20:56 +0100
commitb8752bb26e91bcdcebfb8dd43e5794251ff70a89 (patch)
tree95048f5a2a833c1d43785f6eaea070627c2b9ebe /src/Simulator/IncrementalRedstoneSimulator/RedstoneSimulatorChunkData.h
parentMerge pull request #2776 from cuberite/AtomicBoolIsthread (diff)
parentReorganised the redstone simulator (diff)
downloadcuberite-b8752bb26e91bcdcebfb8dd43e5794251ff70a89.tar
cuberite-b8752bb26e91bcdcebfb8dd43e5794251ff70a89.tar.gz
cuberite-b8752bb26e91bcdcebfb8dd43e5794251ff70a89.tar.bz2
cuberite-b8752bb26e91bcdcebfb8dd43e5794251ff70a89.tar.lz
cuberite-b8752bb26e91bcdcebfb8dd43e5794251ff70a89.tar.xz
cuberite-b8752bb26e91bcdcebfb8dd43e5794251ff70a89.tar.zst
cuberite-b8752bb26e91bcdcebfb8dd43e5794251ff70a89.zip
Diffstat (limited to 'src/Simulator/IncrementalRedstoneSimulator/RedstoneSimulatorChunkData.h')
-rw-r--r--src/Simulator/IncrementalRedstoneSimulator/RedstoneSimulatorChunkData.h70
1 files changed, 70 insertions, 0 deletions
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 <unordered_map>
+
+
+
+
+
+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<int, bool> * 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<Vector3i, std::pair<int, bool>, VectorHasher<int>> m_MechanismDelays;
+ std::unordered_map<Vector3i, bool, VectorHasher<int>> m_UpdateOncePositions;
+
+private:
+
+ cVector3iArray m_ActiveBlocks;
+
+ // TODO: map<Vector3i, int> -> Position of torch + it's heat level
+
+ std::unordered_map<Vector3i, cRedstoneHandler::PoweringData, VectorHasher<int>> m_CachedPowerLevels;
+
+ friend class cRedstoneHandlerFactory;
+
+};