Skip to content

Conversation

@jurassicLizard
Copy link

@jurassicLizard jurassicLizard commented Jan 15, 2026

Note : to test this please configure in Debug mode before building with -A Win32 -DRTS_BUILD_OPTION_IMGUI=On

all the code is gated behind a RTS_IMGUI_ENABLED perprocessor define for debugging purposes

  • What it does : Integrates the Dear Imgui framework and loads a console and demo window overlay
    in debug mode (generalsv, generalszh, WorldBuilderV and WorldBuilderZH)

  • What is missing

    • Some useful command or Ideas what it should look like : this PR will just focus on build and runtime integration via ImGui Demo
    • Currently it is permanently enabled when the game is builtwith the imgui option on Gated behind RTS_BUILD_OPTION_IMGUI
    • Code cleanup and SuperHackers Comments etc... done
    • Backporting to Generals done
Screenshot (9) Screenshot (11)

@jurassicLizard jurassicLizard changed the title feat(gameclient) Introduce imgui framework and console feat(gameclient) Introduce imgui framework Jan 16, 2026
@jurassicLizard jurassicLizard marked this pull request as ready for review January 16, 2026 15:01
@greptile-apps
Copy link

greptile-apps bot commented Jan 16, 2026

Greptile Overview

Greptile Summary

This PR successfully integrates the Dear ImGui framework into both Generals and Zero Hour (GeneralsMD) codebases, including their WorldBuilder tools. The integration is cleanly gated behind the RTS_BUILD_OPTION_IMGUI CMake option and RTS_HAS_IMGUI preprocessor define.

Key Changes:

  • Implements custom DirectX 8 backend (imgui_impl_dx8.cpp/h) since ImGui doesn't officially support DX8
  • Creates RAII wrapper classes (ImGuiContextManager, ImGuiFrameManager) for lifecycle management
  • Integrates into rendering pipeline via DX8Wrapper (context init, device reset handling, frame rendering)
  • Forwards input events through WndProc to ImGui
  • Demonstrates integration with ImGui demo window in GameClient::update() and WorldBuilder
  • Properly handles device reset scenarios by invalidating/recreating ImGui device objects
  • Uses FetchContent to download ImGui library at commit 791ad9b82db44ada9fedb3e26b2d900974ac0959

Code Quality:

  • All previously reported critical issues have been addressed (redundant ImGui::Render() calls, depth buffer error handling)
  • The implementation follows RAII patterns and proper resource cleanup
  • Comprehensive workflow documentation added in WinMain.cpp
  • Consistent implementation across Generals and GeneralsMD codebases
  • Proper error checking throughout the DX8 backend implementation

Note on Style Issues:
Previous review threads identified several style-related items (NULL vs nullptr, missing GPL headers on MIT-licensed files, include style inconsistencies). These were appropriately resolved or explained by the developer - the DX8 backend is a third-party MIT-licensed file where NULL is required for DWORD API parameters, and the developer correctly noted that TheSuperHackers didn't modify the header file.

Confidence Score: 4.5/5

  • This PR is safe to merge with very low risk - the ImGui integration is well-isolated behind compile-time guards and previous critical issues have been addressed
  • The implementation demonstrates solid engineering: RAII patterns for resource management, proper device lifecycle handling, comprehensive error checking in the DX8 backend, and all previously identified critical issues (redundant Render calls, depth buffer handling) have been fixed. The code is properly gated behind RTS_BUILD_OPTION_IMGUI and RTS_HAS_IMGUI, ensuring it won't affect builds without the feature enabled. Minor style issues remain but don't impact functionality
  • No files require special attention - all implementations are consistent and properly integrated

Important Files Changed

Filename Overview
Core/Libraries/Source/ImGui/dx8_backend/imgui_impl_dx8.cpp DirectX 8 rendering backend implementation with proper depth buffer handling and state management
Core/Libraries/Source/ImGui/wrapper/ImGuiContextManager.cpp RAII wrapper for ImGui context lifecycle with proper initialization and cleanup
Core/Libraries/Source/ImGui/wrapper/ImGuiFrameManager.cpp Frame lifecycle management with guard pattern to ensure proper begin/end frame calls
Core/Libraries/Source/ImGui/CMakeLists.txt Fetches ImGui library and configures build with custom DX8 backend
Generals/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp Integrates ImGui context initialization and frame management into DirectX 8 rendering pipeline
GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp Integrates ImGui context initialization and frame management into DirectX 8 rendering pipeline (Zero Hour version)

Sequence Diagram

