-
Notifications
You must be signed in to change notification settings - Fork 3
/
frameskip.patch
172 lines (163 loc) · 4.76 KB
/
frameskip.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
diff --git a/src/engine/behavior_script.c b/src/engine/behavior_script.c
index 4316e04..c13a5fc 100644
--- a/src/engine/behavior_script.c
+++ b/src/engine/behavior_script.c
@@ -11,6 +11,7 @@
#include "game/obj_behaviors_2.h"
#include "game/object_helpers.h"
#include "game/object_list_processor.h"
+#include "game/level_update.h" // Frameskip
#include "graph_node.h"
#include "surface_collision.h"
@@ -919,6 +920,14 @@ void cur_obj_update(void) {
f32 distanceFromMario;
BhvCommandProc bhvCmdProc;
s32 bhvProcResult;
+#ifdef TARGET_N64
+ s32 hasAnimation = (gCurrentObject->header.gfx.node.flags & GRAPH_RENDER_HAS_ANIMATION) != 0;
+ // frameskip
+ if ((doneSkipped >= 0) && hasAnimation && gCurrentObject->header.gfx.animInfo.curAnim != NULL) {
+ gCurrentObject->header.gfx.animInfo.animFrame = geo_update_animation_frame(
+ &gCurrentObject->header.gfx.animInfo, &gCurrentObject->header.gfx.animInfo.animFrameAccelAssist);
+ }
+#endif
// Calculate the distance from the object to Mario.
if (objFlags & OBJ_FLAG_COMPUTE_DIST_TO_MARIO) {
@@ -1014,4 +1023,12 @@ void cur_obj_update(void) {
}
}
}
+
+#ifdef TARGET_N64
+ // frameskip
+ if (gCurrentObject->header.gfx.animInfo.animFrame < 0) {
+ gCurrentObject->header.gfx.animInfo.animFrame = 0;
+ }
+#endif
+
}
diff --git a/src/game/level_update.c b/src/game/level_update.c
index 8f28b73..fe837a2 100644
--- a/src/game/level_update.c
+++ b/src/game/level_update.c
@@ -213,6 +213,14 @@ s8 sWarpCheckpointActive = FALSE;
u8 unused2[4];
u8 unused3[2];
+#ifdef TARGET_N64
+// Frameskip
+u64 deltaTime = 0;
+u64 newTime = 0;
+u64 oldTime = 0;
+s8 doneSkipped;
+#endif
+
u16 level_control_timer(s32 timerOp) {
switch (timerOp) {
case TIMER_CONTROL_SHOW:
@@ -1008,6 +1016,31 @@ void basic_update(UNUSED s16 *arg) {
}
}
+#ifdef TARGET_N64
+void delta_time_handle(void) {
+ OSTime newTime = osGetTime();
+
+ doneSkipped = -1;
+ deltaTime += newTime - oldTime;
+ oldTime = newTime;
+ while (deltaTime > 1562744) {
+ deltaTime -= 1562744;
+ if (sTimerRunning && gHudDisplay.timer < 17999) {
+ gHudDisplay.timer += 1;
+ }
+ area_update_objects();
+ doneSkipped++;
+ }
+}
+#endif
+
+static void delta_time_reset(void) {
+#ifdef TARGET_N64
+ deltaTime = 0;
+ oldTime = osGetTime();
+#endif
+}
+
s32 play_mode_normal(void) {
if (gCurrDemoInput != NULL) {
print_intro_text();
@@ -1023,11 +1056,19 @@ s32 play_mode_normal(void) {
warp_area();
check_instant_warp();
+// Only N64 - shouldn't be necessary in pc-port
+#ifdef TARGET_N64
+ delta_time_handle();
+#else
if (sTimerRunning && gHudDisplay.timer < 17999) {
gHudDisplay.timer++;
}
area_update_objects();
+ // put fast64's scroll_textures() function here for pc-port
+ // scroll_textures();
+#endif
+
update_hud_values();
if (gCurrentArea != NULL) {
@@ -1207,15 +1248,19 @@ s32 update_level(void) {
break;
case PLAY_MODE_PAUSED:
changeLevel = play_mode_paused();
+ delta_time_reset();
break;
case PLAY_MODE_CHANGE_AREA:
changeLevel = play_mode_change_area();
+ delta_time_reset();
break;
case PLAY_MODE_CHANGE_LEVEL:
changeLevel = play_mode_change_level();
+ delta_time_reset();
break;
case PLAY_MODE_FRAME_ADVANCE:
changeLevel = play_mode_frame_advance();
+ delta_time_reset();
break;
#if QOL_FIX_UNUSED_PLAY_MODE
default:
@@ -1320,6 +1365,7 @@ s32 lvl_init_or_update(s16 initOrUpdate, UNUSED s32 unused) {
switch (initOrUpdate) {
case 0:
result = init_level();
+ delta_time_reset();
break;
case 1:
result = update_level();
diff --git a/src/game/level_update.h b/src/game/level_update.h
index 2ca79e1..05c54c3 100644
--- a/src/game/level_update.h
+++ b/src/game/level_update.h
@@ -71,6 +71,11 @@ extern s16 sTransitionTimer;
extern void (*sTransitionUpdate)(s16 *);
extern u8 unused2[4];
+#ifdef TARGET_N64
+// Frameskip
+extern s8 doneSkipped;
+#endif
+
struct WarpDest {
u8 type;
u8 levelNum;
diff --git a/src/game/mario.c b/src/game/mario.c
index fd3a4b5..7daa056 100644
--- a/src/game/mario.c
+++ b/src/game/mario.c
@@ -1405,6 +1405,12 @@ void update_mario_inputs(struct MarioState *m) {
m->collidedObjInteractTypes = m->marioObj->collidedObjInteractTypes;
m->flags &= 0xFFFFFF;
+#ifdef TARGET_N64
+ if (doneSkipped >= 0) {
+ m->controller->buttonPressed = 0;
+ }
+#endif
+
update_mario_button_inputs(m);
update_mario_joystick_inputs(m);
update_mario_geometry_inputs(m);