Skip to content

Commit df4c347

Browse files
two more coll funcs (#232)
* porting data types * load vertice data decompiled * decompile CalculateTrianglePlane * two more functions * missing def * decompile TestTriangle
1 parent efd95da commit df4c347

File tree

14 files changed

+565
-41
lines changed

14 files changed

+565
-41
lines changed

include/ctr/coll.h

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,81 @@ typedef struct CollVertex
2727
{
2828
SVec3 pos;
2929
u16 normalDominantAxis;
30-
Vertex* levVertex;
30+
const Vertex* levVertex;
3131
SVec3 triNormal;
32-
u16 planeDist;
32+
s16 planeDist;
3333
} CollVertex;
3434

3535
typedef struct TestVertex
3636
{
3737
SVec3 pos;
3838
u16 normalDominantAxis;
3939
SVec3 triNormal;
40-
u16 planeDist;
40+
s16 planeDist;
4141
SVec3 interpolationPoint;
4242
} TestVertex;
4343

44+
typedef struct DriverQuadblockCollData
45+
{
46+
SVec3 driverPos;
47+
s16 driverHitRadius;
48+
s32 driverHitRadiusSquared;
49+
SVec3 driverNextPos;
50+
u16 collFlags;
51+
u16 searchFlags;
52+
s16 unk0;
53+
u32 skipCollNoQuadFlagsMatch;
54+
} DriverQuadblockCollData;
55+
56+
typedef union CollInputData
57+
{
58+
DriverQuadblockCollData quadblock;
59+
} CollInputData;
60+
61+
typedef struct CollDCache
62+
{
63+
SVec3 inputNextPos;
64+
s16 inputHitRadius;
65+
s32 inputHitRadiusSquared;
66+
s16 unk0;
67+
s16 unk1;
68+
CollInputData collInput;
69+
const MeshInfo* meshInfo;
70+
BoundingBox bbox;
71+
s16 numVerticesTested;
72+
s16 numTrianglesCollided;
73+
s16 unk2;
74+
s16 numInstancesCollided;
75+
u32 unk3;
76+
const BSPNode* bspNodes;
77+
TestVertex collIntersection;
78+
u8 unk4;
79+
u8 currTriangleIndex;
80+
const Quadblock* currQuadblock;
81+
TestVertex coll;
82+
s8 barycentricTest;
83+
u8 collidedTriangleIndex;
84+
const Quadblock* collidedQuadblock;
85+
s32 speedScale;
86+
u8 unk6[0x44];
87+
const Vertex* collidedVertices[NUM_VERTICES_TRIANGLE];
88+
const CollVertex* currTestVertices[NUM_VERTICES_TRIANGLE];
89+
SVec3 deltaInterpolationIntersection;
90+
s16 unk7;
91+
u16 quadblockThirdIndex;
92+
u16 quadblockFourthIndex;
93+
CollVertex quadblockCollVertices[NUM_VERTICES_QUADBLOCK];
94+
u32 stepFlags;
95+
s16 normalScale;
96+
u8 normalBitshift;
97+
u8 lodShift;
98+
} CollDCache;
99+
100+
#define DCACHE_COLL (*(CollDCache*) 0x1f800000)
101+
44102
void COLL_ProjectPointToEdge(SVec3* out, const SVec3* v1, const SVec3* v2, const SVec3* point);
45-
s32 COLL_BarycentricTest(TestVertex* t, const CollVertex* v1, const CollVertex* v2, const CollVertex* v3);
103+
void COLL_LoadQuadblockData_LowLOD(CollDCache* cache, Quadblock* quadblock);
104+
void COLL_LoadQuadblockData_HighLOD(CollDCache* cache, Quadblock* quadblock);
105+
void COLL_TestTriangle(CollDCache* cache, const CollVertex* v1, const CollVertex* v2, const CollVertex* v3);
106+
107+
extern u32 e_ignoreCollisionDoorFlagTerrain; // 0x8008d728

include/ctr/driver.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#pragma once
2+
3+
#include <ctr/macros.h>
4+
5+
typedef enum StepFlags
6+
{
7+
STEPFLAGS_OUT_OF_BOUNDS = 0x4000,
8+
} StepFlags;

include/ctr/gte.h

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ typedef enum GTE_MAC
4343
GTE_MAC_3, /* s32 */
4444
} GTE_MAC;
4545

