Skip to content

perf(gamelogic): Bound terrain deformation scans - #3258

Open
bobtista wants to merge 4 commits into
TheSuperHackers:mainfrom
bobtista:bobtista/perf/terrain-deformation-row-bounds
Open

bobtista wants to merge 4 commits into
TheSuperHackers:mainfrom
bobtista:bobtista/perf/terrain-deformation-row-bounds

Conversation

@bobtista

@bobtista bobtista commented Sep 4, 2026 •

Copy link
Copy Markdown

createCraterInTerrain and flattenTerrain calculate iMin.y, but their inner loops start at row 0. The shape checks reject rows outside the affected area, so this wastes more work as the Y position increases.

Now starts the loops at iMin.y. Retail compatible builds clamp iMin.y to 0 before the loops to keep the original lower bound and CRC. Without retail compatibility, rows below 0 are processed the same way columns below 0 already are.

Todo:

  • Testing

@bobtista bobtista self-assigned this Sep 4, 2026
@bobtista bobtista added Minor Severity: Minor < Major < Critical < Blocker Performance Is a performance concern labels Sep 4, 2026
@bobtista
bobtista force-pushed the bobtista/perf/terrain-deformation-row-bounds branch from 3bd2141 to 4d81449 Compare September 14, 2026 21:08
@bobtista
bobtista force-pushed the bobtista/perf/terrain-deformation-row-bounds branch from 4d81449 to 56733ad Compare September 23, 2026 19:09
@coderabbitai

coderabbitai Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 19fc1b9f-d3e0-475b-934a-21773d2a60c7

📥 Commits

Reviewing files that changed from the base of the PR and between 0995c38 and 0f18622.

📒 Files selected for processing (1)
  • Core/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp
💤 Files with no reviewable changes (1)
  • Core/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.


Walkthrough

Five loops in flattenTerrain and createCraterInTerrain now start at max(0, iMin.y). Their upper bounds and terrain calculations are unchanged.

Changes

Terrain deformation loop bounds

Layer / File(s) Summary
Bounded terrain loops
Core/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp
The box, sphere/cylinder, and crater loops start at max(0, iMin.y) instead of zero. Their upper bounds and terrain calculations are unchanged.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Refactor · Severity of issue fixed: Low

Suggested reviewers: caball009

Merge Risk: ⚪ Minimal · up to 0f186

The reduced terrain scans preserve the inspected deformation and map-edge behavior. No actionable merge risk remains.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR satisfies issue #3257. createCraterInTerrain and all four flattenTerrain loops now start at std::max(0, iMin.y). The upper bounds and terrain calculations remain unchanged. This removes s…
Out of Scope Changes check ✅ Passed The changes remain within issue #3257. The include cleanup supports the implementation and no unrelated source, API, configuration, or behavior changes are identified.
Title check ✅ Passed The title clearly and concisely describes the main change: reducing unnecessary terrain deformation scans.
Description check ✅ Passed The description explains the affected functions, the performance issue, the compatibility behavior, and the testing status. It is directly related to the changeset.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Comment thread Core/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: f09a5a66-dc2a-43e9-bde7-23ea259246d2

📥 Commits

Reviewing files that changed from the base of the PR and between 56733ad and 0995c38.

📒 Files selected for processing (1)
  • Core/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Comment thread Core/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp Outdated
Comment thread Core/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp Outdated
@bobtista
bobtista marked this pull request as ready for review September 26, 2026 17:11
@greptile-apps

greptile-apps Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 4/5

[Medium risk] Bounds terrain deformation scan loops to valid map range.

The PR should not merge until the non-retail lower-edge deformation behavior is addressed.

Findings

  1. P1 Negative rows enter terrain scans ▶
Summary

The PR starts terrain-flattening and crater scans at their calculated minimum row, avoiding scans from row zero for footprints farther up the map. It adds a retail-compatibility-only clamp at the lower edge.

  • Non-retail builds no longer retain the previous lower-edge bound.

Reviews (2) · Last reviewed commit: "refactor(gamelogic): Clamp deformation r..."

Comment thread Core/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp Outdated
Int numSamples = 0;
for (i=iMin.x; i<=iMax.x; i++) {
for (j=0; j<=iMax.y; j++) {
for (j=std::max(0, iMin.y); j<=iMax.y; ++j) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Are the clamps for zero really needed?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes I think so. The original loops started at row 0, but iMin.y can be negative when the shape crosses y=0. In a VC6 retail-compatible build, I tested a Sneak Attack tunnel near that edge; removing the clamp changed the terrain height, the tunnel's z and the game CRC on the next frame. The clamp preserves the original lower bound.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

That said, normal player placement appears to prevent it. Scripted or directly spawned objects can still reach it. Seems good to keep it imho

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Ok. Can we move the clamping out of the loop and then put it behind RETAIL_COMPATIBLE_CRC?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Moved the clamp before the loops and put it behind RETAIL_COMPATIBLE_CRC.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I moved the clamp, but greptile has a complaint. Are we ok with that for non-retail behavior?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

There are 2 possibilities for non-retail:

  1. clamp min and max coords at map bounds
  2. Do not clamp min and max coords at map bounds

Retail only clamps min, but not max.

I suggest test how it looks in game with clamping and not clamping at the map edges.

@bobtista bobtista Sep 30, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I tested structures centred on the playable edges. Removing the clamp gets rid of the bottom-edge wall; clamping all bounds also introduces walls at the left and right edges. I suggest keeping the current non-retail behavior.

Bottom-edge comparison below, top to bottom: retail, no clamp, clamp all.
zoom_bottom

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No clamp looks best

for (Int i = iMin.x; i <= iMax.x; i++ )
{
for ( Int j=0; j <= iMax.y; j++ )
for ( Int j=iMin.y; j <= iMax.y; ++j )

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Negative rows enter terrain scans

If RETAIL_COMPATIBLE_CRC is disabled, a crater or structure whose footprint crosses the lower map edge now starts scanning at a negative row. The same change affects the flattening loops. Those rows were previously skipped; now they can change the height samples used for flattening and, on maps with a height-map border, allow terrain writes into border cells.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Minor Severity: Minor < Major < Critical < Blocker Performance Is a performance concern

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Terrain deformation loops scan from row 0 wastefully

3 participants