unify(pathfinder): Sanitize and merge AIPathfind and dependencies#2341
unify(pathfinder): Sanitize and merge AIPathfind and dependencies#2341Mauller wants to merge 12 commits intoTheSuperHackers:mainfrom
Conversation
60286bd to
e20892a
Compare
|
| Filename | Overview |
|---|---|
| Generals/Code/GameEngine/Include/GameLogic/AIPathfind.h | Updated function signatures and added conditional compilation support for unification |
| Generals/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp | Major refactoring of PathfindZoneManager with extensive conditional compilation for unification |
| GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp | Refactored PathfindZoneManager zone calculation from while loops to for loops for clarity |
Last reviewed commit: 2ea0f8b
e20892a to
180cc40
Compare
|
Had to fix a small dependency that i missed when building debug in generals |
| { | ||
| #if RTS_GENERALS | ||
| DEBUG_ASSERTCRASH(m_info, ("Has to have info.")); | ||
| #else |
There was a problem hiding this comment.
If m_info is not initialized, this crashes in Generals when m_info->m_pos.x is called.
Therefore the 1.01 patch can be ported to Generals. Game would have crashed at this point anyways, so it will not mismatch.
| return; | ||
| } | ||
| } | ||
| #endif |
There was a problem hiding this comment.
I think this can be simplified to:
if (!ai->isDoingGroundMovement())
{
#if RTS_GENERALS
Bool isUnmannedHelicopter = false;
#else
// exception:sniped choppers are on ground
Bool isUnmannedHelicopter = ( obj->isKindOf( KINDOF_PRODUCED_AT_HELIPAD ) && obj->isDisabledByType( DISABLED_UNMANNED ) ) ;
#endif
if ( ! isUnmannedHelicopter )
{
updateAircraftGoal(obj, newGoalPos);
return;
}
}| } | ||
| #endif | ||
| #if RTS_GENERALS | ||
| m_needToCalculateZones = false; |
| #else | ||
| m_zoneManager.updateZonesForModify(m_map, m_layers, cellBounds, m_extent); | ||
|
|
||
| Int i, j; |
|
updated based on feedback |
75d3750 to
35a0d0a
Compare
| applyZone(r_thisCell, r_topCell, m_crusherZones, m_maxZone); | ||
| } | ||
| #else | ||
| else |
There was a problem hiding this comment.
orphaned else - will cause RTS_ZEROHOUR build to fail
The #if RTS_GENERALS block (lines 2788-2808) contains independent if statements, not an if-else chain. When preprocessing removes this block for RTS_ZEROHOUR, this else has no matching if.
Fix: Move else to line 2787 after the closing brace, matching the pattern at line 2748
| else | |
| } | |
| else | |
| { | |
| #else |
Prompt To Fix With AI
This is a comment left during a code review.
Path: Generals/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp
Line: 2810
Comment:
orphaned `else` - will cause RTS_ZEROHOUR build to fail
The `#if RTS_GENERALS` block (lines 2788-2808) contains independent `if` statements, not an if-else chain. When preprocessing removes this block for RTS_ZEROHOUR, this `else` has no matching `if`.
Fix: Move `else` to line 2787 after the closing brace, matching the pattern at line 2748
```suggestion
}
else
{
#else
```
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
line 2785 - 2787 has the if block that links to the else when the #if RTS_GENERALS conditional block is not used
…ghboringCells, safe merge
…State, safe merge
35a0d0a to
dc18e3d
Compare
| applyZone(r_thisCell, r_topCell, m_crusherZones, m_maxZone); | ||
| } | ||
| #else | ||
| else |
There was a problem hiding this comment.
orphaned else will cause RTS_ZEROHOUR compilation failure
The #if RTS_GENERALS block (lines 2788-2808) contains independent if statements, not an if-else chain. When the preprocessor evaluates this for RTS_ZEROHOUR builds, it removes lines 2788-2808 and keeps the #else block starting at line 2809. This leaves the else at line 2810 with no matching if statement (the matching if at line 2785 has already been closed at line 2787).
Move this else to line 2787 (after the closing brace), matching the pattern at line 2748.
| else | |
| } | |
| else | |
| #if RTS_GENERALS |
Prompt To Fix With AI
This is a comment left during a code review.
Path: Generals/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp
Line: 2810
Comment:
orphaned `else` will cause RTS_ZEROHOUR compilation failure
The `#if RTS_GENERALS` block (lines 2788-2808) contains independent `if` statements, not an if-else chain. When the preprocessor evaluates this for RTS_ZEROHOUR builds, it removes lines 2788-2808 and keeps the `#else` block starting at line 2809. This leaves the `else` at line 2810 with no matching `if` statement (the matching `if` at line 2785 has already been closed at line 2787).
Move this `else` to line 2787 (after the closing brace), matching the pattern at line 2748.
```suggestion
}
else
#if RTS_GENERALS
```
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
line 2785 - 2787 has the if block that links to the else when the #if RTS_GENERALS conditional block is not used
|
|
||
| UnsignedShort m_maxZone; ///< Max zone used. | ||
| Bool m_needToCalculateZones; ///< True if terrain has changed. | ||
| UnsignedInt m_nextFrameToCalculateZones; ///< WHen should I recalculate, next?. |
There was a problem hiding this comment.
typo: WHen should be When
| UnsignedInt m_nextFrameToCalculateZones; ///< WHen should I recalculate, next?. | |
| UnsignedInt m_nextFrameToCalculateZones; ///< When should I recalculate, next?. |
Prompt To Fix With AI
This is a comment left during a code review.
Path: Generals/Code/GameEngine/Include/GameLogic/AIPathfind.h
Line: 578
Comment:
typo: `WHen` should be `When`
```suggestion
UnsignedInt m_nextFrameToCalculateZones; ///< When should I recalculate, next?.
```
How can I resolve this? If you propose a fix, please make it concise.| @@ -576,6 +576,7 @@ class PathfindZoneManager | |||
|
|
|||
| UnsignedShort m_maxZone; ///< Max zone used. | |||
| UnsignedInt m_nextFrameToCalculateZones; ///< WHen should I recalculate, next?. | |||
There was a problem hiding this comment.
typo: WHen should be When
| UnsignedInt m_nextFrameToCalculateZones; ///< WHen should I recalculate, next?. | |
| UnsignedInt m_nextFrameToCalculateZones; ///< When should I recalculate, next?. |
Prompt To Fix With AI
This is a comment left during a code review.
Path: GeneralsMD/Code/GameEngine/Include/GameLogic/AIPathfind.h
Line: 578
Comment:
typo: `WHen` should be `When`
```suggestion
UnsignedInt m_nextFrameToCalculateZones; ///< When should I recalculate, next?.
```
How can I resolve this? If you propose a fix, please make it concise.
Additional Comments (1)
Prompt To Fix With AIThis is a comment left during a code review.
Path: GeneralsMD/Code/GameEngine/Include/GameLogic/AIPathfind.h
Line: 659
Comment:
typo: `onlyk` should be `only`
```suggestion
Bool clientSafeQuickDoesPathExistForUI( const LocomotorSet& locomotorSet, const Coord3D *from, const Coord3D *to ); ///< Can we build any path at all between the locations (terrain only - fast)
```
How can I resolve this? If you propose a fix, please make it concise. |
dc18e3d to
87f4e50
Compare
| applyZone(r_thisCell, r_topCell, m_crusherZones, m_maxZone); | ||
| } | ||
| #else | ||
| else |
There was a problem hiding this comment.
Critical compilation error: orphaned else statement when RTS_ZEROHOUR is defined.
When the preprocessor processes this for RTS_ZEROHOUR builds, it removes the #if RTS_GENERALS block (lines 2788-2808), leaving this else without a matching if statement. The if statement on line 2785 has already closed at line 2787.
The developer's claim that "line 2785 - 2787 has the if block that links to the else" is incorrect. Line 2787 closes the if block from line 2785, so when the #if RTS_GENERALS block is removed by the preprocessor, line 2810's else becomes orphaned.
Move the else to line 2787 (after the closing brace), matching the working pattern at lines 2745-2748.
| else | |
| if (r_thisCell.getType() == r_topCell.getType()) { | |
| applyZone(r_thisCell, r_topCell, m_hierarchicalZones, m_maxZone); | |
| } | |
| else |
Prompt To Fix With AI
This is a comment left during a code review.
Path: Generals/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp
Line: 2810
Comment:
Critical compilation error: orphaned `else` statement when `RTS_ZEROHOUR` is defined.
When the preprocessor processes this for `RTS_ZEROHOUR` builds, it removes the `#if RTS_GENERALS` block (lines 2788-2808), leaving this `else` without a matching `if` statement. The `if` statement on line 2785 has already closed at line 2787.
The developer's claim that "line 2785 - 2787 has the if block that links to the else" is incorrect. Line 2787 closes the `if` block from line 2785, so when the `#if RTS_GENERALS` block is removed by the preprocessor, line 2810's `else` becomes orphaned.
Move the `else` to line 2787 (after the closing brace), matching the working pattern at lines 2745-2748.
```suggestion
if (r_thisCell.getType() == r_topCell.getType()) {
applyZone(r_thisCell, r_topCell, m_hierarchicalZones, m_maxZone);
}
else
```
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
this is not an issue you keep reading the statements wrong
| applyZone(r_thisCell, r_topCell, m_crusherZones, m_maxZone); | ||
| } | ||
| #else | ||
| else |
There was a problem hiding this comment.
Critical compilation error: orphaned else statement when RTS_ZEROHOUR is defined (same issue as in Generals version).
Move the else to line 2787 after the closing brace to match the working pattern at lines 2745-2748.
| else | |
| if (r_thisCell.getType() == r_topCell.getType()) { | |
| applyZone(r_thisCell, r_topCell, m_hierarchicalZones, m_maxZone); | |
| } | |
| else |
Prompt To Fix With AI
This is a comment left during a code review.
Path: GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp
Line: 2810
Comment:
Critical compilation error: orphaned `else` statement when `RTS_ZEROHOUR` is defined (same issue as in Generals version).
Move the `else` to line 2787 after the closing brace to match the working pattern at lines 2745-2748.
```suggestion
if (r_thisCell.getType() == r_topCell.getType()) {
applyZone(r_thisCell, r_topCell, m_hierarchicalZones, m_maxZone);
}
else
```
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
This is not an issue, you keep reading the statements wrong
This PR merged Aipathfind.h and Aipathfind.cpp
The majority of the merge has required conditionals being placed throughout the code, this is due to significant changes between zero hour and generals making the function incompatible.
The majority of the merges are safe and distinct, either directly inherited from zero hour and into generals, or cleaned up from generals into zero hour.
The most involved the majority merge and refactor involves the functions within the PathfindZoneManager, as zero hour changes large portions of this code. The code itself was a mess and i reverted the implementation of parts of it from
whileback toforloops as used within generals to make the code easier to understand.Generals inherited some optimisations from zero hour within PathfindZoneManager but had to retain the original code in other places due to mismatches occuring.
Generals gained the boolean returning versions of the terrain object handling functions, although the generals code does not specifically use them. This was done as a cleaner merge.
Generals also gained some zero hour functions that now check for nulls.
Generals also gained some functional name changes from zero hour which required updating call sites.
Zero hour gained some debugging that was lost from generals and some cleaned up implementation and formatting.
EDIT: I also had to extend an enum in generals' AI.h due to debug changes merged back from zero hour.
I split the unification into commits to make reviewing it easier, the most strenuous commit is the third commit of the PathfindZoneManager. This is where a considerable amount of satinising and refactoring occurred between both implementations.