2022-03-21 21:51:23 -04:00
|
|
|
#include "global.h"
|
|
|
|
#include "objects/gameplay_keep/gameplay_keep.h"
|
2023-08-20 13:59:39 -04:00
|
|
|
#include "soh/Enhancements/game-interactor/GameInteractor.h"
|
2022-03-21 21:51:23 -04:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
/* 0x00 */ s16 drawType; // indicates which draw function to use when displaying the object
|
|
|
|
/* 0x04 */ void* drawArg; // segment address (display list or texture) passed to the draw function when called
|
|
|
|
} DebugDispObjectInfo; // size = 0x8
|
|
|
|
|
2022-11-06 03:24:34 -05:00
|
|
|
typedef void (*DebugDispObject_DrawFunc)(DebugDispObject*, void*, PlayState*);
|
2022-03-21 21:51:23 -04:00
|
|
|
|
2022-11-06 03:24:34 -05:00
|
|
|
void DebugDisplay_DrawSpriteI8(DebugDispObject* dispObj, void* texture, PlayState* play);
|
|
|
|
void DebugDisplay_DrawPolygon(DebugDispObject* dispObj, void* dlist, PlayState* play);
|
2022-03-21 21:51:23 -04:00
|
|
|
|
|
|
|
static DebugDispObject_DrawFunc sDebugObjectDrawFuncTable[] = {
|
|
|
|
DebugDisplay_DrawSpriteI8,
|
|
|
|
DebugDisplay_DrawPolygon,
|
|
|
|
};
|
|
|
|
|
|
|
|
static DebugDispObjectInfo sDebugObjectInfoTable[] = {
|
|
|
|
{ 0, gDebugCircleTex }, { 0, gDebugCrossTex }, { 0, gDebugBallTex },
|
|
|
|
{ 0, gDebugCursorTex }, { 1, gDebugArrowDL }, { 1, gDebugCameraDL },
|
|
|
|
};
|
|
|
|
|
|
|
|
static Lights1 sDebugObjectLights = gdSPDefLights1(0x80, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0x49, 0x49, 0x49);
|
|
|
|
|
|
|
|
static DebugDispObject* sDebugObjectListHead;
|
|
|
|
|
|
|
|
void DebugDisplay_Init(void) {
|
|
|
|
sDebugObjectListHead = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
DebugDispObject* DebugDisplay_AddObject(f32 posX, f32 posY, f32 posZ, s16 rotX, s16 rotY, s16 rotZ, f32 scaleX,
|
|
|
|
f32 scaleY, f32 scaleZ, u8 red, u8 green, u8 blue, u8 alpha, s16 type,
|
|
|
|
GraphicsContext* gfxCtx) {
|
|
|
|
DebugDispObject* prevHead = sDebugObjectListHead;
|
|
|
|
|
2023-08-20 13:59:39 -04:00
|
|
|
if (GameInteractor_NoUIActive()) {
|
|
|
|
return sDebugObjectListHead;
|
|
|
|
}
|
|
|
|
|
2022-03-21 21:51:23 -04:00
|
|
|
sDebugObjectListHead = Graph_Alloc(gfxCtx, sizeof(DebugDispObject));
|
|
|
|
|
|
|
|
sDebugObjectListHead->pos.x = posX;
|
|
|
|
sDebugObjectListHead->pos.y = posY;
|
|
|
|
sDebugObjectListHead->pos.z = posZ;
|
|
|
|
sDebugObjectListHead->rot.x = rotX;
|
|
|
|
sDebugObjectListHead->rot.y = rotY;
|
|
|
|
sDebugObjectListHead->rot.z = rotZ;
|
|
|
|
sDebugObjectListHead->scale.x = scaleX;
|
|
|
|
sDebugObjectListHead->scale.y = scaleY;
|
|
|
|
sDebugObjectListHead->scale.z = scaleZ;
|
|
|
|
sDebugObjectListHead->color.r = red;
|
|
|
|
sDebugObjectListHead->color.g = green;
|
|
|
|
sDebugObjectListHead->color.b = blue;
|
|
|
|
sDebugObjectListHead->color.a = alpha;
|
|
|
|
sDebugObjectListHead->type = type;
|
|
|
|
sDebugObjectListHead->next = prevHead;
|
|
|
|
|
|
|
|
return sDebugObjectListHead;
|
|
|
|
}
|
|
|
|
|
2022-11-06 03:24:34 -05:00
|
|
|
void DebugDisplay_DrawObjects(PlayState* play) {
|
2022-03-21 21:51:23 -04:00
|
|
|
DebugDispObject* dispObj = sDebugObjectListHead;
|
|
|
|
DebugDispObjectInfo* objInfo;
|
|
|
|
|
|
|
|
while (dispObj != NULL) {
|
|
|
|
objInfo = &sDebugObjectInfoTable[dispObj->type];
|
2022-11-06 03:24:34 -05:00
|
|
|
sDebugObjectDrawFuncTable[objInfo->drawType](dispObj, objInfo->drawArg, play);
|
2022-03-21 21:51:23 -04:00
|
|
|
dispObj = dispObj->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-06 03:24:34 -05:00
|
|
|
void DebugDisplay_DrawSpriteI8(DebugDispObject* dispObj, void* texture, PlayState* play) {
|
|
|
|
OPEN_DISPS(play->state.gfxCtx);
|
2022-03-21 21:51:23 -04:00
|
|
|
|
2022-11-29 18:29:36 -05:00
|
|
|
Gfx_SetupDL_47Xlu(play->state.gfxCtx);
|
2022-03-21 21:51:23 -04:00
|
|
|
|
|
|
|
gDPSetPrimColor(POLY_XLU_DISP++, 0, 0, dispObj->color.r, dispObj->color.g, dispObj->color.b, dispObj->color.a);
|
|
|
|
|
|
|
|
Matrix_Translate(dispObj->pos.x, dispObj->pos.y, dispObj->pos.z, MTXMODE_NEW);
|
|
|
|
Matrix_Scale(dispObj->scale.x, dispObj->scale.y, dispObj->scale.z, MTXMODE_APPLY);
|
2022-11-06 03:24:34 -05:00
|
|
|
Matrix_Mult(&play->billboardMtxF, MTXMODE_APPLY);
|
2022-03-21 21:51:23 -04:00
|
|
|
Matrix_RotateZYX(dispObj->rot.x, dispObj->rot.y, dispObj->rot.z, MTXMODE_APPLY);
|
|
|
|
|
|
|
|
gDPLoadTextureBlock(POLY_XLU_DISP++, texture, G_IM_FMT_I, G_IM_SIZ_8b, 16, 16, 0, G_TX_NOMIRROR | G_TX_WRAP,
|
|
|
|
G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD);
|
|
|
|
|
2022-11-06 03:24:34 -05:00
|
|
|
gSPMatrix(POLY_XLU_DISP++, MATRIX_NEWMTX(play->state.gfxCtx),
|
2022-03-21 21:51:23 -04:00
|
|
|
G_MTX_MODELVIEW | G_MTX_LOAD);
|
|
|
|
gSPDisplayList(POLY_XLU_DISP++, gDebugSpriteDL);
|
|
|
|
|
2022-11-06 03:24:34 -05:00
|
|
|
CLOSE_DISPS(play->state.gfxCtx);
|
2022-03-21 21:51:23 -04:00
|
|
|
}
|
|
|
|
|
2022-11-06 03:24:34 -05:00
|
|
|
void DebugDisplay_DrawPolygon(DebugDispObject* dispObj, void* dlist, PlayState* play) {
|
|
|
|
OPEN_DISPS(play->state.gfxCtx);
|
2022-03-21 21:51:23 -04:00
|
|
|
|
2022-11-29 18:29:36 -05:00
|
|
|
Gfx_SetupDL_4Xlu(play->state.gfxCtx);
|
2022-03-21 21:51:23 -04:00
|
|
|
|
|
|
|
gDPSetPrimColor(POLY_XLU_DISP++, 0, 0, dispObj->color.r, dispObj->color.g, dispObj->color.b, dispObj->color.a);
|
|
|
|
|
|
|
|
gSPSetLights1(POLY_XLU_DISP++, sDebugObjectLights);
|
|
|
|
|
|
|
|
Matrix_SetTranslateRotateYXZ(dispObj->pos.x, dispObj->pos.y, dispObj->pos.z, &dispObj->rot);
|
|
|
|
Matrix_Scale(dispObj->scale.x, dispObj->scale.y, dispObj->scale.z, MTXMODE_APPLY);
|
|
|
|
|
2022-11-06 03:24:34 -05:00
|
|
|
gSPMatrix(POLY_XLU_DISP++, MATRIX_NEWMTX(play->state.gfxCtx),
|
2022-03-21 21:51:23 -04:00
|
|
|
G_MTX_MODELVIEW | G_MTX_LOAD);
|
|
|
|
gSPDisplayList(POLY_XLU_DISP++, dlist);
|
|
|
|
|
2022-11-06 03:24:34 -05:00
|
|
|
CLOSE_DISPS(play->state.gfxCtx);
|
2022-03-21 21:51:23 -04:00
|
|
|
}
|