Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
Olympe::PathfindingManager Class Reference

Singleton async pathfinding request manager. More...

#include <PathfindingManager.h>

Classes

struct  RequestEntry
 

Public Types

using RequestID = uint64_t
 Unique identifier for a pathfinding request.
 

Public Member Functions

RequestID Request (const ::Vector &start, const ::Vector &target, float delaySeconds=0.0f)
 Submits an async pathfinding request.
 
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.
 
void Cancel (RequestID id)
 Cancels a pending request and removes its entry.
 

Static Public Member Functions

static PathfindingManagerGet ()
 Returns the singleton PathfindingManager instance.
 

Static Public Attributes

static constexpr RequestID INVALID_REQUEST_ID = 0u
 Sentinel value for an invalid / unsubmitted request.
 

Private Member Functions

 PathfindingManager ()
 
 ~PathfindingManager ()=default
 
 PathfindingManager (const PathfindingManager &)=delete
 
PathfindingManageroperator= (const PathfindingManager &)=delete
 

Private Attributes

std::mutex m_mutex
 
std::unordered_map< RequestID, RequestEntrym_requests
 
std::atomic< uint64_tm_nextID
 

Detailed Description

Singleton async pathfinding request manager.

Requests are identified by a uint64 RequestID. Each request spawns a detached thread that computes a straight-line path string and marks the entry as completed. Callers poll IsComplete() and retrieve the result via GetPathString(), then call Cancel() to release the entry.

Definition at line 51 of file PathfindingManager.h.

Member Typedef Documentation

◆ RequestID

Unique identifier for a pathfinding request.

Definition at line 55 of file PathfindingManager.h.

Constructor & Destructor Documentation

◆ PathfindingManager() [1/2]

Olympe::PathfindingManager::PathfindingManager ( )
private

Definition at line 35 of file PathfindingManager.cpp.

References m_nextID.

◆ ~PathfindingManager()

Olympe::PathfindingManager::~PathfindingManager ( )
privatedefault

◆ PathfindingManager() [2/2]

Olympe::PathfindingManager::PathfindingManager ( const PathfindingManager )
privatedelete

Member Function Documentation

◆ Cancel()

void Olympe::PathfindingManager::Cancel ( RequestID  id)

Cancels a pending request and removes its entry.

If the request is still in-flight the worker thread will see the cancelled flag and skip writing the result. The entry is removed from the map immediately so subsequent calls to IsComplete()/GetPathString() return the default empty/false values.

Safe to call on an already-completed request (releases the entry).

Parameters
idRequestID returned by Request().

Definition at line 141 of file PathfindingManager.cpp.

References GetComponentTypeID_Static(), m_mutex, m_requests, and SYSTEM_LOG.

Referenced by Olympe::Task_RequestPathfinding::Abort(), and Olympe::Task_RequestPathfinding::ExecuteWithContext().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Get()

PathfindingManager & Olympe::PathfindingManager::Get ( )
static

Returns the singleton PathfindingManager instance.

Definition at line 29 of file PathfindingManager.cpp.

Referenced by Olympe::Task_RequestPathfinding::Abort(), and Olympe::Task_RequestPathfinding::ExecuteWithContext().

+ Here is the caller graph for this function:

◆ GetPathString()

std::string Olympe::PathfindingManager::GetPathString ( RequestID  id)

Returns the path string computed for id.

Returns an empty string if the request is not complete or unknown.

Parameters
idRequestID returned by Request().

Definition at line 126 of file PathfindingManager.cpp.

References GetComponentTypeID_Static(), m_mutex, and m_requests.

Referenced by Olympe::Task_RequestPathfinding::ExecuteWithContext().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ IsComplete()

bool Olympe::PathfindingManager::IsComplete ( RequestID  id)

Returns true if the request identified by id has completed.

Returns false for unknown or cancelled requests.

Parameters
idRequestID returned by Request().

Definition at line 111 of file PathfindingManager.cpp.

References GetComponentTypeID_Static(), m_mutex, and m_requests.

+ Here is the call graph for this function:

◆ operator=()

PathfindingManager & Olympe::PathfindingManager::operator= ( const PathfindingManager )
privatedelete

◆ Request()

PathfindingManager::RequestID Olympe::PathfindingManager::Request ( const ::Vector start,
const ::Vector target,
float  delaySeconds = 0.0f 
)

Submits an async pathfinding request.

Launches a detached thread that sleeps for delaySeconds (simulating pathfinding work) and then writes a straight-line path string into the result entry unless the request has been cancelled.

Parameters
startStart position.
targetTarget position.
delaySecondsSimulated computation delay in seconds (0.0 = instant).
Returns
A unique RequestID identifying this request.

Definition at line 45 of file PathfindingManager.cpp.

References GetComponentTypeID_Static(), m_mutex, m_nextID, m_requests, Olympe::PathfindingManager::RequestEntry::start, SYSTEM_LOG, and Vector::x.

Referenced by Olympe::Task_RequestPathfinding::ExecuteWithContext().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ INVALID_REQUEST_ID

constexpr RequestID Olympe::PathfindingManager::INVALID_REQUEST_ID = 0u
staticconstexpr

Sentinel value for an invalid / unsubmitted request.

Definition at line 58 of file PathfindingManager.h.

Referenced by Olympe::Task_RequestPathfinding::Abort(), and Olympe::Task_RequestPathfinding::ExecuteWithContext().

◆ m_mutex

std::mutex Olympe::PathfindingManager::m_mutex
private

Definition at line 139 of file PathfindingManager.h.

Referenced by Cancel(), GetPathString(), IsComplete(), and Request().

◆ m_nextID

std::atomic<uint64_t> Olympe::PathfindingManager::m_nextID
private

Definition at line 141 of file PathfindingManager.h.

Referenced by PathfindingManager(), and Request().

◆ m_requests

std::unordered_map<RequestID, RequestEntry> Olympe::PathfindingManager::m_requests
private

Definition at line 140 of file PathfindingManager.h.

Referenced by Cancel(), GetPathString(), IsComplete(), and Request().


The documentation for this class was generated from the following files: