Skip to content

refactor(ww3d2): Simplify dx8wrapper's frame statistics with struct#2507

Merged
xezon merged 8 commits intoTheSuperHackers:mainfrom
stephanmeesters:refactor/dx8wrapper-statistics-struct
Apr 1, 2026
Merged

refactor(ww3d2): Simplify dx8wrapper's frame statistics with struct#2507
xezon merged 8 commits intoTheSuperHackers:mainfrom
stephanmeesters:refactor/dx8wrapper-statistics-struct

Conversation

@stephanmeesters
Copy link
Copy Markdown

@stephanmeesters stephanmeesters commented Mar 30, 2026

@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Mar 30, 2026

Greptile Summary

This PR refactors the frame-level performance statistics in the DX8 rendering layer by consolidating nine separate static counters (matrix_changes, texture_changes, etc.) and a standalone extern unsigned number_of_DX8_calls into a single DX8FrameStatistics value-type struct, applied identically to both the base-game (Generals/) and the Zero Hour expansion (GeneralsMD/) codebases.

Key changes:

  • New DX8FrameStatistics POD-style struct with a zero-initializing constructor replaces all individual counter variables.
  • A single static DX8FrameStatistics FrameStatistics protected member replaces nine protected statics; a file-static LastFrameStatistics replaces ten last_frame_* statics.
  • Get_Last_Frame_Statistics() (returns const DX8FrameStatistics&) replaces ten individual getter functions — confirmed no existing callers of the old getters remain in the repo.
  • Increment_DX8_CallCount() is introduced as a thin public inline wrapper so the DX8CALL macros (which expand in non-member contexts) can still reach the protected counter.
  • Begin_Statistics(), End_Statistics(), and Reset_Statistics() are substantially simplified.
  • All direct number_of_DX8_calls++ sites in both .cpp files are replaced with DX8_RECORD_DX8_CALLS() for consistency.

The PR description notes an unchecked TODO ("Replicate in Generals"), but both the Generals/ and GeneralsMD/ directories are updated in this PR — the checkbox may simply have been left un-ticked by mistake.

Confidence Score: 5/5

  • Safe to merge — straightforward mechanical refactoring with no logic changes, no remaining callers of the removed API, and both game variants updated consistently.
  • All removed functions (Get_Last_Frame_Matrix_Changes() etc.) have zero callers in the repository. The extern number_of_DX8_calls is fully replaced with the in-struct counter exposed via Increment_DX8_CallCount(). Semantic equivalence of Begin_Statistics, End_Statistics, and Reset_Statistics is preserved. The only finding is a pre-existing macro scoping convention (P2 style note, not a regression).
  • No files require special attention.

Important Files Changed

Filename Overview
Generals/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h Introduces DX8FrameStatistics struct and replaces 9 individual protected static counters + extern global with a single static struct member; replaces 10 per-field getter declarations with Get_Last_Frame_Statistics() and adds Increment_DX8_CallCount() public helper for macro use.
Generals/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp Defines and zero-initializes the new static FrameStatistics/LastFrameStatistics globals; simplifies Reset_Statistics, Begin_Statistics, End_Statistics; removes 10 per-field getter definitions; replaces number_of_DX8_calls++ with DX8_RECORD_DX8_CALLS() at 5 call sites.
GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h Mirror of the Generals header change — identical DX8FrameStatistics struct, macro rewrites, and API surface updates for the Zero Hour expansion.
GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp Mirror of the Generals .cpp change with one additional DX8_RECORD_DX8_CALLS() substitution in Clear() that exists only in the Zero Hour version.

Sequence Diagram

sequenceDiagram
    participant Caller as External caller / DX8CALL macro
    participant DX8W as DX8Wrapper (public API)
    participant FS as FrameStatistics (protected static)
    participant LFS as LastFrameStatistics (file-static)

    Note over Caller,LFS: Per-frame lifecycle

    Caller->>DX8W: Begin_Statistics()
    DX8W->>FS: FrameStatistics = DX8FrameStatistics() (zero-init)

    loop Each D3D call via DX8CALL / DX8_RECORD_*
        Caller->>DX8W: Increment_DX8_CallCount()
        DX8W->>FS: dx8_calls++
        Caller->>DX8W: DX8_RECORD_MATRIX_CHANGE()
        DX8W->>FS: matrix_changes++
    end

    Caller->>DX8W: End_Statistics()
    DX8W->>LFS: LastFrameStatistics = FrameStatistics

    Caller->>DX8W: Get_Last_Frame_Statistics()
    DX8W-->>Caller: const DX8FrameStatistics& (read-only snapshot)
Loading
Prompt To Fix All With AI
This is a comment left during a code review.
Path: Generals/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h
Line: 130-131

Comment:
**Macros reference unqualified `FrameStatistics` — context-dependent correctness**

`DX8_RECORD_DX8_CALLS()` and the other `DX8_RECORD_*` macros expand bare `FrameStatistics.xxx++`. In the old code the individual counters (e.g. `matrix_changes`) were also unqualified in macros and used only inside `DX8Wrapper` member functions, so the same scoping constraint already existed. A grep confirms all current call sites remain inside `DX8Wrapper` member functions. This is not a regression, but it is worth noting that if any of these macros are ever invoked from a non-member context the compiler will silently fail to find `FrameStatistics`, turning a policy violation into a build error rather than a subtle bug.

How can I resolve this? If you propose a fix, please make it concise.

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

@stephanmeesters stephanmeesters changed the title refactor(ww3d2): Replace statistics getter functions with struct refactor(ww3d2): Replace dx8wrapper's statistics getter functions with struct Mar 30, 2026
@xezon xezon added Refactor Edits the code with insignificant behavior changes, is never user facing Debug Is mostly debug functionality labels Mar 30, 2026
@stephanmeesters stephanmeesters force-pushed the refactor/dx8wrapper-statistics-struct branch from cd67862 to c706cd3 Compare March 31, 2026 10:21
@stephanmeesters stephanmeesters force-pushed the refactor/dx8wrapper-statistics-struct branch from c706cd3 to e2ff87c Compare March 31, 2026 10:40
@stephanmeesters stephanmeesters changed the title refactor(ww3d2): Replace dx8wrapper's statistics getter functions with struct refactor(ww3d2): Simplify dx8wrapper's frame statistics with struct Mar 31, 2026
Copy link
Copy Markdown

@xezon xezon left a comment

Choose a reason for hiding this comment

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

Looking good

@xezon xezon merged commit 25ab77d into TheSuperHackers:main Apr 1, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Debug Is mostly debug functionality 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