Repository navigation
refactor(w3ddevice): Read matrix rows through their components instead of Vector3 casts - #3605
Conversation
…d of Vector3 casts The water reflection and the volumetric shadow rotation check read the X, Y and Z of Matrix4x4 rows by casting the Vector4 rows to Vector3 references. Build Vector3 values from the row components instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Note Reviews pausedIt 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
Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Reflected camera transform Core/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWater.cpp |
The mirror and simple-rendering reflection paths use shared helpers to reflect camera transforms. The helpers reflect direction axes across a plane through the origin and translation across the water-level plane. |
Volumetric Shadow Rotation
| Layer / File(s) | Summary |
|---|---|
Transform-row rotation checks Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp, GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp |
Both variants add getRowXYZ and loop over three transform rows. The Generals variant compares absolute dot products with the threshold. The GeneralsMD variant compares signed dot products, so negative values trigger rotation detection. |
Priority:
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Refactor
Possibly related PRs
- TheSuperHackers/GeneralsGameCode#3580: Replaces
Vector3reference casts with explicit component copies at other rendering-code call sites.
Suggested reviewers: xezon
Merge Risk: 
Minimal · up to e4cf2
-
No actionable merge-blocking issue was identified in the reviewed changes.
Pre-merge checks: 
4
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
Comment @coderabbitai help to get the list of available commands.
[Medium impact] The PR appears safe to merge; the latest scope changes preserve all uses of the reflected camera transform.
|
|
Why is this refactor any better than what the code was before? It is still an unreadable mess with long lines and repeated snippets. |
…and loop the shadow row checks Both water reflection paths now call one reflectCameraTransform helper that reads the camera axes and position from the Matrix3D, instead of copying it into a transposed Matrix4x4. The volumetric shadow rotation check loops over the three rows instead of nesting three if/else blocks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fair, reworked it a bit and updated the description As for why it's better than before: reading a |
…the branch that uses it Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d of Vector3 casts (TheSuperHackers#3605) The water reflection and the volumetric shadow rotation check read the X, Y and Z of Matrix4x4 rows by casting the Vector4 rows to Vector3 references. Build Vector3 values from the row components instead. Both water reflection paths now call one reflectCameraTransform helper that reads the camera axes and position from the Matrix3D, instead of copying it into a transposed Matrix4x4. The volumetric shadow rotation check loops over the three rows instead of nesting three if/else blocks.
Some renderer code reads a
Matrix4x4row, aVector4, through aVector3reference. Accessing an object through a reference to an unrelated type is undefined behavior, the same problem as #3521. This is a follow-up to #3532 and #3580, which fix the other casts of this kind.The water code no longer needs the casts: it now reads the camera axes and position straight from the
Matrix3D. The shadow code builds aVector3from each row's X, Y and Z.bit_castcan't do this becauseVector3andVector4aren't trivially copyable and differ in size.Changes
WaterRenderObjClass::renderMirrorand theWATER_TYPE_1_FB_REFLECTIONcase ofWaterRenderObjClass::Renderhad the same 25-line block. It copied the camera transform into aMatrix4x4, transposed it, and cast each row to reflect it across the water plane. The transposed rows are just theMatrix3Dcolumns. A new file-staticreflectCameraTransformreflectsGet_X_Vector,Get_Y_Vector,Get_Z_VectorandGet_Translationinstead, and both places call it. The arithmetic per component is unchanged.Render, the reflected transform is only used inside an#if 0block, so its declaration moved into that block.W3DVolumetricShadow::updateMeshVolumein both games compares three rows of the previous and current transforms to decide whether the mesh is rotating. The three nested if/else checks are now one loop. A new file-staticgetRowXYZreturns a row's X, Y and Z.The
#ifdef CNC3block in the Zero HourupdateMeshVolumehas the same casts. That block is never compiled, so I left it alone.AI Disclosure
Claude Opus 5.5 was used to aid in implementation.