summaryrefslogtreecommitdiffstats
path: root/src/Simulator/IncrementalRedstoneSimulator/RedstoneDataHelper.h
diff options
context:
space:
mode:
authorDebucquoy Anthony tonitch <debucquoy.anthony@gmail.com>2022-06-18 02:09:58 +0200
committerGitHub <noreply@github.com>2022-06-18 02:09:58 +0200
commitf089103c2b121f8128abfd6cdf0bd3cfbeca4465 (patch)
tree89c90001954484d22084cc68e29940cfe19e0e21 /src/Simulator/IncrementalRedstoneSimulator/RedstoneDataHelper.h
parentRemove redundant initialisations (diff)
downloadcuberite-f089103c2b121f8128abfd6cdf0bd3cfbeca4465.tar
cuberite-f089103c2b121f8128abfd6cdf0bd3cfbeca4465.tar.gz
cuberite-f089103c2b121f8128abfd6cdf0bd3cfbeca4465.tar.bz2
cuberite-f089103c2b121f8128abfd6cdf0bd3cfbeca4465.tar.lz
cuberite-f089103c2b121f8128abfd6cdf0bd3cfbeca4465.tar.xz
cuberite-f089103c2b121f8128abfd6cdf0bd3cfbeca4465.tar.zst
cuberite-f089103c2b121f8128abfd6cdf0bd3cfbeca4465.zip
Diffstat (limited to 'src/Simulator/IncrementalRedstoneSimulator/RedstoneDataHelper.h')
-rw-r--r--src/Simulator/IncrementalRedstoneSimulator/RedstoneDataHelper.h30
1 files changed, 22 insertions, 8 deletions
diff --git a/src/Simulator/IncrementalRedstoneSimulator/RedstoneDataHelper.h b/src/Simulator/IncrementalRedstoneSimulator/RedstoneDataHelper.h
index dc97a34d4..3942f803c 100644
--- a/src/Simulator/IncrementalRedstoneSimulator/RedstoneDataHelper.h
+++ b/src/Simulator/IncrementalRedstoneSimulator/RedstoneDataHelper.h
@@ -7,23 +7,37 @@ inline auto & DataForChunk(const cChunk & a_Chunk)
return *static_cast<cIncrementalRedstoneSimulatorChunkData *>(a_Chunk.GetRedstoneSimulatorData());
}
-template <typename... ArrayTypes>
-inline void UpdateAdjustedRelative(const cChunk & From, const cChunk & To, const Vector3i Position, const Vector3i Offset)
+inline void UpdateAdjustedRelative(const cChunk & a_Chunk, const cChunk & a_TickingChunk, const Vector3i a_Position, const Vector3i a_Offset)
{
- DataForChunk(To).WakeUp(cIncrementalRedstoneSimulatorChunkData::RebaseRelativePosition(From, To, Position + Offset));
+ const auto PositionToWake = a_Position + a_Offset;
- for (const auto & LinkedOffset : cSimulator::GetLinkedOffsets(Offset))
+ if (!cChunkDef::IsValidHeight(PositionToWake))
{
- DataForChunk(To).WakeUp(cIncrementalRedstoneSimulatorChunkData::RebaseRelativePosition(From, To, Position + LinkedOffset));
+ // If an offset position is not a valid height, its linked offset positions won't be either.
+ return;
+ }
+
+ auto & ChunkData = DataForChunk(a_TickingChunk);
+
+ // Schedule the block in the requested direction to update:
+ ChunkData.WakeUp(cIncrementalRedstoneSimulatorChunkData::RebaseRelativePosition(a_Chunk, a_TickingChunk, PositionToWake));
+
+ // To follow Vanilla behaviour, update all linked positions:
+ for (const auto & LinkedOffset : cSimulator::GetLinkedOffsets(a_Offset))
+ {
+ if (const auto LinkedPositionToWake = a_Position + LinkedOffset; cChunkDef::IsValidHeight(LinkedPositionToWake))
+ {
+ ChunkData.WakeUp(cIncrementalRedstoneSimulatorChunkData::RebaseRelativePosition(a_Chunk, a_TickingChunk, LinkedPositionToWake));
+ }
}
}
template <typename ArrayType>
-inline void UpdateAdjustedRelatives(const cChunk & From, const cChunk & To, const Vector3i Position, const ArrayType & Relative)
+inline void UpdateAdjustedRelatives(const cChunk & a_Chunk, const cChunk & a_TickingChunk, const Vector3i a_Position, const ArrayType & a_Relative)
{
- for (const auto & Offset : Relative)
+ for (const auto & Offset : a_Relative)
{
- UpdateAdjustedRelative(From, To, Position, Offset);
+ UpdateAdjustedRelative(a_Chunk, a_TickingChunk, a_Position, Offset);
}
}