Skip to content

Commit

Permalink
ShipInit and move ValueViewer rendering out of src (HarbourMasters#5039)
Browse files Browse the repository at this point in the history
  • Loading branch information
Archez authored Feb 12, 2025
1 parent d4b9e8c commit 0ce9807
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 39 deletions.
7 changes: 1 addition & 6 deletions soh/soh/Enhancements/debugger/colViewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@

#include <libultraship/libultraship.h>

#ifdef __cplusplus
extern "C"
#endif
void DrawColViewer();

typedef enum {
COLVIEW_DISABLED,
COLVIEW_SOLID,
Expand All @@ -23,4 +18,4 @@ class ColViewerWindow : public Ship::GuiWindow {
void UpdateElement() override {};
};

#endif
#endif
39 changes: 38 additions & 1 deletion soh/soh/Enhancements/debugger/valueViewer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "valueViewer.h"
#include "soh/SohGui/UIWidgets.hpp"
#include "soh/OTRGlobals.h"
#include "soh/ShipInit.hpp"

extern "C" {
#include <z64.h>
Expand All @@ -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<ValueTableElement> valueTable = {
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 0 additions & 8 deletions soh/soh/Enhancements/debugger/valueViewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,4 @@ class ValueViewerWindow : public Ship::GuiWindow {
void UpdateElement() override {};
};

extern "C" {
#include <z64.h>
#endif

void ValueViewer_Draw(GfxPrint* printer);

#ifdef __cplusplus
}
#endif
24 changes: 0 additions & 24 deletions soh/src/code/graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
#include <stdio.h>
#include <stdlib.h>

#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"
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 0ce9807

Please sign in to comment.