From adb86a75dac91a210149fc28b1dbf5225896f66c Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 29 Jul 2020 20:15:09 +0100 Subject: Do not GetBlock individually in simulators * Have the simulator manager get the block and pass it on + Add new overload for WakeUp, called when the manager wakes face positions --- src/Simulator/SimulatorManager.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'src/Simulator/SimulatorManager.cpp') diff --git a/src/Simulator/SimulatorManager.cpp b/src/Simulator/SimulatorManager.cpp index f10c285e0..07b4a7214 100644 --- a/src/Simulator/SimulatorManager.cpp +++ b/src/Simulator/SimulatorManager.cpp @@ -63,9 +63,29 @@ void cSimulatorManager::WakeUp(cChunk & a_Chunk, Vector3i a_Position) { ASSERT(a_Chunk.IsValid()); - for (cSimulators::iterator itr = m_Simulators.begin(); itr != m_Simulators.end(); ++itr) + for (const auto Item : m_Simulators) + { + Item.first->WakeUp(a_Chunk, a_Position, a_Chunk.GetBlock(a_Position)); + } + + for (const auto Offset : cSimulator::AdjacentOffsets) { - itr->first->WakeUp(a_Chunk, a_Position, a_Chunk.GetBlock(a_Position)); + auto Relative = a_Position + Offset; + auto Chunk = a_Chunk.GetRelNeighborChunkAdjustCoords(Relative); + + if ((Chunk == nullptr) || !Chunk->IsValid()) + { + continue; + } + + // Stored block to give to simulators for performance + // Since they all need this we save them querying it themselves + const auto Block = Chunk->GetBlock(Relative); + + for (const auto Item : m_Simulators) + { + Item.first->WakeUp(*Chunk, Relative, Offset, Block); + } } } -- cgit v1.2.3