summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2016-07-29 07:56:50 +0200
committerGitHub <noreply@github.com>2016-07-29 07:56:50 +0200
commita3112cdc45788babab7af6dd9c777d120f5d6e9c (patch)
tree47bb2d183d541d5f9611260c12eb3f002a07d6f9
parentMerge pull request #3226 from cuberite/redstone (diff)
downloadcuberite-a3112cdc45788babab7af6dd9c777d120f5d6e9c.tar
cuberite-a3112cdc45788babab7af6dd9c777d120f5d6e9c.tar.gz
cuberite-a3112cdc45788babab7af6dd9c777d120f5d6e9c.tar.bz2
cuberite-a3112cdc45788babab7af6dd9c777d120f5d6e9c.tar.lz
cuberite-a3112cdc45788babab7af6dd9c777d120f5d6e9c.tar.xz
cuberite-a3112cdc45788babab7af6dd9c777d120f5d6e9c.tar.zst
cuberite-a3112cdc45788babab7af6dd9c777d120f5d6e9c.zip
-rw-r--r--appveyor.yml4
-rw-r--r--src/Blocks/BlockComparator.h10
-rw-r--r--src/Blocks/BlockPiston.h6
-rw-r--r--src/Simulator/IncrementalRedstoneSimulator/PistonHandler.h29
-rw-r--r--src/Simulator/IncrementalRedstoneSimulator/RedstoneComparatorHandler.h109
5 files changed, 57 insertions, 101 deletions
diff --git a/appveyor.yml b/appveyor.yml
index 8be0cfa70..1f3f30911 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -1,11 +1,11 @@
version: 1.0.{build}
configuration: Debug
-clone_depth: 1
+clone_depth: 50
before_build:
- echo %TIME%
- git submodule update --init
- echo %TIME%
-- cmake .
+- cmake -G "Visual Studio 12" .
- echo %TIME%
build:
project: Cuberite.sln
diff --git a/src/Blocks/BlockComparator.h b/src/Blocks/BlockComparator.h
index 5ba17c691..394b53a15 100644
--- a/src/Blocks/BlockComparator.h
+++ b/src/Blocks/BlockComparator.h
@@ -60,16 +60,6 @@ public:
return true;
}
- inline static bool IsInSubtractionMode(NIBBLETYPE a_Meta)
- {
- return ((a_Meta & 0x4) == 0x4);
- }
-
- inline static bool IsOn(NIBBLETYPE a_Meta)
- {
- return ((a_Meta & 0x8) == 0x8);
- }
-
inline static Vector3i GetSideCoordinate(const Vector3i & a_Position, NIBBLETYPE a_Meta, bool a_bInverse)
{
auto Position = a_Position;
diff --git a/src/Blocks/BlockPiston.h b/src/Blocks/BlockPiston.h
index 18b688256..30ccc168d 100644
--- a/src/Blocks/BlockPiston.h
+++ b/src/Blocks/BlockPiston.h
@@ -93,9 +93,6 @@ public:
return 11;
}
- /** Returns true if the piston (with the specified meta) is extended */
- static inline bool IsExtended(NIBBLETYPE a_PistonMeta) { return ((a_PistonMeta & 0x8) != 0x0); }
-
private:
typedef std::unordered_set<Vector3i, VectorHasher<int>> Vector3iSet;
@@ -103,6 +100,9 @@ private:
/** Returns true if the piston (specified by blocktype) is a sticky piston */
static inline bool IsSticky(BLOCKTYPE a_BlockType) { return (a_BlockType == E_BLOCK_STICKY_PISTON); }
+ /** Returns true if the piston (with the specified meta) is extended */
+ static inline bool IsExtended(NIBBLETYPE a_PistonMeta) { return ((a_PistonMeta & 0x8) != 0x0); }
+
/** Returns true if the specified block can be pushed by a piston (and left intact) */
static inline bool CanPush(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
{
diff --git a/src/Simulator/IncrementalRedstoneSimulator/PistonHandler.h b/src/Simulator/IncrementalRedstoneSimulator/PistonHandler.h
index f82ebdf94..1ee68e521 100644
--- a/src/Simulator/IncrementalRedstoneSimulator/PistonHandler.h
+++ b/src/Simulator/IncrementalRedstoneSimulator/PistonHandler.h
@@ -39,37 +39,14 @@ public:
virtual cVector3iArray Update(const Vector3i & a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData) override
{
// LOGD("Evaluating pisty the piston (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
- auto Data = static_cast<cIncrementalRedstoneSimulator *>(m_World.GetRedstoneSimulator())->GetChunkData();
- auto DelayInfo = Data->GetMechanismDelayInfo(a_Position);
- // Delay is used here to prevent an infinite loop (#3168)
- if (DelayInfo == nullptr)
+ if (a_PoweringData.PowerLevel > 0)
{
- bool ShouldBeExtended = (a_PoweringData.PowerLevel != 0);
- if (ShouldBeExtended != cBlockPistonHandler::IsExtended(a_Meta))
- {
- Data->m_MechanismDelays[a_Position] = std::make_pair(1, ShouldBeExtended);
- }
+ cBlockPistonHandler::ExtendPiston(a_Position, &m_World);
}
else
{
- int DelayTicks;
- bool ShouldBeExtended;
- std::tie(DelayTicks, ShouldBeExtended) = *DelayInfo;
-
- if (DelayTicks == 0)
- {
- if (ShouldBeExtended)
- {
- cBlockPistonHandler::ExtendPiston(a_Position, &m_World);
- }
- else
- {
- cBlockPistonHandler::RetractPiston(a_Position, &m_World);
- }
-
- Data->m_MechanismDelays.erase(a_Position);
- }
+ cBlockPistonHandler::RetractPiston(a_Position, &m_World);
}
return {};
diff --git a/src/Simulator/IncrementalRedstoneSimulator/RedstoneComparatorHandler.h b/src/Simulator/IncrementalRedstoneSimulator/RedstoneComparatorHandler.h
index 34c217e67..95881990d 100644
--- a/src/Simulator/IncrementalRedstoneSimulator/RedstoneComparatorHandler.h
+++ b/src/Simulator/IncrementalRedstoneSimulator/RedstoneComparatorHandler.h
@@ -18,33 +18,8 @@ public:
{
}
- unsigned char GetFrontPowerLevel(const Vector3i & a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, unsigned char a_HighestSidePowerLevel, unsigned char a_HighestRearPowerLevel)
+ unsigned char GetFrontPowerLevel(const Vector3i & a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, unsigned char a_HighestSidePowerLevel)
{
- if (cBlockComparatorHandler::IsInSubtractionMode(a_Meta))
- {
- // Subtraction mode
- return static_cast<unsigned char>(std::max(static_cast<char>(a_HighestRearPowerLevel) - a_HighestSidePowerLevel, 0));
- }
- else
- {
- // Comparison mode
- return (std::max(a_HighestSidePowerLevel, a_HighestRearPowerLevel) == a_HighestSidePowerLevel) ? 0 : a_HighestRearPowerLevel;
- }
- }
-
- virtual unsigned char GetPowerDeliveredToPosition(const Vector3i & a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, const Vector3i & a_QueryPosition, BLOCKTYPE a_QueryBlockType) override
- {
- UNUSED(a_QueryPosition);
- UNUSED(a_QueryBlockType);
-
- return (cBlockComparatorHandler::GetFrontCoordinate(a_Position, a_Meta & 0x3) == a_QueryPosition) ? static_cast<cIncrementalRedstoneSimulator *>(m_World.GetRedstoneSimulator())->GetChunkData()->GetCachedPowerData(a_Position).PowerLevel : 0;
- }
-
- virtual unsigned char GetPowerLevel(const Vector3i & a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta) override
- {
- UNUSED(a_Position);
- UNUSED(a_BlockType);
-
class cContainerCallback : public cBlockEntityCallback
{
public:
@@ -56,13 +31,12 @@ public:
{
auto & Contents = static_cast<cBlockEntityWithItems *>(a_BlockEntity)->GetContents();
float Fullness = 0; // Is a floating-point type to allow later calculation to produce a non-truncated value
-
for (int Slot = 0; Slot != Contents.GetNumSlots(); ++Slot)
{
- Fullness += static_cast<float>(Contents.GetSlot(Slot).m_ItemCount) / Contents.GetSlot(Slot).GetMaxStackSize();
+ Fullness += Contents.GetSlot(Slot).m_ItemCount / Contents.GetSlot(Slot).GetMaxStackSize();
}
- m_SignalStrength = (Fullness < 0.001 /* container empty? */) ? 0 : static_cast<unsigned char>(1 + (Fullness / Contents.GetNumSlots()) * 14);
+ m_SignalStrength = static_cast<unsigned char>(1 + (Fullness / Contents.GetNumSlots()) * 14);
return false;
}
@@ -72,7 +46,6 @@ public:
auto RearCoordinate = cBlockComparatorHandler::GetRearCoordinate(a_Position, a_Meta & 0x3);
m_World.DoWithBlockEntityAt(RearCoordinate.x, RearCoordinate.y, RearCoordinate.z, CCB);
auto RearPower = CCB.m_SignalStrength;
-
auto PotentialSourceHandler = cIncrementalRedstoneSimulator::CreateComponent(m_World, m_World.GetBlock(RearCoordinate), static_cast<cIncrementalRedstoneSimulator *>(m_World.GetRedstoneSimulator())->GetChunkData());
if (PotentialSourceHandler != nullptr)
{
@@ -84,48 +57,64 @@ public:
}
}
- return RearPower;
+ if ((a_Meta & 0x4) == 0x4)
+ {
+ // Subtraction mode
+ return static_cast<unsigned char>(std::max(static_cast<char>(RearPower) - a_HighestSidePowerLevel, 0));
+ }
+ else
+ {
+ // Comparison mode
+ return (std::max(a_HighestSidePowerLevel, RearPower) == a_HighestSidePowerLevel) ? 0 : RearPower;
+ }
}
- virtual cVector3iArray Update(const Vector3i & a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData) override
+ virtual unsigned char GetPowerDeliveredToPosition(const Vector3i & a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, const Vector3i & a_QueryPosition, BLOCKTYPE a_QueryBlockType) override
{
- // Note that a_PoweringData here contains the maximum * side * power level, as specified by GetValidSourcePositions
- // LOGD("Evaluating ALU the comparator (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
- auto Data = static_cast<cIncrementalRedstoneSimulator *>(m_World.GetRedstoneSimulator())->GetChunkData();
- auto DelayInfo = Data->GetMechanismDelayInfo(a_Position);
+ UNUSED(a_QueryPosition);
+ UNUSED(a_QueryBlockType);
- // Delay is used here to prevent an infinite loop (#3168)
- if (DelayInfo == nullptr)
- {
- auto RearPower = GetPowerLevel(a_Position, a_BlockType, a_Meta);
- auto FrontPower = GetFrontPowerLevel(a_Position, a_BlockType, a_Meta, a_PoweringData.PowerLevel, RearPower);
- auto PreviousFrontPower = static_cast<cIncrementalRedstoneSimulator *>(m_World.GetRedstoneSimulator())->GetChunkData()->ExchangeUpdateOncePowerData(a_Position, PoweringData(a_PoweringData.PoweringBlock, FrontPower));
+ return (cBlockComparatorHandler::GetFrontCoordinate(a_Position, a_Meta & 0x3) == a_QueryPosition) ? static_cast<cIncrementalRedstoneSimulator *>(m_World.GetRedstoneSimulator())->GetChunkData()->GetCachedPowerData(a_Position).PowerLevel : 0;
+ }
- bool ShouldBeOn = (RearPower > 0); // Provide visual indication by examining * rear * power level
- bool ShouldUpdate = (FrontPower != PreviousFrontPower.PowerLevel); // "Business logic" (:P) - determine by examining *side* power levels
+ virtual unsigned char GetPowerLevel(const Vector3i & a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta) override
+ {
+ UNUSED(a_Position);
+ UNUSED(a_BlockType);
- if (ShouldUpdate || (ShouldBeOn != cBlockComparatorHandler::IsOn(a_Meta)))
+ auto RearCoordinate = cBlockComparatorHandler::GetRearCoordinate(a_Position, a_Meta & 0x3);
+ auto PotentialSourceHandler = cIncrementalRedstoneSimulator::CreateComponent(m_World, m_World.GetBlock(RearCoordinate), static_cast<cIncrementalRedstoneSimulator *>(m_World.GetRedstoneSimulator())->GetChunkData());
+ if (PotentialSourceHandler != nullptr)
+ {
+ BLOCKTYPE Type;
+ NIBBLETYPE Meta;
+ if (m_World.GetBlockTypeMeta(RearCoordinate.x, RearCoordinate.y, RearCoordinate.z, Type, Meta))
{
- Data->m_MechanismDelays[a_Position] = std::make_pair(1, ShouldBeOn);
+ return PotentialSourceHandler->GetPowerDeliveredToPosition(RearCoordinate, Type, Meta, a_Position, a_BlockType);
}
}
+
+ return 0;
+ }
+
+ virtual cVector3iArray Update(const Vector3i & a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData) override
+ {
+ // LOGD("Evaluating ALU the comparator (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
+
+ if (GetPowerLevel(a_Position, a_BlockType, a_Meta) > 0)
+ {
+ m_World.SetBlockMeta(a_Position, a_Meta | 0x8);
+ }
else
{
- int DelayTicks;
- bool ShouldPowerOn;
- std::tie(DelayTicks, ShouldPowerOn) = *DelayInfo;
+ m_World.SetBlockMeta(a_Position, a_Meta & 0x7);
+ }
- if (DelayTicks == 0)
- {
- m_World.SetBlockMeta(a_Position, ShouldPowerOn ? (a_Meta | 0x8) : (a_Meta & 0x7));
- Data->m_MechanismDelays.erase(a_Position);
-
- // Assume that an update (to front power) is needed.
- // Note: potential inconsistencies will arise as power data is updated before-delay due to limitations of the power data caching functionality (only stores one bool)
- // This means that other mechanisms like wires may get our new power data before our delay has finished
- // This also means that we have to manually update ourselves to be aware of any changes that happened in the previous redstone tick
- return StaticAppend(GetAdjustedRelatives(a_Position, GetRelativeLaterals()), { a_Position });
- }
+ auto Power = GetFrontPowerLevel(a_Position, a_BlockType, a_Meta, a_PoweringData.PowerLevel);
+ auto PreviousFrontPower = static_cast<cIncrementalRedstoneSimulator *>(m_World.GetRedstoneSimulator())->GetChunkData()->ExchangeUpdateOncePowerData(a_Position, PoweringData(a_PoweringData.PoweringBlock, Power));
+ if (Power != PreviousFrontPower.PowerLevel)
+ {
+ return GetAdjustedRelatives(a_Position, GetRelativeLaterals());
}
return {};