Skip to content

Commit

Permalink
#368 GBA optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
XProger committed Dec 28, 2021
1 parent 3e9babf commit ffff0d1
Show file tree
Hide file tree
Showing 48 changed files with 2,844 additions and 1,124 deletions.
63 changes: 0 additions & 63 deletions src/fixed/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ void Camera::update()
if (mode == CAMERA_MODE_FREE)
{
updateFree();
prepareFrustum();
matrixSetView(view.pos, angle.x, angle.y);
return;
}
Expand Down Expand Up @@ -423,71 +422,9 @@ void Camera::update()
vec3i dir = target.pos - view.pos;
anglesFromVector(dir.x, dir.y, dir.z, angle.x, angle.y);

prepareFrustum();

matrixSetView(view.pos, angle.x, angle.y);
}

void Camera::prepareFrustum()
{
#ifndef MODEHW
matrixSetIdentity();
matrixRotateYXZ(angle.x, angle.y, angle.z);

static const vec3i v[5] = {
// near plane
{ 0, 0, 0 },
// far plane
{ -FRUSTUM_FAR_X, -FRUSTUM_FAR_Y, FRUSTUM_FAR_Z },
{ FRUSTUM_FAR_X, -FRUSTUM_FAR_Y, FRUSTUM_FAR_Z },
{ -FRUSTUM_FAR_X, FRUSTUM_FAR_Y, FRUSTUM_FAR_Z },
{ FRUSTUM_FAR_X, FRUSTUM_FAR_Y, FRUSTUM_FAR_Z }
};

const Matrix &m = matrixGet();

frustumBase.minX = 0xFFFFFFF;
frustumBase.maxX = -0xFFFFFFF;
frustumBase.minY = 0xFFFFFFF;
frustumBase.maxY = -0xFFFFFFF;
frustumBase.minZ = 0xFFFFFFF;
frustumBase.maxZ = -0xFFFFFFF;

for (int32 i = 0; i < 5; i++)
{
int32 x = DP43(m.e00, m.e01, m.e02, m.e03, v[i].x, v[i].y, v[i].z) >> FIXED_SHIFT;
int32 y = DP43(m.e10, m.e11, m.e12, m.e13, v[i].x, v[i].y, v[i].z) >> FIXED_SHIFT;
int32 z = DP43(m.e20, m.e21, m.e22, m.e23, v[i].x, v[i].y, v[i].z) >> FIXED_SHIFT;

frustumBase.minX = X_MIN(frustumBase.minX, x);
frustumBase.maxX = X_MAX(frustumBase.maxX, x);
frustumBase.minY = X_MIN(frustumBase.minY, y);
frustumBase.maxY = X_MAX(frustumBase.maxY, y);
frustumBase.minZ = X_MIN(frustumBase.minZ, z);
frustumBase.maxZ = X_MAX(frustumBase.maxZ, z);
}

frustumBase.minX += view.pos.x - 1024;
frustumBase.maxX += view.pos.x + 1024;
frustumBase.minY += view.pos.y - 1024;
frustumBase.maxY += view.pos.y + 1024;
frustumBase.minZ += view.pos.z - 1024;
frustumBase.maxZ += view.pos.z + 1024;
#endif
}

void Camera::updateFrustum(int32 offsetX, int32 offsetY, int32 offsetZ)
{
#ifndef MODEHW
frustumAABB.minX = frustumBase.minX - offsetX;
frustumAABB.maxX = frustumBase.maxX - offsetX;
frustumAABB.minY = frustumBase.minY - offsetY;
frustumAABB.maxY = frustumBase.maxY - offsetY;
frustumAABB.minZ = frustumBase.minZ - offsetZ;
frustumAABB.maxZ = frustumBase.maxZ - offsetZ;
#endif
}

void Camera::toCombat()
{
if (mode == CAMERA_MODE_FREE)
Expand Down
25 changes: 1 addition & 24 deletions src/fixed/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ vec3i cameraViewPos;
Matrix matrixStack[MAX_MATRICES];
Matrix* matrixPtr = matrixStack;

#ifndef MODEHW
AABBi frustumAABB;
#endif

EWRAM_DATA Sphere gSpheres[2][MAX_SPHERES];

const FloorData* gLastFloorData;
Expand All @@ -19,6 +15,7 @@ TargetInfo tinfo;
EWRAM_DATA SaveGame gSaveGame;
EWRAM_DATA Settings gSettings;
EWRAM_DATA int32 gCurTrack;
EWRAM_DATA int32 gAnimTexFrame;

EWRAM_DATA ExtraInfoLara playersExtra[MAX_PLAYERS];

Expand Down Expand Up @@ -1144,7 +1141,6 @@ void matrixSetBasis_c(Matrix &dst, const Matrix &src)
dst.e12 = src.e12;
}

#ifndef IWRAM_MATRIX_LERP
#define LERP_1_2(a, b) a = (b + a) >> 1
#define LERP_1_3(a, b) a = a + (b - a) / 3
#define LERP_2_3(a, b) a = b - (b - a) / 3
Expand Down Expand Up @@ -1181,30 +1177,11 @@ void matrixLerp_c(const Matrix &n, int32 pmul, int32 pdiv)
LERP_MATRIX(LERP_3_4);
}

} else if (pdiv == 3) {

if (pmul == 1) {
LERP_MATRIX(LERP_1_3);
} else {
LERP_MATRIX(LERP_2_3);
}

} else if (pdiv == 5) {

switch (pmul)
{
case 4 : LERP_MATRIX(LERP_4_5); break;
case 3 : LERP_MATRIX(LERP_3_5); break;
case 2 : LERP_MATRIX(LERP_2_5); break;
case 1 : LERP_MATRIX(LERP_1_5); break;
}

} else {
int32 t = pmul * FixedInvU(pdiv) >> 8;
LERP_MATRIX(LERP_SLOW);
}
}
#endif

#define MATRIX_TRANSLATE(x,y,z)\
Matrix &m = matrixGet();\
Expand Down
Loading

0 comments on commit ffff0d1

Please sign in to comment.