Skip to content

refactor(basetype): Refactor functions of Coord3D, Region3D to take reference instead of pointer#2830

Open
xezon wants to merge 6 commits into
TheSuperHackers:mainfrom
xezon:xezon/refactor-basetype-functions
Open

refactor(basetype): Refactor functions of Coord3D, Region3D to take reference instead of pointer#2830
xezon wants to merge 6 commits into
TheSuperHackers:mainfrom
xezon:xezon/refactor-basetype-functions

Conversation

@xezon

@xezon xezon commented Jun 27, 2026

Copy link
Copy Markdown

This change refactors functions of Coord3D, Region3D to take reference instead of pointer.

This is more consistent with how standard C++ operator functions look (operator=(const Coord3D&)). And it clarifies that it expects non-null values.

Affected functions are:

  • Coord3D::set
  • Coord3D::add
  • Coord3D::sub
  • Coord3D::crossProduct
  • Coord3D::isInRegion
  • Coord3D::isInRegionNoZ

Applied by hand.

TODO

  • Run against replays

@xezon xezon added Minor Severity: Minor < Major < Critical < Blocker Refactor Edits the code with insignificant behavior changes, is never user facing labels Jun 27, 2026
@greptile-apps

greptile-apps Bot commented Jun 27, 2026

Copy link
Copy Markdown

Greptile Summary

This PR refactors six methods on Coord3D (set, add, sub, crossProduct) and Region3D (isInRegion, isInRegionNoZ) to accept const Coord3D& references instead of raw pointers, updating all 107 affected call sites consistently.

  • BaseType.h: The six method signatures are changed from pointer to reference parameters; all internal dereferences (->) are updated to dot notation (.).
  • Call sites (106 files): Every call is updated — local variables previously passed as &var are now passed as var; pointer returns from methods (like getPosition(), getStartPos()) are now dereferenced at the call site with *.
  • The null-safety contract is unchanged: all affected methods already crashed on null in the old implementation (they dereferenced a->x internally), so callers that now dereference before calling have the same effective behavior.

Confidence Score: 5/5

Safe to merge — a purely mechanical refactoring with no behavioral changes.

Every call site across all 107 files has been updated consistently. The methods that return pointers to member fields (getPosition, getStartPos, getEndPos) can never return null, so the new dereferences are safe. The one caller that checks for null before calling (PhysicsBehavior::addVelocityTo) still performs that check before dereferencing. The API surface change is limited to six internal utility methods with well-understood semantics.

No files require special attention.

Important Files Changed

Filename Overview
Core/Libraries/Include/Lib/BaseType.h Core change: six methods updated from pointer to reference parameters with correct internal dot-notation access.
Core/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DLaserDraw.cpp Derefs getStartPos()/getEndPos() before passing to refactored methods; both return &m_member so can never be null.
Core/GameEngine/Source/Common/Audio/AudioEventRTS.cpp Constructor and copy/assign operators updated; getPosition() results dereferenced inside null-checked branches.
Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/RailroadGuideAIUpdate.cpp Static crossProduct now called as myDir->crossProduct(*myDir, up, cross); semantically identical to old form, myDir non-null at this point.
GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SpectreGunshipUpdate.cpp All six refactored methods updated correctly; gunship->getPosition() returns a member address, safe to deref.
GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp addVelocityTo retains its if (vel != nullptr) guard before dereferencing, preserving the null-safety contract.
GeneralsMD/Code/GameEngine/Include/GameLogic/Module/ChinookAIUpdate.h Inline recordOriginalPosition updated from set(&pos) to set(pos) — correct, pos is already a const reference.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["Call site has local Coord3D var"] -->|"old: func(&var)"| B["func(const Coord3D* a)\na->x"]
    A -->|"new: func(var)"| C["func(const Coord3D& a)\na.x"]

    D["Call site has Coord3D* ptr"] -->|"old: func(ptr)"| B
    D -->|"new: func(*ptr)"| C

    B -->|null ptr passed| E["UB: nullptr->x inside func"]
    C -->|null ptr deref'd| F["UB: *nullptr at call site"]

    E -.->|"same crash, earlier in call chain"| F

    style C fill:#c8e6c9
    style B fill:#ffccbc
    style E fill:#ef9a9a
    style F fill:#ef9a9a
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A["Call site has local Coord3D var"] -->|"old: func(&var)"| B["func(const Coord3D* a)\na->x"]
    A -->|"new: func(var)"| C["func(const Coord3D& a)\na.x"]

    D["Call site has Coord3D* ptr"] -->|"old: func(ptr)"| B
    D -->|"new: func(*ptr)"| C

    B -->|null ptr passed| E["UB: nullptr->x inside func"]
    C -->|null ptr deref'd| F["UB: *nullptr at call site"]

    E -.->|"same crash, earlier in call chain"| F

    style C fill:#c8e6c9
    style B fill:#ffccbc
    style E fill:#ef9a9a
    style F fill:#ef9a9a
Loading

Reviews (1): Last reviewed commit: "Replicate in Generals" | Re-trigger Greptile

//We succeeded in calculating the best position.
location->set( &newPos );
location->set( newPos );
success = TRUE;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: indentation, same for FALSE below. Untouched by this though, hopefully it'll get fixed with the formatter PR ;)

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 this is outside the scope of this change.

@bobtista

bobtista commented Jun 27, 2026

Copy link
Copy Markdown

LGTM :)

@Caball009 Caball009 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.

Looks alright to me (I only checked the Zero Hour code).

I checked against 2500+ replays and no mismatches because of this change.

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 Refactor Edits the code with insignificant behavior changes, is never user facing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants