From 857e755b92952da8f57a80c0029d368353d15c48 Mon Sep 17 00:00:00 2001 From: joshuarwood Date: Fri, 7 Nov 2025 15:08:50 -0600 Subject: [PATCH 1/4] added flag to ignore line-of-sight hits for transparent background surfaces --- src/game/bg.c | 4 ++++ src/game/prop.c | 13 ++++++++----- src/include/types.h | 3 +++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/game/bg.c b/src/game/bg.c index d1569bdc4..8a2a53615 100644 --- a/src/game/bg.c +++ b/src/game/bg.c @@ -4590,6 +4590,10 @@ bool bgTestHitInRoom(struct coord *frompos, struct coord *topos, s32 roomnum, st numbatches = g_Rooms[roomnum].numvtxbatches; for (i = 0; i < numbatches; batch++, i++) { +#ifndef PLATFORM_N64 + if (hitthing->ignore_xlu && batch->type == VTXBATCHTYPE_XLU) + continue; +#endif j = bg0f1612e4(&batch->bbmin, &batch->bbmax, &from, &dist, &sp94, &hitthing->pos); if (j == 0) { diff --git a/src/game/prop.c b/src/game/prop.c index ae18152d0..05118904e 100644 --- a/src/game/prop.c +++ b/src/game/prop.c @@ -983,7 +983,7 @@ struct prop *shotCalculateHits(s32 handnum, bool isshooting, struct coord *gunpo bool shotTestLos(struct coord *gunpos2d, struct coord *gundir2d, struct coord *gunpos3d, struct coord *gundir3d, struct coord *endpos3d) { struct prop **propptr; - struct hitthing sp664; + struct hitthing hitthing; struct coord delta; struct shotdata shotdata; s32 i; @@ -993,6 +993,9 @@ bool shotTestLos(struct coord *gunpos2d, struct coord *gundir2d, struct coord *g RoomNum *roomsptr; struct prop *prop; + // ignore transparent surfaces + hitthing.ignore_xlu = 1; + shotdata.gunpos3d.x = gunpos3d->x; shotdata.gunpos3d.y = gunpos3d->y; shotdata.gunpos3d.z = gunpos3d->z; @@ -1040,11 +1043,11 @@ bool shotTestLos(struct coord *gunpos2d, struct coord *gundir2d, struct coord *g // Check for BG hits first for (i = 0; rooms[i] != -1; i++) { - if (bgTestHitInRoom(&shotdata.gunpos3d, endpos3d, rooms[i], &sp664)) { + if (bgTestHitInRoom(&shotdata.gunpos3d, endpos3d, rooms[i], &hitthing)) { // check if it's far enough away from the end point - if (fabsf(sp664.pos.x - endpos3d->x) >= 0.1f || - fabsf(sp664.pos.y - endpos3d->y) >= 0.1f || - fabsf(sp664.pos.z - endpos3d->z) >= 0.1f) { + if (fabsf(hitthing.pos.x - endpos3d->x) >= 0.1f || + fabsf(hitthing.pos.y - endpos3d->y) >= 0.1f || + fabsf(hitthing.pos.z - endpos3d->z) >= 0.1f) { return false; } } diff --git a/src/include/types.h b/src/include/types.h index 2bd8fdd2c..5c5c19338 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -5750,6 +5750,9 @@ struct hitthing { s16 unk28; s16 texturenum; s16 unk2c; +#ifndef PLATFORM_N64 + s16 ignore_xlu; +#endif }; struct hit { From 7a728c7febf1ed44662e5bc1085b6b4f4eb4c73a Mon Sep 17 00:00:00 2001 From: joshuarwood Date: Fri, 7 Nov 2025 15:11:09 -0600 Subject: [PATCH 2/4] Removing commit that was intended for a different branch This reverts commit 857e755b92952da8f57a80c0029d368353d15c48. --- src/game/bg.c | 4 ---- src/game/prop.c | 13 +++++-------- src/include/types.h | 3 --- 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/src/game/bg.c b/src/game/bg.c index 8a2a53615..d1569bdc4 100644 --- a/src/game/bg.c +++ b/src/game/bg.c @@ -4590,10 +4590,6 @@ bool bgTestHitInRoom(struct coord *frompos, struct coord *topos, s32 roomnum, st numbatches = g_Rooms[roomnum].numvtxbatches; for (i = 0; i < numbatches; batch++, i++) { -#ifndef PLATFORM_N64 - if (hitthing->ignore_xlu && batch->type == VTXBATCHTYPE_XLU) - continue; -#endif j = bg0f1612e4(&batch->bbmin, &batch->bbmax, &from, &dist, &sp94, &hitthing->pos); if (j == 0) { diff --git a/src/game/prop.c b/src/game/prop.c index 05118904e..ae18152d0 100644 --- a/src/game/prop.c +++ b/src/game/prop.c @@ -983,7 +983,7 @@ struct prop *shotCalculateHits(s32 handnum, bool isshooting, struct coord *gunpo bool shotTestLos(struct coord *gunpos2d, struct coord *gundir2d, struct coord *gunpos3d, struct coord *gundir3d, struct coord *endpos3d) { struct prop **propptr; - struct hitthing hitthing; + struct hitthing sp664; struct coord delta; struct shotdata shotdata; s32 i; @@ -993,9 +993,6 @@ bool shotTestLos(struct coord *gunpos2d, struct coord *gundir2d, struct coord *g RoomNum *roomsptr; struct prop *prop; - // ignore transparent surfaces - hitthing.ignore_xlu = 1; - shotdata.gunpos3d.x = gunpos3d->x; shotdata.gunpos3d.y = gunpos3d->y; shotdata.gunpos3d.z = gunpos3d->z; @@ -1043,11 +1040,11 @@ bool shotTestLos(struct coord *gunpos2d, struct coord *gundir2d, struct coord *g // Check for BG hits first for (i = 0; rooms[i] != -1; i++) { - if (bgTestHitInRoom(&shotdata.gunpos3d, endpos3d, rooms[i], &hitthing)) { + if (bgTestHitInRoom(&shotdata.gunpos3d, endpos3d, rooms[i], &sp664)) { // check if it's far enough away from the end point - if (fabsf(hitthing.pos.x - endpos3d->x) >= 0.1f || - fabsf(hitthing.pos.y - endpos3d->y) >= 0.1f || - fabsf(hitthing.pos.z - endpos3d->z) >= 0.1f) { + if (fabsf(sp664.pos.x - endpos3d->x) >= 0.1f || + fabsf(sp664.pos.y - endpos3d->y) >= 0.1f || + fabsf(sp664.pos.z - endpos3d->z) >= 0.1f) { return false; } } diff --git a/src/include/types.h b/src/include/types.h index 5c5c19338..2bd8fdd2c 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -5750,9 +5750,6 @@ struct hitthing { s16 unk28; s16 texturenum; s16 unk2c; -#ifndef PLATFORM_N64 - s16 ignore_xlu; -#endif }; struct hit { From 42ef08d662327b5475f26b75100d911a13ed4dcb Mon Sep 17 00:00:00 2001 From: joshuarwood Date: Fri, 7 Nov 2025 19:50:42 -0600 Subject: [PATCH 3/4] check surfacetype to better skip glass props --- src/game/prop.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/game/prop.c b/src/game/prop.c index ae18152d0..679247a10 100644 --- a/src/game/prop.c +++ b/src/game/prop.c @@ -1070,7 +1070,9 @@ bool shotTestLos(struct coord *gunpos2d, struct coord *gundir2d, struct coord *g } if (shotdata.hits[0].prop) { // ignore some glass parts and shields - if (shotdata.hits[0].slowsbullet && shotdata.hits[0].hitthing.texturenum != 10000) { + if (shotdata.hits[0].slowsbullet && shotdata.hits[0].hitthing.texturenum != 10000 && + g_Textures[shotdata.hits[0].hitthing.texturenum].surfacetype != SURFACETYPE_GLASS && + g_Textures[shotdata.hits[0].hitthing.texturenum].surfacetype != SURFACETYPE_GLASSXLU) { return false; } } From b53a62189bec81418c24682933ec96c118623790 Mon Sep 17 00:00:00 2001 From: joshuarwood Date: Sun, 9 Nov 2025 01:30:49 -0600 Subject: [PATCH 4/4] protect against surface indexing errors --- src/game/prop.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/game/prop.c b/src/game/prop.c index 679247a10..511f7a6d3 100644 --- a/src/game/prop.c +++ b/src/game/prop.c @@ -992,6 +992,8 @@ bool shotTestLos(struct coord *gunpos2d, struct coord *gundir2d, struct coord *g RoomNum spb8[8]; RoomNum *roomsptr; struct prop *prop; + s16 texturenum; + u32 surfacetype; shotdata.gunpos3d.x = gunpos3d->x; shotdata.gunpos3d.y = gunpos3d->y; @@ -1069,10 +1071,11 @@ bool shotTestLos(struct coord *gunpos2d, struct coord *gundir2d, struct coord *g objTestHit(prop, &shotdata); } if (shotdata.hits[0].prop) { + texturenum = shotdata.hits[0].hitthing.texturenum; + surfacetype = (texturenum >= 0 && texturenum < NUM_TEXTURES) ? g_Textures[texturenum].surfacetype : SURFACETYPE_DEFAULT; // ignore some glass parts and shields - if (shotdata.hits[0].slowsbullet && shotdata.hits[0].hitthing.texturenum != 10000 && - g_Textures[shotdata.hits[0].hitthing.texturenum].surfacetype != SURFACETYPE_GLASS && - g_Textures[shotdata.hits[0].hitthing.texturenum].surfacetype != SURFACETYPE_GLASSXLU) { + if (shotdata.hits[0].slowsbullet && texturenum != 10000 && + surfacetype != SURFACETYPE_GLASS && surfacetype != SURFACETYPE_GLASSXLU) { return false; } }