46-
typedef enum GTE_INTERPOLATE
46+
typedef enum GTE_CALC
4747
{
48-
GTE_INTERPOLATE_INT,
49-
GTE_INTERPOLATE_FLOATING_POINT,
50-
} GTE_INTERPOLATE;
48+
GTE_CALC_INT,
49+
GTE_CALC_FLOATING_POINT,
50+
} GTE_CALC;
5151

5252
/* HELPERS */
5353
#define _CAT(a, b) a##b
@@ -75,12 +75,17 @@ typedef enum GTE_INTERPOLATE
7575
#define _gte_readMac_GTE_MAC_3(out) gte_stlvnl2(out)
7676
#define _gte_readMac_GTE_VECTOR_MAC(out) gte_stlvnl(out)
7777
#define _gte_loadIR_GTE_IR_0(in) gte_lddp(in)
78-
#define _gte_dotProduct_GTE_ROW_INDEX_0(out, matrixType, vecType) gte_mvmva(0, matrixType, vecType, 3, 0); _gte_readMac_GTE_MAC_1(out)
79-
#define _gte_dotProduct_GTE_ROW_INDEX_1(out, matrixType, vecType) gte_mvmva(0, matrixType, vecType, 3, 0); _gte_readMac_GTE_MAC_2(out)
80-
#define _gte_dotProduct_GTE_ROW_INDEX_2(out, matrixType, vecType) gte_mvmva(0, matrixType, vecType, 3, 0); _gte_readMac_GTE_MAC_3(out)
78+
#define _gte_dotProduct_GTE_ROW_INDEX_0_GTE_CALC_INT(out, matrixType, vecType) gte_mvmva(0, matrixType, vecType, 3, 0); _gte_readMac_GTE_MAC_1(out)
79+
#define _gte_dotProduct_GTE_ROW_INDEX_1_GTE_CALC_INT(out, matrixType, vecType) gte_mvmva(0, matrixType, vecType, 3, 0); _gte_readMac_GTE_MAC_2(out)
80+
#define _gte_dotProduct_GTE_ROW_INDEX_2_GTE_CALC_INT(out, matrixType, vecType) gte_mvmva(0, matrixType, vecType, 3, 0); _gte_readMac_GTE_MAC_3(out)
81+
#define _gte_dotProduct_GTE_ROW_INDEX_0_GTE_CALC_FLOATING_POINT(out, matrixType, vecType) gte_mvmva(1, matrixType, vecType, 3, 0); _gte_readMac_GTE_MAC_1(out)
82+
#define _gte_dotProduct_GTE_ROW_INDEX_1_GTE_CALC_FLOATING_POINT(out, matrixType, vecType) gte_mvmva(1, matrixType, vecType, 3, 0); _gte_readMac_GTE_MAC_2(out)
83+
#define _gte_dotProduct_GTE_ROW_INDEX_2_GTE_CALC_FLOATING_POINT(out, matrixType, vecType) gte_mvmva(1, matrixType, vecType, 3, 0); _gte_readMac_GTE_MAC_3(out)
8184
#define _gte_mulMatrixVec(out, matrixType, vecType, shift) gte_mvmva(shift, matrixType, vecType, 3, 0); _gte_readMac_GTE_VECTOR_MAC(out)
82-
#define _gte_interpolate_GTE_INTERPOLATE_INT() gte_gpl0()
83-
#define _gte_interpolate_GTE_INTERPOLATE_FLOATING_POINT() gte_gpl12()
85+
#define _gte_interpolate_GTE_CALC_INT() gte_gpf0()
86+
#define _gte_interpolate_GTE_CALC_FLOATING_POINT() gte_gpf12()
87+
#define _gte_interpolateBase_GTE_CALC_INT() gte_gpl0()
88+
#define _gte_interpolateBase_GTE_CALC_FLOATING_POINT() gte_gpl12()
8489
#define _gte_leadingZeroes(out, in) __asm__ volatile ( \
8590
"mtc2 %1, $30;" \
8691
"nop;" \
@@ -98,6 +103,8 @@ typedef enum GTE_INTERPOLATE
98103
#define gte_loadVec(v, vecType) CAT(_gte_loadVec_, vecType)(v)
99104
#define gte_loadRowMatrix(v, rowIndex, matrixType) CAT3(_gte_loadSVecMatrix_, matrixType, _##rowIndex)(v)
100105
#define gte_mulMatrixVec(out, matrixType, vecType) _gte_mulMatrixVec(out, matrixType, vecType, 1)
101-
#define gte_dotProduct(out, rowIndex, matrixType, vecType) CAT(_gte_dotProduct_, rowIndex)(out, matrixType, vecType)
106+
#define gte_dotProduct(out, rowIndex, matrixType, vecType, calcType) CAT3(_gte_dotProduct_, rowIndex, _##calcType)(out, matrixType, vecType)
102107
#define gte_leadingZeroes(out, in) _gte_leadingZeroes(out, in)
103-
#define gte_interpolate(out, interpolationType) CAT(_gte_interpolate_, interpolationType)(); _gte_readMac_GTE_VECTOR_MAC(out)
108+
#define gte_interpolate(out, calcType) CAT(_gte_interpolate_, calcType)(); _gte_readMac_GTE_VECTOR_MAC(out)
109+
#define gte_interpolateBase(out, calcType) CAT(_gte_interpolateBase_, calcType)(); _gte_readMac_GTE_VECTOR_MAC(out)
110+
#define gte_crossProduct(out, matrix, vector) gte_SetRotMatrix(matrix); gte_loadSVec(vector, GTE_VECTOR_IR); gte_op0(); gte_readMac(out, GTE_VECTOR_MAC)

