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_DEBUG=ON -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 Summary

Integrates Dear ImGui framework for debug overlays in Generals, Zero Hour, and WorldBuilder applications. The implementation is gated behind RTS_BUILD_OPTION_IMGUI CMake flag and RTS_HAS_IMGUI preprocessor define, requiring Debug build mode.

Key Changes:

  • Added custom DirectX 8 backend implementation (imgui_impl_dx8.cpp/h) adapted from official DX9 backend with MIT license
  • Created ImGuiFrameManager wrapper to manage frame lifecycle and prevent duplicate begin/end calls
  • Integrated ImGui rendering into game update loop (GameClient::update()) with demo window
  • Added render data output in DX8Wrapper::End_Scene() after all game rendering completes
  • WorldBuilder tools include message pump integration via ImGui_ImplWin32_WndProcHandler()
  • CMake fetches ImGui v1.91.7 from official repository, builds as static library

Integration Points:

  • Frame lifecycle: BeginFrame() → draw widgets → EndFrame() (calls ImGui::Render())
  • Render output: ImGui_ImplDX8_RenderDrawData() called after game scene render
  • Device lifecycle: InvalidateDeviceObjects()/CreateDeviceObjects() handle DX8 device resets
  • Input handling: WorldBuilder windows process ImGui input via Win32 backend

Previous Issues Addressed:

  • Redundant ImGui::Render() calls removed from dx8wrapper
  • Lock result checking added to prevent null pointer dereferences
  • Typo "moore" fixed in CMakeLists
  • Return value checking for GetDepthStencilSurface() added

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The ImGui integration is well-implemented with proper gating behind preprocessor defines and CMake options. All critical issues from previous reviews have been addressed (redundant render calls, null pointer checks, typos). The code follows a standard ImGui integration pattern with clear separation between frame management, rendering, and device lifecycle. The only remaining issue is a minor style inconsistency in the copyright header of the .h file compared to the .cpp file. The implementation is thoroughly tested across multiple build targets (Generals, Zero Hour, WorldBuilder) and properly handles DirectX 8 state management.
  • No files require special attention

Important Files Changed

Filename Overview
Core/Libraries/Source/ImGui/dx8_backend/imgui_impl_dx8.cpp Custom DX8 backend implementation with MIT license. Previous comments addressed, lock result checks added.
Core/Libraries/Source/ImGui/dx8_backend/imgui_impl_dx8.h Header file for DX8 backend with MIT license, clean API declarations.
Core/Libraries/Source/ImGui/wrapper/ImGuiFrameManager.cpp Simple frame management wrapper, properly gated with frame state tracking.
Generals/Code/GameEngine/Source/GameClient/GameClient.cpp ImGui integration in game update loop with proper frame begin/end calls at appropriate points.
GeneralsMD/Code/GameEngine/Source/GameClient/GameClient.cpp Zero Hour variant with identical ImGui integration pattern to Generals version.

Sequence Diagram

sequenceDiagram
    participant App as Game/WorldBuilder
    participant GC as GameClient
    participant FM as FrameManager
    participant DX8 as DX8Wrapper
    participant Backend as ImGui_DX8Backend
    participant Device as D3DDevice8

    Note over App,Device: Initialization Phase
    App->>DX8: Init(HWND, Width, Height)
    DX8->>Backend: ImGui_ImplWin32_Init(HWND)
    DX8->>Backend: ImGui_ImplDX8_Init(Device)
    Backend->>Device: AddRef()
    
    Note over App,Device: Render Loop
    GC->>FM: BeginFrame()
    FM->>Backend: ImGui_ImplDX8_NewFrame()
    FM->>Backend: ImGui_ImplWin32_NewFrame()
    FM->>FM: ImGui::NewFrame()
    
    GC->>GC: ImGui::ShowDemoWindow()
    
    GC->>FM: EndFrame()
    FM->>FM: ImGui::Render()
    
    GC->>DX8: TheDisplay->DRAW()
    DX8->>Device: BeginScene()
    DX8->>Backend: ImGui_ImplDX8_RenderDrawData()
    Backend->>Device: SetRenderState()
    Backend->>Device: CreateStateBlock()
    Backend->>Device: DrawIndexedPrimitive()
    Backend->>Device: ApplyStateBlock()
    DX8->>Device: EndScene()
    
    Note over App,Device: Device Reset
    DX8->>Backend: ImGui_ImplDX8_InvalidateDeviceObjects()
    Backend->>Device: Release buffers
    DX8->>Backend: ImGui_ImplDX8_CreateDeviceObjects()
    Backend->>Device: CreateTexture/CreateDepthStencilSurface()
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
)
# link imgui if needed
if (RTS_BUILD_OPTION_IMGUI)
target_link_libraries(corei_always INTERFACE lib_imgui)
Copy link

