forked from sm64-port/sm64-port
-
Notifications
You must be signed in to change notification settings - Fork 33
/
fps.patch
65 lines (59 loc) · 1.91 KB
/
fps.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
diff --git a/src/game/game_init.c b/src/game/game_init.c
index e5552ec..b134990 100644
--- a/src/game/game_init.c
+++ b/src/game/game_init.c
@@ -64,6 +64,29 @@ struct DemoInput *gCurrDemoInput = NULL; // demo input sequence
u16 gDemoInputListID = 0;
struct DemoInput gRecordedDemoInput = { 0 }; // possibly removed in EU. TODO: Check
+static OSTime gLastOSTime = 0;
+static u8 gRenderFPS = FALSE;
+
+static void render_fps(void) {
+ // Toggle rendering framerate with the L button.
+ if (gPlayer1Controller->buttonPressed & L_TRIG) {
+ gRenderFPS ^= 1;
+ }
+
+#ifdef _60FPS_PATCH
+ float multiplier = 2.0f;
+#else
+ float multiplier = 1.0f;
+#endif
+ if (gRenderFPS) {
+ OSTime newTime = osGetTime();
+ float fps = multiplier * 1000000.0f / (newTime - gLastOSTime);
+
+ print_text_fmt_int(GFX_DIMENSIONS_RECT_FROM_LEFT_EDGE(22), 184, "FPS %d", fps);
+ gLastOSTime = newTime;
+ }
+}
+
/**
* Initializes the Reality Display Processor (RDP).
* This function initializes settings such as texture filtering mode,
@@ -654,6 +677,8 @@ void game_loop_one_iteration(void) {
levelCommandAddr = level_script_execute(levelCommandAddr);
display_and_vsync();
+
+ render_fps();
// when debug info is enabled, print the "BUF %d" information.
if (gShowDebugText) {
diff --git a/src/pc/ultra_reimplementation.c b/src/pc/ultra_reimplementation.c
index 2b28ea8..541b419 100644
--- a/src/pc/ultra_reimplementation.c
+++ b/src/pc/ultra_reimplementation.c
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <string.h>
+#include <sys/time.h>
#include "lib/src/libultra_internal.h"
#include "macros.h"
@@ -75,7 +76,9 @@ void osViSwapBuffer(UNUSED void *vaddr) {
}
OSTime osGetTime(void) {
- return 0;
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ return (unsigned long)tv.tv_sec * 1000000 + tv.tv_usec;
}
void osWritebackDCacheAll(void) {