diff --git a/soh/soh/Enhancements/debugger/colViewer.h b/soh/soh/Enhancements/debugger/colViewer.h index 5252bc950..b4807e873 100644 --- a/soh/soh/Enhancements/debugger/colViewer.h +++ b/soh/soh/Enhancements/debugger/colViewer.h @@ -2,11 +2,6 @@ #include -#ifdef __cplusplus -extern "C" -#endif -void DrawColViewer(); - typedef enum { COLVIEW_DISABLED, COLVIEW_SOLID, @@ -23,4 +18,4 @@ class ColViewerWindow : public Ship::GuiWindow { void UpdateElement() override {}; }; -#endif \ No newline at end of file +#endif diff --git a/soh/soh/Enhancements/debugger/valueViewer.cpp b/soh/soh/Enhancements/debugger/valueViewer.cpp index 088e69713..7d09dfb63 100644 --- a/soh/soh/Enhancements/debugger/valueViewer.cpp +++ b/soh/soh/Enhancements/debugger/valueViewer.cpp @@ -1,6 +1,7 @@ #include "valueViewer.h" #include "soh/SohGui/UIWidgets.hpp" #include "soh/OTRGlobals.h" +#include "soh/ShipInit.hpp" extern "C" { #include @@ -14,6 +15,10 @@ void GfxPrint_SetPos(GfxPrint* printer, s32 x, s32 y); s32 GfxPrint_Printf(GfxPrint* printer, const char* fmt, ...); } +#define CVAR_NAME CVAR_DEVELOPER_TOOLS("ValueViewerEnablePrinting") +#define CVAR_DEFAULT 0 +#define CVAR_VALUE CVarGetInteger(CVAR_NAME, CVAR_DEFAULT) + ImVec4 WHITE = ImVec4(1.0f, 1.0f, 1.0f, 1.0f); std::vector valueTable = { @@ -104,8 +109,40 @@ extern "C" void ValueViewer_Draw(GfxPrint* printer) { } } +extern "C" void ValueViewer_SetupDraw() { + OPEN_DISPS(gGameState->gfxCtx); + + Gfx* gfx; + Gfx* polyOpa; + GfxPrint printer; + + polyOpa = POLY_OPA_DISP; + gfx = Graph_GfxPlusOne(polyOpa); + gSPDisplayList(OVERLAY_DISP++, gfx); + + GfxPrint_Init(&printer); + GfxPrint_Open(&printer, gfx); + + ValueViewer_Draw(&printer); + + gfx = GfxPrint_Close(&printer); + GfxPrint_Destroy(&printer); + + gSPEndDisplayList(gfx++); + Graph_BranchDlist(polyOpa, gfx); + POLY_OPA_DISP = gfx; + + CLOSE_DISPS(gGameState->gfxCtx); +} + +void RegisterValueViewerHooks() { + COND_HOOK(OnGameFrameUpdate, CVAR_VALUE, []() { ValueViewer_SetupDraw(); }); +} + +RegisterShipInitFunc initFunc(RegisterValueViewerHooks, { CVAR_NAME }); + void ValueViewerWindow::DrawElement() { - UIWidgets::PaddedEnhancementCheckbox("Enable Printing", CVAR_DEVELOPER_TOOLS("ValueViewerEnablePrinting")); + UIWidgets::PaddedEnhancementCheckbox("Enable Printing", CVAR_NAME); ImGui::BeginGroup(); static int selectedElement = -1; diff --git a/soh/soh/Enhancements/debugger/valueViewer.h b/soh/soh/Enhancements/debugger/valueViewer.h index 747d39018..e93491fa5 100644 --- a/soh/soh/Enhancements/debugger/valueViewer.h +++ b/soh/soh/Enhancements/debugger/valueViewer.h @@ -42,12 +42,4 @@ class ValueViewerWindow : public Ship::GuiWindow { void UpdateElement() override {}; }; -extern "C" { -#include #endif - -void ValueViewer_Draw(GfxPrint* printer); - -#ifdef __cplusplus -} -#endif \ No newline at end of file diff --git a/soh/src/code/graph.c b/soh/src/code/graph.c index 06d84aa3b..51f8fcd17 100644 --- a/soh/src/code/graph.c +++ b/soh/src/code/graph.c @@ -6,8 +6,6 @@ #include #include -#include "soh/Enhancements/debugger/colViewer.h" -#include "soh/Enhancements/debugger/valueViewer.h" #include "soh/Enhancements/gameconsole.h" #include "soh/OTRGlobals.h" #include "libultraship/bridge.h" @@ -300,28 +298,6 @@ void Graph_Update(GraphicsContext* gfxCtx, GameState* gameState) { OPEN_DISPS(gfxCtx); - if (CVarGetInteger(CVAR_DEVELOPER_TOOLS("ValueViewerEnablePrinting"), 0)) { - Gfx* gfx; - Gfx* polyOpa; - GfxPrint printer; - - polyOpa = POLY_OPA_DISP; - gfx = Graph_GfxPlusOne(polyOpa); - gSPDisplayList(OVERLAY_DISP++, gfx); - - GfxPrint_Init(&printer); - GfxPrint_Open(&printer, gfx); - - ValueViewer_Draw(&printer); - - gfx = GfxPrint_Close(&printer); - GfxPrint_Destroy(&printer); - - gSPEndDisplayList(gfx++); - Graph_BranchDlist(polyOpa, gfx); - POLY_OPA_DISP = gfx; - } - gDPNoOpString(WORK_DISP++, "WORK_DISP 終了", 0); gDPNoOpString(POLY_OPA_DISP++, "POLY_OPA_DISP 終了", 0); gDPNoOpString(POLY_XLU_DISP++, "POLY_XLU_DISP 終了", 0);