Skip to content

unify(pathfinder): Merge local variable optimizations in PathfindZoneManager::calculateZones() from Zero Hour#2367

Merged
xezon merged 1 commit intoTheSuperHackers:mainfrom
Mauller:Mauller/generals-calczone-optimisations
Mar 1, 2026
Merged

unify(pathfinder): Merge local variable optimizations in PathfindZoneManager::calculateZones() from Zero Hour#2367
xezon merged 1 commit intoTheSuperHackers:mainfrom
Mauller:Mauller/generals-calczone-optimisations

Conversation

@Mauller
Copy link

@Mauller Mauller commented Feb 28, 2026

This PR backports some optimisations from the Zero Hour version of PathfindZoneManager::calculateZones() to make the unification diff a little smaller and easier to comprehend.

This PR adds some local variables for PathfindCell and Zone values that are reused multiple times so the array they are contained within is not constantly accessed on the heap.

@Mauller Mauller self-assigned this Feb 28, 2026
@Mauller Mauller added Major Severity: Minor < Major < Critical < Blocker Gen Relates to Generals labels Feb 28, 2026
@greptile-apps
Copy link

greptile-apps bot commented Feb 28, 2026

Greptile Summary

Added local variable optimizations to PathfindZoneManager::calculateZones() by introducing reference variables (cell, r_thisLayer, r_thisCell, r_leftCell, r_topCell) that cache frequently-accessed array elements, reducing redundant heap accesses.

Key Changes:

  • Introduced PathfindCell &cell to cache map[i][j] in the zone remapping loop
  • Introduced PathfindLayer &r_thisLayer to cache layers[i] in the layer processing loop
  • Introduced PathfindCell &r_thisCell, r_leftCell, and r_topCell in the hierarchical zone calculation loop
  • Local references for neighbor cells (r_leftCell, r_topCell) are correctly created inside boundary-checked conditional blocks, preventing out-of-bounds access
  • All neighbor references properly marked as const since they are read-only

Confidence Score: 5/5

  • This PR is safe to merge with no risk
  • This is a clean performance optimization that reduces heap accesses by caching array elements in local references. The refactoring preserves all original logic, properly handles boundary conditions with short-circuit evaluation, and uses const-correctness appropriately. Previous concerns about out-of-bounds access have been addressed by placing neighbor cell references inside boundary-checked blocks.
  • No files require special attention

Important Files Changed

Filename Overview
Generals/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp Added local variable references to reduce heap accesses in zone calculation loops; boundary checks properly protect against out-of-bounds access

Last reviewed commit: cc74ab2

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, 6 comments

Edit Code Review Agent Settings | Greptile

@Mauller Mauller force-pushed the Mauller/generals-calczone-optimisations branch from 0d6aadf to e959ccc Compare March 1, 2026 12:35
@Mauller
Copy link
Author

Mauller commented Mar 1, 2026

Tweaked based on feedback, also ported that tweak to the Zero Hour version as well

… to Generals PathfindZoneManager::calculateZones()
@Mauller Mauller force-pushed the Mauller/generals-calczone-optimisations branch from e959ccc to cc74ab2 Compare March 1, 2026 12:49
@Mauller
Copy link
Author

Mauller commented Mar 1, 2026

Just reverted that change as it could have been dangerous in the end.

@xezon xezon added the Unify Unifies code between Generals and Zero Hour label Mar 1, 2026
@xezon xezon changed the title refactor(pathfinder): Add local variable optimizations from Zero Hour to Generals PathfindZoneManager::calculateZones() unify(pathfinder): Merge local variable optimizations in PathfindZoneManager::calculateZones() from Zero Hour Mar 1, 2026
@xezon xezon removed the Major Severity: Minor < Major < Critical < Blocker label Mar 1, 2026
@xezon xezon merged commit 674ba9e into TheSuperHackers:main Mar 1, 2026
16 checks passed
@xezon xezon deleted the Mauller/generals-calczone-optimisations branch March 1, 2026 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Gen Relates to Generals Unify Unifies code between Generals and Zero Hour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants