Skip to content

Commit fc273f2

Browse files
committed
#368 GBA use less accurate ray casting in some cases to boost perf
1 parent f8cd4cd commit fc273f2

File tree

4 files changed

+27
-18
lines changed

4 files changed

+27
-18
lines changed

src/platform/gba/camera.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ struct Camera
150150

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

153-
if (trace(target, best))
153+
if (trace(target, best, true))
154154
return best;
155155

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

171-
if (!trace(target, tmpDest) || !trace(tmpDest, tmpView))
171+
if (!trace(target, tmpDest, true) || !trace(tmpDest, tmpView, false))
172172
continue;
173173

174174
distQ = X_SQR(view.pos.x - tmpDest.pos.x) + X_SQR(view.pos.z - tmpDest.pos.z);

src/platform/gba/common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1838,7 +1838,7 @@ void faceAddMesh(const Quad* rFaces, const Quad* crFaces, const Triangle* tFaces
18381838
void flush();
18391839

18401840
void readLevel(const uint8 *data);
1841-
bool trace(const Location &from, Location &to);
1841+
bool trace(const Location &from, Location &to, bool accurate);
18421842

18431843
Lara* getLara(const vec3i &pos);
18441844

src/platform/gba/lara.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3118,7 +3118,7 @@ struct Lara : Item
31183118
} else {
31193119
to.pos += dir;
31203120

3121-
trace(from, to);
3121+
trace(from, to, true);
31223122
fxRicochet(to.room, to.pos, true);
31233123
}
31243124
}
@@ -3583,7 +3583,7 @@ struct Lara : Item
35833583
angleAim.x -= angle.x;
35843584
angleAim.y -= angle.y;
35853585

3586-
if (trace(from, to))
3586+
if (trace(from, to, false))
35873587
{
35883588
if (abs(angleAim.x) <= params.aimX && abs(angleAim.y) <= params.aimY) {
35893589
extraL->armR.aim = extraL->armL.aim = true;
@@ -3632,7 +3632,7 @@ struct Lara : Item
36323632
Location to;
36333633
weaponGetAimPoint(item, to);
36343634

3635-
if (!trace(from, to))
3635+
if (!trace(from, to, false))
36363636
continue;
36373637

36383638
vec3i dir = to.pos - from.pos;

src/platform/gba/level.h

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,24 @@ void readLevel(const uint8* data)
124124
#define TRACE_CHECK(r, x, y, z) \
125125
{ \
126126
const Sector* sector = r->getSector(x, z); \
127-
if (y > sector->getFloor(x, y, z) || y < sector->getCeiling(x, y, z)) \
128-
{ \
129-
to.pos = p; \
130-
to.room = room; \
131-
return false; \
127+
if (accurate) { \
128+
if (y > sector->getFloor(x, y, z) || y < sector->getCeiling(x, y, z)) \
129+
{ \
130+
to.pos = p; \
131+
to.room = room; \
132+
return false; \
133+
} \
134+
} else { \
135+
if (y > (sector->floor << 8) || y < (sector->ceiling << 8)) \
136+
{ \
137+
to.pos = p; \
138+
to.room = room; \
139+
return false; \
140+
} \
132141
} \
133142
}
134143

135-
bool traceX(const Location &from, Location &to)
144+
bool traceX(const Location &from, Location &to, bool accurate)
136145
{
137146
vec3i d = to.pos - from.pos;
138147

@@ -190,7 +199,7 @@ bool traceX(const Location &from, Location &to)
190199
return true;
191200
}
192201

193-
bool traceZ(const Location &from, Location &to)
202+
bool traceZ(const Location &from, Location &to, bool accurate)
194203
{
195204
vec3i d = to.pos - from.pos;
196205

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

251260
#undef TRACE_CHECK
252261

253-
bool trace(const Location &from, Location &to)
262+
bool trace(const Location &from, Location &to, bool accurate)
254263
{
255264
int32 dx = abs(to.pos.x - from.pos.x);
256265
int32 dz = abs(to.pos.z - from.pos.z);
@@ -259,12 +268,12 @@ bool trace(const Location &from, Location &to)
259268
bool res;
260269

261270
if (dz > dx) {
262-
res = traceX(from, to);
263-
if (!traceZ(from, to))
271+
res = traceX(from, to, accurate);
272+
if (!traceZ(from, to, accurate))
264273
return false;
265274
} else {
266-
res = traceZ(from, to);
267-
if (!traceX(from, to))
275+
res = traceZ(from, to, accurate);
276+
if (!traceX(from, to, accurate))
268277
return false;
269278
}
270279

0 commit comments

Comments
 (0)