Skip to content

refactor(sphere): Zero initialize SphereClass by default and add IsEmpty function#2855

Open
stephanmeesters wants to merge 3 commits into
TheSuperHackers:mainfrom
stephanmeesters:refactor/sphere-zero-init
Open

refactor(sphere): Zero initialize SphereClass by default and add IsEmpty function#2855
stephanmeesters wants to merge 3 commits into
TheSuperHackers:mainfrom
stephanmeesters:refactor/sphere-zero-init

Conversation

@stephanmeesters

@stephanmeesters stephanmeesters commented Jul 5, 2026

Copy link
Copy Markdown
  • Changes the constructor of SphereClass to zero-init its members.
  • Adds the IsEmpty function
  • Removes verbose EA comments (2nd commit)
  • Remove unused instances of SphereClass

@greptile-apps

greptile-apps Bot commented Jul 5, 2026

Copy link
Copy Markdown

Greptile Summary

This PR zero-initializes the default SphereClass constructor, adds an IsEmpty() helper that returns true when Radius <= 0, and removes verbose EA-era comment blocks from sphere.h. Call-sites that previously spelled out SphereClass(Vector3(0,0,0), 0) are updated to use the default constructor, and dead/unused SphereClass variable declarations in several .cpp files are cleaned up.

  • sphere.h: Default constructor now member-initializes Center and Radius to zero; IsEmpty() is added and wired into Add_Sphere / Add_Spheres, replacing the narrower == 0.0f check with the more robust <= 0.0.
  • .cpp files (9 files): Call-sites switch to the new default constructor or remove unused SphereClass variables that were computed but never read (e.g., boxrobj.cpp, dazzle.cpp, W3DVolumetricShadow.cpp).

Confidence Score: 5/5

Safe to merge — all call-sites that previously supplied explicit zero arguments now use the semantically equivalent default constructor, and removed variables were confirmed unused.

The default constructor change is backward-compatible: every former explicit zero-initialization and every removed SphereClass variable was already producing the same zero state. The IsEmpty() guard in Add_Sphere/Add_Spheres is strictly broader than the old == 0.0f check (it also handles the degenerate negative-radius case), which is an improvement with no regressions.

No files require special attention.

Important Files Changed

Filename Overview
Core/Libraries/Source/WWVegas/WWMath/sphere.h Core change: default constructor now zero-initializes Center and Radius; IsEmpty() added and used in Add_Sphere/Add_Spheres; verbose EA comment blocks removed. Logic is sound.
Core/Libraries/Source/WWVegas/WW3D2/collect.cpp Replaces explicit SphereClass(Vector3(0,0,0),0) with SphereClass() — behaviour identical given the new default constructor.
Core/Libraries/Source/WWVegas/WW3D2/dynamesh.cpp Trivial call-site cleanup: SphereClass(Vector3(0,0,0),0) → SphereClass().
Core/Libraries/Source/WWVegas/WW3D2/sortingrenderer.cpp Inline temporary SphereClass() replaces named zero-initialized variable; no behaviour change.
Core/Tools/W3DView/ViewerScene.cpp SphereClass accumulator switches to default constructor; functionally identical.
Generals/Code/Libraries/Source/WWVegas/WW3D2/boxrobj.cpp Removes an unused SphereClass variable and Get_Obj_Space_Bounding_Sphere call whose result was never read — clean dead code removal.
Generals/Code/Libraries/Source/WWVegas/WW3D2/dazzle.cpp Three unused SphereClass variables (never read after construction) removed in Render_Dazzle.
Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp Removes declared-but-unused SphereClass bsphere variable in renderShadows.
GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/boxrobj.cpp Mirror of Generals boxrobj.cpp: same unused SphereClass variable removed.
GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dazzle.cpp Mirror of Generals dazzle.cpp: three unused SphereClass variables removed.
GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp Mirror of Generals W3DVolumetricShadow.cpp: unused bsphere variable removed.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[SphereClass default ctor\nbefore: uninitialized] -->|PR change| B[SphereClass default ctor\nCenter=0,0,0 Radius=0]

    B --> C[IsEmpty: Radius <= 0.0]

    C -->|used in| D[Add_Sphere\nold: s.Radius == 0.0f\nnew: s.IsEmpty]
    C -->|used in| E[Add_Spheres\nold: s0.Radius == 0.0f\nnew: s0.IsEmpty]

    F[Call-site cleanup] --> G[collect.cpp\ndynamesh.cpp\nsortingrenderer.cpp\nViewerScene.cpp\nuse SphereClass instead of\nSphereClass Vector3 0 0 0 0]

    H[Dead code removal] --> I[boxrobj.cpp x2\ndazzle.cpp x2\nW3DVolumetricShadow.cpp x2\nunused SphereClass variables\nremoved]
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[SphereClass default ctor\nbefore: uninitialized] -->|PR change| B[SphereClass default ctor\nCenter=0,0,0 Radius=0]

    B --> C[IsEmpty: Radius <= 0.0]

    C -->|used in| D[Add_Sphere\nold: s.Radius == 0.0f\nnew: s.IsEmpty]
    C -->|used in| E[Add_Spheres\nold: s0.Radius == 0.0f\nnew: s0.IsEmpty]

    F[Call-site cleanup] --> G[collect.cpp\ndynamesh.cpp\nsortingrenderer.cpp\nViewerScene.cpp\nuse SphereClass instead of\nSphereClass Vector3 0 0 0 0]

    H[Dead code removal] --> I[boxrobj.cpp x2\ndazzle.cpp x2\nW3DVolumetricShadow.cpp x2\nunused SphereClass variables\nremoved]
Loading

Reviews (2): Last reviewed commit: "Remove unused instances of SphereClass" | Re-trigger Greptile

@stephanmeesters stephanmeesters changed the title refactor(sphere): Zero initialize by default and add IsEmpty function refactor(sphere): Zero initialize Sphere by default and add IsEmpty function Jul 5, 2026
@stephanmeesters stephanmeesters added Gen Relates to Generals ZH Relates to Zero Hour Refactor Edits the code with insignificant behavior changes, is never user facing labels Jul 5, 2026

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

While looking at instances of SphereClass I noticed a couple of places where they're unused:

SphereClass sphere;
Get_Obj_Space_Bounding_Sphere(sphere);

I realize it's slightly outside the scope of this PR, but perhaps these can be removed as well.

Comment thread GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dazzle.cpp Outdated
@stephanmeesters stephanmeesters changed the title refactor(sphere): Zero initialize Sphere by default and add IsEmpty function refactor(sphere): Zero initialize SphereClass by default and add IsEmpty function Jul 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Gen Relates to Generals 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.

2 participants