From 440b74af6cae6c93075f622c815f9e2cf518362e Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 7 Apr 2014 12:02:41 +0100 Subject: Fixed #859 --- src/Simulator/IncrementalRedstoneSimulator.cpp | 26 +++----------------------- 1 file changed, 3 insertions(+), 23 deletions(-) (limited to 'src/Simulator/IncrementalRedstoneSimulator.cpp') diff --git a/src/Simulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator.cpp index 92659fab7..86462f4cb 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.cpp +++ b/src/Simulator/IncrementalRedstoneSimulator.cpp @@ -96,26 +96,6 @@ void cIncrementalRedstoneSimulator::RedstoneAddBlock(int a_BlockX, int a_BlockY, PoweredBlocks->erase(itr); break; } - else if (Block == E_BLOCK_DAYLIGHT_SENSOR) - { - if (!a_Chunk->IsLightValid()) - { - m_World.QueueLightChunk(a_Chunk->GetPosX(), a_Chunk->GetPosZ()); - break; - } - else - { - NIBBLETYPE SkyLight; - a_Chunk->UnboundedRelGetBlockSkyLight(RelX, itr->a_SourcePos.y + 1, RelZ, SkyLight); - - if (a_Chunk->GetTimeAlteredLight(SkyLight) <= 8) // Could use SkyLight - m_World.GetSkyDarkness(); - { - LOGD("cIncrementalRedstoneSimulator: Erased daylight sensor from powered blocks list due to insufficient light level"); - PoweredBlocks->erase(itr); - break; - } - } - } } LinkedBlocksList * LinkedPoweredBlocks = a_Chunk->GetRedstoneSimulatorLinkedBlocksList(); @@ -558,8 +538,8 @@ void cIncrementalRedstoneSimulator::HandleRedstoneWire(int a_BlockX, int a_Block } else { - NIBBLETYPE MetaToSet = 0; NIBBLETYPE MyMeta = m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + NIBBLETYPE MetaToSet = MyMeta; int TimesMetaSmaller = 0, TimesFoundAWire = 0; for (size_t i = 0; i < ARRAYCOUNT(gCrossCoords); i++) // Loop through all directions to transfer or receive power @@ -589,9 +569,9 @@ void cIncrementalRedstoneSimulator::HandleRedstoneWire(int a_BlockX, int a_Block if (SurroundMeta > 1) // Wires of power 1 or 0 cannot transfer power TO ME, don't bother checking { - // Does surrounding wire have a higher power level than self? + // Does surrounding wire have a higher power level than the highest so far (MetaToSet)? // >= 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) + if (SurroundMeta >= MetaToSet) { MetaToSet = SurroundMeta - 1; // To improve performance } -- cgit v1.2.3 From 4f8f686292e8a55ae5b172a191c955ddd1fa9457 Mon Sep 17 00:00:00 2001 From: wiseoldman95 Date: Mon, 7 Apr 2014 19:55:17 +0300 Subject: Slight cleanup It is more efficient and readable if we do nothing unless we're not locked. --- src/Simulator/IncrementalRedstoneSimulator.cpp | 30 +++++++++++++++----------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'src/Simulator/IncrementalRedstoneSimulator.cpp') diff --git a/src/Simulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator.cpp index f12c29211..420d7c3f6 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.cpp +++ b/src/Simulator/IncrementalRedstoneSimulator.cpp @@ -684,22 +684,26 @@ void cIncrementalRedstoneSimulator::HandleRedstoneWire(int a_BlockX, int a_Block void cIncrementalRedstoneSimulator::HandleRedstoneRepeater(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_MyState) { // Create a variable holding my meta to avoid multiple lookups. - NIBBLETYPE a_Meta = m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + NIBBLETYPE a_Meta = m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); - // Do the same for being on, self powered or locked. - bool IsOn = (a_MyState == E_BLOCK_REDSTONE_REPEATER_ON); - bool IsSelfPowered = IsRepeaterPowered(a_BlockX, a_BlockY, a_BlockZ, a_Meta); - bool IsLocked = IsRepeaterLocked(a_BlockX, a_BlockY, a_BlockZ, a_Meta); + - if (IsSelfPowered && !IsOn && !IsLocked) // Queue a power change if powered, but not on and not locked. - { - QueueRepeaterPowerChange(a_BlockX, a_BlockY, a_BlockZ, a_Meta, true); - } - else if (!IsSelfPowered && IsOn && !IsLocked) // Queue a power change if unpowered, on, and not locked. - { - QueueRepeaterPowerChange(a_BlockX, a_BlockY, a_BlockZ, a_Meta, false); + + if (IsRepeaterLocked(a_BlockX, a_BlockY, a_BlockZ, a_Meta)) // If we're locked, change nothing. Otherwise: + { + // Create a variable holding being on or self powered to avoid multiple lookups. + bool IsOn = (a_MyState == E_BLOCK_REDSTONE_REPEATER_ON); + bool IsSelfPowered = IsRepeaterPowered(a_BlockX, a_BlockY, a_BlockZ, a_Meta); + if (IsSelfPowered && !IsOn && !IsLocked) // Queue a power change if powered, but not on and not locked. + { + QueueRepeaterPowerChange(a_BlockX, a_BlockY, a_BlockZ, a_Meta, true); + } + else if (!IsSelfPowered && IsOn && !IsLocked) // Queue a power change if unpowered, on, and not locked. + { + QueueRepeaterPowerChange(a_BlockX, a_BlockY, a_BlockZ, a_Meta, false); + } } - + for (RepeatersDelayList::iterator itr = m_RepeatersDelayList->begin(); itr != m_RepeatersDelayList->end(); ++itr) { if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) -- cgit v1.2.3 From 45eb539a17f92117905ef924db772599d8a146f0 Mon Sep 17 00:00:00 2001 From: wiseoldman95 Date: Mon, 7 Apr 2014 20:00:38 +0300 Subject: Removed unneeded spacings --- src/Simulator/IncrementalRedstoneSimulator.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'src/Simulator/IncrementalRedstoneSimulator.cpp') diff --git a/src/Simulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator.cpp index 420d7c3f6..c8509de12 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.cpp +++ b/src/Simulator/IncrementalRedstoneSimulator.cpp @@ -684,12 +684,9 @@ void cIncrementalRedstoneSimulator::HandleRedstoneWire(int a_BlockX, int a_Block void cIncrementalRedstoneSimulator::HandleRedstoneRepeater(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_MyState) { // Create a variable holding my meta to avoid multiple lookups. - NIBBLETYPE a_Meta = m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + NIBBLETYPE a_Meta = m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); - - - - if (IsRepeaterLocked(a_BlockX, a_BlockY, a_BlockZ, a_Meta)) // If we're locked, change nothing. Otherwise: + if (!IsRepeaterLocked(a_BlockX, a_BlockY, a_BlockZ, a_Meta)) // If we're locked, change nothing. Otherwise: { // Create a variable holding being on or self powered to avoid multiple lookups. bool IsOn = (a_MyState == E_BLOCK_REDSTONE_REPEATER_ON); @@ -703,7 +700,7 @@ void cIncrementalRedstoneSimulator::HandleRedstoneRepeater(int a_BlockX, int a_B QueueRepeaterPowerChange(a_BlockX, a_BlockY, a_BlockZ, a_Meta, false); } } - + for (RepeatersDelayList::iterator itr = m_RepeatersDelayList->begin(); itr != m_RepeatersDelayList->end(); ++itr) { if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) -- cgit v1.2.3 From 011123726b2e394c96a4c67b51bd7a86cc1cb13d Mon Sep 17 00:00:00 2001 From: wiseoldman95 Date: Mon, 7 Apr 2014 20:26:23 +0300 Subject: Removed stray IsLocked --- src/Simulator/IncrementalRedstoneSimulator.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Simulator/IncrementalRedstoneSimulator.cpp') diff --git a/src/Simulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator.cpp index c8509de12..ebe8e2541 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.cpp +++ b/src/Simulator/IncrementalRedstoneSimulator.cpp @@ -691,11 +691,11 @@ void cIncrementalRedstoneSimulator::HandleRedstoneRepeater(int a_BlockX, int a_B // Create a variable holding being on or self powered to avoid multiple lookups. bool IsOn = (a_MyState == E_BLOCK_REDSTONE_REPEATER_ON); bool IsSelfPowered = IsRepeaterPowered(a_BlockX, a_BlockY, a_BlockZ, a_Meta); - if (IsSelfPowered && !IsOn && !IsLocked) // Queue a power change if powered, but not on and not locked. + if (IsSelfPowered && !IsOn) // Queue a power change if powered, but not on and not locked. { QueueRepeaterPowerChange(a_BlockX, a_BlockY, a_BlockZ, a_Meta, true); } - else if (!IsSelfPowered && IsOn && !IsLocked) // Queue a power change if unpowered, on, and not locked. + else if (!IsSelfPowered && IsOn) // Queue a power change if unpowered, on, and not locked. { QueueRepeaterPowerChange(a_BlockX, a_BlockY, a_BlockZ, a_Meta, false); } -- cgit v1.2.3 From dab01b27c68036fff76edba0d96d518867c574a0 Mon Sep 17 00:00:00 2001 From: wiseoldman95 Date: Mon, 7 Apr 2014 21:04:06 +0300 Subject: Fixed IsOn --- src/Simulator/IncrementalRedstoneSimulator.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/Simulator/IncrementalRedstoneSimulator.cpp') diff --git a/src/Simulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator.cpp index ebe8e2541..8f82c454e 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.cpp +++ b/src/Simulator/IncrementalRedstoneSimulator.cpp @@ -685,11 +685,10 @@ void cIncrementalRedstoneSimulator::HandleRedstoneRepeater(int a_BlockX, int a_B { // Create a variable holding my meta to avoid multiple lookups. NIBBLETYPE a_Meta = m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); - + bool IsOn = (a_MyState == E_BLOCK_REDSTONE_REPEATER_ON); + if (!IsRepeaterLocked(a_BlockX, a_BlockY, a_BlockZ, a_Meta)) // If we're locked, change nothing. Otherwise: { - // Create a variable holding being on or self powered to avoid multiple lookups. - bool IsOn = (a_MyState == E_BLOCK_REDSTONE_REPEATER_ON); bool IsSelfPowered = IsRepeaterPowered(a_BlockX, a_BlockY, a_BlockZ, a_Meta); if (IsSelfPowered && !IsOn) // Queue a power change if powered, but not on and not locked. { -- cgit v1.2.3 From 4d32f41b8b01b6c1e74689a3fd73aa3b29b3c940 Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Tue, 8 Apr 2014 14:48:24 +0100 Subject: Fixed the thing properly. --- src/Simulator/IncrementalRedstoneSimulator.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/Simulator/IncrementalRedstoneSimulator.cpp') diff --git a/src/Simulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator.cpp index fc239169c..9903fc7d3 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.cpp +++ b/src/Simulator/IncrementalRedstoneSimulator.cpp @@ -1211,24 +1211,24 @@ bool cIncrementalRedstoneSimulator::IsRepeaterLocked(int a_BlockX, int a_BlockY, { // If the repeater is facing one direction, do one thing. - case 0x0: + case 0x0: case 0x2: { if (m_World.GetBlock(a_BlockX + 1, a_BlockY, a_BlockZ) == E_BLOCK_REDSTONE_REPEATER_ON) // Is right neighbor a - { + { NIBBLETYPE otherRepeaterDir = m_World.GetBlockMeta(a_BlockX + 1, a_BlockY, a_BlockZ) & 0x3; - if (otherRepeaterDir == 0x1) { return true; } + if (otherRepeaterDir == 0x3) { return true; } } - + if (m_World.GetBlock(a_BlockX - 1, a_BlockY, a_BlockZ) == E_BLOCK_REDSTONE_REPEATER_ON) - { + { NIBBLETYPE otherRepeaterDir = m_World.GetBlockMeta(a_BlockX -1, a_BlockY, a_BlockZ) & 0x3; - if (otherRepeaterDir == 0x3) { return true; } + if (otherRepeaterDir == 0x1) { return true; } } - + break; } - + // If another, do the other. case 0x1: case 0x3: -- cgit v1.2.3 From 506f5def049f59059a503d99b59c69b9b2a81b2b Mon Sep 17 00:00:00 2001 From: wiseoldman95 Date: Tue, 8 Apr 2014 17:14:23 +0300 Subject: Added comments regarding latching and orientation No real code was changed. --- src/Simulator/IncrementalRedstoneSimulator.cpp | 40 ++++++++++++++++++++------ 1 file changed, 31 insertions(+), 9 deletions(-) (limited to 'src/Simulator/IncrementalRedstoneSimulator.cpp') diff --git a/src/Simulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator.cpp index 9903fc7d3..26c8355dd 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.cpp +++ b/src/Simulator/IncrementalRedstoneSimulator.cpp @@ -12,7 +12,25 @@ - + // Orientation mini guide: + /* + ^ + | + | Z Axis + + X Axis ----> + + Block Direction, and value of _World.GetBlockMeta(a_BlockX , a_BlockY, a_BlockZ): + + Right (X+): 0x1 + Left (X-): 0x3 + Up (z+): 0x2 + Down (z-): 0x0 + + //TODO: Define those in preprocessor and replace them everywhere in the entire project. + Sun rises from right (X+) + */ + cIncrementalRedstoneSimulator::cIncrementalRedstoneSimulator(cWorld & a_World) : super(a_World) @@ -1206,50 +1224,54 @@ bool cIncrementalRedstoneSimulator::IsRepeaterPowered(int a_BlockX, int a_BlockY bool cIncrementalRedstoneSimulator::IsRepeaterLocked(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_Meta) { - // Change checking direction according to meta rotation. + switch (a_Meta & 0x3) //compare my direction to my neighbor's { - // If the repeater is facing one direction, do one thing. + // If the repeater is looking up or down (If parallel to the Z axis) case 0x0: case 0x2: { + //Check if right neighbor is a powered on repeater who is facing us. if (m_World.GetBlock(a_BlockX + 1, a_BlockY, a_BlockZ) == E_BLOCK_REDSTONE_REPEATER_ON) // Is right neighbor a { NIBBLETYPE otherRepeaterDir = m_World.GetBlockMeta(a_BlockX + 1, a_BlockY, a_BlockZ) & 0x3; - if (otherRepeaterDir == 0x3) { return true; } + if (otherRepeaterDir == 0x3) { return true; } //If so, I am latched/locked. } + //Check if left neighbor is a powered on repeater who is facing us. if (m_World.GetBlock(a_BlockX - 1, a_BlockY, a_BlockZ) == E_BLOCK_REDSTONE_REPEATER_ON) { NIBBLETYPE otherRepeaterDir = m_World.GetBlockMeta(a_BlockX -1, a_BlockY, a_BlockZ) & 0x3; - if (otherRepeaterDir == 0x1) { return true; } + if (otherRepeaterDir == 0x1) { return true; } //If so, I am latched/locked. } break; } - // If another, do the other. + // If the repeater is looking left or right (If parallel to the x axis) case 0x1: case 0x3: { + //Check if upper neighbor is a powered on repeater who is facing us. if (m_World.GetBlock(a_BlockX, a_BlockY, a_BlockZ + 1) == E_BLOCK_REDSTONE_REPEATER_ON) { NIBBLETYPE otherRepeaterDir = m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ + 1) & 0x3; - if (otherRepeaterDir == 0x0) { return true; } + if (otherRepeaterDir == 0x0) { return true; } //If so, am latched/locked. } + //Check if bottom neighbor is a powered on repeater who is facing us. if (m_World.GetBlock(a_BlockX, a_BlockY, a_BlockZ -1) == E_BLOCK_REDSTONE_REPEATER_ON) { NIBBLETYPE otherRepeaterDir = m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ - 1) & 0x3; - if (otherRepeaterDir == 0x2) { return true; } + if (otherRepeaterDir == 0x2) { return true; } //If so, I am latched/locked. } break; } } - return false; + return false; //None of the checks succeeded, I am not a locked repeater. } -- cgit v1.2.3 From fb90afd651a1bf3c3f7fc2599b951365570498c7 Mon Sep 17 00:00:00 2001 From: wiseoldman95 Date: Tue, 8 Apr 2014 17:55:03 +0300 Subject: Comments: Inverted Z axis. -Comments fix, No code has been changed. -Inverted the Z axis in the comments and changed all dependent comments accordingly. -Added NORTH/SOUTH/EAST/WEST in addition to LEFT/RIGHT/UP/DOWN. --- src/Simulator/IncrementalRedstoneSimulator.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'src/Simulator/IncrementalRedstoneSimulator.cpp') diff --git a/src/Simulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator.cpp index 26c8355dd..478bbed7e 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.cpp +++ b/src/Simulator/IncrementalRedstoneSimulator.cpp @@ -14,18 +14,19 @@ // Orientation mini guide: /* - ^ + | | Z Axis + V X Axis ----> Block Direction, and value of _World.GetBlockMeta(a_BlockX , a_BlockY, a_BlockZ): - Right (X+): 0x1 - Left (X-): 0x3 - Up (z+): 0x2 - Down (z-): 0x0 + East (Right) (X+): 0x1 + West (Left) (X-): 0x3 + North (Up) (z-): 0x2 + South (Down) (z+): 0x0 //TODO: Define those in preprocessor and replace them everywhere in the entire project. Sun rises from right (X+) @@ -1232,14 +1233,14 @@ bool cIncrementalRedstoneSimulator::IsRepeaterLocked(int a_BlockX, int a_BlockY, case 0x0: case 0x2: { - //Check if right neighbor is a powered on repeater who is facing us. + //Check if eastern(right) neighbor is a powered on repeater who is facing us. if (m_World.GetBlock(a_BlockX + 1, a_BlockY, a_BlockZ) == E_BLOCK_REDSTONE_REPEATER_ON) // Is right neighbor a { NIBBLETYPE otherRepeaterDir = m_World.GetBlockMeta(a_BlockX + 1, a_BlockY, a_BlockZ) & 0x3; if (otherRepeaterDir == 0x3) { return true; } //If so, I am latched/locked. } - //Check if left neighbor is a powered on repeater who is facing us. + //Check if western(left) neighbor is a powered on repeater who is facing us. if (m_World.GetBlock(a_BlockX - 1, a_BlockY, a_BlockZ) == E_BLOCK_REDSTONE_REPEATER_ON) { NIBBLETYPE otherRepeaterDir = m_World.GetBlockMeta(a_BlockX -1, a_BlockY, a_BlockZ) & 0x3; @@ -1253,14 +1254,14 @@ bool cIncrementalRedstoneSimulator::IsRepeaterLocked(int a_BlockX, int a_BlockY, case 0x1: case 0x3: { - //Check if upper neighbor is a powered on repeater who is facing us. + //Check if southern(down) neighbor is a powered on repeater who is facing us. if (m_World.GetBlock(a_BlockX, a_BlockY, a_BlockZ + 1) == E_BLOCK_REDSTONE_REPEATER_ON) { NIBBLETYPE otherRepeaterDir = m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ + 1) & 0x3; if (otherRepeaterDir == 0x0) { return true; } //If so, am latched/locked. } - //Check if bottom neighbor is a powered on repeater who is facing us. + //Check if northern(up) neighbor is a powered on repeater who is facing us. if (m_World.GetBlock(a_BlockX, a_BlockY, a_BlockZ -1) == E_BLOCK_REDSTONE_REPEATER_ON) { NIBBLETYPE otherRepeaterDir = m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ - 1) & 0x3; -- cgit v1.2.3 From 6a0c122dfb25958eb961d6b421355e599b517a4b Mon Sep 17 00:00:00 2001 From: wiseoldman95 Date: Tue, 8 Apr 2014 17:59:42 +0300 Subject: Uppercased Z Minor, no code changed. --- src/Simulator/IncrementalRedstoneSimulator.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/Simulator/IncrementalRedstoneSimulator.cpp') diff --git a/src/Simulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator.cpp index 478bbed7e..f3482dcc5 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.cpp +++ b/src/Simulator/IncrementalRedstoneSimulator.cpp @@ -25,11 +25,11 @@ East (Right) (X+): 0x1 West (Left) (X-): 0x3 - North (Up) (z-): 0x2 - South (Down) (z+): 0x0 + North (Up) (Z-): 0x2 + South (Down) (Z+): 0x0 //TODO: Define those in preprocessor and replace them everywhere in the entire project. - Sun rises from right (X+) + Sun rises from East (X+) */ -- cgit v1.2.3 From c3fcc5b132556a798c945d751900d9ae21c69b07 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 8 Apr 2014 18:49:53 +0100 Subject: cRedstoneSimulator.cpp style improvements --- src/Simulator/IncrementalRedstoneSimulator.cpp | 81 +++++++++++++------------- 1 file changed, 41 insertions(+), 40 deletions(-) (limited to 'src/Simulator/IncrementalRedstoneSimulator.cpp') diff --git a/src/Simulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator.cpp index f3482dcc5..50cac8d7e 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.cpp +++ b/src/Simulator/IncrementalRedstoneSimulator.cpp @@ -1,3 +1,4 @@ + #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "IncrementalRedstoneSimulator.h" @@ -12,25 +13,6 @@ - // Orientation mini guide: - /* - - | - | Z Axis - V - - X Axis ----> - - Block Direction, and value of _World.GetBlockMeta(a_BlockX , a_BlockY, a_BlockZ): - - East (Right) (X+): 0x1 - West (Left) (X-): 0x3 - North (Up) (Z-): 0x2 - South (Down) (Z+): 0x0 - - //TODO: Define those in preprocessor and replace them everywhere in the entire project. - Sun rises from East (X+) - */ cIncrementalRedstoneSimulator::cIncrementalRedstoneSimulator(cWorld & a_World) @@ -682,12 +664,33 @@ void cIncrementalRedstoneSimulator::HandleRedstoneWire(int a_BlockX, int a_Block void cIncrementalRedstoneSimulator::HandleRedstoneRepeater(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_MyState) { + /* Repeater Orientation Mini Guide: + =================================== + + | + | Z Axis + V + + X Axis ----> + + Repeater directions, values from a cWorld::GetBlockMeta(a_BlockX , a_BlockY, a_BlockZ) lookup: + + East (Right) (X+): 0x1 + West (Left) (X-): 0x3 + North (Up) (Z-): 0x2 + South (Down) (Z+): 0x0 + // TODO: Add E_META_XXX enum entries for all meta values and update project with them + + Sun rises from East (X+) + + */ + // Create a variable holding my meta to avoid multiple lookups. NIBBLETYPE a_Meta = m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); - bool IsOn = (a_MyState == E_BLOCK_REDSTONE_REPEATER_ON); + bool IsOn = (a_MyState == E_BLOCK_REDSTONE_REPEATER_ON); - if (!IsRepeaterLocked(a_BlockX, a_BlockY, a_BlockZ, a_Meta)) // If we're locked, change nothing. Otherwise: - { + if (!IsRepeaterLocked(a_BlockX, a_BlockY, a_BlockZ, a_Meta)) // If we're locked, change nothing. Otherwise: + { bool IsSelfPowered = IsRepeaterPowered(a_BlockX, a_BlockY, a_BlockZ, a_Meta); if (IsSelfPowered && !IsOn) // Queue a power change if powered, but not on and not locked. { @@ -1224,27 +1227,25 @@ bool cIncrementalRedstoneSimulator::IsRepeaterPowered(int a_BlockX, int a_BlockY bool cIncrementalRedstoneSimulator::IsRepeaterLocked(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_Meta) -{ - - switch (a_Meta & 0x3) //compare my direction to my neighbor's +{ + switch (a_Meta & 0x3) // We only want the 'direction' part of our metadata { - // If the repeater is looking up or down (If parallel to the Z axis) case 0x0: case 0x2: { - //Check if eastern(right) neighbor is a powered on repeater who is facing us. - if (m_World.GetBlock(a_BlockX + 1, a_BlockY, a_BlockZ) == E_BLOCK_REDSTONE_REPEATER_ON) // Is right neighbor a + // Check if eastern(right) neighbor is a powered on repeater who is facing us. + if (m_World.GetBlock(a_BlockX + 1, a_BlockY, a_BlockZ) == E_BLOCK_REDSTONE_REPEATER_ON) // Is right neighbor a powered repeater? { - NIBBLETYPE otherRepeaterDir = m_World.GetBlockMeta(a_BlockX + 1, a_BlockY, a_BlockZ) & 0x3; - if (otherRepeaterDir == 0x3) { return true; } //If so, I am latched/locked. + NIBBLETYPE OtherRepeaterDir = m_World.GetBlockMeta(a_BlockX + 1, a_BlockY, a_BlockZ) & 0x3; + if (OtherRepeaterDir == 0x3) { return true; } // If so, I am latched/locked. } - //Check if western(left) neighbor is a powered on repeater who is facing us. + // Check if western(left) neighbor is a powered on repeater who is facing us. if (m_World.GetBlock(a_BlockX - 1, a_BlockY, a_BlockZ) == E_BLOCK_REDSTONE_REPEATER_ON) { - NIBBLETYPE otherRepeaterDir = m_World.GetBlockMeta(a_BlockX -1, a_BlockY, a_BlockZ) & 0x3; - if (otherRepeaterDir == 0x1) { return true; } //If so, I am latched/locked. + NIBBLETYPE OtherRepeaterDir = m_World.GetBlockMeta(a_BlockX -1, a_BlockY, a_BlockZ) & 0x3; + if (OtherRepeaterDir == 0x1) { return true; } // If so, I am latched/locked. } break; @@ -1254,25 +1255,25 @@ bool cIncrementalRedstoneSimulator::IsRepeaterLocked(int a_BlockX, int a_BlockY, case 0x1: case 0x3: { - //Check if southern(down) neighbor is a powered on repeater who is facing us. + // Check if southern(down) neighbor is a powered on repeater who is facing us. if (m_World.GetBlock(a_BlockX, a_BlockY, a_BlockZ + 1) == E_BLOCK_REDSTONE_REPEATER_ON) { - NIBBLETYPE otherRepeaterDir = m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ + 1) & 0x3; - if (otherRepeaterDir == 0x0) { return true; } //If so, am latched/locked. + NIBBLETYPE OtherRepeaterDir = m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ + 1) & 0x3; + if (OtherRepeaterDir == 0x0) { return true; } // If so, am latched/locked. } - //Check if northern(up) neighbor is a powered on repeater who is facing us. + // Check if northern(up) neighbor is a powered on repeater who is facing us. if (m_World.GetBlock(a_BlockX, a_BlockY, a_BlockZ -1) == E_BLOCK_REDSTONE_REPEATER_ON) { - NIBBLETYPE otherRepeaterDir = m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ - 1) & 0x3; - if (otherRepeaterDir == 0x2) { return true; } //If so, I am latched/locked. + NIBBLETYPE OtherRepeaterDir = m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ - 1) & 0x3; + if (OtherRepeaterDir == 0x2) { return true; } // If so, I am latched/locked. } break; } } - return false; //None of the checks succeeded, I am not a locked repeater. + return false; // None of the checks succeeded, I am not a locked repeater. } -- cgit v1.2.3