-
Notifications
You must be signed in to change notification settings - Fork 3
/
ext_bounds_col_patches.patch
4368 lines (4142 loc) · 168 KB
/
ext_bounds_col_patches.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/data/behavior_data.c b/data/behavior_data.c
index 17d3adb..0d1cc8c 100644
--- a/data/behavior_data.c
+++ b/data/behavior_data.c
@@ -5546,7 +5546,11 @@ const BehaviorScript bhvTTCPendulum[] = {
const BehaviorScript bhvTTCTreadmill[] = {
BEGIN(OBJ_LIST_SURFACE),
+#ifdef PLATFORM_DISPLACEMENT_2
+ OR_INT(oFlags, (OBJ_FLAG_COMPUTE_DIST_TO_MARIO | OBJ_FLAG_UPDATE_GFX_POS_AND_ANGLE | OBJ_FLAG_VELOCITY_PLATFORM)),
+#else
OR_INT(oFlags, (OBJ_FLAG_COMPUTE_DIST_TO_MARIO | OBJ_FLAG_UPDATE_GFX_POS_AND_ANGLE)),
+#endif
SET_FLOAT(oCollisionDistance, 750),
CALL_NATIVE(bhv_ttc_treadmill_init),
DELAY(1),
diff --git a/include/config.h b/include/config.h
index a34d9c1..d832e11 100644
--- a/include/config.h
+++ b/include/config.h
@@ -11,6 +11,9 @@
// Qol Defines
#include "qol_defines.h"
+// Ext bounds
+#include "src/engine/extended_bounds.h"
+
// Bug Fixes
// --| Post-JP Version Nintendo Bug Fixes
/// Fixes bug where obtaining over 999 coins sets the number of lives to 999 (or -25)
diff --git a/include/object_constants.h b/include/object_constants.h
index 9f5e8c6..5d60ad0 100644
--- a/include/object_constants.h
+++ b/include/object_constants.h
@@ -43,7 +43,7 @@
#define OBJ_FLAG_1000 (1 << 12) // 0x00001000
#define OBJ_FLAG_COMPUTE_ANGLE_TO_MARIO (1 << 13) // 0x00002000
#define OBJ_FLAG_PERSISTENT_RESPAWN (1 << 14) // 0x00004000
-#define OBJ_FLAG_8000 (1 << 15) // 0x00008000
+#define OBJ_FLAG_VELOCITY_PLATFORM (1 << 15) // 0x00008000 - Used in PLATFORM_DISPLACEMENT_2
#define OBJ_FLAG_DONT_CALC_COLL_DIST (1 << 16) // 0x00010000 - Used in QOL_FEATURES
#define OBJ_FLAG_30 (1 << 30) // 0x40000000
diff --git a/include/sm64.h b/include/sm64.h
index 75de983..ccb753e 100644
--- a/include/sm64.h
+++ b/include/sm64.h
@@ -88,6 +88,7 @@ int strcmp(char *s, char *t);
#define AIR_STEP_GRABBED_LEDGE 3
#define AIR_STEP_GRABBED_CEILING 4
#define AIR_STEP_HIT_LAVA_WALL 6
+#define AIR_STEP_HIT_CEILING 8
#define WATER_STEP_NONE 0
#define WATER_STEP_HIT_FLOOR 1
diff --git a/include/surface_terrains.h b/include/surface_terrains.h
index f555d5b..000a62e 100644
--- a/include/surface_terrains.h
+++ b/include/surface_terrains.h
@@ -4,6 +4,8 @@
// Surface Types
#define SURFACE_DEFAULT 0x0000 // Environment default
#define SURFACE_BURNING 0x0001 // Lava / Frostbite (in SL), but is used mostly for Lava
+#define SURFACE_NEW_WATER 0x0002 // Custom water surface
+#define SURFACE_NEW_WATER_BOTTOM 0x0003 // Custom water surface bottom marker
#define SURFACE_0004 0x0004 // Unused, has no function and has parameters
#define SURFACE_HANGABLE 0x0005 // Ceiling that Mario can climb on
#define SURFACE_SLOW 0x0009 // Slow down Mario, unused
diff --git a/include/types.h b/include/types.h
index c44e154..db1e12a 100644
--- a/include/types.h
+++ b/include/types.h
@@ -334,6 +334,9 @@ struct MarioState {
/*0xBC*/ f32 peakHeight;
/*0xC0*/ f32 quicksandDepth;
/*0xC4*/ f32 unkC4;
+#ifdef CENTERED_COLLISION
+ f32 midY;
+#endif
#ifdef PORT_MOP_OBJS
/*0xd4*/ u8 SelFallDmg; //For certain objects I don't want fall damage ever
#endif
diff --git a/src/engine/extended_bounds.h b/src/engine/extended_bounds.h
new file mode 100644
index 0000000..764ca4a
--- /dev/null
+++ b/src/engine/extended_bounds.h
@@ -0,0 +1,212 @@
+#ifndef EXTENDED_BOUNDS_H
+#define EXTENDED_BOUNDS_H
+
+/*
+ Better Extended Bounds + Collsion Patches
+ Thanks to anonymous_moose for the original Better Extended Bounds patch
+ Thanks to someone2639 for the shiftable segments patch
+ Thanks to Wiseguy for the Surface Pool Full error code and 4x bounds fix
+ Thanks to FramePerfection/chaosBrick for the wall collision rewrite
+ Thanks to Arthurtilly for the platform displacement rewrite
+ Thanks to falcobuster for the long render distance fix
+ Thanks to JoshDuman, Kaze, Arceveti and various people for the QoL collision code changes
+ Patch compilated by AloXado320
+
+ 0: Regular bounds
+ Same as vanilla sm64, boundaries are (-8192 to 8191)
+ 16x16 collision cells.
+ 1: Regular bounds (performance)
+ Same boundaries as vanilla (-8192 to 8191), but with twice the amount of collision cells
+ Trades more RAM usage for faster collision calculations.
+ 2: 2x extended bounds
+ level boundaries are twice as big (-16384 to 16383)
+ Collision calculations remain as fast as vanilla, at the cost of using more RAM.
+ 32x32 collision cells.
+ 3: 4x extended bounds
+ level boundaries are 4 times as big (-32768 to 32767)
+ Collision calculations remain as fast as vanilla, at the cost of using far more RAM (16 times vanilla).
+ 64x64 collision cells.
+ 4: 4x extended bounds (Memory saver)
+ level boundaries are 4 times as big (-32768 to 32767)
+ Collision cells are the same size as vanilla, at the cost of being much slower.
+ 32x32 collision cells.
+
+ If you see "SURFACE POOL FULL" or "SURFACE NODE POOL FULL" in game, you should increase
+ SURFACE_POOL_SIZE or SURFACE_NODE_POOL_SIZE, respectively, or reduce the amount of
+ collision surfaces in your level.
+*/
+
+//set this to the extended bounds mode you want, then do "make clean".
+#define EXTENDED_BOUNDS_MODE 3
+
+// Coordinate overflow fix by falcobuster (World Scale).
+// Your levels will render correctly on console and LLE emulators
+// even when using 2x or 4x bounds, while not hurting anything on HLE plugins.
+
+// SURFACE_POOL_SIZE and SURFACE_NODE_POOL_SIZE only matter on N64
+// On non-N64 targets, surface sizes are allocated using SYSTEM_MALLOC
+// If SYSTEM_MALLOC is not defined on PC Port, then fixed pools are used instead
+
+// SURFACE_POOL_SIZE
+// The maximum amount of collision surfaces (static and dynamic combined)
+// The vanilla value is 2300
+
+// SURFACE_NODE_POOL_SIZE
+// Make this approximately (amount of collision cells) + (SURFACE_POOL_SIZE * 3)
+// The vanilla value is 7000
+
+// Cell and height limits
+// Default cell/floor limit is 20000/-11000 respectively
+#define CELL_HEIGHT_LIMIT 20000
+#define FLOOR_LOWER_LIMIT -11000
+#define FLOOR_LOWER_LIMIT_MISC (FLOOR_LOWER_LIMIT + 1000)
+#define FLOOR_LOWER_LIMIT_SHADOW FLOOR_LOWER_LIMIT_MISC
+
+/* Miscellaneous Tweaks */
+
+// Show ingame text info if any surface pool is full (N64 and Non-sys malloc only)
+#ifndef SYSTEM_MALLOC
+#define SURFACE_POOLS_FULL_MESSAGES
+
+#ifdef SURFACE_POOLS_FULL_MESSAGES
+// Sanity checks if pool gets past the size
+#define NOT_ENOUGH_ROOM_FOR_SURFACES (1 << 0)
+#define NOT_ENOUGH_ROOM_FOR_NODES (1 << 1)
+#endif
+
+#endif
+
+// Set vanilla camera course specific functions
+#define CAMERA_SPECIFIC_FUNCTION_DEFINES
+
+// Platform displacement 2 also known as momentum patch.
+// Makes Mario keep the momemtum from moving platforms.
+// Doesn't break treadmills anymore!
+// (Arthurtilly, HackerSM64)
+#define PLATFORM_DISPLACEMENT_2
+
+// Water surfaces (Thecozies)
+#define NEW_WATER_SURFACES
+
+// Improved wall collision detection, with rounded corners
+// Fixes Mario jittering when walking into multiple walls at once
+// (frameperfection/Frame#5375)
+#define BETTER_WALL_COLLISION
+
+// Ceiling margin from BWC
+// (frameperfection/Frame#5375)
+#define CEILING_MARGINS
+
+// For static floor checks only
+#define FIND_FLOOR_EXCLUDE_DYNAMIC_CHECK
+
+// Push Mario out of sloped ceilings instead of stopping or bonking
+// helps prevent unwanted bonks and softlocks
+// (Arceveti)
+#define BETTER_CEILING_HANDLING
+
+// Properly fixes false ledge grabs
+// Does nothing if BETTER_WALL_COLLISION is enabled.
+// (Arceveti)
+#define FIX_LEDGE_GRABS
+
+// Experimental: Automatic World Scale
+//#define AUTOMATIC_WORLD_SCALE
+
+// Check for floors/ceilings from halfway up Mario's hitbox rather than from the bottom
+// (Arceveti)
+#define CENTERED_COLLISION
+
+#ifdef CENTERED_COLLISION
+// Step height for objects. Comment out the define to use vanilla behavior. (Arceveti)
+#define OBJ_STEP_HEIGHT 40.0f
+#endif
+
+// Maximum number of walls to check (vanilla is 4, higher is recommended)
+#define MAX_REFEREMCED_WALLS 16
+
+// Include steep floors when checking for walls when underwater
+// This fixes the weirdness caused by swimming into such slopes (as seen with the JRB pillars in vanilla)
+// May cause performance issues when underwater due to also iterating through the floors partition
+// in addition to the regular walls partition when checking wall collisions.
+// (Arceveti)
+#define UNDERWATER_STEEP_FLOORS_AS_WALLS
+#define MIN_UNDERWATER_FLOOR_NORMAL_Y 0.1f
+
+// Minimum Y normal for floors (vanilla is 0.01f)
+#define MIN_FLOOR_NORMAL_Y 0.02f
+
+// Minimum Y normal for ceilings (vanilla is -0.01f, -0.2f is recommended)
+#define MAX_CEIL_NORMAL_Y -0.2f
+
+// Number of null floors to check ahead through during a qstep.
+// Fixes many instances of invisible walls but may cause minor
+// issues on actual level boundaries, such as extra knockback
+// (Arceveti)
+#define NULL_FLOOR_STEPS 4
+
+// Number of swimming steps per frame (Vanilla is 1)
+#define WATER_NUM_STEPS 4
+
+// Number of ground steps per frame (Vanilla is 4)
+#define GROUND_NUM_STEPS 4
+
+// Number of air steps per frame (Vanilla is 4)
+#define AIR_NUM_STEPS 4
+
+/* Don't touch the stuff past this point unless you know what you're doing! */
+
+// Default value to check if the user set a proper extended bounds mode
+#define LEVEL_BOUNDARY_MAX 0x0000
+
+// Scales the world down by this factor, increasing how far you can render on
+// console (and PC) in exchange for a slight loss in precision.
+#define WORLD_SCALE 1.0f
+
+#if EXTENDED_BOUNDS_MODE == 0 // Vanilla
+ #undef LEVEL_BOUNDARY_MAX // Undefine the old value to avoid compiler warnings
+ #undef WORLD_SCALE
+ #define LEVEL_BOUNDARY_MAX 0x2000L
+ #define CELL_SIZE 0x400
+ #define SURFACE_POOL_SIZE 4000
+ #define SURFACE_NODE_POOL_SIZE 12000
+ #define WORLD_SCALE 1.0f
+ #define
+#elif EXTENDED_BOUNDS_MODE == 1 // Vanilla size with performance but more RAM usage
+ #undef LEVEL_BOUNDARY_MAX
+ #undef WORLD_SCALE
+ #define LEVEL_BOUNDARY_MAX 0x2000L
+ #define CELL_SIZE 0x200
+ #define SURFACE_POOL_SIZE 4000
+ #define SURFACE_NODE_POOL_SIZE 16000
+ #define WORLD_SCALE 1.0f
+#elif EXTENDED_BOUNDS_MODE == 2 // 2x bounds
+ #undef LEVEL_BOUNDARY_MAX
+ #undef WORLD_SCALE
+ #define LEVEL_BOUNDARY_MAX 0x4000L
+ #define CELL_SIZE 0x400
+ #define SURFACE_POOL_SIZE 8200
+ #define SURFACE_NODE_POOL_SIZE 22000
+ #define WORLD_SCALE 2.0f
+#elif EXTENDED_BOUNDS_MODE == 3 // 4x bounds
+ #undef LEVEL_BOUNDARY_MAX
+ #undef WORLD_SCALE
+ #define LEVEL_BOUNDARY_MAX 0x8000L
+ #define CELL_SIZE 0x400
+ #define SURFACE_POOL_SIZE 8200
+ #define SURFACE_NODE_POOL_SIZE 24600
+ #define WORLD_SCALE 4.0f
+#elif EXTENDED_BOUNDS_MODE == 4 // 4x bounds with big cells (similar to old ext bounds)
+ #undef LEVEL_BOUNDARY_MAX
+ #undef WORLD_SCALE
+ #define LEVEL_BOUNDARY_MAX 0x8000L
+ #define CELL_SIZE 0x800
+ #define SURFACE_POOL_SIZE 8200
+ #define SURFACE_NODE_POOL_SIZE 20600
+ #define WORLD_SCALE 4.0f
+#endif
+
+#define NUM_CELLS (2 * LEVEL_BOUNDARY_MAX / CELL_SIZE)
+#define NUM_CELLS_INDEX (NUM_CELLS - 1)
+
+#endif // EXTENDED_BOUNDS_H
diff --git a/src/engine/math_util.c b/src/engine/math_util.c
index 378a54f..de952b0 100644
--- a/src/engine/math_util.c
+++ b/src/engine/math_util.c
@@ -4,7 +4,7 @@
#include "engine/graph_node.h"
#include "math_util.h"
#include "surface_collision.h"
-
+#include "game/rendering_graph_node.h"
#include "trig_tables.inc.c"
// Variables for a spline curve animation (used for the flight path in the grand star cutscene)
@@ -630,22 +630,19 @@ void mtxf_mul_vec3s(Mat4 mtx, Vec3s b) {
* and no crashes occur.
*/
void mtxf_to_mtx(Mtx *dest, Mat4 src) {
-#ifdef AVOID_UB
- // Avoid type-casting which is technically UB by calling the equivalent
- // guMtxF2L function. This helps little-endian systems, as well.
- guMtxF2L(src, dest);
+#if EXTENDED_BOUNDS_MODE > 1
+ Mat4 temp;
+ register s32 i, j;
+ for( i = 0; i < 4; i++ ) {
+ for( j = 0; j < 3; j++ ) {
+ temp[i][j] = src[i][j] / gWorldScale;
+ }
+ temp[i][3] = src[i][3];
+ }
+
+ guMtxF2L(temp, dest);
#else
- s32 asFixedPoint;
- register s32 i;
- register s16 *a3 = (s16 *) dest; // all integer parts stored in first 16 bytes
- register s16 *t0 = (s16 *) dest + 16; // all fraction parts stored in last 16 bytes
- register f32 *t1 = (f32 *) src;
-
- for (i = 0; i < 16; i++) {
- asFixedPoint = *t1++ * (1 << 16); //! float-to-integer conversion responsible for PU crashes
- *a3++ = GET_HIGH_S16_OF_32(asFixedPoint); // integer part
- *t0++ = GET_LOW_S16_OF_32(asFixedPoint); // fraction part
- }
+ guMtxF2L(temp, dest);
#endif
}
diff --git a/src/engine/surface_collision.c b/src/engine/surface_collision.c
index 46b2385..3472fff 100644
--- a/src/engine/surface_collision.c
+++ b/src/engine/surface_collision.c
@@ -5,6 +5,7 @@
#include "game/level_update.h"
#include "game/mario.h"
#include "game/object_list_processor.h"
+#include "game/rendering_graph_node.h"
#include "surface_collision.h"
#include "surface_load.h"
#include "math_util.h"
@@ -13,149 +14,274 @@
#include "extras/cheats.h"
#endif
+// moved from extended_bounds.h to here since STATIC_ASSERT makes sense in a C file
+STATIC_ASSERT(LEVEL_BOUNDARY_MAX != 0, "You must set a valid extended bounds mode!");
+
/**************************************************
* WALLS *
**************************************************/
+static u32 is_outside_level_bounds(f32 x, f32 z) {
+ return ((x <= -LEVEL_BOUNDARY_MAX)
+ || (x >= LEVEL_BOUNDARY_MAX)
+ || (z <= -LEVEL_BOUNDARY_MAX)
+ || (z >= LEVEL_BOUNDARY_MAX));
+}
+
+/*
+void move_towards_wall(struct MarioState *m, f32 amount) {
+ m->vel[0] += (m->wall->normal.x * amount);
+ m->vel[1] += (m->wall->normal.y * amount);
+ m->vel[2] += (m->wall->normal.z * amount);
+}
+*/
+
/**
* Iterate through the list of walls until all walls are checked and
* have given their wall push.
*/
+#ifdef BETTER_WALL_COLLISION
static s32 find_wall_collisions_from_list(struct SurfaceNode *surfaceNode, struct WallCollisionData *data) {
+ const f32 corner_threshold = (-0.9f);
register struct Surface *surf;
register f32 offset;
register f32 radius = data->radius;
- register f32 x = data->x;
- register f32 y = data->y + data->offsetY;
- register f32 z = data->z;
- register f32 px, pz;
- register f32 w1, w2, w3;
- register f32 y1, y2, y3;
+ register f32 x = data->x;
+ register f32 y = (data->y + data->offsetY);
+ register f32 z = data->z;
+ register f32 v0x, v0y, v0z;
+ register f32 v1x, v1y, v1z;
+ register f32 v2x, v2y, v2z;
+ register f32 d00, d01, d11, d20, d21;
+ register f32 invDenom;
+ register f32 v, w;
+ register f32 margin_radius = (radius - 1.0f);
+ register s16 type = SURFACE_DEFAULT;
s32 numCols = 0;
-
+ //#if EXTENDED_BOUNDS_MODE > 1
+ // const float down_scale = (1.0f / gWorldScale);
+ // radius *= down_scale;
+ // x *= down_scale;
+ // y *= down_scale;
+ // z *= down_scale;
+ // margin_radius *= down_scale;
+ //#endif
// Max collision radius = 200
- if (radius > 200.0f) {
- radius = 200.0f;
- }
-
+ if (radius > 200.0f) radius = 200.0f;
// Stay in this loop until out of walls.
while (surfaceNode != NULL) {
- surf = surfaceNode->surface;
+ surf = surfaceNode->surface;
surfaceNode = surfaceNode->next;
-
+ type = surf->type;
// Exclude a large number of walls immediately to optimize.
- if (y < surf->lowerY || y > surf->upperY) {
- continue;
+ #ifdef NEW_WATER_SURFACES
+ if ((type == SURFACE_NEW_WATER) || (type == SURFACE_NEW_WATER_BOTTOM)) continue;
+ #endif
+ // Determine if checking for the camera or not.
+ if (gCheckingSurfaceCollisionsForCamera) {
+ if (surf->flags & SURFACE_FLAG_NO_CAM_COLLISION) continue;
+ } else {
+ // Ignore camera only surfaces.
+ if (type == SURFACE_CAMERA_BOUNDARY) continue;
+ // If an object can pass through a vanish cap wall, pass through.
+ if ((type == SURFACE_VANISH_CAP_WALLS) && (gCurrentObject != NULL)) {
+ // If an object can pass through a vanish cap wall, pass through.
+ if (gCurrentObject->activeFlags & ACTIVE_FLAG_MOVE_THROUGH_GRATE) continue;
+ // If Mario has a vanish cap, pass through the vanish cap wall.
+ if ((gCurrentObject == gMarioObject) && (gMarioState->flags & MARIO_VANISH_CAP)) continue;
+ }
}
-
- offset = surf->normal.x * x + surf->normal.y * y + surf->normal.z * z + surf->originOffset;
-
- if (offset < -radius || offset > radius) {
- continue;
+ if ((y < surf->lowerY) || (y > surf->upperY)) continue;
+ #ifdef UNDERWATER_STEEP_FLOORS_AS_WALLS
+ if (gIncludeSteepFloorsInWallCollisionCheck && (surf->normal.y > MIN_UNDERWATER_FLOOR_NORMAL_Y)) continue;
+ #endif
+ // Dot of normal and pos, + originOffset
+ offset = ((surf->normal.x * x) + (surf->normal.y * y) + (surf->normal.z * z) + surf->originOffset);
+ if ((offset < -radius) || (offset > radius)) continue;
+ v0x = (f32)(surf->vertex2[0] - surf->vertex1[0]);
+ v0y = (f32)(surf->vertex2[1] - surf->vertex1[1]);
+ v0z = (f32)(surf->vertex2[2] - surf->vertex1[2]);
+ v1x = (f32)(surf->vertex3[0] - surf->vertex1[0]);
+ v1y = (f32)(surf->vertex3[1] - surf->vertex1[1]);
+ v1z = (f32)(surf->vertex3[2] - surf->vertex1[2]);
+ v2x = x - (f32)surf->vertex1[0];
+ v2y = y - (f32)surf->vertex1[1];
+ v2z = z - (f32)surf->vertex1[2];
+ // Face
+ d00 = ( sqr(v0x) + sqr(v0y) + sqr(v0z));
+ d01 = ((v0x * v1x) + (v0y * v1y) + (v0z * v1z));
+ d11 = ( sqr(v1x) + sqr(v1y) + sqr(v1z));
+ d20 = ((v2x * v0x) + (v2y * v0y) + (v2z * v0z));
+ d21 = ((v2x * v1x) + (v2y * v1y) + (v2z * v1z));
+ invDenom = (1.0f / ((d00 * d11) - (d01 * d01)));
+ v = (((d11 * d20) - (d01 * d21)) * invDenom);
+ if ((v < 0.0f) || (v > 1.0f)) goto edge_1_2;
+ w = (((d00 * d21) - (d01 * d20)) * invDenom);
+ if ((w < 0.0f) || (w > 1.0f) || ((v + w) > 1.0f)) goto edge_1_2;
+ x += (surf->normal.x * (radius - offset));
+ z += (surf->normal.z * (radius - offset));
+ goto hasCollision;
+ edge_1_2:
+ if (offset < 0) continue;
+ // Edge 1-2
+ if (v0y != 0.0f) {
+ v = (v2y / v0y);
+ if ((v < 0.0f) || (v > 1.0f)) goto edge_1_3;
+ d00 = ((v0x * v) - v2x);
+ d01 = ((v0z * v) - v2z);
+ invDenom = sqrtf(sqr(d00) + sqr(d01));
+ offset = (invDenom - margin_radius);
+ if (offset > 0.0f) goto edge_1_3;
+ invDenom = (offset / invDenom);
+ x += (d00 *= invDenom);
+ z += (d01 *= invDenom);
+ margin_radius += 0.01f;
+ if ((d00 * surf->normal.x) + (d01 * surf->normal.z) < (corner_threshold * offset)) {
+ continue;
+ } else {
+ goto hasCollision;
+ }
}
-
- px = x;
- pz = z;
-
- //! (Quantum Tunneling) Due to issues with the vertices walls choose and
- // the fact they are floating point, certain floating point positions
- // along the seam of two walls may collide with neither wall or both walls.
- if (surf->flags & SURFACE_FLAG_X_PROJECTION) {
- w1 = -surf->vertex1[2]; w2 = -surf->vertex2[2]; w3 = -surf->vertex3[2];
- y1 = surf->vertex1[1]; y2 = surf->vertex2[1]; y3 = surf->vertex3[1];
-
- if (surf->normal.x > 0.0f) {
- if ((y1 - y) * (w2 - w1) - (w1 - -pz) * (y2 - y1) > 0.0f) {
- continue;
- }
- if ((y2 - y) * (w3 - w2) - (w2 - -pz) * (y3 - y2) > 0.0f) {
- continue;
- }
- if ((y3 - y) * (w1 - w3) - (w3 - -pz) * (y1 - y3) > 0.0f) {
- continue;
- }
+ edge_1_3:
+ // Edge 1-3
+ if (v1y != 0.0f) {
+ v = (v2y / v1y);
+ if ((v < 0.0f) || (v > 1.0f)) goto edge_2_3;
+ d00 = ((v1x * v) - v2x);
+ d01 = ((v1z * v) - v2z);
+ invDenom = sqrtf(sqr(d00) + sqr(d01));
+ offset = (invDenom - margin_radius);
+ if (offset > 0.0f) goto edge_2_3;
+ invDenom = (offset / invDenom);
+ x += (d00 *= invDenom);
+ z += (d01 *= invDenom);
+ margin_radius += 0.01f;
+ if ((d00 * surf->normal.x) + (d01 * surf->normal.z) < (corner_threshold * offset)) {
+ continue;
} else {
- if ((y1 - y) * (w2 - w1) - (w1 - -pz) * (y2 - y1) < 0.0f) {
- continue;
- }
- if ((y2 - y) * (w3 - w2) - (w2 - -pz) * (y3 - y2) < 0.0f) {
- continue;
- }
- if ((y3 - y) * (w1 - w3) - (w3 - -pz) * (y1 - y3) < 0.0f) {
- continue;
- }
+ goto hasCollision;
}
- } else {
- w1 = surf->vertex1[0]; w2 = surf->vertex2[0]; w3 = surf->vertex3[0];
- y1 = surf->vertex1[1]; y2 = surf->vertex2[1]; y3 = surf->vertex3[1];
-
- if (surf->normal.z > 0.0f) {
- if ((y1 - y) * (w2 - w1) - (w1 - px) * (y2 - y1) > 0.0f) {
- continue;
- }
- if ((y2 - y) * (w3 - w2) - (w2 - px) * (y3 - y2) > 0.0f) {
- continue;
- }
- if ((y3 - y) * (w1 - w3) - (w3 - px) * (y1 - y3) > 0.0f) {
- continue;
- }
+ }
+ edge_2_3:
+ // Edge 2-3
+ v1x = (f32)(surf->vertex3[0] - surf->vertex2[0]);
+ v1y = (f32)(surf->vertex3[1] - surf->vertex2[1]);
+ v1z = (f32)(surf->vertex3[2] - surf->vertex2[2]);
+ v2x = x - (f32)surf->vertex2[0];
+ v2y = y - (f32)surf->vertex2[1];
+ v2z = z - (f32)surf->vertex2[2];
+ if (v1y != 0.0f) {
+ v = (v2y / v1y);
+ if ((v < 0.0f) || (v > 1.0f)) continue;
+ d00 = ((v1x * v) - v2x);
+ d01 = ((v1z * v) - v2z);
+ invDenom = sqrtf(sqr(d00) + sqr(d01));
+ offset = (invDenom - margin_radius);
+ if (offset > 0.0f) continue;
+ invDenom = (offset / invDenom);
+ x += (d00 *= invDenom);
+ z += (d01 *= invDenom);
+ margin_radius += 0.01f;
+ if ((d00 * surf->normal.x) + (d01 * surf->normal.z) < (corner_threshold * offset)) {
+ continue;
} else {
- if ((y1 - y) * (w2 - w1) - (w1 - px) * (y2 - y1) < 0.0f) {
- continue;
- }
- if ((y2 - y) * (w3 - w2) - (w2 - px) * (y3 - y2) < 0.0f) {
- continue;
- }
- if ((y3 - y) * (w1 - w3) - (w3 - px) * (y1 - y3) < 0.0f) {
- continue;
- }
+ goto hasCollision;
}
+ } else {
+ continue;
}
+ hasCollision:
+ if (data->numWalls < MAX_REFEREMCED_WALLS) data->walls[data->numWalls++] = surf;
+ numCols++;
+ }
+ //#if EXTENDED_BOUNDS_MODE > 1
+ // x *= gWorldScale;
+ // y *= gWorldScale;
+ // z *= gWorldScale;
+ //#endif
+ data->x = x;
+ data->z = z;
+ return numCols;
+}
+#else
+static s32 find_wall_collisions_from_list(struct SurfaceNode *surfaceNode, struct WallCollisionData *data) {
+ register struct Surface *surf;
+ register f32 offset;
+ register f32 radius = data->radius;
+ // these are f32 in vanilla
+ register s32 x = data->x;
+ register s32 y = (data->y + data->offsetY);
+ register s32 z = data->z;
+ register s32 w1, w2, w3;
+ register s32 y1, y2, y3;
+ s32 numCols = 0;
+ s16 type = SURFACE_DEFAULT;
+ // Max collision radius = 200
+ if (radius > 200.0f) radius = 200.0f;
+ // Stay in this loop until out of walls.
+ while (surfaceNode != NULL) {
+ surf = surfaceNode->surface;
+ surfaceNode = surfaceNode->next;
+ type = surf->type;
+ #ifdef NEW_WATER_SURFACES
+ if ((type == SURFACE_NEW_WATER) || (type == SURFACE_NEW_WATER_BOTTOM)) continue;
+ #endif
// Determine if checking for the camera or not.
if (gCheckingSurfaceCollisionsForCamera) {
- if (surf->flags & SURFACE_FLAG_NO_CAM_COLLISION) {
- continue;
- }
+ if (surf->flags & SURFACE_FLAG_NO_CAM_COLLISION) continue;
} else {
// Ignore camera only surfaces.
- if (surf->type == SURFACE_CAMERA_BOUNDARY) {
- continue;
- }
-
+ if (type == SURFACE_CAMERA_BOUNDARY) continue;
// If an object can pass through a vanish cap wall, pass through.
- if (surf->type == SURFACE_VANISH_CAP_WALLS) {
+ if ((type == SURFACE_VANISH_CAP_WALLS) && (gCurrentObject != NULL)) {
// If an object can pass through a vanish cap wall, pass through.
- if (gCurrentObject != NULL
- && (gCurrentObject->activeFlags & ACTIVE_FLAG_MOVE_THROUGH_GRATE)) {
- continue;
- }
-
+ if (gCurrentObject->activeFlags & ACTIVE_FLAG_MOVE_THROUGH_GRATE) continue;
// If Mario has a vanish cap, pass through the vanish cap wall.
- if (gCurrentObject != NULL && gCurrentObject == gMarioObject
- && (gMarioState->flags & MARIO_VANISH_CAP)) {
- continue;
- }
+ if ((gCurrentObject == gMarioObject) && (gMarioState->flags & MARIO_VANISH_CAP)) continue;
}
}
-
- //! (Wall Overlaps) Because this doesn't update the x and z local variables,
- // multiple walls can push mario more than is required.
- data->x += surf->normal.x * (radius - offset);
- data->z += surf->normal.z * (radius - offset);
-
- //! (Unreferenced Walls) Since this only returns the first four walls,
- // this can lead to wall interaction being missed. Typically unreferenced walls
- // come from only using one wall, however.
- if (data->numWalls < 4) {
- data->walls[data->numWalls++] = surf;
+ if ((y < surf->lowerY) || (y > surf->upperY)) continue;
+ // Exclude a large number of walls immediately to optimize.
+ offset = ((surf->normal.x * x) + (surf->normal.y * y) + (surf->normal.z * z) + surf->originOffset);
+ if ((offset < -radius) || (offset > radius)) continue;
+ // (Quantum Tunneling) Due to issues with the vertices walls choose
+ // and the fact they are floating point, certain floating point positions
+ // along the seam of two walls may collide with neither wall or both walls.
+ y1 = surf->vertex1[1]; y2 = surf->vertex2[1]; y3 = surf->vertex3[1];
+ if (surf->flags & SURFACE_FLAG_X_PROJECTION) {
+ w1 = -surf->vertex1[2]; w2 = -surf->vertex2[2]; w3 = -surf->vertex3[2];
+ if (surf->normal.x > 0.0f) {
+ if (((y1 - y) * (w2 - w1)) - ((w1 - -z) * (y2 - y1)) > 0) continue;
+ if (((y2 - y) * (w3 - w2)) - ((w2 - -z) * (y3 - y2)) > 0) continue;
+ if (((y3 - y) * (w1 - w3)) - ((w3 - -z) * (y1 - y3)) > 0) continue;
+ } else {
+ if (((y1 - y) * (w2 - w1)) - ((w1 - -z) * (y2 - y1)) < 0) continue;
+ if (((y2 - y) * (w3 - w2)) - ((w2 - -z) * (y3 - y2)) < 0) continue;
+ if (((y3 - y) * (w1 - w3)) - ((w3 - -z) * (y1 - y3)) < 0) continue;
+ }
+ } else {
+ w1 = surf->vertex1[0]; w2 = surf->vertex2[0]; w3 = surf->vertex3[0];
+ if (surf->normal.z > 0.0f) {
+ if (((y1 - y) * (w2 - w1)) - ((w1 - x) * (y2 - y1)) > 0) continue;
+ if (((y2 - y) * (w3 - w2)) - ((w2 - x) * (y3 - y2)) > 0) continue;
+ if (((y3 - y) * (w1 - w3)) - ((w3 - x) * (y1 - y3)) > 0) continue;
+ } else {
+ if (((y1 - y) * (w2 - w1)) - ((w1 - x) * (y2 - y1)) < 0) continue;
+ if (((y2 - y) * (w3 - w2)) - ((w2 - x) * (y3 - y2)) < 0) continue;
+ if (((y3 - y) * (w1 - w3)) - ((w3 - x) * (y1 - y3)) < 0) continue;
+ }
}
-
+ x += (surf->normal.x * (radius - offset));
+ z += (surf->normal.z * (radius - offset));
+ data->x = x;
+ data->z = z;
+ if (data->numWalls < MAX_REFEREMCED_WALLS) data->walls[data->numWalls++] = surf;
numCols++;
}
-
return numCols;
}
+#endif
/**
* Formats the position and wall search for find_wall_collisions.
@@ -187,33 +313,34 @@ s32 f32_find_wall_collision(f32 *xPtr, f32 *yPtr, f32 *zPtr, f32 offsetY, f32 ra
*/
s32 find_wall_collisions(struct WallCollisionData *colData) {
struct SurfaceNode *node;
- s16 cellX, cellZ;
s32 numCollisions = 0;
- s16 x = colData->x;
- s16 z = colData->z;
+ s32 x = colData->x;
+ s32 z = colData->z;
colData->numWalls = 0;
- if (x <= -LEVEL_BOUNDARY_MAX || x >= LEVEL_BOUNDARY_MAX) {
- return numCollisions;
- }
- if (z <= -LEVEL_BOUNDARY_MAX || z >= LEVEL_BOUNDARY_MAX) {
- return numCollisions;
- }
+ if (is_outside_level_bounds(x, z)) return numCollisions;
// World (level) consists of a 16x16 grid. Find where the collision is on
// the grid (round toward -inf)
- cellX = ((x + LEVEL_BOUNDARY_MAX) / CELL_SIZE) & NUM_CELLS_INDEX;
- cellZ = ((z + LEVEL_BOUNDARY_MAX) / CELL_SIZE) & NUM_CELLS_INDEX;
-
+ register const s32 cellX = (((x + LEVEL_BOUNDARY_MAX) / CELL_SIZE) & NUM_CELLS_INDEX);
+ register const s32 cellZ = (((z + LEVEL_BOUNDARY_MAX) / CELL_SIZE) & NUM_CELLS_INDEX);
// Check for surfaces belonging to objects.
node = gDynamicSurfacePartition[cellZ][cellX][SPATIAL_PARTITION_WALLS].next;
numCollisions += find_wall_collisions_from_list(node, colData);
-
// Check for surfaces that are a part of level geometry.
node = gStaticSurfacePartition[cellZ][cellX][SPATIAL_PARTITION_WALLS].next;
numCollisions += find_wall_collisions_from_list(node, colData);
-
+#ifdef UNDERWATER_STEEP_FLOORS_AS_WALLS
+ if (gIncludeSteepFloorsInWallCollisionCheck) {
+ // Check for surfaces belonging to objects.
+ node = gDynamicSurfacePartition[cellZ][cellX][SPATIAL_PARTITION_FLOORS].next;
+ numCollisions += find_wall_collisions_from_list(node, colData);
+ // Check for surfaces that are a part of level geometry.
+ node = gStaticSurfacePartition[cellZ][cellX][SPATIAL_PARTITION_FLOORS].next;
+ numCollisions += find_wall_collisions_from_list(node, colData);
+ }
+#endif
// Increment the debug tracker.
gNumCalls.wall++;
@@ -224,134 +351,113 @@ s32 find_wall_collisions(struct WallCollisionData *colData) {
* CEILINGS *
**************************************************/
+// Find the height of the floor at a given location
+static f32 get_surface_height_at_location(s32 x, s32 z, struct Surface *surf) {
+ return -(x * surf->normal.x + surf->normal.z * z + surf->originOffset) / surf->normal.y;
+}
+
+#ifdef CEILING_MARGINS
+void add_ceil_margin(f32 *x, f32 *z, Vec3s target1, Vec3s target2, f32 margin) {
+ register f32 diff_x, diff_z, invDenom;
+ diff_x = target1[0] - *x + target2[0] - *x;
+ diff_z = target1[2] - *z + target2[2] - *z;
+ invDenom = margin / sqrtf(diff_x * diff_x + diff_z * diff_z);
+ *x += diff_x * invDenom;
+ *z += diff_z * invDenom;
+}
+#endif
+
/**
* Iterate through the list of ceilings and find the first ceiling over a given point.
*/
-static struct Surface *find_ceil_from_list(struct SurfaceNode *surfaceNode, s32 x, s32 y, s32 z, f32 *pheight) {
+static struct Surface *find_ceil_from_list(struct SurfaceNode *surfaceNode, f32 x, f32 y, f32 z, f32 *pheight) {
+#ifdef CEILING_MARGINS
+ const f32 margin = 1.5f;
+#endif
register struct Surface *surf;
- register s32 x1, z1, x2, z2, x3, z3;
+ f32 x1, z1, x2, z2, x3, z3;
+ f32 height;
+ s16 type = SURFACE_DEFAULT;
struct Surface *ceil = NULL;
-
- ceil = NULL;
-
+ // *pheight = CELL_HEIGHT_LIMIT;
// Stay in this loop until out of ceilings.
while (surfaceNode != NULL) {
- surf = surfaceNode->surface;
+ surf = surfaceNode->surface;
surfaceNode = surfaceNode->next;
-
+ type = surf->type;
+ // Determine if checking for the camera or not.
+ if (gCheckingSurfaceCollisionsForCamera) {
+ if (surf->flags & SURFACE_FLAG_NO_CAM_COLLISION) continue;
+ // Ignore camera only surfaces.
+ } else if (type == SURFACE_CAMERA_BOUNDARY) {
+ continue;
+ }
+#ifdef NEW_WATER_SURFACES
+ if ((type == SURFACE_NEW_WATER) || (type == SURFACE_NEW_WATER_BOTTOM)) continue;
+#endif
+ // Skip if ceil is too low
+ if (y > surf->upperY) continue;
x1 = surf->vertex1[0];
z1 = surf->vertex1[2];
+#ifdef CEILING_MARGINS
+ if (type != SURFACE_HANGABLE) add_ceil_margin(&x1, &z1, surf->vertex2, surf->vertex3, margin);
+#endif
z2 = surf->vertex2[2];
x2 = surf->vertex2[0];
-
+#ifdef CEILING_MARGINS
+ if (type != SURFACE_HANGABLE) add_ceil_margin(&x2, &z2, surf->vertex3, surf->vertex1, margin);
+#endif
// Checking if point is in bounds of the triangle laterally.
- if ((z1 - z) * (x2 - x1) - (x1 - x) * (z2 - z1) > 0) {
- continue;
- }
-
+ if ((z1 - z) * (x2 - x1) - (x1 - x) * (z2 - z1) > 0) continue;
// Slight optimization by checking these later.
x3 = surf->vertex3[0];
z3 = surf->vertex3[2];
- if ((z2 - z) * (x3 - x2) - (x2 - x) * (z3 - z2) > 0) {
- continue;
- }
- if ((z3 - z) * (x1 - x3) - (x3 - x) * (z1 - z3) > 0) {
- continue;
- }
-
- // Determine if checking for the camera or not.
- if (gCheckingSurfaceCollisionsForCamera != 0) {
- if (surf->flags & SURFACE_FLAG_NO_CAM_COLLISION) {
- continue;
- }
- }
- // Ignore camera only surfaces.
- else if (surf->type == SURFACE_CAMERA_BOUNDARY) {
- continue;
- }
-
- f32 nx = surf->normal.x;
- f32 ny = surf->normal.y;
- f32 nz = surf->normal.z;
- f32 oo = surf->originOffset;
- f32 height;
-
- // If a wall, ignore it. Likely a remnant, should never occur.
- if (ny == 0.0f) {
- continue;
- }
-
+#ifdef CEILING_MARGINS
+ if (type != SURFACE_HANGABLE) add_ceil_margin(&x3, &z3, surf->vertex1, surf->vertex2, margin);
+#endif
+ if ((z2 - z) * (x3 - x2) - (x2 - x) * (z3 - z2) > 0) continue;
+ if ((z3 - z) * (x1 - x3) - (x3 - x) * (z1 - z3) > 0) continue;
// Find the ceil height at the specific point.
- height = -(x * nx + nz * z + oo) / ny;
-
- // Checks for ceiling interaction with a 78 unit buffer.
- //! (Exposed Ceilings) Because any point above a ceiling counts
- // as interacting with a ceiling, ceilings far below can cause
- // "invisible walls" that are really just exposed ceilings.
- if (y - (height - -78.0f) > 0.0f) {
- continue;
- }
-
+ height = get_surface_height_at_location(x, z, surf);
+ if (height >= *pheight) continue;
+ // Checks for ceiling interaction
+ if (y > height ) continue;
+ if (y > surf->upperY) continue;
*pheight = height;
- ceil = surf;
- break;
+ ceil = surf;
+ if (height == y) break;
}
-
- //! (Surface Cucking) Since only the first ceil is returned and not the lowest,
- // lower ceilings can be "cucked" by higher ceilings.
return ceil;
}
/**
* Find the lowest ceiling above a given position and return the height.
*/
-f32 find_ceil(f32 posX, f32 posY, f32 posZ, struct Surface **pceil) {
- s16 cellZ, cellX;
-
+f32 find_ceil(f32 x, f32 y, f32 z, struct Surface **pceil) {
struct Surface *ceil, *dynamicCeil;
struct SurfaceNode *surfaceList;
-
- f32 height = CELL_HEIGHT_LIMIT;
+ f32 height = CELL_HEIGHT_LIMIT;
f32 dynamicHeight = CELL_HEIGHT_LIMIT;
-
- //! (Parallel Universes) Because position is casted to an s16, reaching higher
- // float locations can return ceilings despite them not existing there.
- // (Dynamic ceilings will unload due to the range.)
- s16 x = (s16) posX;
- s16 y = (s16) posY;
- s16 z = (s16) posZ;
-
- *pceil = NULL;
-
- if (x <= -LEVEL_BOUNDARY_MAX || x >= LEVEL_BOUNDARY_MAX) {
- return height;
- }
- if (z <= -LEVEL_BOUNDARY_MAX || z >= LEVEL_BOUNDARY_MAX) {
- return height;
- }
-
+ *pceil = NULL;
+ if (is_outside_level_bounds(x, z)) return height;
// Each level is split into cells to limit load, find the appropriate cell.
- cellX = ((x + LEVEL_BOUNDARY_MAX) / CELL_SIZE) & NUM_CELLS_INDEX;
- cellZ = ((z + LEVEL_BOUNDARY_MAX) / CELL_SIZE) & NUM_CELLS_INDEX;
-
+ register const s32 cellX = ((((s32)x + LEVEL_BOUNDARY_MAX) / CELL_SIZE) & NUM_CELLS_INDEX);
+ register const s32 cellZ = ((((s32)z + LEVEL_BOUNDARY_MAX) / CELL_SIZE) & NUM_CELLS_INDEX);
+ // Check for surfaces that are a part of level geometry.
+ surfaceList = gStaticSurfacePartition[cellZ][cellX][SPATIAL_PARTITION_CEILS].next;
+ ceil = find_ceil_from_list(surfaceList, x, y, z, &height);
+ dynamicHeight = height;
// Check for surfaces belonging to objects.
surfaceList = gDynamicSurfacePartition[cellZ][cellX][SPATIAL_PARTITION_CEILS].next;
dynamicCeil = find_ceil_from_list(surfaceList, x, y, z, &dynamicHeight);
-
- // Check for surfaces that are a part of level geometry.
- surfaceList = gStaticSurfacePartition[cellZ][cellX][SPATIAL_PARTITION_CEILS].next;
- ceil = find_ceil_from_list(surfaceList, x, y, z, &height);
-
+ // Use the dynamic ceiling if it is lower
if (dynamicHeight < height) {
- ceil = dynamicCeil;
+ ceil = dynamicCeil;
height = dynamicHeight;
}
-
*pceil = ceil;
-
// Increment the debug tracker.
gNumCalls.ceil++;
-
return height;
}
@@ -362,120 +468,156 @@ f32 find_ceil(f32 posX, f32 posY, f32 posZ, struct Surface **pceil) {
/**
* Find the height of the highest floor below an object.
*/
-f32 unused_obj_find_floor_height(struct Object *obj) {
+UNUSED f32 unused_obj_find_floor_height(struct Object *obj) {
struct Surface *floor;
f32 floorHeight = find_floor(obj->oPosX, obj->oPosY, obj->oPosZ, &floor);
return floorHeight;