Skip to content

refactor(w3ddevice): Write shadow volume vertex fields instead of casting Vector3 to VertexFormatXYZ - #3628

Open
CryoTheRenegade wants to merge 3 commits into
TheSuperHackers:mainfrom
CryoTheRenegade:refactor/vertex-format-casts
Open

CryoTheRenegade wants to merge 3 commits into
TheSuperHackers:mainfrom
CryoTheRenegade:refactor/vertex-format-casts

Conversation

@CryoTheRenegade

@CryoTheRenegade CryoTheRenegade commented Oct 29, 2026 •

Copy link
Copy Markdown

Follow-up to #3580, #3605 and #3617. The shadow volume code writes a Vector3 over a VertexFormatXYZ through a pointer cast. Accessing an object through an unrelated type is undefined behavior, the same problem as #3521.

W3DVolumetricShadow::constructVolumeVB in both games has 9 of these stores. A new file-static setVertexXYZ copies the three fields:

+static void setVertexXYZ(VertexFormatXYZ& vertex, const Vector3& position)
+{
+	vertex.x = position.X;
+	vertex.y = position.Y;
+	vertex.z = position.Z;
+}
 ...
-	*vb++ = *(VertexFormatXYZ *)&edgeVertex2;
-	*vb++ = *(VertexFormatXYZ *)&extrude2;
+	setVertexXYZ(*vb++, edgeVertex2);
+	setVertexXYZ(*vb++, extrude2);

Generals also had Vector2 reference casts over the u1 and u2 vertex fields in MeshModelClass::compose_deformed_vertex_buffer. Its only caller is MeshClass::Compose_Deformed_Vertex_Buffer, which nothing calls, and Zero Hour no longer has either function. This PR removes both from Generals instead of rewriting them.

 MeshClass
-  Compose_Deformed_Vertex_Buffer        (no callers)
 MeshModelClass
-  compose_deformed_vertex_buffer        (only called by the above)

The (Vector3 *)pvVertices stores in W3DVolumetricShadow.cpp are compiled only when SV_DEBUG is defined, and it is commented out in both games, so I left them alone.

Evidence

  • Disassembly: I compared the rebuilt shadow objects against a build of main. The float arithmetic is the same with both compilers.
    • VS 2026 Release: the differences are loop bookkeeping and register choice.
    • VC6 Release: the differences are loop bookkeeping and fxch reordering of the x87 stack.

AI Disclosure

Claude Opus 5.5 was used to aid in implementation and to compare the disassembly.

CryoTheRenegade and others added 3 commits October 23, 2026 16:45
…ng them to vectors

W3DVolumetricShadow::constructVolumeVB read Vector3 positions as
VertexFormatXYZ, and MeshModelClass::compose_deformed_vertex_buffer in
Generals wrote Vector2 values over the u1 and u2 vertex fields. Assign the
x, y and z or u and v fields one by one.

compose_deformed_vertex_buffer still writes u2/v2 when there are no UVs,
as before. The SV_DEBUG stores in W3DVolumetricShadow are not compiled
and stay unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ertex field writes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…m Generals

MeshClass::Compose_Deformed_Vertex_Buffer has no callers, and Zero Hour no
longer has it or MeshModelClass::compose_deformed_vertex_buffer. Removing
both also removes the Vector2 casts over the u1 and u2 vertex fields.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-29T00:36:42.812999Z
We couldn’t complete this review. Comment @codex review to try again.
aa05803 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b5a5578f-9928-4ffa-9c88-8fd5cffd0ace
Commits

Reviewing files that changed from the base of the PR and between 68d1668 and aa05803.

Files selected for processing: 6
  • Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp
  • Generals/Code/Libraries/Source/WWVegas/WW3D2/mesh.cpp
  • Generals/Code/Libraries/Source/WWVegas/WW3D2/mesh.h
  • Generals/Code/Libraries/Source/WWVegas/WW3D2/meshmdl.cpp
  • Generals/Code/Libraries/Source/WWVegas/WW3D2/meshmdl.h
  • GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp
Files with no reviewable changes: 4
  • Generals/Code/Libraries/Source/WWVegas/WW3D2/meshmdl.h
  • Generals/Code/Libraries/Source/WWVegas/WW3D2/mesh.h
  • Generals/Code/Libraries/Source/WWVegas/WW3D2/mesh.cpp
  • Generals/Code/Libraries/Source/WWVegas/WW3D2/meshmdl.cpp

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

Walkthrough

The changes replace pointer-cast assignments with explicit component writes in shadow-volume construction. They also remove the mesh and mesh-model deformed-vertex-buffer composition method, including its declaration and implementation.

Changes

Shadow-Volume Vertex Writes

Layer / File(s) Summary
Write shadow-volume vertex positions
Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp, GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp
Each file adds setVertexXYZ and uses it to write generated shadow-volume vertex positions. The vertex coordinates and extrusion calculations remain unchanged.

Deformed Vertex Buffer Removal

Layer / File(s) Summary
Remove deformed vertex-buffer composition
Generals/Code/Libraries/Source/WWVegas/WW3D2/mesh.h, Generals/Code/Libraries/Source/WWVegas/WW3D2/meshmdl.h, Generals/Code/Libraries/Source/WWVegas/WW3D2/meshmdl.cpp, Generals/Code/Libraries/Source/WWVegas/WW3D2/mesh.cpp
Removes the MeshClass::Compose_Deformed_Vertex_Buffer declaration and definition, and the MeshModelClass::compose_deformed_vertex_buffer declaration and implementation.

Priority: Low

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

Change: Refactor

Possibly related PRs

Suggested labels: Refactor, Minor

Suggested reviewers: xezon

Merge Risk: Minimal · up to aa058

No actionable merge-blocking risk remains in the reviewed changes.

Pre-merge checks: Passed 4
Check name Status Explanation
Title check Passed The title clearly identifies the main change: writing shadow-volume vertex fields directly instead of casting Vector3 to VertexFormatXYZ.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description directly explains the shadow-volume pointer-cast fixes and the removal of unused deformed-vertex-buffer functions described in the changeset.
  • 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.

❤️ Share

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

@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] This PR appears safe to merge; no actionable issues were found.

Summary

Replaces casts from Vector3 to VertexFormatXYZ with direct field copies in both games. Also removes two unused deformation methods from Generals.

  • Both games copy shadow positions into their vertex buffers by field.
  • Generals no longer exposes its unused skinned-mesh buffer composition path.

Reviews (1) · Last reviewed commit: "refactor(ww3d2): Remove the unused Compo..." · Reviewed by Greptile

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant