Repository navigation
refactor(pathfinder): Split several individual classes off of AIPathfind.cpp into separate source files. #3429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
1bfd351
0b2fbf3
3aefa10
50d0605
58b89ee
db0076e
e92e619
65f1bf1
fff2bbc
992d33e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -79,8 +79,8 @@ class PathfindCell | |
| void clearObstruction() { m_type = CELL_CLEAR; m_obstacleID = INVALID_ID; m_obstacleIsFence = false; m_obstacleIsTransparent = false; } | ||
| #endif | ||
|
|
||
| inline Bool isObstacleTransparent() const; | ||
| inline Bool isObstacleFence() const; | ||
| Bool isObstacleTransparent() const; | ||
| Bool isObstacleFence() const; | ||
|
|
||
| /// Return estimated cost from given cell to reach goal cell | ||
| UnsignedInt costToGoal( PathfindCell *goal ); | ||
|
|
@@ -124,15 +124,15 @@ class PathfindCell | |
| inline UnsignedShort getXIndex() const {return m_info->m_pos.x;} | ||
| inline UnsignedShort getYIndex() const {return m_info->m_pos.y;} | ||
|
|
||
| inline Bool isBlockedByAlly() const; | ||
| inline void setBlockedByAlly(Bool blocked); | ||
| Bool isBlockedByAlly() const; | ||
| void setBlockedByAlly(Bool blocked); | ||
|
|
||
| inline Bool getOpen() const {return m_info->m_open;} | ||
| inline Bool getClosed() const {return m_info->m_closed;} | ||
| inline UnsignedInt getCostSoFar() const {return m_info->m_costSoFar;} | ||
| inline UnsignedInt getTotalCost() const {return m_info->m_totalCost;} | ||
|
|
||
| inline UnsignedInt getTotalCostDifference(PathfindCell& other) const; | ||
| UnsignedInt getTotalCostDifference(PathfindCell& other) const; | ||
|
|
||
| inline void setCostSoFar(UnsignedInt cost) { if( m_info ) m_info->m_costSoFar = cost;} | ||
| inline void setTotalCost(UnsignedInt cost) { if( m_info ) m_info->m_totalCost = cost;} | ||
|
|
@@ -158,14 +158,21 @@ class PathfindCell | |
| inline ObjectID getGoalAircraft() const {ObjectID id = m_info?m_info->m_goalAircraftID:INVALID_ID; return id;} | ||
| inline ObjectID getPosUnit() const {ObjectID id = m_info?m_info->m_posUnitID:INVALID_ID; return id;} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could remove the inline keyword from all of these. They are already implicitly inline. |
||
|
|
||
| inline ObjectID getObstacleID() const; | ||
| ObjectID getObstacleID() const; | ||
|
|
||
| void setLayer( PathfindLayerEnum layer ) { m_layer = layer; } ///< set the cell layer | ||
| PathfindLayerEnum getLayer() const { return (PathfindLayerEnum)m_layer; } ///< get the cell layer | ||
|
|
||
| void setConnectLayer( PathfindLayerEnum layer ) { m_connectsToLayer = layer; } ///< set the cell layer connect id | ||
| PathfindLayerEnum getConnectLayer() const { return (PathfindLayerEnum)m_connectsToLayer; } ///< get the cell layer connect id | ||
|
|
||
| static Bool typesMatch(const PathfindCell& targetCell, const PathfindCell& sourceCell); | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These were global functions that better fit as a static function in the PathfindCell class |
||
| static Bool waterGround(const PathfindCell& targetCell, const PathfindCell& sourceCell); | ||
| static Bool groundRubble(const PathfindCell& targetCell, const PathfindCell& sourceCell); | ||
| static Bool terrain(const PathfindCell& targetCell, const PathfindCell& sourceCell); | ||
| static Bool crusherGround(const PathfindCell& targetCell, const PathfindCell& sourceCell); | ||
| static Bool groundCliff(const PathfindCell& targetCell, const PathfindCell& sourceCell); | ||
|
|
||
| private: | ||
| PathfindCellInfo *m_info; | ||
| ObjectID m_obstacleID; ///< the object ID who overlaps this cell | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,12 @@ class PathfindCellInfo | |
| static void releaseACellInfo(PathfindCellInfo *theInfo); | ||
|
|
||
| protected: | ||
| #if RETAIL_COMPATIBLE_PATHFINDING | ||
| #define CELL_INFOS_TO_ALLOCATE 30000 | ||
| #else | ||
| static constexpr const UnsignedInt CELL_INFOS_TO_ALLOCATE = 30000; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this need to be in the header? |
||
| #endif | ||
|
|
||
| static PathfindCellInfo *s_infoArray; | ||
| static PathfindCellInfo *s_firstFree; ///< | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,46 @@ | ||||||||||
| /* | ||||||||||
| ** Command & Conquer Generals Zero Hour(tm) | ||||||||||
| ** Copyright 2025 TheSuperHackers | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The newly written copyright comments in Rule Used: What: Flag newly created code comments that reference dates prior to the current year (2026). Why: Ensuring comments are up-to-date helps maintain relevance and accuracy in the codebase. Good: Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||||||||||
| ** | ||||||||||
| ** This program is free software: you can redistribute it and/or modify | ||||||||||
| ** it under the terms of the GNU General Public License as published by | ||||||||||
| ** the Free Software Foundation, either version 3 of the License, or | ||||||||||
| ** (at your option) any later version. | ||||||||||
| ** | ||||||||||
| ** This program is distributed in the hope that it will be useful, | ||||||||||
| ** but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||
| ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||||||
| ** GNU General Public License for more details. | ||||||||||
| ** | ||||||||||
| ** You should have received a copy of the GNU General Public License | ||||||||||
| ** along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||||||||
| */ | ||||||||||
|
|
||||||||||
| #define MAX_WALL_PIECES 128 | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The new
Suggested change
Rule Used: Use #pragma once for header include protection instead of traditional include guards (#ifndef/#define/#endif). The pragma directive alone is sufficient and avoids redundancy, macro name conflicts, and unnecessary boilerplate code. (source) Learned From Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||||||||||
| #define PATHFIND_QUEUE_LEN 512 | ||||||||||
|
|
||||||||||
| // how close a unit has to be in z to interact with the layer. | ||||||||||
| extern const Real LAYER_Z_CLOSE_ENOUGH_F; | ||||||||||
|
|
||||||||||
| extern const UnsignedInt PATHFIND_CELL_SIZE; | ||||||||||
| extern const Real PATHFIND_CELL_SIZE_F; | ||||||||||
|
|
||||||||||
| extern const UnsignedInt ZONE_UPDATE_FREQUENCY; | ||||||||||
| extern const UnsignedInt MAX_CELL_COUNT; | ||||||||||
| extern const UnsignedInt MAX_ADJUSTMENT_CELL_COUNT; | ||||||||||
| extern const UnsignedInt MAX_SAFE_PATH_CELL_COUNT; | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we do I think it would compile on VC6 and modern build. |
||||||||||
|
|
||||||||||
| // Number of cells we will search pathfinding per frame. | ||||||||||
| extern const UnsignedInt PATHFIND_CELLS_PER_FRAME; | ||||||||||
|
|
||||||||||
| extern const Int COST_ORTHOGONAL; | ||||||||||
| extern const Int COST_DIAGONAL; | ||||||||||
| extern const Real COST_TO_DISTANCE_FACTOR; | ||||||||||
| extern const Real COST_TO_DISTANCE_FACTOR_SQR; | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume all of these constants in this file are used by at least 2 isolated cpp's? Or would some of these be better fits closer to closely related classes in headers?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They are used in multiple classes. When we revisit each class, we will have a look if they have a better place. |
||||||||||
|
|
||||||||||
| #if RETAIL_COMPATIBLE_PATHFINDING | ||||||||||
| // TheSuperHackers @info This variable is here so the code will run down the retail compatible path till a failure mode is hit | ||||||||||
| // The pathfinding will then switch over to the corrected pathfinding code for SH clients | ||||||||||
| extern Bool s_useFixedPathfinding; | ||||||||||
| extern Bool s_forceCleanCells; | ||||||||||
| #endif | ||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Compiler didn't want to play nice with some of the functions being inlined, so it was removed.