From aecdfebf365d462e5405e21f1998e99d50bc1028 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 9 Dec 2013 23:43:26 +0000 Subject: Changed more FastSetBlocks to SetBlocks Fixes duplication bugs. --- src/Simulator/RedstoneSimulator.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/Simulator/RedstoneSimulator.cpp') diff --git a/src/Simulator/RedstoneSimulator.cpp b/src/Simulator/RedstoneSimulator.cpp index 63e4f04a8..424e22ca4 100644 --- a/src/Simulator/RedstoneSimulator.cpp +++ b/src/Simulator/RedstoneSimulator.cpp @@ -285,7 +285,7 @@ void cRedstoneSimulator::HandleRedstoneTorch(int a_BlockX, int a_BlockY, int a_B if (AreCoordsPowered(X, Y, Z)) { // There was a match, torch goes off - m_World.FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_TORCH_OFF, m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ)); + m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_TORCH_OFF, m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ)); return; } @@ -335,7 +335,7 @@ void cRedstoneSimulator::HandleRedstoneTorch(int a_BlockX, int a_BlockY, int a_B } // Block torch on not powered, can be turned on again! - m_World.FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_TORCH_ON, m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ)); + m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_TORCH_ON, m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ)); } } @@ -572,7 +572,7 @@ void cRedstoneSimulator::HandleRedstoneRepeater(int a_BlockX, int a_BlockY, int { if (IsOn) { - m_World.FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_REPEATER_OFF, a_Meta); + m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_REPEATER_OFF, a_Meta); } } } -- cgit v1.2.3 From ebad87d870174ed2e99be5d4f4404a8ad2aa8ab8 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 9 Dec 2013 23:48:06 +0000 Subject: Slight redstone wire performance improvement --- src/Simulator/RedstoneSimulator.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/Simulator/RedstoneSimulator.cpp') diff --git a/src/Simulator/RedstoneSimulator.cpp b/src/Simulator/RedstoneSimulator.cpp index 424e22ca4..c5fc1fb3f 100644 --- a/src/Simulator/RedstoneSimulator.cpp +++ b/src/Simulator/RedstoneSimulator.cpp @@ -420,6 +420,7 @@ void cRedstoneSimulator::HandleRedstoneWire(int a_BlockX, int a_BlockY, int a_Bl } else { + NIBBLETYPE MetaToSet = 0; NIBBLETYPE MyMeta = m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); int TimesMetaSmaller = 0, TimesFoundAWire = 0; @@ -439,7 +440,7 @@ void cRedstoneSimulator::HandleRedstoneWire(int a_BlockX, int a_BlockY, int a_Bl // >= to fix a bug where wires bordering each other with the same power level will appear (in terms of meta) to power each other, when they aren't actually in the powered list if (SurroundMeta >= MyMeta) { - m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, SurroundMeta - 1); + MetaToSet = SurroundMeta - 1; // To improve performance } } @@ -459,6 +460,10 @@ void cRedstoneSimulator::HandleRedstoneWire(int a_BlockX, int a_BlockY, int a_Bl m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, 0); return; // No need to process block power sets because self not powered } + else + { + m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, MetaToSet); + } SetBlockPowered(a_BlockX, a_BlockY - 1, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_WIRE); // Power block beneath } -- cgit v1.2.3 From 1dec73be0b3967796fc0baf43e19cbb6abd09c1e Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 10 Dec 2013 00:21:24 +0000 Subject: Added repeater delays They DO sometimes get stuck though :P --- src/Simulator/RedstoneSimulator.cpp | 54 ++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) (limited to 'src/Simulator/RedstoneSimulator.cpp') diff --git a/src/Simulator/RedstoneSimulator.cpp b/src/Simulator/RedstoneSimulator.cpp index c5fc1fb3f..2325ce6b6 100644 --- a/src/Simulator/RedstoneSimulator.cpp +++ b/src/Simulator/RedstoneSimulator.cpp @@ -543,6 +543,33 @@ void cRedstoneSimulator::HandleRedstoneRepeater(int a_BlockX, int a_BlockY, int { if (!IsOn) { + // If repeater is not on already (and is POWERED), see if it is in repeater list, or has reached delay time + for (RepeatersDelayList::iterator itr = m_RepeatersDelayList.begin(); itr != m_RepeatersDelayList.end(); itr++) + { + if (itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) + { + if (itr->a_DelayTicks <= itr->a_ElapsedTicks) // Shouldn't need <=; just in case something happens + { + m_RepeatersDelayList.erase(itr); + goto powerrepeater; // Delay time reached, break straight out, and into the powering code + } + else + { + itr->a_ElapsedTicks++; // Increment elapsed ticks and quit + return; + } + } + } + + // Self not in list, add self to list + sRepeatersDelayList RC; + RC.a_BlockPos = Vector3i(a_BlockX, a_BlockY, a_BlockZ); + RC.a_DelayTicks = ((a_Meta & 0xC) >> 0x2) + 1; // Gets the top two bits (delay time), shifts them into the lower two bits, and adds one (meta 0 = 1 tick; 1 = 2 etc.) + RC.a_ElapsedTicks = 0; + m_RepeatersDelayList.push_back(RC); + return; + +powerrepeater: m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_REPEATER_ON, a_Meta); // Only set if not on; SetBlock otherwise server doesn't set it in time for SimulateChunk's invalidation } switch (a_Meta & 0x3) // We only want the direction (bottom) bits @@ -577,7 +604,32 @@ void cRedstoneSimulator::HandleRedstoneRepeater(int a_BlockX, int a_BlockY, int { if (IsOn) { - m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_REPEATER_OFF, a_Meta); + // If repeater is not off already (and is NOT POWERED), see if it is in repeater list, or has reached delay time + for (RepeatersDelayList::iterator itr = m_RepeatersDelayList.begin(); itr != m_RepeatersDelayList.end(); itr++) + { + if (itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) + { + if (itr->a_DelayTicks <= itr->a_ElapsedTicks) // Shouldn't need <=; just in case something happens + { + m_RepeatersDelayList.erase(itr); + m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_REPEATER_OFF, a_Meta); + return; + } + else + { + itr->a_ElapsedTicks++; // Increment elapsed ticks and quit + return; + } + } + } + + // Self not in list, add self to list + sRepeatersDelayList RC; + RC.a_BlockPos = Vector3i(a_BlockX, a_BlockY, a_BlockZ); + RC.a_DelayTicks = ((a_Meta & 0xC) >> 0x2) + 1; + RC.a_ElapsedTicks = 0; + m_RepeatersDelayList.push_back(RC); + return; } } } -- cgit v1.2.3 From b6e02349858a31028e0faacc2d717556a4f1b5dd Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 10 Dec 2013 10:29:36 +0000 Subject: Fixed compile (alas, no more goto) --- src/Simulator/RedstoneSimulator.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'src/Simulator/RedstoneSimulator.cpp') diff --git a/src/Simulator/RedstoneSimulator.cpp b/src/Simulator/RedstoneSimulator.cpp index 2325ce6b6..93ad5890b 100644 --- a/src/Simulator/RedstoneSimulator.cpp +++ b/src/Simulator/RedstoneSimulator.cpp @@ -1,4 +1,3 @@ - #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "RedstoneSimulator.h" @@ -543,6 +542,7 @@ void cRedstoneSimulator::HandleRedstoneRepeater(int a_BlockX, int a_BlockY, int { if (!IsOn) { + bool ShouldCreate = true; // If repeater is not on already (and is POWERED), see if it is in repeater list, or has reached delay time for (RepeatersDelayList::iterator itr = m_RepeatersDelayList.begin(); itr != m_RepeatersDelayList.end(); itr++) { @@ -551,7 +551,8 @@ void cRedstoneSimulator::HandleRedstoneRepeater(int a_BlockX, int a_BlockY, int if (itr->a_DelayTicks <= itr->a_ElapsedTicks) // Shouldn't need <=; just in case something happens { m_RepeatersDelayList.erase(itr); - goto powerrepeater; // Delay time reached, break straight out, and into the powering code + ShouldCreate = false; + break; // Delay time reached, break straight out, and into the powering code } else { @@ -561,15 +562,17 @@ void cRedstoneSimulator::HandleRedstoneRepeater(int a_BlockX, int a_BlockY, int } } - // Self not in list, add self to list - sRepeatersDelayList RC; - RC.a_BlockPos = Vector3i(a_BlockX, a_BlockY, a_BlockZ); - RC.a_DelayTicks = ((a_Meta & 0xC) >> 0x2) + 1; // Gets the top two bits (delay time), shifts them into the lower two bits, and adds one (meta 0 = 1 tick; 1 = 2 etc.) - RC.a_ElapsedTicks = 0; - m_RepeatersDelayList.push_back(RC); - return; - -powerrepeater: + if (ShouldCreate) + { + // Self not in list, add self to list + sRepeatersDelayList RC; + RC.a_BlockPos = Vector3i(a_BlockX, a_BlockY, a_BlockZ); + RC.a_DelayTicks = ((a_Meta & 0xC) >> 0x2) + 1; // Gets the top two bits (delay time), shifts them into the lower two bits, and adds one (meta 0 = 1 tick; 1 = 2 etc.) + RC.a_ElapsedTicks = 0; + m_RepeatersDelayList.push_back(RC); + return; + } + m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_REPEATER_ON, a_Meta); // Only set if not on; SetBlock otherwise server doesn't set it in time for SimulateChunk's invalidation } switch (a_Meta & 0x3) // We only want the direction (bottom) bits -- cgit v1.2.3 From e2e8c9624c62999114f0c84b33317172b3a7ca4a Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 10 Dec 2013 10:31:42 +0000 Subject: Readded initial line --- src/Simulator/RedstoneSimulator.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/Simulator/RedstoneSimulator.cpp') diff --git a/src/Simulator/RedstoneSimulator.cpp b/src/Simulator/RedstoneSimulator.cpp index 93ad5890b..9328b9fcb 100644 --- a/src/Simulator/RedstoneSimulator.cpp +++ b/src/Simulator/RedstoneSimulator.cpp @@ -1,3 +1,4 @@ + #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "RedstoneSimulator.h" -- cgit v1.2.3