refactor(sphere): Zero initialize SphereClass by default and add Is_Valid function#2855
Conversation
|
| Filename | Overview |
|---|---|
| Core/Libraries/Source/WWVegas/WWMath/sphere.h | Core change: default constructor now zero-initializes Center and Radius; adds Is_Valid() (Radius > 0.0f); updates Add_Sphere and Add_Spheres to use Is_Valid() instead of raw == 0.0f comparisons. |
| Core/Libraries/Source/WWVegas/WW3D2/sortingrenderer.cpp | Flips if/else branches to use Is_Valid() for bounding sphere check; eliminates a local SphereClass variable in the overload; logic is equivalent to the original Radius <= 0.0 check. |
| Core/Libraries/Source/WWVegas/WW3D2/collect.cpp | Replaces explicit SphereClass(Vector3(0,0,0),0) with default constructor; semantically identical after zero-init constructor change. |
| Core/Libraries/Source/WWVegas/WW3D2/dynamesh.cpp | Replaces explicit zero-initialized SphereClass constructor with default constructor before Get_Bounding_Sphere call; behavior unchanged. |
| Core/Tools/W3DView/ViewerScene.cpp | Replaces explicit zero-init SphereClass constructor with default constructor in Get_Bounding_Sphere accumulation loop; semantically identical. |
| Generals/Code/Libraries/Source/WWVegas/WW3D2/boxrobj.cpp | Removes dead-code SphereClass variable that was declared and populated but never used. |
| Generals/Code/Libraries/Source/WWVegas/WW3D2/dazzle.cpp | Removes three dead-code SphereClass variable declarations immediately before DX8Wrapper draw calls with no intervening usage. |
| Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp | Removes unused SphereClass bsphere local variable from renderShadows; confirmed bsphere was never referenced after declaration. |
| GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/boxrobj.cpp | Same dead-code removal as Generals/ counterpart. |
| GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dazzle.cpp | Same dead-code removal as Generals/ counterpart. |
| GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp | Same unused variable removal as Generals/ counterpart. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["SphereClass()"] -->|"new: Center=(0,0,0), Radius=0"| B[Zero-initialized sphere]
B --> C{Is_Valid?}
C -->|"Radius > 0.0f"| D[Valid sphere]
C -->|"Radius <= 0.0f"| E[Invalid / empty sphere]
D --> F["Add_Sphere(s)"]
F --> G{s.Is_Valid?}
G -->|No| H[Return early]
G -->|Yes| I[Compute enclosing sphere]
D --> J["Add_Spheres(s0, s1)"]
J --> K{s0.Is_Valid?}
K -->|Yes| L[Expand s0 to include s1]
K -->|No| M[Return s1]
B --> N["sortingrenderer.cpp"]
N --> O{bounding_sphere.Is_Valid?}
O -->|Yes| P[Sort: compute transformed center]
O -->|No| Q[Unsorted list]
%%{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()"] -->|"new: Center=(0,0,0), Radius=0"| B[Zero-initialized sphere]
B --> C{Is_Valid?}
C -->|"Radius > 0.0f"| D[Valid sphere]
C -->|"Radius <= 0.0f"| E[Invalid / empty sphere]
D --> F["Add_Sphere(s)"]
F --> G{s.Is_Valid?}
G -->|No| H[Return early]
G -->|Yes| I[Compute enclosing sphere]
D --> J["Add_Spheres(s0, s1)"]
J --> K{s0.Is_Valid?}
K -->|Yes| L[Expand s0 to include s1]
K -->|No| M[Return s1]
B --> N["sortingrenderer.cpp"]
N --> O{bounding_sphere.Is_Valid?}
O -->|Yes| P[Sort: compute transformed center]
O -->|No| Q[Unsorted list]
Reviews (4): Last reviewed commit: "Add f" | Re-trigger Greptile
Caball009
left a comment
There was a problem hiding this comment.
While looking at instances of SphereClass I noticed a couple of places where they're unused:
GeneralsGameCode/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/boxrobj.cpp
Lines 514 to 516 in 838f9d0
I realize it's slightly outside the scope of this PR, but perhaps these can be removed as well.
Caball009
left a comment
There was a problem hiding this comment.
I don't really have an opinion on the removal of the EA / Westwood comments, but the code changes look fine to me.
4f6ec5c to
09e0333
Compare
|
|
||
| inline bool SphereClass::Is_Valid() const | ||
| { | ||
| return Radius > 0.0; |
SphereClassto zero-init its members.Is_ValidfunctionRemoves verbose EA comments (2nd commit)SphereClass