Index: ps/trunk/source/simulation2/components/CCmpPathfinder.cpp =================================================================== --- ps/trunk/source/simulation2/components/CCmpPathfinder.cpp +++ ps/trunk/source/simulation2/components/CCmpPathfinder.cpp @@ -185,6 +185,15 @@ m_TerrainDirty = true; UpdateGrid(); break; + case MT_Deserialized: + UpdateGrid(); + // In case we were serialised with requests pending, we need to process them. + if (!m_ShortPathRequests.empty() || !m_LongPathRequests.empty()) + { + ENSURE(CmpPtr(GetSystemEntity())); + StartProcessingMoves(false); + } + break; } } @@ -773,6 +782,10 @@ { PROFILE2("FetchAsyncResults"); + // We may now clear existing requests. + m_ShortPathRequests.clear(); + m_LongPathRequests.clear(); + // WARNING: the order in which moves are pulled must be consistent when using 1 or n workers. // We fetch in the same order we inserted in, but we push moves backwards, so this works. std::vector results; @@ -794,8 +807,8 @@ void CCmpPathfinder::StartProcessingMoves(bool useMax) { - std::vector longRequests = PopMovesToProcess(m_LongPathRequests, useMax, m_MaxSameTurnMoves); - std::vector shortRequests = PopMovesToProcess(m_ShortPathRequests, useMax, m_MaxSameTurnMoves - longRequests.size()); + std::vector longRequests = GetMovesToProcess(m_LongPathRequests, useMax, m_MaxSameTurnMoves); + std::vector shortRequests = GetMovesToProcess(m_ShortPathRequests, useMax, m_MaxSameTurnMoves - longRequests.size()); PushRequestsToWorkers(longRequests); PushRequestsToWorkers(shortRequests); @@ -805,25 +818,20 @@ } template -std::vector CCmpPathfinder::PopMovesToProcess(std::vector& requests, bool useMax, size_t maxMoves) +std::vector CCmpPathfinder::GetMovesToProcess(std::vector& requests, bool useMax, size_t maxMoves) { - std::vector poppedRequests; + // Keep the original requests in which we need to serialize. + std::vector copiedRequests; if (useMax) { size_t amount = std::min(requests.size(), maxMoves); if (amount > 0) - { - poppedRequests.insert(poppedRequests.begin(), std::make_move_iterator(requests.end() - amount), std::make_move_iterator(requests.end())); - requests.erase(requests.end() - amount, requests.end()); - } + copiedRequests.insert(copiedRequests.begin(), requests.end() - amount, requests.end()); } else - { - poppedRequests.swap(requests); - requests.clear(); - } + copiedRequests = requests; - return poppedRequests; + return copiedRequests; } template Index: ps/trunk/source/simulation2/components/CCmpPathfinder_Common.h =================================================================== --- ps/trunk/source/simulation2/components/CCmpPathfinder_Common.h +++ ps/trunk/source/simulation2/components/CCmpPathfinder_Common.h @@ -87,6 +87,7 @@ public: static void ClassInit(CComponentManager& componentManager) { + componentManager.SubscribeToMessageType(MT_Deserialized); componentManager.SubscribeToMessageType(MT_Update); componentManager.SubscribeToMessageType(MT_RenderSubmit); // for debug overlays componentManager.SubscribeToMessageType(MT_TerrainChanged); @@ -225,7 +226,7 @@ virtual void StartProcessingMoves(bool useMax); template - std::vector PopMovesToProcess(std::vector& requests, bool useMax = false, size_t maxMoves = 0); + std::vector GetMovesToProcess(std::vector& requests, bool useMax = false, size_t maxMoves = 0); template void PushRequestsToWorkers(std::vector& from);