Skip to content

Commit 1fd3cd5

Browse files
author
Niko
committed
profiler on-screen text
1 parent e698ef8 commit 1fd3cd5

File tree

5 files changed

+122
-4
lines changed

5 files changed

+122
-4
lines changed

decompile/General/AltMods/DebugMenu/Font.c

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,102 @@ void DebugFont_DrawLine(char* text, int posX, int posY, int color)
136136

137137
i++;
138138
}
139+
}
140+
141+
// Jam this here, cause byte budget
142+
static int timeFrame;
143+
static int timeCpu;
144+
static int timeGpu;
145+
static int timeRed;
146+
static int timeGreen;
147+
static int timeBlue;
148+
149+
void DebugProfiler_ListAllDebugStats()
150+
{
151+
if((sdata->gGT->gameMode1 & DEBUG_MENU) != 0)
152+
return;
153+
154+
int Debug_GetNumSections();
155+
int numSectionsUsed = Debug_GetNumSections();
156+
157+
int Debug_GetFirstSect();
158+
struct ProfilerSection* ptrSectArr = Debug_GetFirstSect();
159+
160+
if((sdata->gGT->timer & FPS_DOUBLE(16)) != 0)
161+
{
162+
timeFrame =
163+
ptrSectArr[numSectionsUsed-1].timeEnd -
164+
ptrSectArr[0].timeStart;
165+
166+
timeCpu =
167+
ptrSectArr[numSectionsUsed-2].timeEnd -
168+
ptrSectArr[0].timeStart;
169+
170+
for(int i = 0; i < numSectionsUsed; i++)
171+
{
172+
if((ptrSectArr[i].flagsVDT & 2) != 0)
173+
{
174+
timeGpu =
175+
ptrSectArr[i].posD -
176+
ptrSectArr[0].timeStart;
177+
}
178+
179+
if(*(int*)&ptrSectArr[i].a == 0xff00)
180+
{
181+
timeRed =
182+
ptrSectArr[i].timeEnd -
183+
ptrSectArr[i].timeStart;
184+
}
185+
186+
if(*(int*)&ptrSectArr[i].a == 0xff0000)
187+
{
188+
timeGreen =
189+
ptrSectArr[i].timeEnd -
190+
ptrSectArr[i].timeStart;
191+
}
192+
193+
if(*(int*)&ptrSectArr[i].a == 0xff000000)
194+
{
195+
timeBlue =
196+
ptrSectArr[i].timeEnd -
197+
ptrSectArr[i].timeStart;
198+
}
199+
}
200+
}
201+
202+
if(timeFrame == 0) return;
203+
if(timeCpu == 0) return;
204+
if(timeGpu == 0) return;
205+
if(timeRed == 0) return;
206+
if(timeGreen == 0) return;
207+
if(timeBlue == 0) return;
208+
209+
#ifndef REBUILD_PC
210+
char* string = 0x1f800000;
211+
#else
212+
char string[128];
213+
#endif
214+
215+
// Time units:
216+
// 262 -> 1 vsync (60fps)
217+
// 524 -> 2 vsync (30fps)
218+
// 15720 -> 1 full second
219+
220+
sprintf(string, "FULL %d %dFPS", timeFrame, 15720/timeFrame);
221+
DECOMP_DecalFont_DrawLine(string, 0x14, 0x44, FONT_SMALL, 0);
222+
223+
sprintf(string, "CPU %d %dFPS", timeCpu, 15720/timeCpu);
224+
DECOMP_DecalFont_DrawLine(string, 0x14, 0x4C, FONT_SMALL, 0);
225+
226+
sprintf(string, "GPU %d %dFPS", timeGpu, 15720/timeGpu);
227+
DECOMP_DecalFont_DrawLine(string, 0x14, 0x54, FONT_SMALL, 0);
228+
229+
sprintf(string, "RED %d", timeRed);
230+
DECOMP_DecalFont_DrawLine(string, 0x14, 0x5C, FONT_SMALL, 0);
231+
232+
sprintf(string, "GREN %d", timeGreen);
233+
DECOMP_DecalFont_DrawLine(string, 0x14, 0x64, FONT_SMALL, 0);
234+
235+
sprintf(string, "BLUE %d", timeBlue);
236+
DECOMP_DecalFont_DrawLine(string, 0x14, 0x6C, FONT_SMALL, 0);
139237
}

decompile/General/AltMods/DebugMenu/Profiler.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,25 @@
55

66
// No room, need MEMPACK_AllocMem
77
// static struct ProfilerSection sections[32];
8-
struct ProfilerSection* ptrSectArr=0;
9-
struct ProfilerSection* ptrOpenSect=0;
8+
static struct ProfilerSection* ptrSectArr=0;
9+
static struct ProfilerSection* ptrOpenSect=0;
1010

1111
// No room, use global PrimMem instead,
1212
// especially since we have PrimMem expansion
1313
// POLY_F4 polyArrF4[128];
1414

1515
static int numSectionsUsed = 0;
1616

17+
int Debug_GetNumSections()
18+
{
19+
return numSectionsUsed;
20+
}
21+
22+
int Debug_GetFirstSect()
23+
{
24+
return ptrSectArr;
25+
}
26+
1727
int Debug_GetPreciseTime()
1828
{
1929
int sysClock =
@@ -150,6 +160,9 @@ int DebugProfiler_Scale(int input)
150160

151161
void DebugProfiler_Draw()
152162
{
163+
void DebugProfiler_ListAllDebugStats();
164+
DebugProfiler_ListAllDebugStats();
165+
153166
struct GameTracker* gGT = sdata->gGT;
154167

155168
struct PrimMem* primMem = &gGT->backBuffer->primMem;

decompile/General/MAIN/MainFrame_08_RenderFrame.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,11 @@ void DrawUnpluggedMsg(struct GameTracker* gGT, struct GamepadSystem* gGamepads)
494494
RECT window;
495495
int i;
496496

497+
#ifdef USE_PROFILER
498+
// cause it annoys me when I'm busy
499+
return;
500+
#endif
501+
497502
// dont draw error if demo mode, or cutscene,
498503
// or if no controllers are missing currently
499504
if(gGT->boolDemoMode == 1) return;

ghidra/MAIN.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ void FUN_80034d54(uint *param_1,int param_2)
431431
// divide by ~3
432432
uVar5 = (iVar10 << 5) / 100;
433433

434-
// 1000 * 16000 units / 5246 / 3 = 1000ms
434+
// 1000 * 15720 units / 5246 / 3 = 1000ms
435435
// 1000 * elapsedUnits / 5246 / 3 = milliseconds
436436

437437
// elapsed milliseconds per frame

rebuild_PC/CrashTeamRacingPC.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@
3030
#endif
3131

3232
// work around for PsyCross
33+
// no$psx executes vsync callback once every 262 units,
34+
// determined by rcntTotalUnits global, 262*60 = 15720
3335
#include <time.h>
3436
clock_t startClock;
3537
#define ResetRCnt(x) startClock = clock();
36-
#define GetRCnt(x) ((clock() - startClock) * 16000) / CLOCKS_PER_SEC_FIX
38+
#define GetRCnt(x) ((clock() - startClock) * 15720) / CLOCKS_PER_SEC_FIX
3739

3840
// ======= Syntax Correction =============
3941

0 commit comments

Comments
 (0)