Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 66 additions & 4 deletions include/ctr/coll.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,81 @@ typedef struct CollVertex
{
SVec3 pos;
u16 normalDominantAxis;
Vertex* levVertex;
const Vertex* levVertex;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can const-ifying be done elsewhere too?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can const-fy most of these scratchpad pointers as they seem to be used for read only purposes. As for data in other headers, they need to be analyzed in a case by case scenario, which means decompiling a ton of functions before making such decisions

SVec3 triNormal;
u16 planeDist;
s16 planeDist;
} CollVertex;

typedef struct TestVertex
{
SVec3 pos;
u16 normalDominantAxis;
SVec3 triNormal;
u16 planeDist;
s16 planeDist;
SVec3 interpolationPoint;
} TestVertex;

typedef struct DriverQuadblockCollData
{
SVec3 driverPos;
s16 driverHitRadius;
s32 driverHitRadiusSquared;
SVec3 driverNextPos;
u16 collFlags;
u16 searchFlags;
s16 unk0;
u32 skipCollNoQuadFlagsMatch;
} DriverQuadblockCollData;

typedef union CollInputData
{
DriverQuadblockCollData quadblock;
} CollInputData;

typedef struct CollDCache
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this start at 0x1f800000 or 0x1f800108?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0x1f800000

{
SVec3 inputNextPos;
s16 inputHitRadius;
s32 inputHitRadiusSquared;
s16 unk0;
s16 unk1;
CollInputData collInput;
const MeshInfo* meshInfo;
BoundingBox bbox;
s16 numVerticesTested;
s16 numTrianglesCollided;
s16 unk2;
s16 numInstancesCollided;
u32 unk3;
const BSPNode* bspNodes;
TestVertex collIntersection;
u8 unk4;
u8 currTriangleIndex;
const Quadblock* currQuadblock;
TestVertex coll;
s8 barycentricTest;
u8 collidedTriangleIndex;
const Quadblock* collidedQuadblock;
s32 speedScale;
u8 unk6[0x44];
const Vertex* collidedVertices[NUM_VERTICES_TRIANGLE];
const CollVertex* currTestVertices[NUM_VERTICES_TRIANGLE];
SVec3 deltaInterpolationIntersection;
s16 unk7;
u16 quadblockThirdIndex;
u16 quadblockFourthIndex;
CollVertex quadblockCollVertices[NUM_VERTICES_QUADBLOCK];
u32 stepFlags;
s16 normalScale;
u8 normalBitshift;
u8 lodShift;
} CollDCache;

#define DCACHE_COLL (*(CollDCache*) 0x1f800000)

void COLL_ProjectPointToEdge(SVec3* out, const SVec3* v1, const SVec3* v2, const SVec3* point);
s32 COLL_BarycentricTest(TestVertex* t, const CollVertex* v1, const CollVertex* v2, const CollVertex* v3);
void COLL_LoadQuadblockData_LowLOD(CollDCache* cache, Quadblock* quadblock);
void COLL_LoadQuadblockData_HighLOD(CollDCache* cache, Quadblock* quadblock);
void COLL_TestTriangle(CollDCache* cache, const CollVertex* v1, const CollVertex* v2, const CollVertex* v3);

extern u32 e_ignoreCollisionDoorFlagTerrain; // 0x8008d728
8 changes: 8 additions & 0 deletions include/ctr/driver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

#include <ctr/macros.h>

typedef enum StepFlags
{
STEPFLAGS_OUT_OF_BOUNDS = 0x4000,
} StepFlags;
29 changes: 18 additions & 11 deletions include/ctr/gte.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ typedef enum GTE_MAC
GTE_MAC_3, /* s32 */
} GTE_MAC;

typedef enum GTE_INTERPOLATE
typedef enum GTE_CALC
{
GTE_INTERPOLATE_INT,
GTE_INTERPOLATE_FLOATING_POINT,
} GTE_INTERPOLATE;
GTE_CALC_INT,
GTE_CALC_FLOATING_POINT,
} GTE_CALC;