include/ctr/lev.h

Lines changed: 128 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
#include <ctr/macros.h>
44
#include <ctr/math.h>
5+
#include <ctr/prim.h>
6+
7+
#define NUM_VERTICES_QUADBLOCK 9
8+
#define NUM_VERTICES_TRIANGLE 3
59

610
typedef union Color
711
{
@@ -15,10 +19,133 @@ typedef union Color
1519
u32 color;
1620
} Color;
1721

22+
typedef struct TextureLayout
23+
{
24+
UV uv0;
25+
CLUT clut;
26+
UV uv1;
27+
PolyTexpage texpage;
28+
UV uv2;
29+
UV uv3;
30+
} TextureLayout;
31+
32+
typedef struct TextureGroup
33+
{
34+
TextureLayout far;
35+
TextureLayout middle;
36+
TextureLayout near;
37+
TextureLayout mosaic;
38+
} TextureGroup;
39+
1840
typedef struct Vertex
1941
{
2042
SVec3 pos;
2143
u16 flags;
2244
Color colorHi;
2345
Color colorLo;
24-
} Vertex;
46+
} Vertex;
47+
48+
typedef struct VisibleSet
49+
{
50+
u32* visibleBSPNodes;
51+
u32* visibleQuadblocks;
52+
u32* visibleInstances;
53+
u32* visibleExtra;
54+
} VisibleSet;
55+
56+
typedef enum QuadFlags
57+
{
58+
QUADFLAGS_INVISIBLE = 1 << 0,
59+
QUADFLAGS_MOON_GRAVITY = 1 << 1,
60+
QUADFLAGS_REFLECTION = 1 << 2,
61+
QUADFLAGS_KICKERS = 1 << 3,
62+
QUADFLAGS_OUT_OF_BOUNDS = 1 << 4,
63+
QUADFLAGS_NEVER_USED = 1 << 5,
64+
QUADFLAGS_TRIGGER_SCRIPT = 1 << 6,
65+
QUADFLAGS_REVERB = 1 << 7,
66+
QUADFLAGS_KICKERS_TWO = 1 << 8,
67+
QUADFLAGS_MASK_GRAB = 1 << 9,
68+
QUADFLAGS_TIGER_TEMPLE_DOOR = 1 << 10,
69+
QUADFLAGS_COLLISION_TRIGGER = 1 << 11,
70+
QUADFLAGS_GROUND = 1 << 12,
71+
QUADFLAGS_WALL = 1 << 13,
72+
QUADFLAGS_NO_COLLISION = 1 << 14,
73+
QUADFLAGS_INVISIBLE_TRIGGER = 1 << 15,
74+
} QuadFlags;
75+
76+
typedef struct DrawOrder
77+
{
78+
u32 drawOrder : 8;
79+
u32 rotFlipFace0 : 3;
80+
u32 drawModeFace0 : 2;
81+
u32 rotFlipFace1 : 3;
82+
u32 drawModeFace1 : 2;
83+
u32 rotFlipFace2 : 3;
84+
u32 drawModeFace2 : 2;
85+
u32 rotFlipFace3 : 3;
86+
u32 drawModeFace3 : 2;
87+
u32 unk : 3;
88+
u32 doubleSided : 1;
89+
} DrawOrder;
90+
91+
typedef struct Quadblock
92+
{
93+
u16 index[NUM_VERTICES_QUADBLOCK]; // 0x0
94+
u16 flags; // 0x12
95+
DrawOrder drawOrderLow; // 0x14
96+
u32 drawOrderHigh; // 0x18
97+
u32 offMidTextures[4]; // 0x1C
98+
BoundingBox bbox; // 0x2C
99+
u8 terrain; // 0x38
100+
u8 weatherIntensity; // 0x39
101+
u8 weatherVanishRate; // 0x3A
102+
s8 speedImpact; // 0x3B
103+
u16 id; // 0x3C
104+
u8 checkpointIndex; // 0x3E
105+
u8 triNormalVecBitshift; // 0x3F
106+
u32 offLowTexture; // 0x40
107+
VisibleSet* visibleSet; // 0x44
108+
s16 triNormalVecDividend[NUM_VERTICES_QUADBLOCK + 1]; // 0x48
109+
} Quadblock;
110+
111+
typedef struct BSPBranch
112+
{
113+
u16 flags; // 0x0
114+
u16 id; // 0x2
115+
BoundingBox bbox; // 0x4
116+
SVec3 axis; // 0x10
117+
u16 likelyPadding; // 0x16
118+
u16 leftChildID; // 0x18
119+
u16 rightChildID; // 0x1A
120+
u16 unk1; // 0x1C
121+
u16 unk2; // 0x1E
122+
} BSPBranch;
123+
124+
typedef struct BSPLeaf
125+
{
126+
u16 flags; // 0x0
127+
u16 id; // 0x2
128+
BoundingBox bbox; // 0x4
129+
u32 likelyPadding; // 0x10
130+
u32 offHitbox; // 0x14
131+
u32 numQuads; // 0x18
132+
Quadblock* quadblocks; // 0x1C
133+
} BSPLeaf;
134+
135+
typedef union BSPNode
136+
{
137+
BSPBranch branch;
138+
BSPLeaf leaf;
139+
} BSPNode;
140+
141+
typedef struct MeshInfo
142+
{
143+
u32 numQuadblocks; // 0x0
144+
u32 numVertices; // 0x4
145+
u32 unk1; // 0x8
146+
Quadblock* quadblocks; // 0xC
147+
Vertex* vertices; // 0x10
148+
u32 unk2; // 0x14
149+
BSPNode* bspNodes; // 0x18
150+
u32 numBSPNodes; // 0x1C
151+
} MeshInfo;

