1+ #ifdef REWRITE_PROFILER
2+
13#include <ctr/profiler.h>
24#include <ctr/nd.h>
35
4- #ifdef REWRITE_PROFILER
5-
66// No Vehicle.h
77struct MetaPhys
88{
@@ -42,69 +42,87 @@ struct MetaPhys
4242#include <namespace_UI.h>
4343#include <regionsEXE.h>
4444
45+ void ND_EnterCriticalSection ();
46+ void ND_ExitCriticalSection ();
47+
4548void ND_DrawOTag (int a );
4649void ND_DecalFont_DrawLine (char * a , int b , int c , int d , int e );
4750
48-
4951int ND_GetRCnt (int a );
52+ int ND_ResetRCnt (int a );
5053
51- int Debug_GetPreciseTime ()
52- {
53- int sysClock =
54- ND_GetRCnt (0xf2000001 ) +
55- sdata -> rcntTotalUnits ;
56-
57- return sysClock ;
58- }
54+ // OG = Original
55+ // RW = Rewrite
56+ int timeOG_COLL_ProjectPointToEdge ;
57+ int timeRW_COLL_ProjectPointToEdge ;
5958
60- // Jam this here, cause byte budget
61- static int timeRed = 0 ;
62- static int timeStart = 0 ;
63- static int timeEnd = 0 ;
64- void Hook_DrawOTag (int a )
65- {
66- // Calculate ONE time, then save persistently
67- if (timeRed == 0 )
68- {
69- timeStart = Debug_GetPreciseTime ();
59+ #define JMP (dest ) (((unsigned long)dest & 0x3FFFFFF) >> 2 | 0x8000000)
60+ #define JAL (dest ) (((unsigned long)dest & 0x3FFFFFF) >> 2 | 0xC000000)
7061
71- void RunBenchmark ();
72- RunBenchmark ();
62+ void Hook_DrawOTag (int a );
63+ void RunCollOG ();
64+ void RunCollRW ();
7365
74- timeEnd = Debug_GetPreciseTime ();
66+ // When running OG functions,
67+ // dont forget to undefine these in ctr\test.h:
68+ // TEST_MATH_IMPL, TEST_RNG_IMPL, TEST_COLL_IMPL
7569
70+ // Also, required to run RW function before OG,
71+ // because of how assembly hooking system works
7672
77- timeRed = timeEnd - timeStart ;
78- }
73+ void LoadProfilerPatches ()
74+ {
75+ * (int * )0x800379b0 = JAL (Hook_DrawOTag );
76+ }
7977
80- struct GameTracker * gGT = sdata -> gGT ;
78+ int doThisOnce = 0 ;
79+ void RunAllBenchmarks ()
80+ {
81+ if (doThisOnce != 0 )
82+ return ;
83+
84+ int r = 0 ;
85+ doThisOnce = 1 ;
86+
87+ ND_ResetRCnt (0xf2000001 );
88+ RunCollRW ();
89+ r = ND_GetRCnt (0xf2000001 );
90+ timeRW_COLL_ProjectPointToEdge = r ;
91+
92+ ND_ResetRCnt (0xf2000001 );
93+ RunCollOG ();
94+ r = ND_GetRCnt (0xf2000001 );
95+ timeOG_COLL_ProjectPointToEdge = r ;
96+ }
8197
98+ void Hook_DrawOTag (int a )
99+ {
100+ ND_EnterCriticalSection ();
101+ RunAllBenchmarks ();
102+ ND_ExitCriticalSection ();
103+
104+ // Why does this break on console?
105+ // struct GameTracker* gGT = sdata->gGT;
106+ struct GameTracker * gGT = (struct GameTracker * )0x80096b20 ;
107+
82108 if ((gGT -> gameMode1 & (LOADING |1 )) == 0 )
83109 {
84110 // reset depth to CLOSEST
85111 gGT -> pushBuffer_UI .ptrOT =
86- gGT -> otSwapchainDB [gGT -> swapchainIndex ];
87-
112+ gGT -> otSwapchainDB [gGT -> swapchainIndex ];
88113
89- #ifndef REBUILD_PC
90- char * string = (char * )0x1f800000 ;
91- #else
92114 char string [128 ];
93- #endif
94-
95- ND_sprintf (string , "RED %d" , timeRed );
96- ND_DecalFont_DrawLine (string , 0x14 , 0x5C , FONT_SMALL , 0 );
115+
116+ ND_DecalFont_DrawLine ("1s 15720" , 0x14 , 0x8 , FONT_SMALL , 0 );
117+
118+ ND_sprintf (string , "RW %d" , timeRW_COLL_ProjectPointToEdge );
119+ ND_DecalFont_DrawLine (string , 0x14 , 0x10 , FONT_SMALL , 0 );
120+
121+ ND_sprintf (string , "OG %d" , timeOG_COLL_ProjectPointToEdge );
122+ ND_DecalFont_DrawLine (string , 0x14 , 0x18 , FONT_SMALL , 0 );
97123 }
98-
124+
99125 ND_DrawOTag (a );
100126}
101127
102- #define JMP (dest ) (((unsigned long)dest & 0x3FFFFFF) >> 2 | 0x8000000)
103- #define JAL (dest ) (((unsigned long)dest & 0x3FFFFFF) >> 2 | 0xC000000)
104-
105- void LoadProfilerPatches ()
106- {
107- * (int * )0x800379b0 = JAL (Hook_DrawOTag );
108- }
109-
110- #endif // REWRITE_PROFILER
128+ #endif
0 commit comments