Show imgui window when starting app with --debug (#138)

* Show imgui window when starting app with --debug

* g_closed test in SDL_AppIterate is still needed

* Allow disabling isleapp debugging by configuring with -DISLE_DEBUG=OFF

* clang-format
This commit is contained in:
Anonymous Maarten 2025-05-20 23:36:51 +02:00 committed by GitHub
parent 70b1ebea87
commit 9d06cd9e53
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 258 additions and 15 deletions

3
.gitmodules vendored
View File

@ -4,3 +4,6 @@
[submodule "3rdparty/miniaudio"]
path = 3rdparty/miniaudio
url = https://github.com/mackron/miniaudio
[submodule "imgui"]
path = 3rdparty/imgui
url = https://github.com/ocornut/imgui

View File

@ -15,7 +15,6 @@ else()
target_include_directories(miniaudio PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/miniaudio/extras/miniaudio_split")
endif()
set_property(TARGET miniaudio PROPERTY ARCHIVE_OUTPUT_NAME "miniaudio$<$<CONFIG:Debug>:d>")
# Disable most features since we don't need them.
target_compile_definitions(miniaudio PUBLIC
MA_ENABLE_ONLY_SPECIFIC_BACKENDS
@ -45,5 +44,30 @@ endif()
add_library(libsmacker STATIC
${libsmacker_SOURCE_DIR}/smacker.c
)
set_property(TARGET libsmacker PROPERTY ARCHIVE_OUTPUT_NAME "libsmacker$<$<CONFIG:Debug>:d>")
target_include_directories(libsmacker PUBLIC ${libsmacker_SOURCE_DIR})
if(DOWNLOAD_DEPENDENCIES)
include(FetchContent)
FetchContent_Declare(
imgui
GIT_REPOSITORY "https://github.com/ocornut/imgui"
GIT_TAG f5befd2d29e66809cd1110a152e375a7f1981f06
)
FetchContent_MakeAvailable(imgui)
else()
set(imgui_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/imgui")
endif()
add_library(imgui STATIC
${imgui_SOURCE_DIR}/imgui.cpp
${imgui_SOURCE_DIR}/imgui_draw.cpp
${imgui_SOURCE_DIR}/imgui_tables.cpp
${imgui_SOURCE_DIR}/imgui_widgets.cpp
${imgui_SOURCE_DIR}/imgui_demo.cpp
${imgui_SOURCE_DIR}/backends/imgui_impl_sdl3.cpp
${imgui_SOURCE_DIR}/backends/imgui_impl_sdlrenderer3.cpp
)
target_include_directories(imgui PUBLIC ${imgui_SOURCE_DIR})
target_link_libraries(imgui PUBLIC SDL3::Headers)
target_link_libraries(imgui PRIVATE SDL3::SDL3)
set_property(TARGET imgui PROPERTY CXX_CLANG_TIDY "")

1
3rdparty/imgui vendored Submodule

@ -0,0 +1 @@
Subproject commit f5befd2d29e66809cd1110a152e375a7f1981f06

View File

@ -22,6 +22,7 @@ option(ISLE_BUILD_APP "Build isle application" ON)
option(ISLE_ASAN "Enable Address Sanitizer" OFF)
option(ISLE_UBSAN "Enable Undefined Behavior Sanitizer" OFF)
option(ISLE_WERROR "Treat warnings as errors" OFF)
option(ISLE_DEBUG "Enable imgui debug" ON)
cmake_dependent_option(ISLE_USE_DX5 "Build with internal DirectX 5 SDK" "${NOT_MINGW}" "WIN32;CMAKE_SIZEOF_VOID_P EQUAL 4" OFF)
cmake_dependent_option(ISLE_MINIWIN "Use miniwin and minimfc" ON "NOT ISLE_USE_DX5" OFF)
cmake_dependent_option(ISLE_BUILD_CONFIG "Build CONFIG.EXE application" ON "MSVC OR ISLE_MINIWIN" OFF)
@ -34,6 +35,7 @@ message(STATUS "Isle app: ${ISLE_BUILD_APP}")
message(STATUS "Config app: ${ISLE_BUILD_CONFIG}")
message(STATUS "Internal DirectX5 SDK: ${ISLE_USE_DX5}")
message(STATUS "Internal miniwin: ${ISLE_MINIWIN}")
message(STATUS "Isle debugging: ${ISLE_DEBUG}")
if (DOWNLOAD_DEPENDENCIES)
# FetchContent downloads and configures dependencies
@ -344,6 +346,7 @@ if (WIN32)
target_link_libraries(lego1 INTERFACE winmm)
endif()
target_link_libraries(lego1 PRIVATE libsmacker miniaudio)
target_include_directories(lego1 PUBLIC $<BUILD_INTERFACE:$<TARGET_PROPERTY:miniaudio,INTERFACE_INCLUDE_DIRECTORIES>>)
# lego1_impl sources
target_sources(lego1 PRIVATE
@ -490,6 +493,13 @@ if (ISLE_BUILD_APP)
endif()
# Link LEGO1
target_link_libraries(isle PRIVATE lego1)
if(ISLE_DEBUG)
target_sources(isle PRIVATE
ISLE/isledebug.cpp
)
target_compile_definitions(isle PRIVATE ISLE_DEBUG)
target_link_libraries(isle PRIVATE imgui)
endif()
endif()
if (ISLE_BUILD_CONFIG)

View File

@ -2,6 +2,7 @@
#include "3dmanager/lego3dmanager.h"
#include "decomp.h"
#include "isledebug.h"
#include "legoanimationmanager.h"
#include "legobuildingmanager.h"
#include "legogamestate.h"
@ -30,8 +31,6 @@
#include "roi/legoroi.h"
#include "viewmanager/viewmanager.h"
#include <SDL3/SDL_init.h>
#define SDL_MAIN_USE_CALLBACKS
#include <SDL3/SDL.h>
#include <SDL3/SDL_main.h>
@ -303,6 +302,8 @@ SDL_AppResult SDL_AppIterate(void* appstate)
}
if (!g_closed) {
IsleDebug_Render();
if (g_reqEnableRMDevice) {
g_reqEnableRMDevice = FALSE;
VideoManager()->EnableRMDevice();
@ -341,6 +342,10 @@ SDL_AppResult SDL_AppEvent(void* appstate, SDL_Event* event)
return SDL_APP_CONTINUE;
}
if (IsleDebug_Event(event)) {
return SDL_APP_CONTINUE;
}
// [library:window]
// Remaining functionality to be implemented:
// Full screen - crashes when minimizing/maximizing, but this will probably be fixed once DirectDraw is replaced
@ -348,12 +353,16 @@ SDL_AppResult SDL_AppEvent(void* appstate, SDL_Event* event)
switch (event->type) {
case SDL_EVENT_WINDOW_FOCUS_GAINED:
g_isle->SetWindowActive(TRUE);
Lego()->Resume();
if (!g_debugEnabled) {
g_isle->SetWindowActive(TRUE);
Lego()->Resume();
}
break;
case SDL_EVENT_WINDOW_FOCUS_LOST:
g_isle->SetWindowActive(FALSE);
Lego()->Pause();
if (!g_debugEnabled) {
g_isle->SetWindowActive(FALSE);
Lego()->Pause();
}
break;
case SDL_EVENT_WINDOW_CLOSE_REQUESTED:
if (!g_closed) {
@ -566,6 +575,8 @@ MxResult IsleApp::SetupWindow()
}
}
IsleDebug_Init();
return SUCCESS;
}
@ -832,6 +843,12 @@ MxResult IsleApp::ParseArguments(int argc, char** argv)
m_iniPath = argv[i + 1];
consumed = 2;
}
#ifdef ISLE_DEBUG
else if (strcmp(argv[i], "--debug") == 0) {
g_debugEnabled = true;
consumed = 1;
}
#endif
if (consumed <= 0) {
SDL_Log("Invalid argument(s): %s", argv[i]);
return FAILURE;

View File

@ -6,8 +6,7 @@
#include "mxtypes.h"
#include "mxvideoparam.h"
#include <SDL3/SDL_mouse.h>
#include <SDL3/SDL_video.h>
#include <SDL3/SDL.h>
#ifdef MINIWIN
#include "miniwin.h"
#else
@ -87,4 +86,6 @@ private:
char* m_iniPath;
};
extern IsleApp* g_isle;
#endif // ISLEAPP_H

155
ISLE/isledebug.cpp Normal file
View File

@ -0,0 +1,155 @@
#include "isledebug.h"
#include "isleapp.h"
#include "legobuildingmanager.h"
#include "legogamestate.h"
#include "legoplantmanager.h"
#include "legosoundmanager.h"
#include "legovideomanager.h"
#include "misc.h"
#include <SDL3/SDL.h>
#include <backends/imgui_impl_sdl3.h>
#include <backends/imgui_impl_sdlrenderer3.h>
#include <imgui.h>
bool g_debugEnabled;
bool g_debugPaused;
SDL_Window* g_debugWindow;
SDL_Renderer* g_debugRenderer;
void IsleDebug_Init()
{
do {
if (!g_debugEnabled) {
break;
}
if (!SDL_CreateWindowAndRenderer(
"Debug ISLE",
640,
480,
SDL_WINDOW_RESIZABLE,
&g_debugWindow,
&g_debugRenderer
)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to create debug window");
break;
}
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGui::StyleColorsDark();
if (!ImGui_ImplSDL3_InitForSDLRenderer(g_debugWindow, g_debugRenderer)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "ImGui_ImplSDL3_InitForSDLRenderer failed");
g_debugEnabled = false;
break;
}
if (!ImGui_ImplSDLRenderer3_Init(g_debugRenderer)) {
g_debugEnabled = false;
break;
}
} while (0);
if (!g_debugEnabled) {
if (g_debugRenderer) {
SDL_DestroyRenderer(g_debugRenderer);
g_debugRenderer = nullptr;
}
if (g_debugWindow) {
SDL_DestroyWindow(g_debugWindow);
g_debugWindow = nullptr;
}
}
}
bool IsleDebug_Event(SDL_Event* event)
{
if (!g_debugEnabled) {
return false;
}
if (SDL_GetWindowFromEvent(event) != g_debugWindow) {
return false;
}
ImGui_ImplSDL3_ProcessEvent(event);
return true;
}
void IsleDebug_Render()
{
if (!g_debugEnabled) {
return;
}
const ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
ImGui_ImplSDLRenderer3_NewFrame();
ImGui_ImplSDL3_NewFrame();
ImGui::NewFrame();
ImGuiIO& io = ImGui::GetIO();
{
ImGui::BeginMainMenuBar();
if (ImGui::MenuItem(g_debugPaused ? "Resume" : "Pause")) {
g_debugPaused = !g_debugPaused;
if (g_debugPaused) {
g_isle->SetWindowActive(false);
Lego()->Pause();
}
else {
g_isle->SetWindowActive(true);
Lego()->Resume();
}
}
ImGui::EndMainMenuBar();
LegoOmni* lego = Lego();
if (ImGui::Begin("LEGO")) {
if (ImGui::TreeNode("Game State")) {
LegoGameState* gameState = lego->GetGameState();
ImGui::Value("Actor Id", gameState->GetActorId());
ImGui::Text("Actor Name: %s", gameState->GetActorName());
ImGui::Text("Current act: %d", gameState->GetCurrentAct());
ImGui::Text("Loaded act: %d", gameState->GetLoadedAct());
ImGui::Text("Previous area: %d", gameState->GetPreviousArea());
ImGui::Text("Unknown 0x42c: %d", gameState->GetUnknown0x42c());
ImGui::Value("Player count", gameState->GetPlayerCount());
ImGui::TreePop();
}
if (ImGui::TreeNode("Sound Manager")) {
LegoSoundManager* soundManager = lego->GetSoundManager();
Sint32 oldVolume = soundManager->GetVolume();
Sint32 volume = oldVolume;
ImGui::SliderInt("volume", &volume, 0, 100);
if (volume != oldVolume) {
soundManager->SetVolume(volume);
}
ImGui::TreePop();
}
if (ImGui::TreeNode("Video Manager")) {
LegoVideoManager* videoManager = lego->GetVideoManager();
ImGui::Text("Elapsed: %g", static_cast<float>(videoManager->GetElapsedSeconds()));
ImGui::Value("Render3D", videoManager->GetRender3D());
ImGui::TreePop();
}
if (ImGui::TreeNode("Plant Manager")) {
LegoPlantManager* plantManager = lego->GetPlantManager();
ImGui::Value("#plants", plantManager->GetNumPlants());
ImGui::TreePop();
}
if (ImGui::TreeNode("Building Manager")) {
LegoBuildingManager* buildingManager = lego->GetBuildingManager();
ImGui::TreePop();
}
}
ImGui::End();
}
ImGui::ShowDemoWindow(nullptr);
ImGui::Render();
SDL_RenderClear(g_debugRenderer);
SDL_SetRenderScale(g_debugRenderer, io.DisplayFramebufferScale.x, io.DisplayFramebufferScale.y);
SDL_SetRenderDrawColor(
g_debugRenderer,
(Uint8) (clear_color.x * 255),
(Uint8) (clear_color.y * 255),
(Uint8) (clear_color.z * 255),
(Uint8) (clear_color.w * 255)
);
ImGui_ImplSDLRenderer3_RenderDrawData(ImGui::GetDrawData(), g_debugRenderer);
SDL_RenderPresent(g_debugRenderer);
}

32
ISLE/isledebug.h Normal file
View File

@ -0,0 +1,32 @@
#ifndef ISLEDEBUG_H
#define ISLEDEBUG_H
#if defined(ISLE_DEBUG)
extern bool g_debugEnabled;
typedef union SDL_Event SDL_Event;
extern void IsleDebug_Init();
extern bool IsleDebug_Event(SDL_Event* event);
extern void IsleDebug_Render();
#else
#define IsleDebug_Init() \
do { \
} while (0)
#define IsleDebug_Event(EVENT) false
#define IsleDebug_Render() \
do { \
} while (0)
#define g_debugEnabled false
#endif
#endif

View File

@ -15,7 +15,7 @@ class LegoStorage;
class MxVariableTable;
class MxString;
extern const char* g_actorNames[7];
LEGO1_EXPORT extern const char* g_actorNames[7];
// SIZE 0x08
struct ColorStringStruct {

View File

@ -14,7 +14,7 @@ class LegoWorld;
// VTABLE: LEGO1 0x100d6758
// SIZE 0x2c
class LegoPlantManager : public MxCore {
class LEGO1_EXPORT LegoPlantManager : public MxCore {
public:
// SIZE 0x0c
struct AnimEntry {

View File

@ -16,7 +16,7 @@
#define CALLBACK
#define FAR
#define WINAPI
#define HWND_NOTOPMOST -2
#define HWND_NOTOPMOST ((HWND) -2)
#define RGB(r, g, b) (((BYTE) (r) | ((BYTE) (g) << 8) | ((BYTE) (b) << 16)))
#define S_OK ((HRESULT) 0)
#define E_NOINTERFACE (0x80004002)
@ -154,7 +154,7 @@ protected:
int m_refCount;
};
BOOL SetWindowPos(HWND hWnd, int hWndInsertAfter, int X, int Y, int cx, int cy, UINT uFlags);
BOOL SetWindowPos(HWND hWnd, HWND hWndInsertAfter, int X, int Y, int cx, int cy, UINT uFlags);
inline HDC WINAPI GetDC(HWND hWnd)
{

View File

@ -27,7 +27,7 @@ HRESULT IUnknown::QueryInterface(const GUID& riid, void** ppvObject)
return E_NOINTERFACE;
}
BOOL SetWindowPos(HWND hWnd, int hWndInsertAfter, int X, int Y, int cx, int cy, UINT uFlags)
BOOL SetWindowPos(HWND hWnd, HWND hWndInsertAfter, int X, int Y, int cx, int cy, UINT uFlags)
{
if (!hWnd) {
return FALSE;