include/ctr/math.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,18 @@ typedef union Vec4
6969
s32 v[4];
7070
} Vec4;
7171

72-
typedef struct Matrix {
72+
typedef struct Matrix
73+
{
7374
s16 m[3][3];
7475
Vec3 t;
7576
} Matrix;
7677

78+
typedef struct BoundingBox
79+
{
80+
SVec3 min;
81+
SVec3 max;
82+
} BoundingBox;
83+
7784
typedef struct TrigTable
7885
{
7986
s16 sin;

include/ctr/nd.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
#include <ctr/coll.h>
77

88
void ND_LOAD_XnfFile(char* filename, u32 address, char* dummy);
9+
void ND_LOAD_InitCD();
10+
911
s32 ND_SquareRoot0_stub(s32 n);
1012
int ND_printf(const char* format, ...);
1113
int ND_sprintf(const char* outStr, const char* format, ...);
12-
void ND_LOAD_InitCD();
1314

1415
/* MATH */
1516
s32 ND_MATH_Sin(u32 angle);
@@ -29,4 +30,9 @@ u32 ND_RNG_Random(RNGSeed* seed);
2930

3031
/* COLL */
3132
void ND_COLL_ProjectPointToEdge(SVec3* out, const SVec3* v1, const SVec3* v2, const SVec3* point);
32-
s32 ND_COLL_BarycentricTest(TestVertex* t, const CollVertex* v1, const CollVertex* v2, const CollVertex* v3);
33+
void ND_COLL_LoadQuadblockData_LowLOD(CollDCache* cache, Quadblock* quadblock);
34+
void ND_COLL_LoadQuadblockData_HighLOD(CollDCache* cache, Quadblock* quadblock);
35+
void ND_COLL_CalculateTrianglePlane(const CollDCache* cache, CollVertex* v1, const CollVertex* v2, const CollVertex* v3);
36+
void ND_COLL_LoadVerticeData(CollDCache* cache);
37+
s32 ND_COLL_BarycentricTest(TestVertex* t, const CollVertex* v1, const CollVertex* v2, const CollVertex* v3);
38+
void ND_COLL_TestTriangle(CollDCache* cache, const CollVertex* v1, const CollVertex* v2, const CollVertex* v3);

include/ctr/prim.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
#include <ctr/macros.h>
44

5-
enum VertexCount
5+
typedef enum VertexCount
66
{
77
VertexCount_Point = 1,
88
VertexCount_Line = 2,
99
VertexCount_Tri = 3,
1010
VertexCount_Quad = 4,
11-
};
11+
} VertexCount;
1212

1313
typedef union Tag
1414
{
@@ -41,18 +41,18 @@ typedef union Texpage
4141
u32 self;
4242
} Texpage;
4343

44-
typedef struct
44+
typedef struct TPage
4545
{
4646
Tag tag;
4747
Texpage texpage;
4848
} TPage;
4949

50-
enum RenderCode
50+
typedef enum RenderCode
5151
{
5252
RenderCode_Polygon = 1,
5353
RenderCode_Line = 2,
5454
RenderCode_Rectangle = 3,
55-
};
55+
} RenderCode;
5656

5757
typedef union PrimCode
5858
{
@@ -100,8 +100,6 @@ typedef union ColorCode
100100
u32 self;
101101
} ColorCode;
102102

103-
typedef ColorCode Color;
104-
105103
#define MakeColorCode(red, green, blue, renderCode) (ColorCode) { .r = red, .g = green, .b = blue, .code = renderCode }
106104
#define MakeColor(red, green, blue) (Color) { .r = red, .g = green, .b = blue }
107105

0 commit comments

Comments
 (0)