Skip to content

Commit

Permalink
#368 GBA use less accurate ray casting in some cases to boost perf
Browse files Browse the repository at this point in the history
  • Loading branch information
XProger committed Aug 19, 2021
1 parent f8cd4cd commit fc273f2
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/platform/gba/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ struct Camera

Location best = getLocationForAngle(targetAngleY, distH, distV);

if (trace(target, best))
if (trace(target, best, true))
return best;

if (clip && best.pos != target.pos)
Expand All @@ -168,7 +168,7 @@ struct Camera
Location tmpDest = getLocationForAngle(i * ANGLE_90, distH, distV);
Location tmpView = view;

if (!trace(target, tmpDest) || !trace(tmpDest, tmpView))
if (!trace(target, tmpDest, true) || !trace(tmpDest, tmpView, false))
continue;

distQ = X_SQR(view.pos.x - tmpDest.pos.x) + X_SQR(view.pos.z - tmpDest.pos.z);
Expand Down
2 changes: 1 addition & 1 deletion src/platform/gba/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -1838,7 +1838,7 @@ void faceAddMesh(const Quad* rFaces, const Quad* crFaces, const Triangle* tFaces
void flush();

void readLevel(const uint8 *data);
bool trace(const Location &from, Location &to);
bool trace(const Location &from, Location &to, bool accurate);

Lara* getLara(const vec3i &pos);

Expand Down
6 changes: 3 additions & 3 deletions src/platform/gba/lara.h
Original file line number Diff line number Diff line change
Expand Up @@ -3118,7 +3118,7 @@ struct Lara : Item
} else {
to.pos += dir;

trace(from, to);
trace(from, to, true);
fxRicochet(to.room, to.pos, true);
}
}
Expand Down Expand Up @@ -3583,7 +3583,7 @@ struct Lara : Item
angleAim.x -= angle.x;
angleAim.y -= angle.y;

if (trace(from, to))
if (trace(from, to, false))
{
if (abs(angleAim.x) <= params.aimX && abs(angleAim.y) <= params.aimY) {
extraL->armR.aim = extraL->armL.aim = true;
Expand Down Expand Up @@ -3632,7 +3632,7 @@ struct Lara : Item
Location to;
weaponGetAimPoint(item, to);

if (!trace(from, to))
if (!trace(from, to, false))
continue;

vec3i dir = to.pos - from.pos;
Expand Down
33 changes: 21 additions & 12 deletions src/platform/gba/level.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,24 @@ void readLevel(const uint8* data)
#define TRACE_CHECK(r, x, y, z) \
{ \
const Sector* sector = r->getSector(x, z); \
if (y > sector->getFloor(x, y, z) || y < sector->getCeiling(x, y, z)) \
{ \
to.pos = p; \
to.room = room; \
return false; \
if (accurate) { \
if (y > sector->getFloor(x, y, z) || y < sector->getCeiling(x, y, z)) \
{ \
to.pos = p; \
to.room = room; \
return false; \
} \
} else { \
if (y > (sector->floor << 8) || y < (sector->ceiling << 8)) \
{ \
to.pos = p; \
to.room = room; \
return false; \
} \
} \
}

bool traceX(const Location &from, Location &to)
bool traceX(const Location &from, Location &to, bool accurate)
{
vec3i d = to.pos - from.pos;

Expand Down Expand Up @@ -190,7 +199,7 @@ bool traceX(const Location &from, Location &to)
return true;
}

bool traceZ(const Location &from, Location &to)
bool traceZ(const Location &from, Location &to, bool accurate)
{
vec3i d = to.pos - from.pos;

Expand Down Expand Up @@ -250,7 +259,7 @@ bool traceZ(const Location &from, Location &to)

#undef TRACE_CHECK

bool trace(const Location &from, Location &to)
bool trace(const Location &from, Location &to, bool accurate)
{
int32 dx = abs(to.pos.x - from.pos.x);
int32 dz = abs(to.pos.z - from.pos.z);
Expand All @@ -259,12 +268,12 @@ bool trace(const Location &from, Location &to)
bool res;

if (dz > dx) {
res = traceX(from, to);
if (!traceZ(from, to))
res = traceX(from, to, accurate);
if (!traceZ(from, to, accurate))
return false;
} else {
res = traceZ(from, to);
if (!traceX(from, to))
res = traceZ(from, to, accurate);
if (!traceX(from, to, accurate))
return false;
}

Expand Down

0 comments on commit fc273f2

Please sign in to comment.