Skip to content

Commit 49bd2f2

Browse files
author
Niko
committed
profiler rework to make OG hooking easier
1 parent 2f10a5d commit 49bd2f2

File tree

4 files changed

+141
-49
lines changed

4 files changed

+141
-49
lines changed

decompile/General/AltMods/DebugMenu/Profiler.c

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void DebugProfiler_Init()
3434
ptrSectArr = DECOMP_MEMPACK_AllocMem(size);
3535
}
3636

37-
void DebugProiler_Reset()
37+
void DebugProfiler_Reset()
3838
{
3939
// normally happens in DebugMenu_DrawMenuTwice,
4040
// debug menu is not implemented in retail yet
@@ -64,16 +64,26 @@ void DebugProfiler_SectionStart(char* name, char r, char g, char b)
6464
ptrOpenSect->g = g;
6565
ptrOpenSect->b = b;
6666
ptrOpenSect->a = 0;
67-
67+
6868
ptrOpenSect->flagsVDT = 0;
6969

7070
ptrOpenSect->timeStart = Debug_GetPreciseTime();
7171
}
7272

7373
void DebugProfiler_Subsection(int flag)
7474
{
75+
bool fakeSectionOpen = 0;
76+
7577
if(ptrOpenSect == 0)
76-
return;
78+
{
79+
if(flag != 2)
80+
return;
81+
82+
fakeSectionOpen = 1;
83+
84+
void DebugProfiler_SectionStart(char* name, char r, char g, char b);
85+
DebugProfiler_SectionStart(0, 0xFF, 0xFF, 0xFF);
86+
}
7787

7888
ptrOpenSect->flagsVDT |= flag;
7989

@@ -86,6 +96,7 @@ void DebugProfiler_Subsection(int flag)
8696

8797
if((flag & 2) != 0)
8898
{
99+
printf("DrawSync: %d %d\n", fakeSectionOpen, time);
89100
ptrOpenSect->posD = time;
90101
}
91102

@@ -95,6 +106,12 @@ void DebugProfiler_Subsection(int flag)
95106
ptrOpenSect->posT = time;
96107
}
97108
#endif
109+
110+
if (fakeSectionOpen)
111+
{
112+
int DebugProfiler_SectionEnd();
113+
DebugProfiler_SectionEnd();
114+
}
98115
}
99116

