2020-10-03 15:22:44 +00:00
|
|
|
#include "global.h"
|
2022-11-01 23:17:11 +00:00
|
|
|
#include "terminal.h"
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-10-29 20:44:27 +00:00
|
|
|
/**
|
|
|
|
* How much time the audio update on the audio thread (`func_800E4FE0`) took in total, between scheduling the last two
|
|
|
|
* graphics tasks.
|
|
|
|
*/
|
|
|
|
volatile OSTime gAudioThreadUpdateTimeTotalPerGfxTask;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* How much time elapsed between scheduling the previous graphics task and the current one being ready (the previous
|
|
|
|
* task not necessarily being finished yet), without the amount of time spent on the audio update in the audio thread.
|
|
|
|
*/
|
|
|
|
volatile OSTime gGfxTaskSentToNextReadyMinusAudioThreadUpdateTime;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* How much time the RSP ran audio tasks for over the course of `gGraphUpdatePeriod`.
|
|
|
|
*/
|
|
|
|
volatile OSTime gRSPAudioTimeTotal;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* How much time the RSP ran graphics tasks for over the course of `gGraphUpdatePeriod`.
|
|
|
|
* Typically the RSP runs 1 graphics task per `Graph_Update` cycle, but may run 0 (see `Graph_Update`).
|
|
|
|
*/
|
|
|
|
volatile OSTime gRSPGfxTimeTotal;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* How much time the RDP ran for over the course of `gGraphUpdatePeriod`.
|
|
|
|
*/
|
|
|
|
volatile OSTime gRDPTimeTotal;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* How much time elapsed between the last two `Graph_Update` ending.
|
|
|
|
* This is expected to be at least the duration of a single frame, since it includes the time spent waiting on the
|
|
|
|
* graphics task to be done.
|
|
|
|
*/
|
|
|
|
volatile OSTime gGraphUpdatePeriod;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The time at which the audio thread audio update started.
|
|
|
|
*/
|
|
|
|
volatile OSTime gAudioThreadUpdateTimeStart;
|
|
|
|
|
|
|
|
// Accumulator for `gAudioThreadUpdateTimeStart`
|
|
|
|
volatile OSTime gAudioThreadUpdateTimeAcc;
|
|
|
|
|
|
|
|
// Accumulator for `gRSPAudioTimeTotal`
|
|
|
|
volatile OSTime gRSPAudioTimeAcc;
|
|
|
|
|
|
|
|
// Accumulator for `gRSPGfxTimeTotal`.
|
|
|
|
volatile OSTime gRSPGfxTimeAcc;
|
|
|
|
|
|
|
|
volatile OSTime gRSPOtherTimeAcc;
|
2020-05-26 15:39:27 +00:00
|
|
|
volatile OSTime D_8016A578;
|
2022-10-29 20:44:27 +00:00
|
|
|
|
|
|
|
// Accumulator for `gRDPTimeTotal`
|
|
|
|
volatile OSTime gRDPTimeAcc;
|
|
|
|
|
2021-12-06 19:03:42 +00:00
|
|
|
SpeedMeterTimeEntry* sSpeedMeterTimeEntryPtr;
|
2020-05-26 15:39:27 +00:00
|
|
|
|
2020-05-13 03:05:55 +00:00
|
|
|
SpeedMeterTimeEntry sSpeedMeterTimeEntryArray[] = {
|
2022-10-29 20:44:27 +00:00
|
|
|
{ &gAudioThreadUpdateTimeTotalPerGfxTask, 0, 0, GPACK_RGBA5551(255, 0, 0, 1) },
|
|
|
|
{ &gGfxTaskSentToNextReadyMinusAudioThreadUpdateTime, 0, 2, GPACK_RGBA5551(255, 255, 0, 1) },
|
|
|
|
{ &gRSPAudioTimeTotal, 0, 4, GPACK_RGBA5551(0, 0, 255, 1) },
|
|
|
|
{ &gRSPGfxTimeTotal, 0, 6, GPACK_RGBA5551(255, 128, 128, 1) },
|
|
|
|
{ &gRDPTimeTotal, 0, 8, GPACK_RGBA5551(0, 255, 0, 1) },
|
|
|
|
{ &gGraphUpdatePeriod, 0, 10, GPACK_RGBA5551(255, 0, 255, 1) },
|
2020-05-13 03:05:55 +00:00
|
|
|
};
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-07-30 21:49:10 +00:00
|
|
|
#define gDrawRect(gfx, color, ulx, uly, lrx, lry) \
|
2020-05-13 03:05:55 +00:00
|
|
|
gDPPipeSync(gfx); \
|
|
|
|
gDPSetFillColor(gfx, ((color) << 16) | (color)); \
|
|
|
|
gDPFillRectangle(gfx, (ulx), (uly), (lrx), (lry)); \
|
2022-07-30 21:49:10 +00:00
|
|
|
gDPPipeSync(gfx)
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-05-13 03:05:55 +00:00
|
|
|
void SpeedMeter_InitImpl(SpeedMeter* this, u32 arg1, u32 y) {
|
|
|
|
LogUtils_CheckNullPointer("this", this, "../speed_meter.c", 181);
|
|
|
|
this->unk_18 = arg1;
|
|
|
|
this->y = y;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-05-13 03:05:55 +00:00
|
|
|
void SpeedMeter_Init(SpeedMeter* this) {
|
|
|
|
SpeedMeter_InitImpl(this, 32, 22);
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-05-13 03:05:55 +00:00
|
|
|
void SpeedMeter_Destroy(SpeedMeter* this) {
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-05-13 03:05:55 +00:00
|
|
|
void SpeedMeter_DrawTimeEntries(SpeedMeter* this, GraphicsContext* gfxCtx) {
|
2020-07-30 19:50:18 +00:00
|
|
|
s32 pad[2];
|
2020-05-13 03:05:55 +00:00
|
|
|
u32 baseX = 32;
|
2022-10-29 20:44:27 +00:00
|
|
|
s32 width;
|
2020-05-13 03:05:55 +00:00
|
|
|
s32 i;
|
|
|
|
s32 uly;
|
|
|
|
s32 lry;
|
|
|
|
View view;
|
|
|
|
u32 pad2[3];
|
|
|
|
Gfx* gfx;
|
|
|
|
|
|
|
|
uly = this->y;
|
|
|
|
lry = this->y + 2;
|
|
|
|
|
2020-08-29 23:00:17 +00:00
|
|
|
OPEN_DISPS(gfxCtx, "../speed_meter.c", 225);
|
2020-05-13 03:05:55 +00:00
|
|
|
|
2020-08-29 23:00:17 +00:00
|
|
|
/*! @bug if gIrqMgrRetraceTime is 0, CLOSE_DISPS will never be reached */
|
2020-05-13 03:05:55 +00:00
|
|
|
if (gIrqMgrRetraceTime == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-12-06 19:03:42 +00:00
|
|
|
sSpeedMeterTimeEntryPtr = &sSpeedMeterTimeEntryArray[0];
|
2020-05-13 03:05:55 +00:00
|
|
|
for (i = 0; i < ARRAY_COUNT(sSpeedMeterTimeEntryArray); i++) {
|
2022-10-29 20:44:27 +00:00
|
|
|
width = ((f64)*sSpeedMeterTimeEntryPtr->time / gIrqMgrRetraceTime) * 64.0;
|
|
|
|
sSpeedMeterTimeEntryPtr->x = baseX + width;
|
2021-12-06 19:03:42 +00:00
|
|
|
sSpeedMeterTimeEntryPtr++;
|
2020-05-13 03:05:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
View_Init(&view, gfxCtx);
|
2022-04-08 22:50:28 +00:00
|
|
|
view.flags = VIEW_VIEWPORT | VIEW_PROJECTION_ORTHO;
|
2020-05-13 03:05:55 +00:00
|
|
|
|
2020-06-14 02:59:58 +00:00
|
|
|
SET_FULLSCREEN_VIEWPORT(&view);
|
|
|
|
|
2020-10-29 21:31:09 +00:00
|
|
|
gfx = OVERLAY_DISP;
|
2022-04-08 22:50:28 +00:00
|
|
|
View_ApplyTo(&view, VIEW_ALL, &gfx);
|
2020-05-13 03:05:55 +00:00
|
|
|
|
|
|
|
gDPPipeSync(gfx++);
|
|
|
|
gDPSetOtherMode(gfx++,
|
|
|
|
G_AD_PATTERN | G_CD_MAGICSQ | G_CK_NONE | G_TC_CONV | G_TF_POINT | G_TT_NONE | G_TL_TILE |
|
|
|
|
G_TD_CLAMP | G_TP_NONE | G_CYC_FILL | G_PM_NPRIMITIVE,
|
|
|
|
G_AC_NONE | G_ZS_PIXEL | G_RM_NOOP | G_RM_NOOP2);
|
|
|
|
|
2022-07-30 21:49:10 +00:00
|
|
|
gDrawRect(gfx++, GPACK_RGBA5551(0, 0, 255, 1), baseX + 64 * 0, uly, baseX + 64 * 1, lry);
|
|
|
|
gDrawRect(gfx++, GPACK_RGBA5551(0, 255, 0, 1), baseX + 64 * 1, uly, baseX + 64 * 2, lry);
|
|
|
|
gDrawRect(gfx++, GPACK_RGBA5551(255, 0, 0, 1), baseX + 64 * 2, uly, baseX + 64 * 3, lry);
|
|
|
|
gDrawRect(gfx++, GPACK_RGBA5551(255, 0, 255, 1), baseX + 64 * 3, uly, baseX + 64 * 4, lry);
|
2020-05-13 03:05:55 +00:00
|
|
|
|
2021-12-06 19:03:42 +00:00
|
|
|
sSpeedMeterTimeEntryPtr = &sSpeedMeterTimeEntryArray[0];
|
2020-05-13 03:05:55 +00:00
|
|
|
for (i = 0; i < ARRAY_COUNT(sSpeedMeterTimeEntryArray); i++) {
|
2022-07-30 21:49:10 +00:00
|
|
|
gDrawRect(gfx++, sSpeedMeterTimeEntryPtr->color, baseX, lry + sSpeedMeterTimeEntryPtr->y,
|
|
|
|
sSpeedMeterTimeEntryPtr->x, lry + sSpeedMeterTimeEntryPtr->y + 1);
|
2021-12-06 19:03:42 +00:00
|
|
|
sSpeedMeterTimeEntryPtr++;
|
2020-05-13 03:05:55 +00:00
|
|
|
}
|
|
|
|
gDPPipeSync(gfx++);
|
|
|
|
|
2020-10-29 21:31:09 +00:00
|
|
|
OVERLAY_DISP = gfx;
|
2020-08-29 23:00:17 +00:00
|
|
|
|
|
|
|
CLOSE_DISPS(gfxCtx, "../speed_meter.c", 276);
|
2020-05-13 03:05:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SpeedMeter_InitAllocEntry(SpeedMeterAllocEntry* this, u32 maxval, u32 val, u16 backColor, u16 foreColor, u32 ulx,
|
|
|
|
u32 lrx, u32 uly, u32 lry) {
|
|
|
|
this->maxval = maxval;
|
|
|
|
this->val = val;
|
|
|
|
this->backColor = backColor;
|
|
|
|
this->foreColor = foreColor;
|
|
|
|
this->ulx = ulx;
|
|
|
|
this->lrx = lrx;
|
|
|
|
this->uly = uly;
|
|
|
|
this->lry = lry;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpeedMeter_DrawAllocEntry(SpeedMeterAllocEntry* this, GraphicsContext* gfxCtx) {
|
|
|
|
s32 usedOff;
|
|
|
|
View view;
|
|
|
|
Gfx* gfx;
|
|
|
|
|
|
|
|
if (this->maxval == 0) {
|
|
|
|
osSyncPrintf(VT_FGCOL(RED));
|
|
|
|
LOG_NUM("this->maxval", this->maxval, "../speed_meter.c", 313);
|
|
|
|
osSyncPrintf(VT_RST);
|
|
|
|
} else {
|
2020-08-29 23:00:17 +00:00
|
|
|
OPEN_DISPS(gfxCtx, "../speed_meter.c", 318);
|
2020-05-13 03:05:55 +00:00
|
|
|
|
|
|
|
View_Init(&view, gfxCtx);
|
2022-04-08 22:50:28 +00:00
|
|
|
view.flags = VIEW_VIEWPORT | VIEW_PROJECTION_ORTHO;
|
2020-05-13 03:05:55 +00:00
|
|
|
|
2020-06-14 02:59:58 +00:00
|
|
|
SET_FULLSCREEN_VIEWPORT(&view);
|
2020-05-13 03:05:55 +00:00
|
|
|
|
2020-10-29 21:31:09 +00:00
|
|
|
gfx = OVERLAY_DISP;
|
2022-04-08 22:50:28 +00:00
|
|
|
View_ApplyTo(&view, VIEW_ALL, &gfx);
|
2020-05-13 03:05:55 +00:00
|
|
|
|
|
|
|
gDPPipeSync(gfx++);
|
|
|
|
gDPSetOtherMode(gfx++,
|
|
|
|
G_AD_PATTERN | G_CD_MAGICSQ | G_CK_NONE | G_TC_CONV | G_TF_POINT | G_TT_NONE | G_TL_TILE |
|
|
|
|
G_TD_CLAMP | G_TP_NONE | G_CYC_FILL | G_PM_NPRIMITIVE,
|
|
|
|
G_AC_NONE | G_ZS_PIXEL | G_RM_NOOP | G_RM_NOOP2);
|
|
|
|
|
|
|
|
usedOff = ((this->lrx - this->ulx) * this->val) / this->maxval + this->ulx;
|
2022-07-30 21:49:10 +00:00
|
|
|
gDrawRect(gfx++, this->backColor, usedOff, this->uly, this->lrx, this->lry);
|
|
|
|
gDrawRect(gfx++, this->foreColor, this->ulx, this->uly, usedOff, this->lry);
|
2020-05-13 03:05:55 +00:00
|
|
|
|
|
|
|
gDPPipeSync(gfx++);
|
|
|
|
|
2020-10-29 21:31:09 +00:00
|
|
|
OVERLAY_DISP = gfx;
|
2020-08-29 23:00:17 +00:00
|
|
|
CLOSE_DISPS(gfxCtx, "../speed_meter.c", 339);
|
2020-05-13 03:05:55 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-05-13 03:05:55 +00:00
|
|
|
void SpeedMeter_DrawAllocEntries(SpeedMeter* meter, GraphicsContext* gfxCtx, GameState* state) {
|
2022-10-29 20:44:27 +00:00
|
|
|
s32 pad1[2];
|
2020-05-13 03:05:55 +00:00
|
|
|
u32 ulx = 30;
|
|
|
|
u32 lrx = 290;
|
|
|
|
SpeedMeterAllocEntry entry;
|
2022-10-29 20:44:27 +00:00
|
|
|
u32 pad2;
|
2020-05-13 03:05:55 +00:00
|
|
|
s32 y;
|
|
|
|
TwoHeadGfxArena* thga;
|
|
|
|
u32 zeldaFreeMax;
|
|
|
|
u32 zeldaFree;
|
|
|
|
u32 zeldaAlloc;
|
|
|
|
s32 sysFreeMax;
|
|
|
|
s32 sysFree;
|
|
|
|
s32 sysAlloc;
|
|
|
|
|
|
|
|
y = 212;
|
2022-10-29 20:44:27 +00:00
|
|
|
if (R_ENABLE_ARENA_DBG > 2) {
|
2022-08-30 21:35:00 +00:00
|
|
|
if (ZeldaArena_IsInitialized()) {
|
2020-05-13 03:05:55 +00:00
|
|
|
ZeldaArena_GetSizes(&zeldaFreeMax, &zeldaFree, &zeldaAlloc);
|
2020-07-17 01:37:53 +00:00
|
|
|
SpeedMeter_InitAllocEntry(&entry, zeldaFree + zeldaAlloc, zeldaAlloc, GPACK_RGBA5551(0, 0, 255, 1),
|
|
|
|
GPACK_RGBA5551(255, 255, 255, 1), ulx, lrx, y, y + 1);
|
2020-05-13 03:05:55 +00:00
|
|
|
SpeedMeter_DrawAllocEntry(&entry, gfxCtx);
|
|
|
|
y++;
|
|
|
|
y++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-29 20:44:27 +00:00
|
|
|
if (R_ENABLE_ARENA_DBG > 1) {
|
2021-02-14 00:49:40 +00:00
|
|
|
SystemArena_GetSizes((u32*)&sysFreeMax, (u32*)&sysFree, (u32*)&sysAlloc);
|
2020-05-13 03:05:55 +00:00
|
|
|
SpeedMeter_InitAllocEntry(&entry, sysFree + sysAlloc - state->tha.size, sysAlloc - state->tha.size,
|
2020-07-17 01:37:53 +00:00
|
|
|
GPACK_RGBA5551(0, 0, 255, 1), GPACK_RGBA5551(255, 128, 128, 1), ulx, lrx, y, y);
|
2020-05-13 03:05:55 +00:00
|
|
|
SpeedMeter_DrawAllocEntry(&entry, gfxCtx);
|
|
|
|
y++;
|
|
|
|
}
|
|
|
|
|
|
|
|
thga = (TwoHeadGfxArena*)&state->tha;
|
|
|
|
SpeedMeter_InitAllocEntry(&entry, thga->size, thga->size - THA_GetSize((TwoHeadArena*)thga),
|
2020-07-17 01:37:53 +00:00
|
|
|
GPACK_RGBA5551(0, 0, 255, 1), GPACK_RGBA5551(0, 255, 0, 1), ulx, lrx, y, y);
|
2020-05-13 03:05:55 +00:00
|
|
|
SpeedMeter_DrawAllocEntry(&entry, gfxCtx);
|
|
|
|
y++;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-05-13 03:05:55 +00:00
|
|
|
thga = &gfxCtx->polyOpa;
|
2020-07-17 01:37:53 +00:00
|
|
|
SpeedMeter_InitAllocEntry(&entry, thga->size, thga->size - THGA_GetSize(thga), GPACK_RGBA5551(0, 0, 255, 1),
|
|
|
|
GPACK_RGBA5551(255, 0, 255, 1), ulx, lrx, y, y);
|
2020-05-13 03:05:55 +00:00
|
|
|
SpeedMeter_DrawAllocEntry(&entry, gfxCtx);
|
|
|
|
y++;
|
|
|
|
|
|
|
|
thga = &gfxCtx->polyXlu;
|
2020-07-17 01:37:53 +00:00
|
|
|
SpeedMeter_InitAllocEntry(&entry, thga->size, thga->size - THGA_GetSize(thga), GPACK_RGBA5551(0, 0, 255, 1),
|
|
|
|
GPACK_RGBA5551(255, 255, 0, 1), ulx, lrx, y, y);
|
2020-05-13 03:05:55 +00:00
|
|
|
SpeedMeter_DrawAllocEntry(&entry, gfxCtx);
|
|
|
|
y++;
|
|
|
|
|
|
|
|
thga = &gfxCtx->overlay;
|
2020-07-17 01:37:53 +00:00
|
|
|
SpeedMeter_InitAllocEntry(&entry, thga->size, thga->size - THGA_GetSize(thga), GPACK_RGBA5551(0, 0, 255, 1),
|
|
|
|
GPACK_RGBA5551(255, 0, 0, 1), ulx, lrx, y, y);
|
2020-05-13 03:05:55 +00:00
|
|
|
SpeedMeter_DrawAllocEntry(&entry, gfxCtx);
|
|
|
|
y++;
|
|
|
|
}
|