Skip to content

Conversation

@Mauller
Copy link

@Mauller Mauller commented Sep 22, 2025

Rebase and merge

This PR cleans up various functions within the pathfinding, the goal to improve readability where possible and to improve performance where possible.

I have broken each function down into it's own commit to aid review.

This PR covers the functions

  • PathfindCell::releaseInfo
  • Pathfinder::checkChangeLayers
  • Pathfinder::examineNeighboringCells
  • Pathfinder::internal_findHierarchicalPath

A few of the refactors cover code simplification by inverting the logic and returning early or by simplifying functionality.


Todo

  • Replicate in generals
  • Test performance improvements, if any.

@Mauller Mauller self-assigned this Sep 22, 2025
@Mauller Mauller added Minor Severity: Minor < Major < Critical < Blocker Gen Relates to Generals ZH Relates to Zero Hour Refactor Edits the code with insignificant behavior changes, is never user facing labels Sep 22, 2025
Copy link

@xezon xezon left a comment

Choose a reason for hiding this comment

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

Generally, I do not think you need to merge multiline conditions into single line condition if it takes away the opportunity to place breakpoints.

@Mauller
Copy link
Author

Mauller commented Sep 23, 2025

Generally, I do not think you need to merge multiline conditions into single line condition if it takes away the opportunity to place breakpoints.

It's the only real way to gain performance right now. if it needs debugging then the conditions can always be broken out again and checked at the time.

@xezon
Copy link

xezon commented Sep 23, 2025

It's the only real way to gain performance right now. if it needs debugging then the conditions can always be broken out again and checked at the time.

Are you sure it gives performance? I expect that the generated assembler will be the same.

@xezon
Copy link

xezon commented Sep 23, 2025

Here is a simple example with godbolt:

On O1 the generated code is already the same.

https://godbolt.org/z/7q7qcKGq8

@Mauller
Copy link
Author

Mauller commented Sep 23, 2025

Here is a simple example with godbolt:

On O1 the generated code is already the same.

https://godbolt.org/z/7q7qcKGq8

The main thing would be if VC6 does this or something different.

I am certainly getting better performance from some of the changes.

@xezon
Copy link

xezon commented Sep 23, 2025

It could be placebo. In the hope of better performance it is perceived as such. Merging conditions is not a strategy that is expected to give performance gains. At least I am not aware of it. Assembler has no concept of merged conditionals either. It separates merged conditions into separate instructions.

@Mauller
Copy link
Author

Mauller commented Sep 23, 2025

It could be placebo. In the hope of better performance it is perceived as such. Merging conditions is not a strategy that is expected to give performance gains. At least I am not aware of it. Assembler has no concept of merged conditionals either. It separates merged conditions into separate instructions.

I mean this PR in general has visible performance improvements when i run it compared to without the changes.
But that could be due to some of the other tweaks simplifying code in places and early returning.

I will take a look later and see if not combining the conditionals makes any difference.
It could just be the other structural and functional changes that i made which are giving the boost.

@Mauller Mauller force-pushed the refactor-pathfinding-simplify-code branch from 367bc04 to 460b860 Compare September 23, 2025 18:10
@Mauller
Copy link
Author

Mauller commented Sep 23, 2025

Tweaked and pushed

@xezon
Copy link

xezon commented Sep 26, 2025

Is this ready to continue review?

@Mauller
Copy link
Author

Mauller commented Sep 26, 2025

Is this ready to continue review?

just need to make those two tweaks, just a sec.

@Mauller Mauller force-pushed the refactor-pathfinding-simplify-code branch from 460b860 to 4a40608 Compare September 26, 2025 14:38
@Mauller
Copy link
Author

Mauller commented Sep 26, 2025

Made the tweaks, should be good now

Copy link

@xezon xezon left a comment

Choose a reason for hiding this comment

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

Is the change title still accurate?

@Mauller Mauller changed the title refactor(pathfinding): cleanup functions to improve readability and reduce branching when possible - Part 1 refactor(pathfinding): simplify functions to improve readability - Part 1 Sep 28, 2025
@Mauller Mauller force-pushed the refactor-pathfinding-simplify-code branch from 4a40608 to a9d3754 Compare September 28, 2025 08:04
@Mauller
Copy link
Author

Mauller commented Sep 28, 2025

Addressed comments and updated

@Mauller
Copy link
Author

Mauller commented Sep 28, 2025

will sort out replicating to generals in a bit

@Mauller
Copy link
Author

Mauller commented Sep 28, 2025

copied across to generals, testing each change at a time, hence the split commits. No real total performance improvement but i think it helps some areas that lag at times.

Generals has a small difference in examineNeighbouringCells which was causing mismatching and some annoyance. But it was a single extra value within:

if (info.allyFixedCount>0) {
				newCostSoFar += 3*COST_DIAGONAL*info.allyFixedCount;

while zero hour ommits the info.allyFixedCount portion

Not sure how we want to merge these, as individual commits or as squashed?
Individual would make it easier to test which change may have caused a mismatch, but with all my testing i did not see any mismatching.

If we go with individual commits i can rename all the commits to something more suitable etc.

@xezon xezon requested a review from Skyaero42 September 29, 2025 17:41
@xezon
Copy link

xezon commented Sep 29, 2025

Can do 4 commits. Merge the Generals replications into the respective ZH commits.

For commit title, use "refactor(pathfinder)"

Also, sentence behind colon always starts with upper case.

And append Pull number to commit titles.

Copy link

@Skyaero42 Skyaero42 left a comment

Choose a reason for hiding this comment

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

ok

@Mauller
Copy link
Author

Mauller commented Sep 30, 2025

Can do 4 commits. Merge the Generals replications into the respective ZH commits.

For commit title, use "refactor(pathfinder)"

Also, sentence behind colon always starts with upper case.

And append Pull number to commit titles.

Will look at doing that later, i will also pull out the function for checking cell extents into it's own commit as it will get used in other commits so don't want to lose it by mistake if the commit it is part of got reverted.

@Mauller Mauller force-pushed the refactor-pathfinding-simplify-code branch from 0db6f1f to 555d0dd Compare September 30, 2025 19:26
@Mauller
Copy link
Author

Mauller commented Sep 30, 2025

Got the commits in order, should be good to go now, once this is merged i will tweak part 2 and add the changes to generals.

@xezon xezon merged commit 6c6e05b into TheSuperHackers:main Sep 30, 2025
18 checks passed
xezon pushed a commit that referenced this pull request Sep 30, 2025
xezon pushed a commit that referenced this pull request Sep 30, 2025
xezon pushed a commit that referenced this pull request Sep 30, 2025
xezon pushed a commit that referenced this pull request Sep 30, 2025
@xezon xezon deleted the refactor-pathfinding-simplify-code branch September 30, 2025 19:46
fbraz3 pushed a commit to fbraz3/GeneralsX that referenced this pull request Nov 10, 2025
fbraz3 pushed a commit to fbraz3/GeneralsX that referenced this pull request Nov 10, 2025
fbraz3 pushed a commit to fbraz3/GeneralsX that referenced this pull request Nov 10, 2025
fbraz3 pushed a commit to fbraz3/GeneralsX that referenced this pull request Nov 10, 2025
fbraz3 pushed a commit to fbraz3/GeneralsX that referenced this pull request Nov 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Gen Relates to Generals Minor Severity: Minor < Major < Critical < Blocker Refactor Edits the code with insignificant behavior changes, is never user facing ZH Relates to Zero Hour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants