From 01577bed9d9840f48766a16095ab2b1fce8c02ff Mon Sep 17 00:00:00 2001 From: faketruth Date: Tue, 6 Mar 2012 21:06:51 +0000 Subject: Yay redstone repeaters! git-svn-id: http://mc-server.googlecode.com/svn/trunk@374 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cRedstoneSimulator.h | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'source/cRedstoneSimulator.h') diff --git a/source/cRedstoneSimulator.h b/source/cRedstoneSimulator.h index 853816f3b..927902f5a 100644 --- a/source/cRedstoneSimulator.h +++ b/source/cRedstoneSimulator.h @@ -26,17 +26,56 @@ public: 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 ); } private: + struct sRepeaterChange + { + Vector3i Position; + int Ticks; + bool bPowerOn; + bool bPowerOffNextTime; + }; + typedef std::deque BlockList; + typedef std::deque< sRepeaterChange > RepeaterList; + RepeaterList m_SetRepeaters; + void SetRepeater( const Vector3i & a_Position, int a_Ticks, bool a_bPowerOn ) + { + for( RepeaterList::iterator itr = m_SetRepeaters.begin(); itr != m_SetRepeaters.end(); ++itr ) + { + sRepeaterChange & Change = *itr; + if( Change.Position.Equals( a_Position ) ) + { + if( Change.bPowerOn && a_bPowerOn == false ) + { + Change.bPowerOffNextTime = true; + } + if( a_bPowerOn == true ) + { + Change.bPowerOffNextTime = false; + } + Change.bPowerOn |= a_bPowerOn; + return; + } + } + + sRepeaterChange RC; + RC.Position = a_Position; + RC.Ticks = a_Ticks; + RC.bPowerOn = a_bPowerOn; + RC.bPowerOffNextTime = false; + m_SetRepeaters.push_back( RC ); + } + 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 ); + 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; @@ -44,6 +83,7 @@ private: BlockList m_RefreshPistons; BlockList m_RefreshTorchesAround; + void RefreshTorchesAround( const Vector3i & a_BlockPos ); cCriticalSection m_CS; -- cgit v1.2.3