summaryrefslogtreecommitdiffstats
path: root/source/Simulator/RedstoneSimulator.h
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-10-13 11:53:28 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-10-13 11:53:28 +0200
commitf7da7c2536b438db92bc28b88c4139d9af15e44f (patch)
tree4710e9e41ebcf2317ebacade2801732ba9184b41 /source/Simulator/RedstoneSimulator.h
parentProtoProxy: Fixed parsing of the PACKET_PLAYER_ABILITIES packet. (diff)
downloadcuberite-f7da7c2536b438db92bc28b88c4139d9af15e44f.tar
cuberite-f7da7c2536b438db92bc28b88c4139d9af15e44f.tar.gz
cuberite-f7da7c2536b438db92bc28b88c4139d9af15e44f.tar.bz2
cuberite-f7da7c2536b438db92bc28b88c4139d9af15e44f.tar.lz
cuberite-f7da7c2536b438db92bc28b88c4139d9af15e44f.tar.xz
cuberite-f7da7c2536b438db92bc28b88c4139d9af15e44f.tar.zst
cuberite-f7da7c2536b438db92bc28b88c4139d9af15e44f.zip
Diffstat (limited to 'source/Simulator/RedstoneSimulator.h')
-rw-r--r--source/Simulator/RedstoneSimulator.h81
1 files changed, 81 insertions, 0 deletions
diff --git a/source/Simulator/RedstoneSimulator.h b/source/Simulator/RedstoneSimulator.h
new file mode 100644
index 000000000..f26b6b46b
--- /dev/null
+++ b/source/Simulator/RedstoneSimulator.h
@@ -0,0 +1,81 @@
+
+#pragma once
+
+#include "Simulator.h"
+
+
+
+
+
+class cRedstoneSimulator :
+ public cSimulator
+{
+ typedef cSimulator super;
+public:
+ cRedstoneSimulator( cWorld* a_World );
+ ~cRedstoneSimulator();
+
+ virtual void Simulate( float a_Dt ) override;
+ virtual bool IsAllowedBlock( BLOCKTYPE a_BlockType ) override { return true; }
+
+ virtual void WakeUp( int a_X, int a_Y, int a_Z ) override;
+
+ enum eRedstoneDirection
+ {
+ REDSTONE_NONE = 0,
+ REDSTONE_X_POS = 0x1,
+ REDSTONE_X_NEG = 0x2,
+ REDSTONE_Z_POS = 0x4,
+ REDSTONE_Z_NEG = 0x8,
+ };
+ eRedstoneDirection GetDirection( int a_X, int a_Y, int a_Z );
+ eRedstoneDirection GetDirection( const Vector3i & a_Pos ) { return GetDirection( a_Pos.x, a_Pos.y, a_Pos.z ); }
+
+ static bool IsRepeaterPointingTo (const Vector3i & a_RepeaterPos, char a_MetaData, const Vector3i & a_BlockPos);
+ static bool IsRepeaterPointingAway(const Vector3i & a_RepeaterPos, char a_MetaData, const Vector3i & a_BlockPos);
+ static NIBBLETYPE RepeaterRotationToMetaData(float a_Rotation);
+ static Vector3i GetRepeaterDirection(NIBBLETYPE a_MetaData);
+
+
+private:
+ struct sRepeaterChange
+ {
+ Vector3i Position;
+ int Ticks;
+ bool bPowerOn;
+ bool bPowerOffNextTime;
+ };
+
+ typedef std::deque <Vector3i> BlockList;
+
+ typedef std::deque< sRepeaterChange > RepeaterList;
+ RepeaterList m_SetRepeaters;
+
+ void SetRepeater(const Vector3i & a_Position, int a_Ticks, bool a_bPowerOn);
+
+ virtual void AddBlock(int a_X, int a_Y, int a_Z) {}
+
+ void HandleChange( const Vector3i & a_BlockPos );
+ BlockList RemoveCurrent( const Vector3i & a_BlockPos );
+
+ bool PowerBlock( const Vector3i & a_BlockPos, const Vector3i & a_FromBlock, char a_Power );
+ int UnPowerBlock( const Vector3i & a_BlockPos, const Vector3i & a_FromBlock );
+
+ bool IsPowered( const Vector3i & a_BlockPos, bool a_bOnlyByWire = false );
+ bool IsPowering( const Vector3i & a_PowerPos, const Vector3i & a_BlockPos, eRedstoneDirection a_WireDirection, bool a_bOnlyByWire );
+
+ BlockList m_Blocks;
+ BlockList m_BlocksBuffer;
+
+ BlockList m_RefreshPistons;
+
+ BlockList m_RefreshTorchesAround;
+
+ void RefreshTorchesAround( const Vector3i & a_BlockPos );
+
+ cCriticalSection m_CS;
+};
+
+
+
+