21#include "../../system/system_utils.h"
46 const ::Vector& target,
55 entry.target = target;
56 entry.completed =
false;
57 entry.cancelled =
false;
61 SYSTEM_LOG <<
"[PathfindingManager] Submitted request " <<
id
62 <<
" from (" << start.
x <<
"," << start.y <<
")"
63 <<
" to (" << target.x <<
"," << target.y <<
")"
75 using namespace std::chrono;
80 std::lock_guard<std::mutex>
lock(
mgr->m_mutex);
82 auto it =
mgr->m_requests.find(
id);
83 if (
it ==
mgr->m_requests.end() ||
it->second.cancelled)
85 SYSTEM_LOG <<
"[PathfindingManager] Request " <<
id
86 <<
" was cancelled - discarding result\n";
91 std::ostringstream
oss;
92 oss <<
"(" << start.x <<
"," << start.y <<
"," << start.z <<
")"
94 <<
"(" << target.x <<
"," << target.y <<
"," << target.z <<
")";
96 it->second.result =
oss.str();
97 it->second.completed =
true;
99 SYSTEM_LOG <<
"[PathfindingManager] Request " <<
id
100 <<
" completed: " <<
it->second.result <<
"\n";
119 return it->second.completed;
132 return std::string();
134 return it->second.result;
149 it->second.cancelled =
true;
152 SYSTEM_LOG <<
"[PathfindingManager] Request " <<
id <<
" cancelled\n";
ComponentTypeID GetComponentTypeID_Static()
Async pathfinding request manager for the Atomic Task System.
Singleton async pathfinding request manager.
static PathfindingManager & Get()
Returns the singleton PathfindingManager instance.
uint64_t RequestID
Unique identifier for a pathfinding request.
void Cancel(RequestID id)
Cancels a pending request and removes its entry.
std::atomic< uint64_t > m_nextID
RequestID Request(const ::Vector &start, const ::Vector &target, float delaySeconds=0.0f)
Submits an async pathfinding request.
std::unordered_map< RequestID, RequestEntry > m_requests
bool IsComplete(RequestID id)
Returns true if the request identified by id has completed.
std::string GetPathString(RequestID id)
Returns the path string computed for id.
< Provides AssetID and INVALID_ASSET_ID