sequenceDiagram
    participant App as WinMain
    participant WndProc as WndProc
    participant DX8 as DX8Wrapper
    participant ImGuiCtx as ImGuiContextManager
    participant GameClient as GameClient
    participant ImGuiFrame as ImGuiFrameManager
    participant ImGuiBackend as ImGui_ImplDX8

    Note over App,ImGuiBackend: Application Startup
    App->>DX8: Init()
    DX8->>DX8: Create_Device()
    DX8->>ImGuiCtx: Init(hwnd, device)
    ImGuiCtx->>ImGuiBackend: ImGui_ImplDX8_Init(device)
    ImGuiCtx->>ImGuiBackend: ImGui_ImplWin32_Init(hwnd)
    
    Note over App,ImGuiBackend: Frame Rendering Loop
    loop Every Frame
        WndProc->>WndProc: ImGui_ImplWin32_WndProcHandler()
        Note over WndProc: Forward input events to ImGui
        
        GameClient->>ImGuiFrame: FrameGuard constructor
        ImGuiFrame->>ImGuiBackend: ImGui_ImplDX8_NewFrame()
        ImGuiFrame->>ImGuiBackend: ImGui_ImplWin32_NewFrame()
        ImGuiFrame->>ImGuiBackend: ImGui::NewFrame()
        
        GameClient->>GameClient: ImGui::ShowDemoWindow()
        Note over GameClient: Build ImGui UI
        
        GameClient->>ImGuiFrame: FrameGuard destructor
        ImGuiFrame->>ImGuiBackend: ImGui::Render()
        ImGuiFrame->>ImGuiBackend: ImGui_ImplDX8_RenderDrawData()
        
        DX8->>DX8: Begin_Scene()
        Note over DX8: Render game content
        DX8->>DX8: End_Scene()
    end
    
    Note over App,ImGuiBackend: Device Reset (resolution change, etc.)
    DX8->>ImGuiBackend: ImGui_ImplDX8_InvalidateDeviceObjects()
    DX8->>DX8: Reset device
    DX8->>ImGuiBackend: ImGui_ImplDX8_CreateDeviceObjects()
    
    Note over App,ImGuiBackend: Application Shutdown
    App->>DX8: Shutdown()
    DX8->>ImGuiCtx: ~ContextManager()
    ImGuiCtx->>ImGuiBackend: ImGui_ImplDX8_Shutdown()
    ImGuiCtx->>ImGuiBackend: ImGui_ImplWin32_Shutdown()
    ImGuiCtx->>ImGuiBackend: ImGui::DestroyContext()
Loading

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

14 files reviewed, 4 comments

Edit Code Review Agent Settings | Greptile

@greptile-apps
Copy link

greptile-apps bot commented Jan 16, 2026

Greptile found no issues!

From now on, if a review finishes and we haven't found any issues, we will not post anything, but you can confirm that we reviewed your changes in the status check section.

This feature can be toggled off in your Code Review Settings by deselecting "Create a status check for each PR".

@jurassicLizard jurassicLizard force-pushed the feature/imgui_console_integration branch from ab35d8a to 742f8be Compare January 16, 2026 16:09
@jurassicLizard
Copy link
Author

@greptileai

@jurassicLizard
Copy link
Author

relates to : #387 and #2084 (comment)

@jurassicLizard jurassicLizard force-pushed the feature/imgui_console_integration branch from de59853 to d7e3765 Compare January 18, 2026 08:11
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

14 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@jurassicLizard jurassicLizard changed the title feat(gameclient) Introduce imgui framework feat(gameclient): Introduce imgui framework Jan 19, 2026
@jurassicLizard jurassicLizard force-pushed the feature/imgui_console_integration branch from d7e3765 to 4e08d7e Compare January 19, 2026 09:51
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

14 files reviewed, 4 comments

Edit Code Review Agent Settings | Greptile

@jurassicLizard
Copy link
Author

@greptileai

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

14 files reviewed, 3 comments

Edit Code Review Agent Settings | Greptile

@xezon xezon added Enhancement Is new feature or request Major Severity: Minor < Major < Critical < Blocker Gen Relates to Generals ZH Relates to Zero Hour Debug Is mostly debug functionality labels Jan 19, 2026
@jurassicLizard jurassicLizard force-pushed the feature/imgui_console_integration branch from 86dec82 to d72b80f Compare January 20, 2026 08:20
@jurassicLizard jurassicLizard force-pushed the feature/imgui_console_integration branch from bc453ca to eb5f3f1 Compare January 29, 2026 14:19
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

6 files reviewed, 3 comments

Edit Code Review Agent Settings | Greptile

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

6 files reviewed, 5 comments

Edit Code Review Agent Settings | Greptile

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

7 files reviewed, 6 comments

Edit Code Review Agent Settings | Greptile

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

5 files reviewed, 6 comments

Edit Code Review Agent Settings | Greptile

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

8 files reviewed, 4 comments

Edit Code Review Agent Settings | Greptile

@jurassicLizard
Copy link
Author

jurassicLizard commented Jan 29, 2026

A bunch of small comments added.

This needs more work.

I tested in Zero Hour.

Observed bugs

* The mouse cursor is alternating between game and desktop cursor when moving the mouse cursor anywhere in game

* The demo Window has no Close (x) button (there is a global imgui option for this to set, I think)

* Boot load screen doesn ot show imgui

Frame Management

I am not fond of the current frame management. It is incoherent.

I made a commit here with a more coherent frame management proposal: xezon@a382fbf

The idea is to have GameClient::update using a top level BeginFrame and EndFrame pair, and DXWrapper using a lower level BeginFrame and EndFrame pair. They work together. The pair can also be added anywhere else necessary. For example I have seen that ImGui does render during Boot load screen which you can look into as well.

Additionally, the code in GameClient::update can be simplified and robustified with an RAII helper: xezon@638685c

SUMMARY (of what has been achieved in that direction):

  • Streamlined Framemanagement via FrameGuard and RAII
  • Dx8wrapper and Gameclient help each other out with the ending of the frame <-- this is good
  • Fixed ImGui cursor alternating (side effect of previous 2) : probably as you said the order of when it is drawn is critical
  • ⚠️ Bootscreen imgui (This will have to wait i have no idea how to do this now ill do some R&D next week)
  • Added Context manager so that ImGui resources are managed via RAII
  • Removed CMakeLists.txt conditionals for lib_imgui (uses interface library pattern)

jurassicLizard and others added 4 commits January 29, 2026 18:25
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

6 files reviewed, 4 comments

Edit Code Review Agent Settings | Greptile

@jurassicLizard jurassicLizard requested a review from xezon January 29, 2026 18:01
@jurassicLizard
Copy link
Author

@greptileai

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

Labels

Debug Is mostly debug functionality Enhancement Is new feature or request Gen Relates to Generals Major Severity: Minor < Major < Critical < Blocker ZH Relates to Zero Hour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants