forked from sm64-port/sm64-port
-
Notifications
You must be signed in to change notification settings - Fork 33
/
60fps.patch
2028 lines (1903 loc) · 87.1 KB
/
60fps.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
diff --git a/Makefile b/Makefile
index 780e51b..6033981 100644
--- a/Makefile
+++ b/Makefile
@@ -504,7 +504,7 @@ ifeq ($(TARGET_N3DS),1)
CTRULIB := $(DEVKITPRO)/libctru
LIBDIRS := $(CTRULIB)
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
- PLATFORM_CFLAGS := -mtp=soft -DTARGET_N3DS -DARM11 -DosGetTime=n64_osGetTime -D_3DS -D__3DS__ -march=armv6k -mtune=mpcore -mfloat-abi=hard -mword-relocations -fomit-frame-pointer -ffast-math $(foreach dir,$(LIBDIRS),-I$(dir)/include)
+ PLATFORM_CFLAGS := -mtp=soft -DTARGET_N3DS -D_60FPS_PATCH -DARM11 -DosGetTime=n64_osGetTime -D_3DS -D__3DS__ -march=armv6k -mtune=mpcore -mfloat-abi=hard -mword-relocations -fomit-frame-pointer -ffast-math $(foreach dir,$(LIBDIRS),-I$(dir)/include)
PLATFORM_LDFLAGS := $(LIBPATHS) -lcitro3d -lctru -lm -specs=3dsx.specs -g -marm -mthumb-interwork -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft
ifeq ($(DISABLE_AUDIO),1)
PLATFORM_CFLAGS += -DDISABLE_AUDIO
diff --git a/include/types.h b/include/types.h
index a33dc72..18887a4 100644
--- a/include/types.h
+++ b/include/types.h
@@ -118,6 +118,10 @@ struct GraphNodeObject_sub
/*0x0A 0x42*/ u16 animTimer;
/*0x0C 0x44*/ s32 animFrameAccelAssist;
/*0x10 0x48*/ s32 animAccel;
+ s16 prevAnimFrame;
+ s16 prevAnimID;
+ u32 prevAnimFrameTimestamp;
+ struct Animation *prevAnimPtr;
};
struct GraphNodeObject
@@ -128,11 +132,22 @@ struct GraphNodeObject
/*0x19*/ s8 unk19;
/*0x1A*/ Vec3s angle;
/*0x20*/ Vec3f pos;
+ Vec3s prevAngle;
+ Vec3f prevPos;
+ u32 prevTimestamp;
+ Vec3f prevShadowPos;
+ u32 prevShadowPosTimestamp;
/*0x2C*/ Vec3f scale;
+ Vec3f prevScale;
+ u32 prevScaleTimestamp;
/*0x38*/ struct GraphNodeObject_sub unk38;
/*0x4C*/ struct SpawnInfo *unk4C;
/*0x50*/ Mat4 *throwMatrix; // matrix ptr
+ Mat4 prevThrowMatrix;
+ u32 prevThrowMatrixTimestamp;
+ Mat4 *throwMatrixInterpolated;
/*0x54*/ Vec3f cameraToObject;
+ u32 skipInterpolationTimestamp;
};
struct ObjectNode
@@ -243,6 +258,10 @@ struct Surface
} normal;
/*0x28*/ f32 originOffset;
/*0x2C*/ struct Object *object;
+ Vec3s prevVertex1;
+ Vec3s prevVertex2;
+ Vec3s prevVertex3;
+ u32 modifiedTimestamp;
};
struct MarioBodyState
diff --git a/src/engine/graph_node.h b/src/engine/graph_node.h
index a680f70..a31bb8a 100644
--- a/src/engine/graph_node.h
+++ b/src/engine/graph_node.h
@@ -109,6 +109,8 @@ struct GraphNodePerspective
/*0x1C*/ f32 fov; // horizontal field of view in degrees
/*0x20*/ s16 near; // near clipping plane
/*0x22*/ s16 far; // far clipping plane
+ f32 prevFov;
+ f32 prevTimestamp;
};
/** An entry in the master list. It is a linked list of display lists
@@ -117,7 +119,9 @@ struct GraphNodePerspective
struct DisplayListNode
{
Mtx *transform;
+ void *transformInterpolated;
void *displayList;
+ void *displayListInterpolated;
struct DisplayListNode *next;
};
@@ -184,7 +188,11 @@ struct GraphNodeCamera
} config;
/*0x1C*/ Vec3f pos;
/*0x28*/ Vec3f focus;
+ Vec3f prevPos;
+ Vec3f prevFocus;
+ u32 prevTimestamp;
/*0x34*/ Mat4 *matrixPtr; // pointer to look-at matrix of this camera as a Mat4
+ Mat4 *matrixPtrInterpolated;
/*0x38*/ s16 roll; // roll in look at matrix. Doesn't account for light direction unlike rollScreen.
/*0x3A*/ s16 rollScreen; // rolls screen while keeping the light direction consistent
};
@@ -225,7 +233,8 @@ struct GraphNodeRotation
/*0x00*/ struct GraphNode node;
/*0x14*/ void *displayList;
/*0x18*/ Vec3s rotation;
- u8 pad1E[2];
+ Vec3s prevRotation;
+ u32 prevTimestamp;
};
/** GraphNode part that transforms itself and its children based on animation
@@ -322,6 +331,9 @@ struct GraphNodeBackground
/*0x00*/ struct FnGraphNode fnNode;
/*0x18*/ s32 unused;
/*0x1C*/ s32 background; // background ID, or rgba5551 color if fnNode.func is null
+ Vec3f prevCameraPos;
+ Vec3f prevCameraFocus;
+ u32 prevCameraTimestamp;
};
/** Renders the object that Mario is holding.
@@ -332,6 +344,8 @@ struct GraphNodeHeldObject
/*0x18*/ s32 playerIndex;
/*0x1C*/ struct Object *objNode;
/*0x20*/ Vec3s translation;
+ Vec3f prevShadowPos;
+ u32 prevShadowPosTimestamp;
};
/** A node that allows an object to specify a different culling radius than the
diff --git a/src/engine/math_util.h b/src/engine/math_util.h
index cb37d52..27fb7d1 100644
--- a/src/engine/math_util.h
+++ b/src/engine/math_util.h
@@ -71,4 +71,18 @@ void spline_get_weights(Vec4f result, f32 t, UNUSED s32 c);
void anim_spline_init(Vec4s *keyFrames);
s32 anim_spline_poll(Vec3f result);
+// For 60FPS patch
+inline void interpolate_vectors(Vec3f res, Vec3f a, Vec3f b) {
+ res[0] = (a[0] + b[0]) / 2.0f;
+ res[1] = (a[1] + b[1]) / 2.0f;
+ res[2] = (a[2] + b[2]) / 2.0f;
+}
+
+// For 60FPS patch
+inline void interpolate_vectors_s16(Vec3s res, Vec3s a, Vec3s b) {
+ res[0] = (a[0] + b[0]) / 2;
+ res[1] = (a[1] + b[1]) / 2;
+ res[2] = (a[2] + b[2]) / 2;
+}
+
#endif // MATH_UTIL_H
diff --git a/src/engine/surface_collision.c b/src/engine/surface_collision.c
index 9aff62f..d92553d 100644
--- a/src/engine/surface_collision.c
+++ b/src/engine/surface_collision.c
@@ -1,5 +1,6 @@
#include <PR/ultratypes.h>
+#include "game/game_init.h"
#include "sm64.h"
#include "game/debug.h"
#include "game/level_update.h"
@@ -393,26 +394,44 @@ f32 find_floor_height_and_data(f32 xPos, f32 yPos, f32 zPos, struct FloorGeometr
return floorHeight;
}
+u8 gInterpolatingSurfaces;
+
/**
* Iterate through the list of floors and find the first floor under a given point.
*/
static struct Surface *find_floor_from_list(struct SurfaceNode *surfaceNode, s32 x, s32 y, s32 z, f32 *pheight) {
register struct Surface *surf;
- register s32 x1, z1, x2, z2, x3, z3;
+ register f32 x1, z1, x2, z2, x3, z3;
f32 nx, ny, nz;
f32 oo;
f32 height;
struct Surface *floor = NULL;
+ s32 interpolate;
// Iterate through the list of floors until there are no more floors.
while (surfaceNode != NULL) {
surf = surfaceNode->surface;
surfaceNode = surfaceNode->next;
+ interpolate = gInterpolatingSurfaces && surf->modifiedTimestamp == gGlobalTimer;
x1 = surf->vertex1[0];
z1 = surf->vertex1[2];
x2 = surf->vertex2[0];
z2 = surf->vertex2[2];
+ if (interpolate) {
+ f32 diff = (surf->prevVertex1[0] - x1) * (surf->prevVertex1[0] - x1);
+ diff += (surf->prevVertex1[1] - surf->vertex1[1]) * (surf->prevVertex1[1] - surf->vertex1[1]);
+ diff += (surf->prevVertex1[2] - z1) * (surf->prevVertex1[2] - z1);
+ //printf("%f\n", sqrtf(diff));
+ if (diff > 10000) {
+ interpolate = FALSE;
+ } else {
+ x1 = (surf->prevVertex1[0] + x1) / 2;
+ z1 = (surf->prevVertex1[2] + z1) / 2;
+ x2 = (surf->prevVertex2[0] + x2) / 2;
+ z2 = (surf->prevVertex2[2] + z2) / 2;
+ }
+ }
// Check that the point is within the triangle bounds.
if ((z1 - z) * (x2 - x1) - (x1 - x) * (z2 - z1) < 0) {
@@ -422,6 +441,10 @@ static struct Surface *find_floor_from_list(struct SurfaceNode *surfaceNode, s32
// To slightly save on computation time, set this later.
x3 = surf->vertex3[0];
z3 = surf->vertex3[2];
+ if (interpolate) {
+ x3 = (surf->prevVertex3[0] + x3) / 2;
+ z3 = (surf->prevVertex3[2] + z3) / 2;
+ }
if ((z2 - z) * (x3 - x2) - (x2 - x) * (z3 - z2) < 0) {
continue;
@@ -441,10 +464,30 @@ static struct Surface *find_floor_from_list(struct SurfaceNode *surfaceNode, s32
continue;
}
- nx = surf->normal.x;
- ny = surf->normal.y;
- nz = surf->normal.z;
- oo = surf->originOffset;
+ if (interpolate) {
+ f32 y1, y2, y3;
+ f32 mag;
+ y1 = (surf->prevVertex1[1] + surf->vertex1[1]) / 2;
+ y2 = (surf->prevVertex2[1] + surf->vertex2[1]) / 2;
+ y3 = (surf->prevVertex3[1] + surf->vertex3[1]) / 2;
+ nx = (y2 - y1) * (z3 - z2) - (z2 - z1) * (y3 - y2);
+ ny = (z2 - z1) * (x3 - x2) - (x2 - x1) * (z3 - z2);
+ nz = (x2 - x1) * (y3 - y2) - (y2 - y1) * (x3 - x2);
+ mag = sqrtf(nx * nx + ny * ny + nz * nz);
+ if (mag < 0.0001) {
+ continue;
+ }
+ mag = (f32)(1.0 / mag);
+ nx *= mag;
+ ny *= mag;
+ nz *= mag;
+ oo = -(nx * x1 + ny * y1 + nz * z1);
+ } else {
+ nx = surf->normal.x;
+ ny = surf->normal.y;
+ nz = surf->normal.z;
+ oo = surf->originOffset;
+ }
// If a wall, ignore it. Likely a remnant, should never occur.
if (ny == 0.0f) {
@@ -459,6 +502,15 @@ static struct Surface *find_floor_from_list(struct SurfaceNode *surfaceNode, s32
}
*pheight = height;
+ if (interpolate) {
+ static struct Surface s;
+ s.type = surf->type;
+ s.normal.x = nx;
+ s.normal.y = ny;
+ s.normal.z = nz;
+ s.originOffset = oo;
+ return &s;
+ }
floor = surf;
break;
}
diff --git a/src/engine/surface_load.c b/src/engine/surface_load.c
index 6936d8a..ad3ed03 100644
--- a/src/engine/surface_load.c
+++ b/src/engine/surface_load.c
@@ -14,6 +14,8 @@
#include "game/mario.h"
#include "game/object_list_processor.h"
#include "surface_load.h"
+#include "game/game_init.h"
+#include "math_util.h"
s32 unused8038BE90;
@@ -359,6 +361,11 @@ static struct Surface *read_surface_data(s16 *vertexData, s16 **vertexIndices) {
surface = alloc_surface();
+ vec3s_copy(surface->prevVertex1, surface->vertex1);
+ vec3s_copy(surface->prevVertex2, surface->vertex2);
+ vec3s_copy(surface->prevVertex3, surface->vertex3);
+ surface->modifiedTimestamp = gGlobalTimer;
+
surface->vertex1[0] = x1;
surface->vertex2[0] = x2;
surface->vertex3[0] = x3;
diff --git a/src/game/camera.c b/src/game/camera.c
index 30ad26e..578837c 100644
--- a/src/game/camera.c
+++ b/src/game/camera.c
@@ -483,6 +483,10 @@ CameraTransition sModeTransitions[] = {
extern u8 sDanceCutsceneIndexTable[][4];
extern u8 sZoomOutAreaMasks[];
+static void skip_camera_interpolation(void) {
+ gLakituState.skipCameraInterpolationTimestamp = gGlobalTimer;
+}
+
/**
* Starts a camera shake triggered by an interaction
*/
@@ -5505,6 +5509,7 @@ s32 set_camera_mode_fixed(struct Camera *c, s16 x, s16 y, s16 z) {
c->mode = CAMERA_MODE_FIXED;
vec3f_set(c->pos, sFixedModeBasePosition[0], sMarioCamState->pos[1],
sFixedModeBasePosition[2]);
+ skip_camera_interpolation();
}
return basePosSet;
}
@@ -5655,6 +5660,7 @@ BAD_RETURN(s32) cam_rr_enter_building_side(struct Camera *c) {
if (c->mode != CAMERA_MODE_FIXED) {
sStatusFlags &= ~CAM_FLAG_SMOOTH_MOVEMENT;
c->mode = CAMERA_MODE_FIXED;
+ skip_camera_interpolation();
}
}
@@ -5850,6 +5856,7 @@ BAD_RETURN(s32) cam_castle_enter_lobby(struct Camera *c) {
sStatusFlags &= ~CAM_FLAG_SMOOTH_MOVEMENT;
set_fixed_cam_axis_sa_lobby(c->mode);
c->mode = CAMERA_MODE_FIXED;
+ skip_camera_interpolation();
}
}
@@ -7217,6 +7224,7 @@ BAD_RETURN(s32) cutscene_unused_loop(UNUSED struct Camera *c) {
BAD_RETURN(s32) cutscene_ending_mario_fall_start(struct Camera *c) {
vec3f_set(c->focus, -26.f, 0.f, -137.f);
vec3f_set(c->pos, 165.f, 4725.f, 324.f);
+ skip_camera_interpolation();
}
/**
@@ -7249,6 +7257,7 @@ BAD_RETURN(s32) cutscene_ending_mario_fall(struct Camera *c) {
BAD_RETURN(s32) cutscene_ending_mario_land_closeup(struct Camera *c) {
vec3f_set(c->focus, 85.f, 826.f, 250.f);
vec3f_set(c->pos, -51.f, 988.f, -202.f);
+ skip_camera_interpolation();
player2_rotate_cam(c, -0x2000, 0x2000, -0x2000, 0x2000);
}
@@ -7258,6 +7267,7 @@ BAD_RETURN(s32) cutscene_ending_mario_land_closeup(struct Camera *c) {
BAD_RETURN(s32) cutscene_ending_reset_spline(UNUSED struct Camera *c) {
sCutsceneVars[9].point[0] = 0.f;
cutscene_reset_spline();
+ skip_camera_interpolation();
}
/**
@@ -7293,6 +7303,7 @@ BAD_RETURN(s32) cutscene_ending_peach_appear_closeup(struct Camera *c) {
vec3f_set(c->pos, 179.f, 2463.f, -1216.f);
c->pos[1] = gCutsceneFocus->oPosY + 35.f;
vec3f_set(c->focus, gCutsceneFocus->oPosX, gCutsceneFocus->oPosY + 125.f, gCutsceneFocus->oPosZ);
+ skip_camera_interpolation();
}
/**
@@ -7311,6 +7322,7 @@ BAD_RETURN(s32) cutscene_ending_peach_appears(struct Camera *c) {
BAD_RETURN(s32) cutscene_ending_peach_descends_start(UNUSED struct Camera *c) {
cutscene_reset_spline();
sCutsceneVars[2].point[1] = 150.f;
+ skip_camera_interpolation();
}
/**
@@ -7397,6 +7409,7 @@ BAD_RETURN(s32) cutscene_ending_peach_wakeup(struct Camera *c) {
BAD_RETURN(s32) cutscene_ending_dialog(struct Camera *c) {
vec3f_set(c->focus, 11.f, 983.f, -1273.f);
vec3f_set(c->pos, -473.f, 970.f, -1152.f);
+ skip_camera_interpolation();
player2_rotate_cam(c, -0x800, 0x2000, -0x2000, 0x2000);
}
@@ -7407,6 +7420,7 @@ BAD_RETURN(s32) cutscene_ending_kiss_closeup(struct Camera *c) {
set_fov_function(CAM_FOV_SET_29);
vec3f_set(c->focus, 350.f, 1034.f, -1216.f);
vec3f_set(c->pos, -149.f, 1021.f, -1216.f);
+ skip_camera_interpolation();
}
/**
@@ -7442,6 +7456,7 @@ BAD_RETURN(s32) cutscene_ending_kiss(struct Camera *c) {
BAD_RETURN(s32) cutscene_ending_look_at_sky(struct Camera *c) {
move_point_along_spline(c->focus, sEndingLookAtSkyFocus, &sCutsceneSplineSegment, &sCutsceneSplineSegmentProgress);
vec3f_set(c->pos, 699.f, 1680.f, -703.f);
+ skip_camera_interpolation();
}
/**
@@ -10263,6 +10278,7 @@ BAD_RETURN(s32) cutscene_door_start(struct Camera *c) {
BAD_RETURN(s32) cutscene_door_fix_cam(struct Camera *c) {
vec3f_copy(c->pos, sCutsceneVars[0].point);
vec3f_copy(c->focus, sCutsceneVars[1].point);
+ skip_camera_interpolation();
}
/**
@@ -10296,6 +10312,7 @@ BAD_RETURN(s32) cutscene_door_move_behind_mario(struct Camera *c) {
}
offset_rotated(c->pos, sMarioCamState->pos, camOffset, sCutsceneVars[0].angle);
+ skip_camera_interpolation();
}
/**
diff --git a/src/game/camera.h b/src/game/camera.h
index f56ed02..2b682ed 100644
--- a/src/game/camera.h
+++ b/src/game/camera.h
@@ -654,6 +654,8 @@ struct LakituState
/// Mario's action from the previous frame. Only used to determine if Mario just finished a dive.
/*0xB8*/ u32 lastFrameAction;
/*0xBC*/ s16 unused;
+
+ u32 skipCameraInterpolationTimestamp;
};
// bss order hack to not affect BSS order. if possible, remove me, but it will be hard to match otherwise
diff --git a/src/game/envfx_bubbles.c b/src/game/envfx_bubbles.c
index 16a9272..ee1b029 100644
--- a/src/game/envfx_bubbles.c
+++ b/src/game/envfx_bubbles.c
@@ -35,6 +35,20 @@ Vtx_t gBubbleTempVtx[3] = {
{ { 0, 0, 0 }, 0, { -498, 964 }, { 0xFF, 0xFF, 0xFF, 0xFF } },
};
+static Gfx sGfxSaved[60 / 5];
+static Gfx *sBubbleInterpolatedDisplayListPos[60 / 5];
+static Vec3s sPrevBubblePositions[60];
+
+void patch_interpolated_bubble_particles(void) {
+ s32 i;
+ for (i = 0; i < 60 / 5; i++) {
+ if (sBubbleInterpolatedDisplayListPos[i] != NULL) {
+ *sBubbleInterpolatedDisplayListPos[i] = sGfxSaved[i];
+ sBubbleInterpolatedDisplayListPos[i] = NULL;
+ }
+ }
+}
+
/**
* Check whether the particle with the given index is
* laterally within distance of point (x, z). Used to
@@ -241,6 +255,7 @@ void envfx_update_whirlpool(void) {
(gEnvFxBuffer + i)->yPos = (i + gEnvFxBuffer)->bubbleY;
(gEnvFxBuffer + i)->unusedBubbleVar = 0;
(gEnvFxBuffer + i)->isAlive = 1;
+ (gEnvFxBuffer + i)->spawnTimestamp = gGlobalTimer;
envfx_rotate_around_whirlpool(&(gEnvFxBuffer + i)->xPos, &(gEnvFxBuffer + i)->yPos,
&(gEnvFxBuffer + i)->zPos);
@@ -299,6 +314,7 @@ void envfx_update_jetstream(void) {
+ coss((gEnvFxBuffer + i)->angleAndDist[0]) * (gEnvFxBuffer + i)->angleAndDist[1];
(gEnvFxBuffer + i)->yPos =
gEnvFxBubbleConfig[ENVFX_STATE_SRC_Y] + (random_float() * 400.0f - 200.0f);
+ (gEnvFxBuffer + i)->spawnTimestamp = gGlobalTimer;
} else {
(gEnvFxBuffer + i)->angleAndDist[1] += 10;
(gEnvFxBuffer + i)->xPos += sins((gEnvFxBuffer + i)->angleAndDist[0]) * 10.0f;
@@ -506,6 +522,12 @@ Gfx *envfx_update_bubble_particles(s32 mode, UNUSED Vec3s marioPos, Vec3s camFro
Vec3s vertex1;
Vec3s vertex2;
Vec3s vertex3;
+ Vec3s interpolatedVertices[3];
+
+ static Vec3s prevVertex1;
+ static Vec3s prevVertex2;
+ static Vec3s prevVertex3;
+ static u32 prevTimestamp;
Gfx *gfxStart;
@@ -521,18 +543,52 @@ Gfx *envfx_update_bubble_particles(s32 mode, UNUSED Vec3s marioPos, Vec3s camFro
envfx_bubbles_update_switch(mode, camTo, vertex1, vertex2, vertex3);
rotate_triangle_vertices(vertex1, vertex2, vertex3, pitch, yaw);
+ if (gGlobalTimer == prevTimestamp + 1) {
+ interpolate_vectors_s16(interpolatedVertices[0], prevVertex1, vertex1);
+ interpolate_vectors_s16(interpolatedVertices[1], prevVertex2, vertex2);
+ interpolate_vectors_s16(interpolatedVertices[2], prevVertex3, vertex3);
+ }
+ vec3s_copy(prevVertex1, vertex1);
+ vec3s_copy(prevVertex2, vertex2);
+ vec3s_copy(prevVertex3, vertex3);
+ prevTimestamp = gGlobalTimer;
+
gSPDisplayList(sGfxCursor++, &tiny_bubble_dl_0B006D38);
for (i = 0; i < sBubbleParticleMaxCount; i += 5) {
+ Vtx *interpolatedVertBuf = alloc_display_list(15 * sizeof(Vtx));
+ s32 j, k;
gDPPipeSync(sGfxCursor++);
envfx_set_bubble_texture(mode, i);
- append_bubble_vertex_buffer(sGfxCursor++, i, vertex1, vertex2, vertex3, (Vtx *) gBubbleTempVtx);
+ sBubbleInterpolatedDisplayListPos[i / 5] = sGfxCursor;
+ for (j = 0; j < 5; j++) {
+ for (k = 0; k < 3; k++) {
+ Vtx *v = &interpolatedVertBuf[j * 3 + k];
+ v->v = gBubbleTempVtx[k];
+ if (gGlobalTimer != gEnvFxBuffer[i + j].spawnTimestamp && mode != ENVFX_LAVA_BUBBLES) {
+ v->v.ob[0] = (sPrevBubblePositions[i + j][0] + gEnvFxBuffer[i + j].xPos) / 2.0f + interpolatedVertices[k][0];
+ v->v.ob[1] = (sPrevBubblePositions[i + j][1] + gEnvFxBuffer[i + j].yPos) / 2.0f + interpolatedVertices[k][1];
+ v->v.ob[2] = (sPrevBubblePositions[i + j][2] + gEnvFxBuffer[i + j].zPos) / 2.0f + interpolatedVertices[k][2];
+ } else {
+ v->v.ob[0] = gEnvFxBuffer[i + j].xPos + interpolatedVertices[k][0];
+ v->v.ob[1] = gEnvFxBuffer[i + j].yPos + interpolatedVertices[k][1];
+ v->v.ob[2] = gEnvFxBuffer[i + j].zPos + interpolatedVertices[k][2];
+ }
+ }
+ }
+ gSPVertex(sGfxCursor++, VIRTUAL_TO_PHYSICAL(interpolatedVertBuf), 15, 0);
+ append_bubble_vertex_buffer(&sGfxSaved[i / 5], i, vertex1, vertex2, vertex3, (Vtx *) gBubbleTempVtx);
gSP1Triangle(sGfxCursor++, 0, 1, 2, 0);
gSP1Triangle(sGfxCursor++, 3, 4, 5, 0);
gSP1Triangle(sGfxCursor++, 6, 7, 8, 0);
gSP1Triangle(sGfxCursor++, 9, 10, 11, 0);
gSP1Triangle(sGfxCursor++, 12, 13, 14, 0);
}
+ for (i = 0; i < sBubbleParticleMaxCount; i++) {
+ sPrevBubblePositions[i][0] = gEnvFxBuffer[i].xPos;
+ sPrevBubblePositions[i][1] = gEnvFxBuffer[i].yPos;
+ sPrevBubblePositions[i][2] = gEnvFxBuffer[i].zPos;
+ }
gSPDisplayList(sGfxCursor++, &tiny_bubble_dl_0B006AB0);
gSPEndDisplayList(sGfxCursor++);
diff --git a/src/game/envfx_snow.c b/src/game/envfx_snow.c
index f6802da..8031e28 100644
--- a/src/game/envfx_snow.c
+++ b/src/game/envfx_snow.c
@@ -54,6 +54,26 @@ extern Gfx tiny_bubble_dl_0B006AB0[];
extern Gfx tiny_bubble_dl_0B006A50[];
extern Gfx tiny_bubble_dl_0B006CD8[];
+static struct {
+ Gfx *pos;
+ Vtx vertices[15];
+} sPrevSnowVertices[140 / 5];
+static s16 sPrevSnowParticleCount;
+static u32 sPrevSnowTimestamp;
+
+void patch_interpolated_snow_particles(void) {
+ int i;
+
+ if (gGlobalTimer != sPrevSnowTimestamp + 1) {
+ return;
+ }
+
+ for (i = 0; i < sPrevSnowParticleCount; i += 5) {
+ gSPVertex(sPrevSnowVertices[i / 5].pos,
+ VIRTUAL_TO_PHYSICAL(sPrevSnowVertices[i / 5].vertices), 15, 0);
+ }
+}
+
/**
* Initialize snow particles by allocating a buffer for storing their state
* and setting a start amount.
@@ -217,6 +237,7 @@ void envfx_update_snow_normal(s32 snowCylinderX, s32 snowCylinderY, s32 snowCyli
400.0f * random_float() - 200.0f + snowCylinderZ + (s16)(deltaZ * 2);
(gEnvFxBuffer + i)->yPos = 200.0f * random_float() + snowCylinderY;
(gEnvFxBuffer + i)->isAlive = 1;
+ (gEnvFxBuffer + i)->spawnTimestamp = gGlobalTimer;
} else {
(gEnvFxBuffer + i)->xPos += random_float() * 2 - 1.0f + (s16)(deltaX / 1.2);
(gEnvFxBuffer + i)->yPos -= 2 -(s16)(deltaY * 0.8);
@@ -251,6 +272,7 @@ void envfx_update_snow_blizzard(s32 snowCylinderX, s32 snowCylinderY, s32 snowCy
400.0f * random_float() - 200.0f + snowCylinderZ + (s16)(deltaZ * 2);
(gEnvFxBuffer + i)->yPos = 400.0f * random_float() - 200.0f + snowCylinderY;
(gEnvFxBuffer + i)->isAlive = 1;
+ (gEnvFxBuffer + i)->spawnTimestamp = gGlobalTimer;
} else {
(gEnvFxBuffer + i)->xPos += random_float() * 2 - 1.0f + (s16)(deltaX / 1.2) + 20.0f;
(gEnvFxBuffer + i)->yPos -= 5 -(s16)(deltaY * 0.8);
@@ -294,6 +316,7 @@ void envfx_update_snow_water(s32 snowCylinderX, s32 snowCylinderY, s32 snowCylin
(gEnvFxBuffer + i)->zPos = 400.0f * random_float() - 200.0f + snowCylinderZ;
(gEnvFxBuffer + i)->yPos = 400.0f * random_float() - 200.0f + snowCylinderY;
(gEnvFxBuffer + i)->isAlive = 1;
+ (gEnvFxBuffer + i)->spawnTimestamp = gGlobalTimer;
}
}
}
@@ -346,6 +369,8 @@ void rotate_triangle_vertices(Vec3s vertex1, Vec3s vertex2, Vec3s vertex3, s16 p
void append_snowflake_vertex_buffer(Gfx *gfx, s32 index, Vec3s vertex1, Vec3s vertex2, Vec3s vertex3) {
s32 i = 0;
Vtx *vertBuf = (Vtx *) alloc_display_list(15 * sizeof(Vtx));
+ Vtx *vertBufInterpolated = (Vtx *) alloc_display_list(15 * sizeof(Vtx));
+ Vtx *v;
#ifdef VERSION_EU
Vtx *p;
#endif
@@ -395,7 +420,23 @@ void append_snowflake_vertex_buffer(Gfx *gfx, s32 index, Vec3s vertex1, Vec3s ve
#endif
}
- gSPVertex(gfx, VIRTUAL_TO_PHYSICAL(vertBuf), 15, 0);
+ for (i = 0; i < 15; i++) {
+ v = &sPrevSnowVertices[index / 5].vertices[i];
+ vertBufInterpolated[i] = gSnowTempVtx[i % 3];
+ if (index < sPrevSnowParticleCount && gGlobalTimer == sPrevSnowTimestamp + 1 &&
+ gGlobalTimer != gEnvFxBuffer[index + i / 3].spawnTimestamp) {
+ vertBufInterpolated[i].v.ob[0] = (v->v.ob[0] + vertBuf[i].v.ob[0]) / 2;
+ vertBufInterpolated[i].v.ob[1] = (v->v.ob[1] + vertBuf[i].v.ob[1]) / 2;
+ vertBufInterpolated[i].v.ob[2] = (v->v.ob[2] + vertBuf[i].v.ob[2]) / 2;
+ } else {
+ vertBufInterpolated[i].v.ob[0] = vertBuf[i].v.ob[0];
+ vertBufInterpolated[i].v.ob[1] = vertBuf[i].v.ob[1];
+ vertBufInterpolated[i].v.ob[2] = vertBuf[i].v.ob[2];
+ }
+ *v = vertBuf[i];
+ }
+ sPrevSnowVertices[index / 5].pos = gfx;
+ gSPVertex(gfx, VIRTUAL_TO_PHYSICAL(vertBufInterpolated), 15, 0);
}
/**
@@ -479,6 +520,8 @@ Gfx *envfx_update_snow(s32 snowMode, Vec3s marioPos, Vec3s camFrom, Vec3s camTo)
gSP1Triangle(gfx++, 9, 10, 11, 0);
gSP1Triangle(gfx++, 12, 13, 14, 0);
}
+ sPrevSnowParticleCount = gSnowParticleCount;
+ sPrevSnowTimestamp = gGlobalTimer;
gSPDisplayList(gfx++, &tiny_bubble_dl_0B006AB0) gSPEndDisplayList(gfx++);
diff --git a/src/game/envfx_snow.h b/src/game/envfx_snow.h
index 7a83b53..3b21da5 100644
--- a/src/game/envfx_snow.h
+++ b/src/game/envfx_snow.h
@@ -25,7 +25,7 @@ struct EnvFxParticle {
s32 angleAndDist[2]; // for whirpools, [0] = angle from center, [1] = distance from center
s32 unusedBubbleVar; // set to zero for bubbles when respawning, never used elsewhere
s32 bubbleY; // for Bubbles, yPos is always set to this
- s8 filler20[56 - 0x20];
+ u32 spawnTimestamp;
};
extern s8 gEnvFxMode;
diff --git a/src/game/hud.c b/src/game/hud.c
index 8d4daa5..7ce2b22 100644
--- a/src/game/hud.c
+++ b/src/game/hud.c
@@ -57,6 +57,20 @@ static struct UnusedHUDStruct sUnusedHUDValues = { 0x00, 0x0A, 0x00 };
static struct CameraHUD sCameraHUD = { CAM_STATUS_NONE };
+static u32 sPowerMeterLastRenderTimestamp;
+static s16 sPowerMeterLastY;
+static Gfx *sPowerMeterDisplayListPos;
+
+void patch_interpolated_hud(void) {
+ if (sPowerMeterDisplayListPos != NULL) {
+ Mtx *mtx = alloc_display_list(sizeof(Mtx));
+ guTranslate(mtx, (f32) sPowerMeterHUD.x, (f32) sPowerMeterHUD.y, 0);
+ gSPMatrix(sPowerMeterDisplayListPos, VIRTUAL_TO_PHYSICAL(mtx),
+ G_MTX_MODELVIEW | G_MTX_MUL | G_MTX_PUSH);
+ sPowerMeterDisplayListPos = NULL;
+ }
+}
+
/**
* Renders a rgba16 16x16 glyph texture from a table list.
*/
@@ -109,6 +123,7 @@ void render_power_meter_health_segment(s16 numHealthWedges) {
*/
void render_dl_power_meter(s16 numHealthWedges) {
Mtx *mtx;
+ f32 interpolatedY;
mtx = alloc_display_list(sizeof(Mtx));
@@ -116,7 +131,15 @@ void render_dl_power_meter(s16 numHealthWedges) {
return;
}
- guTranslate(mtx, (f32) sPowerMeterHUD.x, (f32) sPowerMeterHUD.y, 0);
+ if (gGlobalTimer == sPowerMeterLastRenderTimestamp + 1) {
+ interpolatedY = (sPowerMeterLastY + sPowerMeterHUD.y) / 2.0f;
+ } else {
+ interpolatedY = sPowerMeterHUD.y;
+ }
+ guTranslate(mtx, (f32) sPowerMeterHUD.x, interpolatedY, 0);
+ sPowerMeterLastY = sPowerMeterHUD.y;
+ sPowerMeterLastRenderTimestamp = gGlobalTimer;
+ sPowerMeterDisplayListPos = gDisplayListHead;
gSPMatrix(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(mtx++),
G_MTX_MODELVIEW | G_MTX_MUL | G_MTX_PUSH);
diff --git a/src/game/ingame_menu.c b/src/game/ingame_menu.c
index b9a43df..281e0f3 100644
--- a/src/game/ingame_menu.c
+++ b/src/game/ingame_menu.c
@@ -111,6 +111,41 @@ u8 gMenuHoldKeyIndex = 0;
u8 gMenuHoldKeyTimer = 0;
s32 gDialogResponse = 0;
+static Gfx *sInterpolatedDialogOffsetPos;
+static f32 sInterpolatedDialogOffset;
+static Gfx *sInterpolatedDialogRotationPos;
+static f32 sInterpolatedDialogScale;
+static f32 sInterpolatedDialogRotation;
+static Gfx *sInterpolatedDialogZoomPos;
+
+void patch_interpolated_dialog(void) {
+ Mtx *matrix;
+
+ if (sInterpolatedDialogOffsetPos != NULL) {
+ matrix = (Mtx *) alloc_display_list(sizeof(Mtx));
+ guTranslate(matrix, 0, sInterpolatedDialogOffset, 0);
+ gSPMatrix(sInterpolatedDialogOffsetPos, VIRTUAL_TO_PHYSICAL(matrix), G_MTX_MODELVIEW | G_MTX_MUL | G_MTX_NOPUSH);
+ sInterpolatedDialogOffsetPos = NULL;
+ }
+ if (sInterpolatedDialogRotationPos != NULL) {
+ matrix = (Mtx *) alloc_display_list(sizeof(Mtx));
+ guScale(matrix, 1.0 / sInterpolatedDialogScale, 1.0 / sInterpolatedDialogScale, 1.0f);
+ gSPMatrix(sInterpolatedDialogRotationPos++, VIRTUAL_TO_PHYSICAL(matrix), G_MTX_MODELVIEW | G_MTX_MUL | G_MTX_NOPUSH);
+ matrix = (Mtx *) alloc_display_list(sizeof(Mtx));
+ guRotate(matrix, sInterpolatedDialogRotation * 4.0f, 0, 0, 1.0f);
+ gSPMatrix(sInterpolatedDialogRotationPos, VIRTUAL_TO_PHYSICAL(matrix), G_MTX_MODELVIEW | G_MTX_MUL | G_MTX_NOPUSH);
+ sInterpolatedDialogRotationPos = NULL;
+ }
+ if (sInterpolatedDialogZoomPos != NULL) {
+ matrix = (Mtx *) alloc_display_list(sizeof(Mtx));
+ guTranslate(matrix, 65.0 - (65.0 / sInterpolatedDialogScale), (40.0 / sInterpolatedDialogScale) - 40, 0);
+ gSPMatrix(sInterpolatedDialogZoomPos++, VIRTUAL_TO_PHYSICAL(matrix), G_MTX_MODELVIEW | G_MTX_MUL | G_MTX_NOPUSH);
+ matrix = (Mtx *) alloc_display_list(sizeof(Mtx));
+ guScale(matrix, 1.0 / sInterpolatedDialogScale, 1.0 / sInterpolatedDialogScale, 1.0f);
+ gSPMatrix(sInterpolatedDialogZoomPos, VIRTUAL_TO_PHYSICAL(matrix), G_MTX_MODELVIEW | G_MTX_MUL | G_MTX_NOPUSH);
+ sInterpolatedDialogZoomPos = NULL;
+ }
+}
void create_dl_identity_matrix(void) {
Mtx *matrix = (Mtx *) alloc_display_list(sizeof(Mtx));
@@ -947,6 +982,14 @@ void render_dialog_box_type(struct DialogEntry *dialog, s8 linesPerBox) {
switch (gDialogBoxType) {
case DIALOG_TYPE_ROTATE: // Renders a dialog black box with zoom and rotation
if (gDialogBoxState == DIALOG_STATE_OPENING || gDialogBoxState == DIALOG_STATE_CLOSING) {
+ sInterpolatedDialogRotationPos = gDisplayListHead;
+ if (gDialogBoxState == DIALOG_STATE_OPENING) {
+ sInterpolatedDialogScale = gDialogBoxScale - 2 / 2;
+ sInterpolatedDialogRotation = gDialogBoxOpenTimer - 7.5f / 2;
+ } else {
+ sInterpolatedDialogScale = gDialogBoxScale + 2 / 2;
+ sInterpolatedDialogRotation = gDialogBoxOpenTimer + 7.5f / 2;
+ }
create_dl_scale_matrix(MENU_MTX_NOPUSH, 1.0 / gDialogBoxScale, 1.0 / gDialogBoxScale, 1.0f);
// convert the speed into angle
create_dl_rotation_matrix(MENU_MTX_NOPUSH, gDialogBoxOpenTimer * 4.0f, 0, 0, 1.0f);
@@ -955,6 +998,12 @@ void render_dialog_box_type(struct DialogEntry *dialog, s8 linesPerBox) {
break;
case DIALOG_TYPE_ZOOM: // Renders a dialog white box with zoom
if (gDialogBoxState == DIALOG_STATE_OPENING || gDialogBoxState == DIALOG_STATE_CLOSING) {
+ sInterpolatedDialogZoomPos = gDisplayListHead;
+ if (gDialogBoxState == DIALOG_STATE_OPENING) {
+ sInterpolatedDialogScale = gDialogBoxScale - 2 / 2;
+ } else {
+ sInterpolatedDialogScale = gDialogBoxScale + 2 / 2;
+ }
create_dl_translation_matrix(MENU_MTX_NOPUSH, 65.0 - (65.0 / gDialogBoxScale),
(40.0 / gDialogBoxScale) - 40, 0);
create_dl_scale_matrix(MENU_MTX_NOPUSH, 1.0 / gDialogBoxScale, 1.0 / gDialogBoxScale, 1.0f);
@@ -1237,6 +1286,8 @@ void handle_dialog_text_and_pages(s8 colorMode, struct DialogEntry *dialog, s8 l
#ifdef VERSION_EU
gDialogY -= gDialogScrollOffsetY;
#else
+ sInterpolatedDialogOffset = gDialogScrollOffsetY + dialog->linesPerBox;
+ sInterpolatedDialogOffsetPos = gDisplayListHead;
create_dl_translation_matrix(MENU_MTX_NOPUSH, 0, (f32) gDialogScrollOffsetY, 0);
#endif
}
diff --git a/src/game/level_geo.c b/src/game/level_geo.c
index 4c98e70..abc5121 100644
--- a/src/game/level_geo.c
+++ b/src/game/level_geo.c
@@ -34,12 +34,16 @@ Gfx *geo_envfx_main(s32 callContext, struct GraphNode *node, Mat4 mtxf) {
vec3f_to_vec3s(marioPos, gPlayerCameraState->pos);
particleList = envfx_update_particles(snowMode, marioPos, camTo, camFrom);
if (particleList != NULL) {
+#if 0
Mtx *mtx = alloc_display_list(sizeof(*mtx));
gfx = alloc_display_list(2 * sizeof(*gfx));
mtxf_to_mtx(mtx, mtxf);
gSPMatrix(&gfx[0], VIRTUAL_TO_PHYSICAL(mtx), G_MTX_MODELVIEW | G_MTX_LOAD | G_MTX_NOPUSH);
gSPBranchList(&gfx[1], VIRTUAL_TO_PHYSICAL(particleList));
+#else
+ gfx = particleList;
+#endif
execNode->fnNode.node.flags = (execNode->fnNode.node.flags & 0xFF) | 0x400;
}
SET_HIGH_U16_OF_32(*params, gAreaUpdateCounter);
diff --git a/src/game/object_helpers.c b/src/game/object_helpers.c
index 0acc5b4..8a57a81 100644
--- a/src/game/object_helpers.c
+++ b/src/game/object_helpers.c
@@ -1575,6 +1575,7 @@ void cur_obj_set_pos_to_home(void) {
o->oPosX = o->oHomeX;
o->oPosY = o->oHomeY;
o->oPosZ = o->oHomeZ;
+ o->header.gfx.skipInterpolationTimestamp = gGlobalTimer;
}
void cur_obj_set_pos_to_home_and_stop(void) {
diff --git a/src/game/paintings.c b/src/game/paintings.c
index 205a9ea..9583c64 100644
--- a/src/game/paintings.c
+++ b/src/game/paintings.c
@@ -189,6 +189,32 @@ struct Painting **sPaintingGroups[] = {
s16 gPaintingUpdateCounter = 1;
s16 gLastPaintingUpdateCounter = 0;
+static Vtx sLastVertices[2 * 264 * 3];
+static u32 sLastVerticesTimestamp;
+static Vtx *sVerticesPtr[2];
+static s32 sVerticesCount;
+
+void patch_interpolated_paintings(void) {
+ if (sVerticesPtr[0] != NULL) {
+ s32 i;
+ if (sVerticesPtr[1] != NULL) {
+ for (i = 0; i < sVerticesCount / 2; i++) {
+ sVerticesPtr[0][i] = sLastVertices[i];
+ }
+ for (; i < sVerticesCount; i++) {
+ sVerticesPtr[1][i - sVerticesCount / 2] = sLastVertices[i];
+ }
+ } else {
+ for (i = 0; i < sVerticesCount; i++) {
+ sVerticesPtr[0][i] = sLastVertices[i];
+ }
+ }
+ sVerticesPtr[0] = NULL;
+ sVerticesPtr[1] = NULL;
+ sVerticesCount = 0;
+ }
+}
+
/**
* Stop paintings in paintingGroup from rippling if their id is different from *idptr.
*/
@@ -890,6 +916,23 @@ Gfx *render_painting(u8 *img, s16 tWidth, s16 tHeight, s16 *textureMap, s16 mapV
gSP1Triangle(gfx++, group * 3, group * 3 + 1, group * 3 + 2, 0);
}
+ if (sVerticesCount >= numVtx * 2) {
+ sVerticesCount = 0;
+ }
+ for (map = 0; map < numVtx; map++) {
+ Vtx v = verts[map];
+ if (gGlobalTimer == sLastVerticesTimestamp + 1) {
+ s32 i;
+ for (i = 0; i < 3; i++) {
+ verts[map].n.ob[i] = (v.n.ob[i] + sLastVertices[sVerticesCount + map].n.ob[i]) / 2;
+ verts[map].n.n[i] = (v.n.n[i] + sLastVertices[sVerticesCount + map].n.n[i]) / 2;
+ }
+ }
+ sLastVertices[sVerticesCount + map] = v;
+ }
+ sVerticesPtr[sVerticesCount / numVtx] = verts;
+ sVerticesCount += numVtx;
+
gSPEndDisplayList(gfx);
return dlist;
}
@@ -954,6 +997,7 @@ Gfx *painting_ripple_image(struct Painting *painting) {
meshTris = textureMap[meshVerts * 3 + 1];
gSPDisplayList(gfx++, render_painting(textures[i], tWidth, tHeight, textureMap, meshVerts, meshTris, painting->alpha));
}
+ sLastVerticesTimestamp = gGlobalTimer;
// Update the ripple, may automatically reset the painting's state.
painting_update_ripple_state(painting);
@@ -991,6 +1035,7 @@ Gfx *painting_ripple_env_mapped(struct Painting *painting) {
meshVerts = textureMap[0];
meshTris = textureMap[meshVerts * 3 + 1];
gSPDisplayList(gfx++, render_painting(tArray[0], tWidth, tHeight, textureMap, meshVerts, meshTris, painting->alpha));
+ sLastVerticesTimestamp = gGlobalTimer;
// Update the ripple, may automatically reset the painting's state.
painting_update_ripple_state(painting);
diff --git a/src/game/rendering_graph_node.c b/src/game/rendering_graph_node.c
index 0e8a856..5ae8362 100644
--- a/src/game/rendering_graph_node.c
+++ b/src/game/rendering_graph_node.c
@@ -44,6 +44,8 @@
s16 gMatStackIndex;
Mat4 gMatStack[32];
Mtx *gMatStackFixed[32];
+Mat4 gMatStackInterpolated[32];
+Mtx *gMatStackInterpolatedFixed[32];
/**
* Animation nodes have state in global variables, so this struct captures
@@ -57,6 +59,7 @@ struct GeoAnimState {
/*0x04*/ f32 translationMultiplier;
/*0x08*/ u16 *attribute;
/*0x0C*/ s16 *data;
+ s16 prevFrame;
};
// For some reason, this is a GeoAnimState struct, but the current state consists
@@ -66,6 +69,7 @@ struct GeoAnimState gGeoTempState;
u8 gCurAnimType;
u8 gCurAnimEnabled;
s16 gCurrAnimFrame;
+s16 gPrevAnimFrame;
f32 gCurAnimTranslationMultiplier;
u16 *gCurrAnimAttribute;
s16 *gCurAnimData;
@@ -134,6 +138,46 @@ u16 gAreaUpdateCounter = 0;
LookAt lookAt;
#endif
+static Gfx *sPerspectivePos;
+static Mtx *sPerspectiveMtx;
+
+struct {
+ Gfx *pos;
+ void *mtx;
+ void *displayList;
+} gMtxTbl[6400];
+s32 gMtxTblSize;
+
+static Gfx *sViewportPos;
+static Vp sPrevViewport;
+
+void mtx_patch_interpolated(void) {
+ s32 i;
+
+ if (sPerspectivePos != NULL) {
+ gSPMatrix(sPerspectivePos, VIRTUAL_TO_PHYSICAL(sPerspectiveMtx), G_MTX_PROJECTION | G_MTX_LOAD | G_MTX_NOPUSH);
+ }
+
+ for (i = 0; i < gMtxTblSize; i++) {
+ Gfx *pos = gMtxTbl[i].pos;
+ gSPMatrix(pos++, VIRTUAL_TO_PHYSICAL(gMtxTbl[i].mtx),
+ G_MTX_MODELVIEW | G_MTX_LOAD | G_MTX_NOPUSH);
+ gSPDisplayList(pos++, gMtxTbl[i].displayList);
+ }
+
+ if (sViewportPos != NULL) {
+ Gfx *saved = gDisplayListHead;
+ gDisplayListHead = sViewportPos;
+ make_viewport_clip_rect(&sPrevViewport);
+ gSPViewport(gDisplayListHead, VIRTUAL_TO_PHYSICAL(&sPrevViewport));
+ gDisplayListHead = saved;
+ }
+
+ gMtxTblSize = 0;
+ sPerspectivePos = NULL;
+ sViewportPos = NULL;
+}
+
/**
* Process a master list node.
*/
@@ -161,9 +205,14 @@ static void geo_process_master_list_sub(struct GraphNodeMasterList *node) {
if ((currList = node->listHeads[i]) != NULL) {
gDPSetRenderMode(gDisplayListHead++, modeList->modes[i], mode2List->modes[i]);
while (currList != NULL) {
- gSPMatrix(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(currList->transform),
+ if ((u32) gMtxTblSize < sizeof(gMtxTbl) / sizeof(gMtxTbl[0])) {
+ gMtxTbl[gMtxTblSize].pos = gDisplayListHead;
+ gMtxTbl[gMtxTblSize].mtx = currList->transform;
+ gMtxTbl[gMtxTblSize++].displayList = currList->displayList;
+ }
+ gSPMatrix(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(currList->transformInterpolated),
G_MTX_MODELVIEW | G_MTX_LOAD | G_MTX_NOPUSH);
- gSPDisplayList(gDisplayListHead++, currList->displayList);
+ gSPDisplayList(gDisplayListHead++, currList->displayListInterpolated);
currList = currList->next;
}
}
@@ -179,7 +228,7 @@ static void geo_process_master_list_sub(struct GraphNodeMasterList *node) {
* parameter. Look at the RenderModeContainer struct to see the corresponding
* render modes of layers.
*/
-static void geo_append_display_list(void *displayList, s16 layer) {
+static void geo_append_display_list2(void *displayList, void *displayListInterpolated, s16 layer) {
#ifdef F3DEX_GBI_2
gSPLookAt(gDisplayListHead++, &lookAt);
@@ -189,7 +238,9 @@ static void geo_append_display_list(void *displayList, s16 layer) {
alloc_only_pool_alloc(gDisplayListHeap, sizeof(struct DisplayListNode));
listNode->transform = gMatStackFixed[gMatStackIndex];
+ listNode->transformInterpolated = gMatStackInterpolatedFixed[gMatStackIndex];
listNode->displayList = displayList;
+ listNode->displayListInterpolated = displayListInterpolated;
listNode->next = 0;
if (gCurGraphNodeMasterList->listHeads[layer] == 0) {
gCurGraphNodeMasterList->listHeads[layer] = listNode;
@@ -200,6 +251,10 @@ static void geo_append_display_list(void *displayList, s16 layer) {