/* HELPERS */
#define _CAT(a, b) a##b
Expand Down Expand Up @@ -75,12 +75,17 @@ typedef enum GTE_INTERPOLATE
#define _gte_readMac_GTE_MAC_3(out) gte_stlvnl2(out)
#define _gte_readMac_GTE_VECTOR_MAC(out) gte_stlvnl(out)
#define _gte_loadIR_GTE_IR_0(in) gte_lddp(in)
#define _gte_dotProduct_GTE_ROW_INDEX_0(out, matrixType, vecType) gte_mvmva(0, matrixType, vecType, 3, 0); _gte_readMac_GTE_MAC_1(out)
#define _gte_dotProduct_GTE_ROW_INDEX_1(out, matrixType, vecType) gte_mvmva(0, matrixType, vecType, 3, 0); _gte_readMac_GTE_MAC_2(out)
#define _gte_dotProduct_GTE_ROW_INDEX_2(out, matrixType, vecType) gte_mvmva(0, matrixType, vecType, 3, 0); _gte_readMac_GTE_MAC_3(out)
#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)
#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)
#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)
#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)
#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)
#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)
#define _gte_mulMatrixVec(out, matrixType, vecType, shift) gte_mvmva(shift, matrixType, vecType, 3, 0); _gte_readMac_GTE_VECTOR_MAC(out)
#define _gte_interpolate_GTE_INTERPOLATE_INT() gte_gpl0()
#define _gte_interpolate_GTE_INTERPOLATE_FLOATING_POINT() gte_gpl12()
#define _gte_interpolate_GTE_CALC_INT() gte_gpf0()
#define _gte_interpolate_GTE_CALC_FLOATING_POINT() gte_gpf12()
#define _gte_interpolateBase_GTE_CALC_INT() gte_gpl0()
#define _gte_interpolateBase_GTE_CALC_FLOATING_POINT() gte_gpl12()
#define _gte_leadingZeroes(out, in) __asm__ volatile ( \
"mtc2 %1, $30;" \
"nop;" \
Expand All @@ -98,6 +103,8 @@ typedef enum GTE_INTERPOLATE
#define gte_loadVec(v, vecType) CAT(_gte_loadVec_, vecType)(v)
#define gte_loadRowMatrix(v, rowIndex, matrixType) CAT3(_gte_loadSVecMatrix_, matrixType, _##rowIndex)(v)
#define gte_mulMatrixVec(out, matrixType, vecType) _gte_mulMatrixVec(out, matrixType, vecType, 1)
#define gte_dotProduct(out, rowIndex, matrixType, vecType) CAT(_gte_dotProduct_, rowIndex)(out, matrixType, vecType)
#define gte_dotProduct(out, rowIndex, matrixType, vecType, calcType) CAT3(_gte_dotProduct_, rowIndex, _##calcType)(out, matrixType, vecType)
#define gte_leadingZeroes(out, in) _gte_leadingZeroes(out, in)
#define gte_interpolate(out, interpolationType) CAT(_gte_interpolate_, interpolationType)(); _gte_readMac_GTE_VECTOR_MAC(out)
#define gte_interpolate(out, calcType) CAT(_gte_interpolate_, calcType)(); _gte_readMac_GTE_VECTOR_MAC(out)
#define gte_interpolateBase(out, calcType) CAT(_gte_interpolateBase_, calcType)(); _gte_readMac_GTE_VECTOR_MAC(out)
#define gte_crossProduct(out, matrix, vector) gte_SetRotMatrix(matrix); gte_loadSVec(vector, GTE_VECTOR_IR); gte_op0(); gte_readMac(out, GTE_VECTOR_MAC)
129 changes: 128 additions & 1 deletion include/ctr/lev.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

#include <ctr/macros.h>
#include <ctr/math.h>
#include <ctr/prim.h>

#define NUM_VERTICES_QUADBLOCK 9
#define NUM_VERTICES_TRIANGLE 3

typedef union Color
{
Expand All @@ -15,10 +19,133 @@ typedef union Color
u32 color;
} Color;

typedef struct TextureLayout
{
UV uv0;
CLUT clut;
UV uv1;
PolyTexpage texpage;
UV uv2;
UV uv3;
} TextureLayout;

typedef struct TextureGroup
{
TextureLayout far;
TextureLayout middle;
TextureLayout near;
TextureLayout mosaic;
} TextureGroup;

typedef struct Vertex
{
SVec3 pos;
u16 flags;
Color colorHi;
Color colorLo;
} Vertex;
} Vertex;

typedef struct VisibleSet
{
u32* visibleBSPNodes;
u32* visibleQuadblocks;
u32* visibleInstances;
u32* visibleExtra;
} VisibleSet;

typedef enum QuadFlags
{
QUADFLAGS_INVISIBLE = 1 << 0,
QUADFLAGS_MOON_GRAVITY = 1 << 1,
QUADFLAGS_REFLECTION = 1 << 2,
QUADFLAGS_KICKERS = 1 << 3,
QUADFLAGS_OUT_OF_BOUNDS = 1 << 4,
QUADFLAGS_NEVER_USED = 1 << 5,
QUADFLAGS_TRIGGER_SCRIPT = 1 << 6,
QUADFLAGS_REVERB = 1 << 7,
QUADFLAGS_KICKERS_TWO = 1 << 8,
QUADFLAGS_MASK_GRAB = 1 << 9,
QUADFLAGS_TIGER_TEMPLE_DOOR = 1 << 10,
QUADFLAGS_COLLISION_TRIGGER = 1 << 11,
QUADFLAGS_GROUND = 1 << 12,
QUADFLAGS_WALL = 1 << 13,
QUADFLAGS_NO_COLLISION = 1 << 14,
QUADFLAGS_INVISIBLE_TRIGGER = 1 << 15,
} QuadFlags;

typedef struct DrawOrder
{
u32 drawOrder : 8;
u32 rotFlipFace0 : 3;
u32 drawModeFace0 : 2;
u32 rotFlipFace1 : 3;
u32 drawModeFace1 : 2;
u32 rotFlipFace2 : 3;
u32 drawModeFace2 : 2;
u32 rotFlipFace3 : 3;
u32 drawModeFace3 : 2;
u32 unk : 3;
u32 doubleSided : 1;
} DrawOrder;