100117
void DebugProfiler_SectionRestart(int time)
@@ -148,6 +165,12 @@ void DebugProfiler_Draw()
148165
{
149166
struct ProfilerSection* s = &ptrSectArr[i];
150167

168+
if(i == 0) printf("\n\n");
169+
printf("Start: %d %08x %d\n",
170+
i,
171+
*(int*)&s->a,
172+
s->timeStart);
173+
151174
if((s->flagsVDT & 1) != 0)
152175
{
153176
DECOMP_DecalFont_DrawLine("V",

decompile/General/MAIN/MainFrame_02_GameLogic.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,7 @@ void DECOMP_MainFrame_GameLogic(struct GameTracker* gGT, struct GamepadSystem* g
184184
{
185185
psVar8->quip2 = (short)iVar4;
186186
}
187-
188-
#ifdef USE_PROFILER
189-
void DebugProfiler_SectionStart(char* name, char r, char g, char b);
190-
DebugProfiler_SectionStart(0, 0xFF, 0, 0);
191-
#endif
192-
187+
193188
for (iVar4 = 0; iVar4 < NUM_BUCKETS; iVar4++)
194189
{
195190
if
@@ -300,11 +295,6 @@ void DECOMP_MainFrame_GameLogic(struct GameTracker* gGT, struct GamepadSystem* g
300295
}
301296
}
302297

303-
#ifdef USE_PROFILER
304-
int DebugProfiler_SectionEnd();
305-
DebugProfiler_SectionEnd();
306-
#endif
307-
308298
#ifndef REBUILD_PS1
309299
BOTS_UpdateGlobals();
310300
#endif

decompile/General/MAIN/MainFrame_08_RenderFrame.c

Lines changed: 98 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,6 @@ void DECOMP_MainFrame_RenderFrame(struct GameTracker* gGT, struct GamepadSystem*
264264

265265
RenderAllHUD(gGT);
266266

267-
// Instance profiler
268-
#ifdef USE_PROFILER
269-
void DebugProfiler_SectionStart(char* name, char r, char g, char b);
270-
DebugProfiler_SectionStart(0, 0, 0xFF, 0);
271-
#endif
272-
273267
#ifndef REBUILD_PS1
274268
RenderAllBeakerRain(gGT);
275269
RenderAllBoxSceneSplitLines(gGT);
@@ -304,33 +298,43 @@ void DECOMP_MainFrame_RenderFrame(struct GameTracker* gGT, struct GamepadSystem*
304298
if ((gGT->renderFlags & 0x20) != 0)
305299
{
306300
RenderDispEnv_World(gGT); // == RenderDispEnv_World ==
301+
302+
// Instance profiler
303+
#ifdef USE_PROFILER
304+
void DebugProfiler_SectionStart(char* name, char r, char g, char b);
305+
DebugProfiler_SectionStart(0, 0, 0xFF, 0);
306+
#endif
307+
307308
void TEST_DrawInstances(struct GameTracker* gGT);
308309
TEST_DrawInstances(gGT);
310+
311+
// Instance Profiler
312+
#ifdef USE_PROFILER
313+
int DebugProfiler_SectionEnd();
314+
//int x =
315+
DebugProfiler_SectionEnd();
316+
//printf("Retail Instance: %d\n", x);
317+
#endif
309318
}
310319
#endif
311320

312-
// Instance Profiler
313-
#ifdef USE_PROFILER
314-
int DebugProfiler_SectionEnd();
315-
int x =
316-
DebugProfiler_SectionEnd();
317-
318-
printf("Retail Instance: %d\n", x);
319-
#endif
320-
321321
DECOMP_PushBuffer_FadeAllWindows();
322322

323-
// Level profiler
324-
#ifdef USE_PROFILER
325-
void DebugProfiler_SectionStart(char* name, char r, char g, char b);
326-
DebugProfiler_SectionStart(0, 0, 0, 0xFF);
327-
#endif
328-
329323
if((gGT->renderFlags & 1) != 0)
330324
{
325+
331326
#ifndef REBUILD_PS1
327+
332328
RenderAllLevelGeometry(gGT);
329+
333330
#else
331+
332+
// Level profiler
333+
#ifdef USE_PROFILER
334+
void DebugProfiler_SectionStart(char* name, char r, char g, char b);
335+
DebugProfiler_SectionStart(0, 0, 0, 0xFF);
336+
#endif
337+
334338
for (int i = 0; i < gGT->numPlyrCurrGame; i++)
335339
{
336340
// 226-229
@@ -349,9 +353,15 @@ void DECOMP_MainFrame_RenderFrame(struct GameTracker* gGT, struct GamepadSystem*
349353
&gGT->pushBuffer[i],
350354
&gGT->backBuffer->primMem);
351355
}
356+
357+
// Level Profiler
358+
#ifdef USE_PROFILER
359+
int DebugProfiler_SectionEnd();
360+
DebugProfiler_SectionEnd();
361+
#endif
362+
352363
#endif
353-
354-
364+
355365
RenderDispEnv_World(gGT); // == RenderDispEnv_World ==
356366

357367
MultiplayerWumpaHUD(gGT);
@@ -404,12 +414,6 @@ void DECOMP_MainFrame_RenderFrame(struct GameTracker* gGT, struct GamepadSystem*
404414
#endif
405415
}
406416

407-
// Level Profiler
408-
#ifdef USE_PROFILER
409-
int DebugProfiler_SectionEnd();
410-
DebugProfiler_SectionEnd();
411-
#endif
412-
413417
#ifndef REBUILD_PS1
414418
// If in main menu, or in adventure arena,
415419
// or in End-Of-Race menu
@@ -1096,9 +1100,25 @@ void RenderBucket_ExecuteAllInstances(struct GameTracker* gGT)
10961100
{
10971101
if((gGT->renderFlags & 0x20) == 0) return;
10981102

1103+
// Instance profiler
1104+
#ifdef USE_PROFILER
1105+
void DebugProfiler_SectionStart(char* name, char r, char g, char b);
1106+
DebugProfiler_SectionStart(0, 0, 0xFF, 0);
1107+
#endif
1108+
10991109
RenderBucket_Execute(
11001110
gGT->ptrRenderBucketInstance,
11011111
&gGT->backBuffer->primMem);
1112+
1113+
// Instance Profiler
1114+
#ifdef USE_PROFILER
1115+
int DebugProfiler_SectionEnd();
1116+
//int x =
1117+
DebugProfiler_SectionEnd();
1118+
//printf("Retail Instance: %d\n", x);
1119+
#endif
1120+
1121+
11021122
}
11031123

11041124
void RenderAllTires(struct GameTracker* gGT)
@@ -1237,11 +1257,18 @@ void RenderAllLevelGeometry(struct GameTracker* gGT)
12371257
struct CameraDC dc0;
12381258
memcpy(&dc0, &gGT->cameraDC[0], sizeof(struct CameraDC));
12391259

1260+
// Level profiler
1261+
#ifdef USE_PROFILER
1262+
void DebugProfiler_SectionStart(char* name, char r, char g, char b);
1263+
DebugProfiler_SectionStart(0, 0, 0, 0xFF);
1264+
#endif
1265+
12401266
for(int i = 0; i < numPlyrCurrGame; i++)
12411267
{
12421268
pushBuffer = &gGT->pushBuffer[i];
12431269

12441270
CTR_ClearRenderLists_1P2P(gGT, 1);
1271+
12451272
RenderLists_PreInit();
12461273

12471274
if(i != 0)
@@ -1292,6 +1319,12 @@ void RenderAllLevelGeometry(struct GameTracker* gGT)
12921319
&pushBuffer->ptrOT[0x3ff]);
12931320
}
12941321
}
1322+
1323+
// Level Profiler
1324+
#ifdef USE_PROFILER
1325+
int DebugProfiler_SectionEnd();
1326+
DebugProfiler_SectionEnd();
1327+
#endif
12951328

12961329
// restore
12971330
gGT->drivers[0] = d0;
@@ -1319,6 +1352,12 @@ void RenderAllLevelGeometry(struct GameTracker* gGT)
13191352

13201353
if(numPlyrCurrGame == 1)
13211354
{
1355+
// Level profiler
1356+
#ifdef USE_PROFILER
1357+
void DebugProfiler_SectionStart(char* name, char r, char g, char b);
1358+
DebugProfiler_SectionStart(0, 0, 0, 0xFF);
1359+
#endif
1360+
13221361
CTR_ClearRenderLists_1P2P(gGT, 1);
13231362

13241363
// === Temporary 60FPS macros ===
@@ -1417,6 +1456,12 @@ void RenderAllLevelGeometry(struct GameTracker* gGT)
14171456
level1->ptr_skybox,
14181457
pushBuffer,
14191458
&gGT->backBuffer->primMem);
1459+
1460+
// Level Profiler
1461+
#ifdef USE_PROFILER
1462+
int DebugProfiler_SectionEnd();
1463+
DebugProfiler_SectionEnd();
1464+
#endif
14201465

14211466
// skybox gradient
14221467
if((level1->configFlags & 1) != 0)
@@ -1429,6 +1474,12 @@ void RenderAllLevelGeometry(struct GameTracker* gGT)
14291474

14301475
if(numPlyrCurrGame == 2)
14311476
{
1477+
// Level profiler
1478+
#ifdef USE_PROFILER
1479+
void DebugProfiler_SectionStart(char* name, char r, char g, char b);
1480+
DebugProfiler_SectionStart(0, 0, 0, 0xFF);
1481+
#endif
1482+
14321483
CTR_ClearRenderLists_1P2P(gGT, 2);
14331484

14341485
// if no SCVert
@@ -1465,10 +1516,22 @@ void RenderAllLevelGeometry(struct GameTracker* gGT)
14651516
gGT->visMem1->visFaceList[0],
14661517
gGT->visMem1->visFaceList[1],
14671518
level1->ptr_tex_waterEnvMap); // waterEnvMap?
1519+
1520+
// Level Profiler
1521+
#ifdef USE_PROFILER
1522+
int DebugProfiler_SectionEnd();
1523+
DebugProfiler_SectionEnd();
1524+
#endif
14681525

14691526
goto SkyboxGlow;
14701527
}
14711528

1529+
// Level profiler
1530+
#ifdef USE_PROFILER
1531+
void DebugProfiler_SectionStart(char* name, char r, char g, char b);
1532+
DebugProfiler_SectionStart(0, 0, 0, 0xFF);
1533+
#endif
1534+
14721535
// 3P or 4P
14731536
CTR_ClearRenderLists_3P4P(gGT, numPlyrCurrGame);
14741537

@@ -1539,6 +1602,12 @@ void RenderAllLevelGeometry(struct GameTracker* gGT)
15391602
gGT->visMem1->visFaceList[3],
15401603
level1->ptr_tex_waterEnvMap); // waterEnvMap?
15411604
}
1605+
1606+
// Level Profiler
1607+
#ifdef USE_PROFILER
1608+
int DebugProfiler_SectionEnd();
1609+
DebugProfiler_SectionEnd();
1610+
#endif
15421611

15431612
SkyboxGlow:
15441613

decompile/General/MAIN/MainMain.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,11 @@ u_int DECOMP_main()
339339
// Start new frame (ClearOTagR)
340340
DECOMP_MainFrame_ResetDB(gGT);
341341

342+
#ifdef USE_PROFILER
343+
void DebugProfiler_Reset();
344+
DebugProfiler_Reset();
345+
#endif
346+
342347
if
343348
(
344349
// If you're in Demo Mode
@@ -400,16 +405,21 @@ u_int DECOMP_main()
400405
DECOMP_DecalFont_DrawMultiLine(sdata->lngStrings[0x8c0 / 4], 0x100, uVar12, 0x200, 2, 0xffff8000);
401406
}
402407

403-
#ifdef USE_PROFILER
404-
void DebugProiler_Reset();
405-
DebugProiler_Reset();
406-
#endif
407-
408408
if ((gGT->gameMode1 & LOADING) == 0)
409409
{
410+
#ifdef USE_PROFILER
411+
void DebugProfiler_SectionStart(char* name, char r, char g, char b);
412+
DebugProfiler_SectionStart(0, 0xFF, 0, 0);
413+
#endif
414+
410415
DECOMP_MainFrame_GameLogic(gGT, gGS);
416+
417+
#ifdef USE_PROFILER
418+
int DebugProfiler_SectionEnd();
419+
DebugProfiler_SectionEnd();
420+
#endif
411421
}
412-
422+
413423
// If you are in demo mode
414424
if (gGT->boolDemoMode != '\0')
415425
{

0 commit comments

Comments
 (0)