Choose a reason for hiding this comment

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

I think imgui is not suitable for _always lib. _always lib is meant to be included in all targets. But there are build targets that have no rendering and never will.

Copy link
Author

Choose a reason for hiding this comment

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

@xezon : i made changes to this in 1e31c3c. please check if that is sufficient to resolve this

Copy link

Choose a reason for hiding this comment

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

Doesn't that still mean that it is added to all targets through corei_always ?

Copy link
Author

Choose a reason for hiding this comment

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

I saw that corei_always doesnot mean gi_always and zi_always these are lower down the chain ?

instead of having them in corei_always once. it is added twice once to gi_always and zi_always because multiple targets depend on it from both generals and zero hours, specifically guiedit (x2), worldbuilder (x2) and GameClient (x2), so it is only visible to those targets that link gi_always or zi_always i removed it from corei_always so not all targets can see it . GuiEdit for example can because it links against gi_always (or zi_always) . An alternative would be to go further down the chain and have imgui lib linked to the individual targets that need it but that means i would have to add it in 4*2 places depending on how granular we want to go.

THe problem is that imgui_lib is needed in multiple locations (WinMain, dx8wrapper, GameClient and wb3dclient) so the lower we go the more places we have to add it . Any suggestions other than zi_always and gi_always ?

Copy link
Author

Choose a reason for hiding this comment

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

target_link_libraries(corei_always INTERFACE

core_config

core_utility

corei_libraries_include

resources

)

i think only targets that need generals or zerohour codebase link against gi_always and zi_always but you are obviously more knowleadgeable about the codebase. So i could be wrong

Copy link

Choose a reason for hiding this comment

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

If you search for d3d8lib in cmake files then you find all targets that link Direct X. I suggest put imgui right there for all necessary targets. I think Game exe and World Builder exe are good for starters. W3DView and GUIEdit are not important to have it.

Copy link
Author

@jurassicLizard jurassicLizard Jan 26, 2026

Choose a reason for hiding this comment

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

i have moved it where it is needed at the deepest possible component. gameclient is part of the gameengine so that is where i hadded it. we are lucky also that the gameengine is used by worldbuilder so that's good.

32a61c4

Copy link
Author

Choose a reason for hiding this comment

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

imgui is failing to render after this change

Copy link
Author

Choose a reason for hiding this comment

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

UPDATE: multiple regressions happened . ImGui failing to render after these compile changes. apparently many more targets need to link to libimgui to get it work, will investigate when i have more time. This is curently a major showstopper as imgui nolonger shows in Worldbuilder (both of them).

@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 d579452 to 21171d1 Compare January 26, 2026 09:17
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.

21 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@jurassicLizard
Copy link
Author

A tip for bringing the DX8 backend code style closer to the original DX9 backend code: Use a diff tool and put them side by side, then merge over to DX8 everything that should not be different.

A tip for bringing the DX8 backend code style closer to the original DX9 backend code: Use a diff tool and put them side by side, then merge over to DX8 everything that should not be different.

Thanks. i did exactly that but given the large differences between both backends, some braces might slip the net while i am scanning. i hope i got them all now

 after moving link location multiple targets fail to render
 imgui. this has been fixed in ZH and generals but is yet
 to be fixed in worldbuilder
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.

25 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

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