typedef struct Quadblock
{
u16 index[NUM_VERTICES_QUADBLOCK]; // 0x0
u16 flags; // 0x12
DrawOrder drawOrderLow; // 0x14
u32 drawOrderHigh; // 0x18
u32 offMidTextures[4]; // 0x1C
BoundingBox bbox; // 0x2C
u8 terrain; // 0x38
u8 weatherIntensity; // 0x39
u8 weatherVanishRate; // 0x3A
s8 speedImpact; // 0x3B
u16 id; // 0x3C
u8 checkpointIndex; // 0x3E
u8 triNormalVecBitshift; // 0x3F
u32 offLowTexture; // 0x40
VisibleSet* visibleSet; // 0x44
s16 triNormalVecDividend[NUM_VERTICES_QUADBLOCK + 1]; // 0x48
} Quadblock;

typedef struct BSPBranch
{
u16 flags; // 0x0
u16 id; // 0x2
BoundingBox bbox; // 0x4
SVec3 axis; // 0x10
u16 likelyPadding; // 0x16
u16 leftChildID; // 0x18
u16 rightChildID; // 0x1A
u16 unk1; // 0x1C
u16 unk2; // 0x1E
} BSPBranch;

typedef struct BSPLeaf
{
u16 flags; // 0x0
u16 id; // 0x2
BoundingBox bbox; // 0x4
u32 likelyPadding; // 0x10
u32 offHitbox; // 0x14
u32 numQuads; // 0x18
Quadblock* quadblocks; // 0x1C
} BSPLeaf;

typedef union BSPNode
{
BSPBranch branch;
BSPLeaf leaf;
} BSPNode;

typedef struct MeshInfo
{
u32 numQuadblocks; // 0x0
u32 numVertices; // 0x4
u32 unk1; // 0x8
Quadblock* quadblocks; // 0xC
Vertex* vertices; // 0x10
u32 unk2; // 0x14
BSPNode* bspNodes; // 0x18
u32 numBSPNodes; // 0x1C
} MeshInfo;
9 changes: 8 additions & 1 deletion include/ctr/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,18 @@ typedef union Vec4
s32 v[4];
} Vec4;

typedef struct Matrix {
typedef struct Matrix
{
s16 m[3][3];
Vec3 t;
} Matrix;

typedef struct BoundingBox
{
SVec3 min;
SVec3 max;
} BoundingBox;

typedef struct TrigTable
{
s16 sin;
Expand Down
10 changes: 8 additions & 2 deletions include/ctr/nd.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
#include <ctr/coll.h>

void ND_LOAD_XnfFile(char* filename, u32 address, char* dummy);
void ND_LOAD_InitCD();

s32 ND_SquareRoot0_stub(s32 n);
int ND_printf(const char* format, ...);
int ND_sprintf(const char* outStr, const char* format, ...);
void ND_LOAD_InitCD();

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

/* COLL */
void ND_COLL_ProjectPointToEdge(SVec3* out, const SVec3* v1, const SVec3* v2, const SVec3* point);
s32 ND_COLL_BarycentricTest(TestVertex* t, const CollVertex* v1, const CollVertex* v2, const CollVertex* v3);
void ND_COLL_LoadQuadblockData_LowLOD(CollDCache* cache, Quadblock* quadblock);
void ND_COLL_LoadQuadblockData_HighLOD(CollDCache* cache, Quadblock* quadblock);
void ND_COLL_CalculateTrianglePlane(const CollDCache* cache, CollVertex* v1, const CollVertex* v2, const CollVertex* v3);
void ND_COLL_LoadVerticeData(CollDCache* cache);
s32 ND_COLL_BarycentricTest(TestVertex* t, const CollVertex* v1, const CollVertex* v2, const CollVertex* v3);
void ND_COLL_TestTriangle(CollDCache* cache, const CollVertex* v1, const CollVertex* v2, const CollVertex* v3);
12 changes: 5 additions & 7 deletions include/ctr/prim.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

#include <ctr/macros.h>

enum VertexCount
typedef enum VertexCount
{
VertexCount_Point = 1,
VertexCount_Line = 2,
VertexCount_Tri = 3,
VertexCount_Quad = 4,
};
} VertexCount;

typedef union Tag
{
Expand Down Expand Up @@ -41,18 +41,18 @@ typedef union Texpage
u32 self;
} Texpage;

typedef struct
typedef struct TPage
{
Tag tag;
Texpage texpage;
} TPage;

enum RenderCode
typedef enum RenderCode
{
RenderCode_Polygon = 1,
RenderCode_Line = 2,
RenderCode_Rectangle = 3,
};
} RenderCode;

typedef union PrimCode
{
Expand Down Expand Up @@ -100,8 +100,6 @@ typedef union ColorCode
u32 self;
} ColorCode;

typedef ColorCode Color;

#define MakeColorCode(red, green, blue, renderCode) (ColorCode) { .r = red, .g = green, .b = blue, .code = renderCode }
#define MakeColor(red, green, blue) (Color) { .r = red, .g = green, .b = blue }

Expand Down
Loading