From 225c2fa9f6bc2ebffcc9160090482e6833a220ce Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 29 Jul 2020 01:18:59 +0100 Subject: Always use relative coordinates in AddBlock + Pass block, use relatives * Fixes everything immediately converting abs back to rel and getting block, when these data were already available --- src/Chunk.cpp | 40 ++++++---------------------------------- 1 file changed, 6 insertions(+), 34 deletions(-) (limited to 'src/Chunk.cpp') diff --git a/src/Chunk.cpp b/src/Chunk.cpp index cb14b36a0..1c06ed3b3 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -1241,40 +1241,12 @@ void cChunk::WakeUpSimulators(void) for (size_t BlockIdx = 0; BlockIdx != cChunkData::SectionBlockCount; ++BlockIdx) { - auto BlockType = Section->m_BlockTypes[BlockIdx]; - - // Defer calculation until it's actually needed - auto WorldPos = [&] - { - auto RelPos = IndexToCoordinate(BlockIdx); - RelPos.y += static_cast(SectionIdx * cChunkData::SectionHeight); - return RelativeToAbsolute(RelPos); - }; + const auto BlockType = Section->m_BlockTypes[BlockIdx]; + const auto Position = IndexToCoordinate(BlockIdx); - // The redstone sim takes multiple blocks, use the inbuilt checker - if (RedstoneSimulator->IsAllowedBlock(BlockType)) - { - RedstoneSimulator->AddBlock(WorldPos(), this); - continue; - } - - switch (BlockType) - { - case E_BLOCK_WATER: - { - WaterSimulator->AddBlock(WorldPos(), this); - break; - } - case E_BLOCK_LAVA: - { - LavaSimulator->AddBlock(WorldPos(), this); - break; - } - default: - { - break; - } - } // switch (BlockType) + RedstoneSimulator->AddBlock(*this, Position, BlockType); + WaterSimulator->AddBlock(*this, Position, BlockType); + LavaSimulator->AddBlock(*this, Position, BlockType); } } } @@ -1316,7 +1288,7 @@ void cChunk::SetBlock(Vector3i a_RelPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_Blo // TODO: use relative coordinates, cChunk reference // Wake up the simulators for this block: - GetWorld()->GetSimulatorManager()->WakeUp(RelativeToAbsolute(a_RelPos), this); + GetWorld()->GetSimulatorManager()->WakeUp(*this, a_RelPos); // If there was a block entity, remove it: cBlockEntity * BlockEntity = GetBlockEntityRel(a_RelPos); -- cgit v1.2.3