void CCmpPathfinder::ProcessSameTurnMoves() { u32 moveCount; if (!m_AsyncLongPathRequests.empty()) { // Figure out how many moves we can do this time moveCount = m_MaxSameTurnMoves - m_SameTurnMovesCount; if (moveCount <= 0) return; // Copy the long request elements we are going to process into a new array std::vector<AsyncLongPathRequest> longRequests; if (m_AsyncLongPathRequests.size() <= moveCount) { m_AsyncLongPathRequests.swap(longRequests); moveCount = longRequests.size(); } else { longRequests.resize(moveCount); copy(m_AsyncLongPathRequests.begin(), m_AsyncLongPathRequests.begin() + moveCount, longRequests.begin()); m_AsyncLongPathRequests.erase(m_AsyncLongPathRequests.begin(), m_AsyncLongPathRequests.begin() + moveCount); } ProcessLongRequests(longRequests); m_SameTurnMovesCount += moveCount; } if (!m_AsyncShortPathRequests.empty()) { // Figure out how many moves we can do now moveCount = m_MaxSameTurnMoves - m_SameTurnMovesCount; if (moveCount <= 0) return; // Copy the short request elements we are going to process into a new array std::vector<AsyncShortPathRequest> shortRequests; if (m_AsyncShortPathRequests.size() <= moveCount) { m_AsyncShortPathRequests.swap(shortRequests); moveCount = shortRequests.size(); } else { shortRequests.resize(moveCount); copy(m_AsyncShortPathRequests.begin(), m_AsyncShortPathRequests.begin() + moveCount, shortRequests.begin()); m_AsyncShortPathRequests.erase(m_AsyncShortPathRequests.begin(), m_AsyncShortPathRequests.begin() + moveCount); } ProcessShortRequests(shortRequests); m_SameTurnMovesCount += moveCount; } }
void CCmpPathfinder::FinishAsyncRequests() { // Save the request queue in case it gets modified while iterating std::vector<AsyncLongPathRequest> longRequests; m_AsyncLongPathRequests.swap(longRequests); std::vector<AsyncShortPathRequest> shortRequests; m_AsyncShortPathRequests.swap(shortRequests); // TODO: we should only compute one path per entity per turn // TODO: this computation should be done incrementally, spread // across multiple frames (or even multiple turns) ProcessLongRequests(longRequests); ProcessShortRequests(shortRequests); }