From fc273f2c1c974c27e26acfa3a37d0164da2f3b10 Mon Sep 17 00:00:00 2001 From: XProger Date: Thu, 19 Aug 2021 11:12:14 +0300 Subject: [PATCH] #368 GBA use less accurate ray casting in some cases to boost perf --- src/platform/gba/camera.h | 4 ++-- src/platform/gba/common.h | 2 +- src/platform/gba/lara.h | 6 +++--- src/platform/gba/level.h | 33 +++++++++++++++++++++------------ 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/platform/gba/camera.h b/src/platform/gba/camera.h index 8043caaa..6811b88f 100644 --- a/src/platform/gba/camera.h +++ b/src/platform/gba/camera.h @@ -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) @@ -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); diff --git a/src/platform/gba/common.h b/src/platform/gba/common.h index 2e509677..1b0847ca 100644 --- a/src/platform/gba/common.h +++ b/src/platform/gba/common.h @@ -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); diff --git a/src/platform/gba/lara.h b/src/platform/gba/lara.h index 8da13ac3..a34d0b7e 100644 --- a/src/platform/gba/lara.h +++ b/src/platform/gba/lara.h @@ -3118,7 +3118,7 @@ struct Lara : Item } else { to.pos += dir; - trace(from, to); + trace(from, to, true); fxRicochet(to.room, to.pos, true); } } @@ -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; @@ -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; diff --git a/src/platform/gba/level.h b/src/platform/gba/level.h index 37887798..16a010a8 100644 --- a/src/platform/gba/level.h +++ b/src/platform/gba/level.h @@ -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; @@ -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; @@ -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); @@ -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; }