From 675b4aa878f16291ce33fced48a2bc7425f635ae Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Sun, 24 Nov 2013 14:19:41 +0000 Subject: Moved source to src --- src/Simulator/RedstoneSimulator.h | 86 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 src/Simulator/RedstoneSimulator.h (limited to 'src/Simulator/RedstoneSimulator.h') diff --git a/src/Simulator/RedstoneSimulator.h b/src/Simulator/RedstoneSimulator.h new file mode 100644 index 000000000..c0d5795c7 --- /dev/null +++ b/src/Simulator/RedstoneSimulator.h @@ -0,0 +1,86 @@ + +#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_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk) override; + + enum eRedstoneDirection + { + REDSTONE_NONE = 0, + REDSTONE_X_POS = 0x1, + REDSTONE_X_NEG = 0x2, + REDSTONE_Z_POS = 0x4, + REDSTONE_Z_NEG = 0x8, + }; + eRedstoneDirection GetWireDirection(int a_BlockX, int a_BlockY, int a_BlockZ); + eRedstoneDirection GetWireDirection(const Vector3i & a_Pos) { return GetWireDirection(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(double a_Rotation); + static Vector3i GetRepeaterDirection(NIBBLETYPE a_MetaData); + static NIBBLETYPE LeverDirectionToMetaData(char a_Dir); + static bool IsLeverOn(cWorld * a_World, const Vector3i & a_BlockPos); + static bool IsLeverOn(NIBBLETYPE a_BlockMeta); + + +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); + + virtual void AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk) override {} + + 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_RefreshDropSpensers; + + BlockList m_RefreshTorchesAround; + + void RefreshTorchesAround( const Vector3i & a_BlockPos ); + + // TODO: The entire simulator is synchronized, no need to lock data structures; remove this + cCriticalSection m_CS; +}; + + + + -- cgit v1.2.3 From 1d69c80ad38b494f737bde455225259192093c15 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 29 Nov 2013 22:27:08 +0000 Subject: Implemented trapdoors, fixes #43 and #105 Also updated redstone simulator to support it --- src/Simulator/RedstoneSimulator.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/Simulator/RedstoneSimulator.h') diff --git a/src/Simulator/RedstoneSimulator.h b/src/Simulator/RedstoneSimulator.h index d3002394a..9e244d7da 100644 --- a/src/Simulator/RedstoneSimulator.h +++ b/src/Simulator/RedstoneSimulator.h @@ -93,6 +93,8 @@ private: void HandleDoor(int a_BlockX, int a_BlockY, int a_BlockZ); /// Handles activator, detector, and powered rails void HandleRail(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_MyType); + /// Handles trapdoors + void HandleTrapdoor(int a_BlockX, int a_BlockY, int a_BlockZ); /* ===================== */ /* ====== Helper functions ====== */ -- cgit v1.2.3 From 455686e3ade61999d377965e02315603959ae2a4 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 30 Nov 2013 12:11:39 +0000 Subject: Pistons no longer accept power through front face This fixes #60. --- src/Simulator/RedstoneSimulator.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/Simulator/RedstoneSimulator.h') diff --git a/src/Simulator/RedstoneSimulator.h b/src/Simulator/RedstoneSimulator.h index 9e244d7da..59400b614 100644 --- a/src/Simulator/RedstoneSimulator.h +++ b/src/Simulator/RedstoneSimulator.h @@ -111,6 +111,8 @@ private: bool AreCoordsPowered(int a_BlockX, int a_BlockY, int a_BlockZ); /// Returns if a repeater is powered bool IsRepeaterPowered(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_Meta); + /// Returns if a piston is powered + bool IsPistonPowered(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_Meta); /// Returns if lever metadata marks it as emitting power bool IsLeverOn(NIBBLETYPE a_BlockMeta); -- cgit v1.2.3 From 1932cc38a1fba31a61be2f1a5d17ced46d5915ad Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 7 Dec 2013 14:41:58 +0000 Subject: Fixed trapdoors not toggling The redstone simulator kept on resetting them. --- src/Simulator/RedstoneSimulator.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/Simulator/RedstoneSimulator.h') diff --git a/src/Simulator/RedstoneSimulator.h b/src/Simulator/RedstoneSimulator.h index 59400b614..e094150e8 100644 --- a/src/Simulator/RedstoneSimulator.h +++ b/src/Simulator/RedstoneSimulator.h @@ -50,12 +50,20 @@ private: BLOCKTYPE a_SourceBlock; BLOCKTYPE a_MiddleBlock; }; + + struct sSimulatedPlayerToggleableList + { + Vector3i a_BlockPos; + bool WasLastStatePowered; + }; typedef std::vector PoweredBlocksList; typedef std::vector LinkedBlocksList; + typedef std::vector SimulatedPlayerToggleableList; PoweredBlocksList m_PoweredBlocks; LinkedBlocksList m_LinkedPoweredBlocks; + SimulatedPlayerToggleableList m_SimulatedPlayerToggleableBlocks; virtual void AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk) override; @@ -102,6 +110,8 @@ private: void SetBlockPowered(int a_BlockX, int a_BlockY, int a_BlockZ, int a_SourceX, int a_SourceY, int a_SourceZ, BLOCKTYPE a_SourceBlock); /// Marks a block as being powered through another block void SetBlockLinkedPowered(int a_BlockX, int a_BlockY, int a_BlockZ, int a_MiddleX, int a_MiddleY, int a_MiddleZ, int a_SourceX, int a_SourceY, int a_SourceZ, BLOCKTYPE a_SourceBlock, BLOCKTYPE a_MiddeBlock); + /// Marks a block as simulated, who should not be simulated further unless their power state changes, to accomodate a player manually toggling the block without triggering the simulator toggling it back + void SetPlayerToggleableBlockAsSimulated(int a_BlockX, int a_BlockY, int a_BlockZ, bool WasLastStatePowered); /// Marks the second block in a direction as linked powered void SetDirectionLinkedPowered(int a_BlockX, int a_BlockY, int a_BlockZ, char a_Direction, BLOCKTYPE a_SourceBlock); /// Marks all blocks immediately surrounding a coordinate as powered @@ -109,6 +119,8 @@ private: /// Returns if a coordinate is powered or linked powered bool AreCoordsPowered(int a_BlockX, int a_BlockY, int a_BlockZ); + /// Returns if a coordinate was marked as simulated (for blocks toggleable by players) + bool AreCoordsSimulated(int a_BlockX, int a_BlockY, int a_BlockZ, bool IsCurrentStatePowered); /// Returns if a repeater is powered bool IsRepeaterPowered(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_Meta); /// Returns if a piston is powered -- cgit v1.2.3