Skip to content

Commit 2aaf313

Browse files
Maullerxezon
authored andcommitted
refactor(pathfinder): Implement PathfindCellList class for the pathfindcell openList (#2327)
1 parent 312ebd8 commit 2aaf313

4 files changed

Lines changed: 406 additions & 194 deletions

File tree

Generals/Code/GameEngine/Include/GameLogic/AIPathfind.h

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,24 @@ class PathfindCellInfo
247247
UnsignedInt m_closed:1; ///< place for marking this cell as on the closed list
248248
};
249249

250+
// TheSuperHackers @info The PathfindCellList class acts as a new management class for the pathfindcell open and closed lists
251+
class PathfindCellList
252+
{
253+
friend class PathfindCell;
254+
255+
public:
256+
PathfindCellList() : m_head(nullptr) {}
257+
258+
void reset(PathfindCell* newHead = nullptr) { m_head = newHead; }
259+
260+
PathfindCell* getHead() const { return m_head; }
261+
262+
Bool empty() const { return m_head == nullptr; }
263+
264+
private:
265+
PathfindCell* m_head;
266+
};
267+
250268
/**
251269
* This represents one cell in the pathfinding grid.
252270
* These cells categorize the world into idealized cellular states,
@@ -307,11 +325,11 @@ class PathfindCell
307325

308326
UnsignedInt costSoFar( PathfindCell *parent );
309327

310-
/// put self on "open" list in ascending cost order, return new list
311-
PathfindCell *putOnSortedOpenList( PathfindCell *list );
328+
/// put self on "open" list in ascending cost order
329+
void putOnSortedOpenList( PathfindCellList &list );
312330

313331
/// remove self from "open" list
314-
PathfindCell *removeFromOpenList( PathfindCell *list );
332+
void removeFromOpenList( PathfindCellList &list );
315333

316334
/// put self on "closed" list, return new list
317335
PathfindCell *putOnClosedList( PathfindCell *list );
@@ -323,7 +341,7 @@ class PathfindCell
323341
static Int releaseClosedList( PathfindCell *list );
324342

325343
/// remove all cells from closed list.
326-
static Int releaseOpenList( PathfindCell *list );
344+
static Int releaseOpenList( PathfindCellList &list );
327345

328346
inline PathfindCell *getNextOpen(void) {return m_info->m_nextOpen?m_info->m_nextOpen->m_cell: nullptr;}
329347

@@ -848,7 +866,7 @@ class Pathfinder : PathfindServicesInterface, public Snapshot
848866
IRegion2D m_extent; ///< Grid extent limits
849867
IRegion2D m_logicalExtent; ///< Logical grid extent limits
850868

851-
PathfindCell *m_openList; ///< Cells ready to be explored
869+
PathfindCellList m_openList; ///< Cells ready to be explored
852870
PathfindCell *m_closedList; ///< Cells already explored
853871

854872
Bool m_isMapReady; ///< True if all cells of map have been classified

0 commit comments

Comments
 (0)