Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/components/CCmpPathfinder.cpp
/* Copyright (C) 2021 Wildfire Games. | /* Copyright (C) 2021 Wildfire Games. | ||||
Lint: Inaccurate Copyright Year: Inaccurate Copyright Year | |||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 91 Lines • ▼ Show 20 Lines | |||||
CCmpPathfinder::~CCmpPathfinder() {}; | CCmpPathfinder::~CCmpPathfinder() {}; | ||||
void CCmpPathfinder::Deinit() | void CCmpPathfinder::Deinit() | ||||
{ | { | ||||
SetDebugOverlay(false); // cleans up memory | SetDebugOverlay(false); // cleans up memory | ||||
// Wait on all pathfinding tasks. | // Wait on all pathfinding tasks. | ||||
for (Future<void>& future : m_Futures) | for (Future<FutureFunction>& future : m_Futures) | ||||
future.Cancel(); | future.Cancel(); | ||||
m_Futures.clear(); | m_Futures.clear(); | ||||
SAFE_DELETE(m_AtlasOverlay); | SAFE_DELETE(m_AtlasOverlay); | ||||
SAFE_DELETE(m_Grid); | SAFE_DELETE(m_Grid); | ||||
SAFE_DELETE(m_TerrainOnlyGrid); | SAFE_DELETE(m_TerrainOnlyGrid); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 679 Lines • ▼ Show 20 Lines | void CCmpPathfinder::SendRequestedPaths() | ||||
if (!m_LongPathRequests.m_ComputeDone || !m_ShortPathRequests.m_ComputeDone) | if (!m_LongPathRequests.m_ComputeDone || !m_ShortPathRequests.m_ComputeDone) | ||||
{ | { | ||||
// Also start computing on the main thread to finish faster. | // Also start computing on the main thread to finish faster. | ||||
m_ShortPathRequests.Compute(*this, m_VertexPathfinders.front()); | m_ShortPathRequests.Compute(*this, m_VertexPathfinders.front()); | ||||
m_LongPathRequests.Compute(*this, *m_LongPathfinder); | m_LongPathRequests.Compute(*this, *m_LongPathfinder); | ||||
} | } | ||||
// We're done, clear futures. | // We're done, clear futures. | ||||
// Use CancelOrWait instead of just Cancel to ensure determinism. | // Use CancelOrWait instead of just Cancel to ensure determinism. | ||||
for (Future<void>& future : m_Futures) | for (Future<FutureFunction>& future : m_Futures) | ||||
future.CancelOrWait(); | future.CancelOrWait(); | ||||
{ | { | ||||
PROFILE2("PostMessages"); | PROFILE2("PostMessages"); | ||||
for (PathResult& path : m_ShortPathRequests.m_Results) | for (PathResult& path : m_ShortPathRequests.m_Results) | ||||
{ | { | ||||
CMessagePathResult msg(path.ticket, path.path); | CMessagePathResult msg(path.ticket, path.path); | ||||
GetSimContext().GetComponentManager().PostMessage(path.notify, msg); | GetSimContext().GetComponentManager().PostMessage(path.notify, msg); | ||||
Show All 15 Lines | void CCmpPathfinder::StartProcessingMoves(bool useMax) | ||||
m_LongPathRequests.PrepareForComputation(useMax ? m_MaxSameTurnMoves : 0); | m_LongPathRequests.PrepareForComputation(useMax ? m_MaxSameTurnMoves : 0); | ||||
Threading::TaskManager& taskManager = Threading::TaskManager::Instance(); | Threading::TaskManager& taskManager = Threading::TaskManager::Instance(); | ||||
for (size_t i = 0; i < m_Futures.size(); ++i) | for (size_t i = 0; i < m_Futures.size(); ++i) | ||||
{ | { | ||||
ENSURE(!m_Futures[i].Valid()); | ENSURE(!m_Futures[i].Valid()); | ||||
// Pass the i+1th vertex pathfinder to keep the first for the main thread, | // Pass the i+1th vertex pathfinder to keep the first for the main thread, | ||||
// each thread get its own instance to avoid conflicts in cached data. | // each thread get its own instance to avoid conflicts in cached data. | ||||
m_Futures[i] = taskManager.PushTask([&pathfinder=*this, &vertexPfr=m_VertexPathfinders[i + 1]]() { | m_Futures[i] = taskManager.PushTask(FutureFunction{*this, m_VertexPathfinders[i + 1]}); | ||||
PROFILE2("Async pathfinding"); | |||||
pathfinder.m_ShortPathRequests.Compute(pathfinder, vertexPfr); | |||||
pathfinder.m_LongPathRequests.Compute(pathfinder, *pathfinder.m_LongPathfinder); | |||||
}); | |||||
} | } | ||||
} | } | ||||
////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////// | ||||
bool CCmpPathfinder::IsGoalReachable(entity_pos_t x0, entity_pos_t z0, const PathGoal& goal, pass_class_t passClass) | bool CCmpPathfinder::IsGoalReachable(entity_pos_t x0, entity_pos_t z0, const PathGoal& goal, pass_class_t passClass) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 105 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
Inaccurate Copyright Year