Skip to content

Commit

Permalink
GBA data aligned level format, optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
XProger committed May 28, 2021
1 parent 7e8c9d5 commit e9d6731
Show file tree
Hide file tree
Showing 24 changed files with 1,039 additions and 917 deletions.
2 changes: 1 addition & 1 deletion src/platform/gba/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ soundbank.bin soundbank.h : $(AUDIOFILES)
#---------------------------------------------------------------------------------
@mmutil $^ -osoundbank.bin -hsoundbank.h

%.PHD.o %_PHD.h : %.PHD
%.PKD.o %_PKD.h : %.PKD
@echo $(notdir $<)
@$(bin2o)

Expand Down
6 changes: 3 additions & 3 deletions src/platform/gba/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ struct Camera
{
view.room = view.room->getRoom(view.pos.x, view.pos.y, view.pos.z);

const RoomInfo::Sector* sector = view.room->getSector(view.pos.x, view.pos.z);
const Sector* sector = view.room->getSector(view.pos.x, view.pos.z);
int32 floor = sector->getFloor(view.pos.x, view.pos.y, view.pos.z);
int32 ceiling = sector->getCeiling(view.pos.x, view.pos.y, view.pos.z) - 256;

Expand Down Expand Up @@ -161,14 +161,14 @@ struct Camera
int32 ty = item->pos.y;
int32 tz = item->pos.z;

const Box &box = item->getBoundingBox();
const Bounds &box = item->getBoundingBox();
ty += box.maxY + ((box.minY - box.maxY) * 3 >> 2);

target.pos.x = tx;
target.pos.y += (ty - target.pos.y) >> 2;
target.pos.z = tz;

int16 angle = item->angleY + targetAngleY;
int16 angle = item->angle.y + targetAngleY;

int32 dy = targetDist * phd_sin(targetAngleX) >> FIXED_SHIFT;
int32 dz = targetDist * phd_cos(targetAngleX) >> FIXED_SHIFT;
Expand Down
21 changes: 12 additions & 9 deletions src/platform/gba/collision.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ bool collideStatic(Room* room, CollisionInfo &cinfo, const vec3i &p, int32 heigh
cinfo.staticHit = false;
cinfo.offset = vec3i(0);

Box objBox;
Bounds objBox;
objBox.minX = -cinfo.radius;
objBox.maxX = cinfo.radius;
objBox.minZ = -cinfo.radius;
Expand All @@ -128,23 +128,26 @@ bool collideStatic(Room* room, CollisionInfo &cinfo, const vec3i &p, int32 heigh
{
const Room* room = *nearRoom++;

for (int i = 0; i < room->mCount; i++)
for (int i = 0; i < room->info->meshesCount; i++)
{
const RoomInfo::Mesh* mesh = room->meshes + i;
const RoomMesh* mesh = room->data.meshes + i;

#ifdef NO_STATIC_MESHES
if (mesh->staticMeshId != STATIC_MESH_GATE) continue;
if (mesh->id != STATIC_MESH_GATE) continue;
#endif

const StaticMesh* staticMesh = staticMeshes + staticMeshesMap[mesh->staticMeshId];
const StaticMesh* staticMesh = staticMeshes + mesh->id;

if (staticMesh->flags & 1) continue;
if (staticMesh->flags & STATIC_MESH_FLAG_NO_COLLISION) continue;

Box meshBox = boxRotate(staticMesh->cbox, mesh->rotation);
Bounds meshBox = boxRotate(staticMesh->cbox, (mesh->rot - 2) * ANGLE_90);

// TODO align RoomInfo::Mesh (room relative int16?)
vec3i pos;
memcpy(&pos, &(mesh->pos[0]), sizeof(pos));
pos.x = mesh->pos.x + (room->info->x << 8);
pos.y = mesh->pos.y;
pos.z = mesh->pos.z + (room->info->z << 8);

pos -= p;

boxTranslate(meshBox, pos);
Expand Down Expand Up @@ -202,7 +205,7 @@ void collideRoom(Item* item, int32 height, int32 yOffset = 0)

#define CHECK_HEIGHT(v) {\
const Room* room = item->room->getRoom(v.x, cy, v.z);\
const RoomInfo::Sector* sector = room->getSector(v.x, v.z);\
const Sector* sector = room->getSector(v.x, v.z);\
floor = sector->getFloor(v.x, cy, v.z);\
if (floor != WALL) floor -= p.y;\
ceiling = sector->getCeiling(v.x, cy, v.z);\
Expand Down
24 changes: 12 additions & 12 deletions src/platform/gba/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ vec3i cameraViewPos;
Matrix matrixStack[MAX_MATRICES];
int32 matrixStackIndex = 0;

SaveGame gSaveGame;
EWRAM_DATA SaveGame gSaveGame;

const FloorData* gLastFloorData;
FloorData gLastFloorSlant;

const uint16 divTable[DIV_TABLE_SIZE] = {
const uint16 divTable[DIV_TABLE_SIZE] = { // ROM, not a big difference with IWRAM
0xFFFF, 0xFFFF, 0x8000, 0x5555, 0x4000, 0x3333, 0x2AAA, 0x2492,
0x2000, 0x1C71, 0x1999, 0x1745, 0x1555, 0x13B1, 0x1249, 0x1111,
0x1000, 0x0F0F, 0x0E38, 0x0D79, 0x0CCC, 0x0C30, 0x0BA2, 0x0B21,
Expand Down Expand Up @@ -143,7 +143,7 @@ const uint16 divTable[DIV_TABLE_SIZE] = {
0x0040, 0x0040, 0x0040, 0x0040, 0x0040, 0x0040, 0x0040, 0x0040
};

const int16 sinTable[1025] = {
const int16 sinTable[1025] = { // ROM
0x0000, 0x0019, 0x0032, 0x004B, 0x0065, 0x007E, 0x0097, 0x00B0,
0x00C9, 0x00E2, 0x00FB, 0x0114, 0x012E, 0x0147, 0x0160, 0x0179,
0x0192, 0x01AB, 0x01C4, 0x01DD, 0x01F7, 0x0210, 0x0229, 0x0242,
Expand Down Expand Up @@ -274,7 +274,7 @@ const int16 sinTable[1025] = {
0x3FFF, 0x3FFF, 0x3FFF, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000
};

const int16 atanTable[2050] = {
const int16 atanTable[2050] = { // ROM
0x0000, 0x0005, 0x000A, 0x000F, 0x0014, 0x0019, 0x001F, 0x0024,
0x0029, 0x002E, 0x0033, 0x0038, 0x003D, 0x0042, 0x0047, 0x004C,
0x0051, 0x0057, 0x005C, 0x0061, 0x0066, 0x006B, 0x0070, 0x0075,
Expand Down Expand Up @@ -617,19 +617,19 @@ void anglesFromVector(int32 x, int32 y, int32 z, int16 &angleX, int16 &angleY)
}
}

Box boxRotate(const Box &box, int16 angle)
Bounds boxRotate(const Bounds &box, int16 angle)
{
if (angle == ANGLE_90) {
return Box( box.minZ, box.maxZ, box.minY, box.maxY, -box.maxX, -box.minX );
return Bounds( box.minZ, box.maxZ, box.minY, box.maxY, -box.maxX, -box.minX );
} else if (angle == -ANGLE_90) {
return Box( -box.maxZ, -box.minZ, box.minY, box.maxY, box.minX, box.maxX );
return Bounds( -box.maxZ, -box.minZ, box.minY, box.maxY, box.minX, box.maxX );
} else if (angle == ANGLE_180) {
return Box( -box.maxX, -box.minX, box.minY, box.maxY, -box.maxZ, -box.minZ );
return Bounds( -box.maxX, -box.minX, box.minY, box.maxY, -box.maxZ, -box.minZ );
}
return box;
}

void boxTranslate(Box &box, const vec3i &offset)
void boxTranslate(Bounds &box, const vec3i &offset)
{
box.minX += offset.x;
box.maxX += offset.x;
Expand All @@ -639,21 +639,21 @@ void boxTranslate(Box &box, const vec3i &offset)
box.maxZ += offset.z;
}

bool boxIntersect(const Box &a, const Box &b)
bool boxIntersect(const Bounds &a, const Bounds &b)
{
return !(a.maxX <= b.minX || a.minX >= b.maxX ||
a.maxY <= b.minY || a.minY >= b.maxY ||
a.maxZ <= b.minZ || a.minZ >= b.maxZ);
}

bool boxContains(const Box &a, const vec3i &p)
bool boxContains(const Bounds &a, const vec3i &p)
{
return !(a.minX > p.x || a.maxX < p.x ||
a.minY > p.y || a.maxY < p.y ||
a.minZ > p.z || a.maxZ < p.z);
}

vec3i boxPushOut(const Box &a, const Box &b)
vec3i boxPushOut(const Bounds &a, const Bounds &b)
{
int32 ax = b.maxX - a.minX;
int32 bx = a.maxX - b.minX;
Expand Down
Loading

0 comments on commit e9d6731

Please sign in to comment.