Show imgui window when starting app with --debug

This commit is contained in:
Anonymous Maarten 2025-05-20 22:18:02 +02:00
parent cd32924c47
commit 42effe8961
12 changed files with 231 additions and 18 deletions

3
.gitmodules vendored
View File

@ -4,3 +4,6 @@
[submodule "3rdparty/miniaudio"] [submodule "3rdparty/miniaudio"]
path = 3rdparty/miniaudio path = 3rdparty/miniaudio
url = https://github.com/mackron/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") target_include_directories(miniaudio PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/miniaudio/extras/miniaudio_split")
endif() endif()
set_property(TARGET miniaudio PROPERTY ARCHIVE_OUTPUT_NAME "miniaudio$<$<CONFIG:Debug>:d>")
# Disable most features since we don't need them. # Disable most features since we don't need them.
target_compile_definitions(miniaudio PUBLIC target_compile_definitions(miniaudio PUBLIC
MA_ENABLE_ONLY_SPECIFIC_BACKENDS MA_ENABLE_ONLY_SPECIFIC_BACKENDS
@ -45,5 +44,30 @@ endif()
add_library(libsmacker STATIC add_library(libsmacker STATIC
${libsmacker_SOURCE_DIR}/smacker.c ${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}) 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

@ -344,6 +344,7 @@ if (WIN32)
target_link_libraries(lego1 INTERFACE winmm) target_link_libraries(lego1 INTERFACE winmm)
endif() endif()
target_link_libraries(lego1 PRIVATE libsmacker miniaudio) target_link_libraries(lego1 PRIVATE libsmacker miniaudio)
target_include_directories(lego1 PUBLIC $<BUILD_INTERFACE:$<TARGET_PROPERTY:miniaudio,INTERFACE_INCLUDE_DIRECTORIES>>)
# lego1_impl sources # lego1_impl sources
target_sources(lego1 PRIVATE target_sources(lego1 PRIVATE
@ -467,6 +468,7 @@ if (ISLE_BUILD_APP)
add_executable(isle WIN32 add_executable(isle WIN32
ISLE/res/isle.rc ISLE/res/isle.rc
ISLE/isleapp.cpp ISLE/isleapp.cpp
ISLE/isledebug.cpp
) )
list(APPEND isle_targets isle) list(APPEND isle_targets isle)
if (WIN32) if (WIN32)
@ -490,6 +492,7 @@ if (ISLE_BUILD_APP)
endif() endif()
# Link LEGO1 # Link LEGO1
target_link_libraries(isle PRIVATE lego1) target_link_libraries(isle PRIVATE lego1)
target_link_libraries(isle PRIVATE imgui)
endif() endif()
if (ISLE_BUILD_CONFIG) if (ISLE_BUILD_CONFIG)

View File

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

View File

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

14
ISLE/isledebug.h Normal file
View File

@ -0,0 +1,14 @@
#ifndef ISLEDEBUG_H
#define ISLEDEBUG_H
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();
#endif

View File

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

View File

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

View File

@ -16,7 +16,7 @@
#define CALLBACK #define CALLBACK
#define FAR #define FAR
#define WINAPI #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 RGB(r, g, b) (((BYTE) (r) | ((BYTE) (g) << 8) | ((BYTE) (b) << 16)))
#define S_OK ((HRESULT) 0) #define S_OK ((HRESULT) 0)
#define E_NOINTERFACE (0x80004002) #define E_NOINTERFACE (0x80004002)
@ -154,7 +154,7 @@ struct IUnknown {
int m_refCount; 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) inline HDC WINAPI GetDC(HWND hWnd)
{ {

View File

@ -27,7 +27,7 @@ HRESULT IUnknown::QueryInterface(const GUID& riid, void** ppvObject)
return E_NOINTERFACE; 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) { if (!hWnd) {
return FALSE; return FALSE;