Update RedstoneSimulator to delete unused cached PowerData
When a new block was placed that has a corresponding RedstoneHandler the PowerData for the position was cached, but never deleted and remained unchanged when the block got destroyed. The RedstoneSimulator now erases all cached PowerData for positions where the block doesn't have a RedstoneHandler (i.e. Air).
This commit is contained in:
parent
f76a964f65
commit
af514acd8c
@ -125,8 +125,11 @@ void cIncrementalRedstoneSimulator::Simulate(float a_dt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto CurrentHandler = cIncrementalRedstoneSimulator::CreateComponent(m_World, CurrentBlock, &m_Data);
|
auto CurrentHandler = cIncrementalRedstoneSimulator::CreateComponent(m_World, CurrentBlock, &m_Data);
|
||||||
if (CurrentHandler == nullptr)
|
if (CurrentHandler == nullptr) // Block at CurrentPosition doesn't have a corresponding redstone handler
|
||||||
{
|
{
|
||||||
|
// Clean up cached PowerData for CurrentPosition
|
||||||
|
static_cast<cIncrementalRedstoneSimulator *>(m_World.GetRedstoneSimulator())->GetChunkData()->ErasePowerData(CurrentLocation);
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,6 +41,12 @@ public:
|
|||||||
return (Result == m_MechanismDelays.end()) ? nullptr : &Result->second;
|
return (Result == m_MechanismDelays.end()) ? nullptr : &Result->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Erase cached PowerData for position */
|
||||||
|
void ErasePowerData(const Vector3i & a_Position)
|
||||||
|
{
|
||||||
|
m_CachedPowerLevels.erase(a_Position);
|
||||||
|
}
|
||||||
|
|
||||||
cRedstoneHandler::PoweringData ExchangeUpdateOncePowerData(const Vector3i & a_Position, cRedstoneHandler::PoweringData a_PoweringData)
|
cRedstoneHandler::PoweringData ExchangeUpdateOncePowerData(const Vector3i & a_Position, cRedstoneHandler::PoweringData a_PoweringData)
|
||||||
{
|
{
|
||||||
auto Result = m_CachedPowerLevels.find(a_Position);
|
auto Result = m_CachedPowerLevels.find(a_Position);
|
||||||
|
Loading…
Reference in New Issue
Block a user