From 61cb08b54698e9b70f629858a6a9c5b389db8b3e Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 28 Jun 2014 20:44:34 +0100 Subject: Implemented tripwire(s) (hooks) * Fixes #944 --- src/Simulator/IncrementalRedstoneSimulator.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/Simulator/IncrementalRedstoneSimulator.h') diff --git a/src/Simulator/IncrementalRedstoneSimulator.h b/src/Simulator/IncrementalRedstoneSimulator.h index 9c1f9460c..6cefdebf2 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.h +++ b/src/Simulator/IncrementalRedstoneSimulator.h @@ -102,6 +102,11 @@ private: void HandleDaylightSensor(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ); /** Handles pressure plates */ void HandlePressurePlate(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ, BLOCKTYPE a_MyType); + /** Handles tripwire hooks + Performs correct meta and power setting for self by going in the direction it faces and looking for a continous line of tripwire bounded by another oppositely facing hook + If this line is complete, it verifies that at least on wire reports an entity is on top (via its meta), and performs its task + */ + void HandleTripwireHook(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ); /* ==================== */ /* ====== CARRIERS ====== */ @@ -134,6 +139,8 @@ private: void HandleFenceGate(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ); /** Handles noteblocks */ void HandleNoteBlock(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ); + /** Handles tripwires */ + void HandleTripwire(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ); /* ===================== */ /* ====== Helper functions ====== */ @@ -271,6 +278,7 @@ private: case E_BLOCK_TNT: case E_BLOCK_TRAPDOOR: case E_BLOCK_TRIPWIRE_HOOK: + case E_BLOCK_TRIPWIRE: case E_BLOCK_WOODEN_BUTTON: case E_BLOCK_WOODEN_DOOR: case E_BLOCK_WOODEN_PRESSURE_PLATE: -- cgit v1.2.3 From 9e44b0aae164f2456a452714f869cc9670732d8e Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 6 Jul 2014 23:50:22 +0100 Subject: Implemented trapped chests & others + Added trapped chests * Fixed a bunch of bugs in the redstone simulator concerning wires and repeaters * Other potential bugfixes --- src/Simulator/IncrementalRedstoneSimulator.h | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'src/Simulator/IncrementalRedstoneSimulator.h') diff --git a/src/Simulator/IncrementalRedstoneSimulator.h b/src/Simulator/IncrementalRedstoneSimulator.h index 6cefdebf2..ce987a60f 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.h +++ b/src/Simulator/IncrementalRedstoneSimulator.h @@ -107,6 +107,8 @@ private: If this line is complete, it verifies that at least on wire reports an entity is on top (via its meta), and performs its task */ void HandleTripwireHook(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ); + /** Handles trapped chests */ + void HandleTrappedChest(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ); /* ==================== */ /* ====== CARRIERS ====== */ @@ -114,8 +116,6 @@ private: void HandleRedstoneWire(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ); /** Handles repeaters */ void HandleRedstoneRepeater(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ, BLOCKTYPE a_MyState); - /** Handles delayed updates to Repeaters **/ - void HandleRedstoneRepeaterDelays(); /* ====================== */ /* ====== DEVICES ====== */ @@ -156,6 +156,10 @@ private: void SetAllDirsAsPowered(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ, unsigned char a_PowerLevel = MAX_POWER_LEVEL); /** Queues a repeater to be powered or unpowered and returns if the m_RepeatersDelayList iterators were invalidated */ bool QueueRepeaterPowerChange(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ, NIBBLETYPE a_Meta, bool ShouldPowerOn); + /** Removes a block from the Powered and LinkedPowered lists + Used for variable sources such as tripwire hooks, daylight sensors, and trapped chests + */ + void SetSourceUnpowered(int a_RelSourceX, int a_RelSourceY, int a_RelSourceZ, cChunk * a_Chunk, bool a_IsFirstCall = true); /** Returns if a coordinate is powered or linked powered */ bool AreCoordsPowered(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ) { return AreCoordsDirectlyPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ) || AreCoordsLinkedPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ); } @@ -174,7 +178,8 @@ private: /** Returns if a wire is powered The only diffence between this and a normal AreCoordsPowered is that this function checks for a wire powering another wire */ bool IsWirePowered(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ, unsigned char & a_PowerLevel); - + /** Handles delayed updates to repeaters **/ + void HandleRedstoneRepeaterDelays(void); /** Returns if lever metadata marks it as emitting power */ bool IsLeverOn(NIBBLETYPE a_BlockMeta); @@ -186,7 +191,9 @@ private: /** Returns if a block is viable to be the MiddleBlock of a SetLinkedPowered operation */ inline static bool IsViableMiddleBlock(BLOCKTYPE Block) { return cBlockInfo::FullyOccupiesVoxel(Block); } - /** Returns if a block is a mechanism (something that accepts power and does something) */ + /** Returns if a block is a mechanism (something that accepts power and does something) + Used by torches to determine if they power a block whilst not standing on the ground + */ inline static bool IsMechanism(BLOCKTYPE Block) { switch (Block) @@ -209,6 +216,7 @@ private: case E_BLOCK_REDSTONE_REPEATER_OFF: case E_BLOCK_REDSTONE_REPEATER_ON: case E_BLOCK_POWERED_RAIL: + case E_BLOCK_REDSTONE_WIRE: { return true; } @@ -235,6 +243,7 @@ private: case E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE: case E_BLOCK_STONE_PRESSURE_PLATE: case E_BLOCK_WOODEN_PRESSURE_PLATE: + case E_BLOCK_TRAPPED_CHEST: { return true; } @@ -277,6 +286,7 @@ private: case E_BLOCK_STONE_PRESSURE_PLATE: case E_BLOCK_TNT: case E_BLOCK_TRAPDOOR: + case E_BLOCK_TRAPPED_CHEST: case E_BLOCK_TRIPWIRE_HOOK: case E_BLOCK_TRIPWIRE: case E_BLOCK_WOODEN_BUTTON: @@ -289,6 +299,16 @@ private: default: return false; } } + + inline static bool AreCoordsOnChunkBoundary(int a_BlockX, int a_BlockY, int a_BlockZ) + { + return ( // Are we on a chunk boundary? +- 2 because of LinkedPowered blocks + ((a_BlockX % cChunkDef::Width) <= 1) || + ((a_BlockX % cChunkDef::Width) >= 14) || + ((a_BlockZ % cChunkDef::Width) <= 1) || + ((a_BlockZ % cChunkDef::Width) >= 14) + ); + } }; -- cgit v1.2.3 From 82fe5c05f0456a11fcb2079eaf44ee0565b0c3c7 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 14 Jul 2014 23:03:30 +0100 Subject: Fixed redstone simulator crash * Fixes #1176 * Fixed #1186 --- src/Simulator/IncrementalRedstoneSimulator.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Simulator/IncrementalRedstoneSimulator.h') diff --git a/src/Simulator/IncrementalRedstoneSimulator.h b/src/Simulator/IncrementalRedstoneSimulator.h index ce987a60f..1faf4187b 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.h +++ b/src/Simulator/IncrementalRedstoneSimulator.h @@ -162,9 +162,9 @@ private: void SetSourceUnpowered(int a_RelSourceX, int a_RelSourceY, int a_RelSourceZ, cChunk * a_Chunk, bool a_IsFirstCall = true); /** Returns if a coordinate is powered or linked powered */ - bool AreCoordsPowered(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ) { return AreCoordsDirectlyPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ) || AreCoordsLinkedPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ); } + bool AreCoordsPowered(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ) { return AreCoordsDirectlyPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ, m_Chunk) || AreCoordsLinkedPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ); } /** Returns if a coordinate is in the directly powered blocks list */ - bool AreCoordsDirectlyPowered(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ); + bool AreCoordsDirectlyPowered(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ, cChunk * a_Chunk); /** Returns if a coordinate is in the indirectly powered blocks list */ bool AreCoordsLinkedPowered(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ); /** Returns if a coordinate was marked as simulated (for blocks toggleable by players) */ -- cgit v1.2.3 From 2423fbf2efa39e28cc348acc11b9269e573dcdef Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 17 Jul 2014 22:15:34 +0200 Subject: Normalized comments. This was mostly done automatically and then visually inspected for obvious errors. All //-style comments should have a 2-space separation from the code, and 1 space after the comment sign. --- src/Simulator/IncrementalRedstoneSimulator.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/Simulator/IncrementalRedstoneSimulator.h') diff --git a/src/Simulator/IncrementalRedstoneSimulator.h b/src/Simulator/IncrementalRedstoneSimulator.h index 1faf4187b..878f88b71 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.h +++ b/src/Simulator/IncrementalRedstoneSimulator.h @@ -38,33 +38,33 @@ private: #define MAX_POWER_LEVEL 15 - struct sPoweredBlocks // Define structure of the directly powered blocks list + struct sPoweredBlocks // Define structure of the directly powered blocks list { - Vector3i a_BlockPos; // Position of powered block - Vector3i a_SourcePos; // Position of source powering the block at a_BlockPos + Vector3i a_BlockPos; // Position of powered block + Vector3i a_SourcePos; // Position of source powering the block at a_BlockPos unsigned char a_PowerLevel; }; - struct sLinkedPoweredBlocks // Define structure of the indirectly powered blocks list (i.e. repeaters powering through a block to the block at the other side) + struct sLinkedPoweredBlocks // Define structure of the indirectly powered blocks list (i.e. repeaters powering through a block to the block at the other side) { Vector3i a_BlockPos; - Vector3i a_MiddlePos; // Position of block that is betwixt a source and the destination + Vector3i a_MiddlePos; // Position of block that is betwixt a source and the destination Vector3i a_SourcePos; unsigned char a_PowerLevel; }; - struct sSimulatedPlayerToggleableList // Define structure of the list containing simulate-on-update blocks (such as trapdoors that respond once to a block update, and can be toggled by a player) + struct sSimulatedPlayerToggleableList // Define structure of the list containing simulate-on-update blocks (such as trapdoors that respond once to a block update, and can be toggled by a player) { Vector3i a_RelBlockPos; - bool WasLastStatePowered; // Was the last state powered or not? Determines whether a source update has happened and if I should resimulate + bool WasLastStatePowered; // Was the last state powered or not? Determines whether a source update has happened and if I should resimulate }; - struct sRepeatersDelayList // Define structure of list containing repeaters' delay states + struct sRepeatersDelayList // Define structure of list containing repeaters' delay states { Vector3i a_RelBlockPos; - unsigned char a_DelayTicks; // For how many ticks should the repeater delay - unsigned char a_ElapsedTicks; // How much of the previous has been elapsed? - bool ShouldPowerOn; // What happens when the delay time is fulfilled? + unsigned char a_DelayTicks; // For how many ticks should the repeater delay + unsigned char a_ElapsedTicks; // How much of the previous has been elapsed? + bool ShouldPowerOn; // What happens when the delay time is fulfilled? }; public: @@ -302,7 +302,7 @@ private: inline static bool AreCoordsOnChunkBoundary(int a_BlockX, int a_BlockY, int a_BlockZ) { - return ( // Are we on a chunk boundary? +- 2 because of LinkedPowered blocks + return ( // Are we on a chunk boundary? +- 2 because of LinkedPowered blocks ((a_BlockX % cChunkDef::Width) <= 1) || ((a_BlockX % cChunkDef::Width) >= 14) || ((a_BlockZ % cChunkDef::Width) <= 1) || -- cgit v1.2.3 From c03161f75d22a7965aea20fb9843ae580a07079a Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 17 Jul 2014 23:15:53 +0200 Subject: Fixed tabs used for alignment. --- src/Simulator/IncrementalRedstoneSimulator.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Simulator/IncrementalRedstoneSimulator.h') diff --git a/src/Simulator/IncrementalRedstoneSimulator.h b/src/Simulator/IncrementalRedstoneSimulator.h index 878f88b71..79740a8f6 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.h +++ b/src/Simulator/IncrementalRedstoneSimulator.h @@ -294,7 +294,7 @@ private: case E_BLOCK_WOODEN_PRESSURE_PLATE: case E_BLOCK_PISTON: { - return true; + return true; } default: return false; } -- cgit v1.2.3