From b68c66dae62870adae5fbc0e954964b40676b4da Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 17 Nov 2021 23:53:11 +0100 Subject: [PATCH] -Duke/RR: started migrating hitscan to pointer usage. --- source/build/include/build.h | 6 ++-- source/games/duke/src/actors.cpp | 7 ++-- source/games/duke/src/dukeactor.h | 13 ++++++- source/games/duke/src/player.cpp | 29 +++++++--------- source/games/duke/src/player_d.cpp | 56 ++++++++++++++++-------------- source/games/duke/src/player_r.cpp | 8 ++--- 6 files changed, 63 insertions(+), 56 deletions(-) diff --git a/source/build/include/build.h b/source/build/include/build.h index 9d57bec97..b66793d46 100644 --- a/source/build/include/build.h +++ b/source/build/include/build.h @@ -411,9 +411,9 @@ inline int hitscan(int x, int y, int z, int16_t sectnum, int32_t vx, int32_t vy, vec3_t v{ x,y,z }; hitdata_t hd{}; int res = hitscan(&v, sectnum, vx, vy, vz, &hd, cliptype); - *hitsect = hd.sect; - *hitwall = hd.wall; - *hitspr = hd.sprite; + if (hitsect) *hitsect = hd.sect; + if (hitwall) *hitwall = hd.wall; + if (hitspr) *hitspr = hd.sprite; *hitx = hd.pos.x; *hity = hd.pos.y; *hitz = hd.pos.z ; diff --git a/source/games/duke/src/actors.cpp b/source/games/duke/src/actors.cpp index fec099f7a..8813b5ac6 100644 --- a/source/games/duke/src/actors.cpp +++ b/source/games/duke/src/actors.cpp @@ -5072,9 +5072,8 @@ int dodge(DDukeActor* actor) int furthestangle(DDukeActor *actor, int angs) { auto s = actor->s; - int j, hitsect, hitwall, furthest_angle = 0, angincs; + int j, furthest_angle = 0, angincs; int hx, hy, hz, d, greatestd; - DDukeActor* dd; greatestd = -(1 << 30); angincs = 2048 / angs; @@ -5084,7 +5083,7 @@ int furthestangle(DDukeActor *actor, int angs) for (j = s->ang; j < (2048 + s->ang); j += angincs) { - hitscan(s->x, s->y, s->z - (8 << 8), s->sectnum, bcos(j), bsin(j), 0, &hitsect, &hitwall, &dd, &hx, &hy, &hz, CLIPMASK1); + hitscan(s->x, s->y, s->z - (8 << 8), s->sectnum, bcos(j), bsin(j), 0, nullptr, nullptr, nullptr, &hx, &hy, &hz, CLIPMASK1); d = abs(hx - s->x) + abs(hy - s->y); @@ -5119,7 +5118,7 @@ int furthestcanseepoint(DDukeActor *actor, DDukeActor* tosee, int* dax, int* day auto ts = tosee->s; for (j = ts->ang; j < (2048 + ts->ang); j += (angincs - (krand() & 511))) { - hitscan(ts->x, ts->y, ts->z - (16 << 8), ts->sectnum, bcos(j), bsin(j), 16384 - (krand() & 32767), + hitscanw(ts->x, ts->y, ts->z - (16 << 8), ts->sectnum, bcos(j), bsin(j), 16384 - (krand() & 32767), &hitsect, &hitwall, &dd, &hx, &hy, &hz, CLIPMASK1); d = abs(hx - ts->x) + abs(hy - ts->y); diff --git a/source/games/duke/src/dukeactor.h b/source/games/duke/src/dukeactor.h index 8b4373acb..a693b6f4e 100644 --- a/source/games/duke/src/dukeactor.h +++ b/source/games/duke/src/dukeactor.h @@ -197,7 +197,7 @@ inline void getzrange_ex(int x, int y, int z, int sectnum, int32_t* ceilz, Colli florhit.setFromEngine(fh); } -inline int hitscan(int x, int y, int z, int sectnum, int32_t vx, int32_t vy, int32_t vz, +inline int hitscanw(int x, int y, int z, int sectnum, int32_t vx, int32_t vy, int32_t vz, int* hitsect, int* hitwall, DDukeActor** hitspr, int* hitx, int* hity, int* hitz, uint32_t cliptype) { short hitsprt, hitsct, hitwal; @@ -208,6 +208,17 @@ inline int hitscan(int x, int y, int z, int sectnum, int32_t vx, int32_t vy, int return res; } +inline int hitscan(int x, int y, int z, int sectnum, int32_t vx, int32_t vy, int32_t vz, + sectortype** hitsect, walltype** hitwall, DDukeActor** hitspr, int* hitx, int* hity, int* hitz, uint32_t cliptype) +{ + short hitsprt, hitsct, hitwal; + int res = ::hitscan(x, y, z, sectnum, vx, vy, vz, &hitsct, &hitwal, &hitsprt, hitx, hity, hitz, cliptype); + if (hitspr) *hitspr = hitsprt == -1 ? nullptr : &hittype[hitsprt]; + if (hitsect) *hitsect = hitsct >= 0? §or[hitsct] : nullptr; + if (hitwall) *hitwall = hitwal >= 0? &wall[hitwal] : nullptr; + return res; +} + inline void neartag(int32_t xs, int32_t ys, int32_t zs, int sectnum, int ange, int* neartagsector, int* neartagwall, DDukeActor** neartagsprite, int32_t* neartaghitdist, int32_t neartagrange, uint8_t tagsearch) diff --git a/source/games/duke/src/player.cpp b/source/games/duke/src/player.cpp index 8c2167a27..1ca12aa8a 100644 --- a/source/games/duke/src/player.cpp +++ b/source/games/duke/src/player.cpp @@ -170,15 +170,12 @@ int hits(DDukeActor* actor) { auto sp = actor->s; int sx, sy, sz; - int sect; - int hw; int zoff; - DDukeActor* d; if (sp->picnum == TILE_APLAYER) zoff = isRR() ? PHEIGHT_RR : PHEIGHT_DUKE; else zoff = 0; - hitscan(sp->x, sp->y, sp->z - zoff, sp->sectnum, bcos(sp->ang), bsin(sp->ang), 0, §, &hw, &d, &sx, &sy, &sz, CLIPMASK1); + hitscan(sp->x, sp->y, sp->z - zoff, sp->sectnum, bcos(sp->ang), bsin(sp->ang), 0, nullptr, nullptr, nullptr, &sx, &sy, &sz, CLIPMASK1); return (FindDistance2D(sx - sp->x, sy - sp->y)); } @@ -193,16 +190,16 @@ int hitasprite(DDukeActor* actor, DDukeActor** hitsp) { auto sp = actor->s; int sx, sy, sz, zoff; - int sect, hw; + walltype* wal; if (badguy(actor)) zoff = (42 << 8); else if (sp->picnum == TILE_APLAYER) zoff = (39 << 8); else zoff = 0; - hitscan(sp->x, sp->y, sp->z - zoff, sp->sectnum, bcos(sp->ang), bsin(sp->ang), 0, §, &hw, hitsp, &sx, &sy, &sz, CLIPMASK1); + hitscan(sp->x, sp->y, sp->z - zoff, sp->sectnum, bcos(sp->ang), bsin(sp->ang), 0, nullptr, &wal, hitsp, &sx, &sy, &sz, CLIPMASK1); - if (hw >= 0 && (wall[hw].cstat & 16) && badguy(actor)) + if (wal != nullptr && (wal->cstat & 16) && badguy(actor)) return((1 << 30)); return (FindDistance2D(sx - sp->x, sy - sp->y)); @@ -217,11 +214,10 @@ int hitasprite(DDukeActor* actor, DDukeActor** hitsp) int hitawall(struct player_struct* p, int* hitw) { int sx, sy, sz; - int sect, hitw1; - DDukeActor* d; + int hitw1; - hitscan(p->pos.x, p->pos.y, p->pos.z, p->cursectnum, - p->angle.ang.bcos(), p->angle.ang.bsin(), 0, §, &hitw1, &d, &sx, &sy, &sz, CLIPMASK0); + hitscanw(p->pos.x, p->pos.y, p->pos.z, p->cursectnum, + p->angle.ang.bcos(), p->angle.ang.bsin(), 0, nullptr, &hitw1, nullptr, &sx, &sy, &sz, CLIPMASK0); *hitw = hitw1; return (FindDistance2D(sx - p->pos.x, sy - p->pos.y)); @@ -1006,8 +1002,9 @@ void shootbloodsplat(DDukeActor* actor, int p, int sx, int sy, int sz, int sa, i spritetype* const s = actor->s; int sect = s->sectnum; int zvel; - int hitsect, hitwall; int hitx, hity, hitz; + sectortype* hitsectp; + walltype* wal; DDukeActor* d; if (p >= 0) @@ -1019,14 +1016,12 @@ void shootbloodsplat(DDukeActor* actor, int p, int sx, int sy, int sz, int sa, i hitscan(sx, sy, sz, sect, bcos(sa), bsin(sa), zvel << 6, - &hitsect, &hitwall, &d, &hitx, &hity, &hitz, CLIPMASK1); + &hitsectp, &wal, &d, &hitx, &hity, &hitz, CLIPMASK1); - auto wal = hitwall < 0? nullptr : &wall[hitwall]; - auto hitsectp = hitsect < 0? nullptr : §or[hitsect]; // oh my... if (FindDistance2D(sx - hitx, sy - hity) < 1024 && - (hitwall >= 0 && wal->overpicnum != BIGFORCE) && - ((wal->nextsector >= 0 && hitsect >= 0 && + (wal != nullptr && wal->overpicnum != BIGFORCE) && + ((wal->nextsector >= 0 && hitsectp != nullptr && wal->nextSector()->lotag == 0 && hitsectp->lotag == 0 && (hitsectp->floorz - wal->nextSector()->floorz) > (16 << 8)) || diff --git a/source/games/duke/src/player_d.cpp b/source/games/duke/src/player_d.cpp index 0d1dca846..4e95577d6 100644 --- a/source/games/duke/src/player_d.cpp +++ b/source/games/duke/src/player_d.cpp @@ -232,9 +232,10 @@ static void shootknee(DDukeActor* actor, int p, int sx, int sy, int sz, int sa) auto s = actor->s; int sect = s->sectnum; int zvel; - int hitsect, hitwall; int hitx, hity, hitz; DDukeActor* hitsprt; + sectortype* hitsectp; + walltype* hitwallp; if (p >= 0) { @@ -253,16 +254,16 @@ static void shootknee(DDukeActor* actor, int p, int sx, int sy, int sz, int sa) hitscan(sx, sy, sz, sect, bcos(sa), bsin(sa), zvel << 6, - &hitsect, &hitwall, &hitsprt, &hitx, &hity, &hitz, CLIPMASK1); + &hitsectp, &hitwallp, &hitsprt, &hitx, &hity, &hitz, CLIPMASK1); - if (hitsect < 0) return; + if (hitsectp == nullptr) return; if ((abs(sx - hitx) + abs(sy - hity)) < 1024) { - if (hitwall >= 0 || hitsprt) + if (hitwallp || hitsprt) { - auto knee = EGS(hitsect, hitx, hity, hitz, KNEE, -15, 0, 0, sa, 32, 0, actor, 4); + auto knee = EGS(sectnum(hitsectp), hitx, hity, hitz, KNEE, -15, 0, 0, sa, 32, 0, actor, 4); knee->s->extra += (krand() & 7); if (p >= 0) { @@ -280,9 +281,9 @@ static void shootknee(DDukeActor* actor, int p, int sx, int sy, int sz, int sa) if (p >= 0) fi.checkhitswitch(p, -1, hitsprt); } - else if (hitwall >= 0) + else if (hitwallp) { - auto wal = &wall[hitwall]; + auto wal = hitwallp; if (wal->cstat & 2) if (wal->nextsector >= 0) if (hitz >= (wal->nextSector()->floorz)) @@ -295,7 +296,7 @@ static void shootknee(DDukeActor* actor, int p, int sx, int sy, int sz, int sa) } } } - else if (p >= 0 && zvel > 0 && sector[hitsect].lotag == 1) + else if (p >= 0 && zvel > 0 && hitsectp->lotag == 1) { auto splash = spawn(ps[p].GetActor(), WATERSPLASH2); splash->s->x = hitx; @@ -320,9 +321,10 @@ static void shootweapon(DDukeActor *actor, int p, int sx, int sy, int sz, int sa auto s = actor->s; int sect = s->sectnum; int zvel = 0; - int hitsect, hitwall; int hitx, hity, hitz; DDukeActor* hitact; + sectortype* hitsectp; + walltype* hitwallp; if (s->extra >= 0) s->shade = -96; @@ -407,34 +409,34 @@ static void shootweapon(DDukeActor *actor, int p, int sx, int sy, int sz, int sa hitscan(sx, sy, sz, sect, bcos(sa), bsin(sa), - zvel << 6, &hitsect, &hitwall, &hitact, &hitx, &hity, &hitz, CLIPMASK1); + zvel << 6, &hitsectp, &hitwallp, &hitact, &hitx, &hity, &hitz, CLIPMASK1); s->cstat |= 257; - if (hitsect < 0) return; + if (hitsectp == nullptr) return; - if ((krand() & 15) == 0 && sector[hitsect].lotag == 2) + if ((krand() & 15) == 0 && hitsectp->lotag == 2) tracers(hitx, hity, hitz, sx, sy, sz, 8 - (ud.multimode >> 1)); DDukeActor* spark; if (p >= 0) { - spark = EGS(hitsect, hitx, hity, hitz, SHOTSPARK1, -15, 10, 10, sa, 0, 0, actor, 4); + spark = EGS(sectnum(hitsectp), hitx, hity, hitz, SHOTSPARK1, -15, 10, 10, sa, 0, 0, actor, 4); spark->s->extra = ScriptCode[gs.actorinfo[atwith].scriptaddress]; spark->s->extra += (krand() % 6); - if (hitwall == -1 && hitact == nullptr) + if (hitwallp == nullptr && hitact == nullptr) { if (zvel < 0) { - if (sector[hitsect].ceilingstat & 1) + if (hitsectp->ceilingstat & 1) { spark->s->xrepeat = 0; spark->s->yrepeat = 0; return; } else - fi.checkhitceiling(hitsect); + fi.checkhitceiling(sectnum(hitsectp)); } spawn(spark, SMALLSMOKE); } @@ -467,10 +469,10 @@ static void shootweapon(DDukeActor *actor, int p, int sx, int sy, int sz, int sa return; } } - else if (hitwall >= 0) + else if (hitwallp) { spawn(spark, SMALLSMOKE); - auto wal = &wall[hitwall]; + auto wal = hitwallp; if (fi.isadoorwall(wal->picnum) == 1) goto SKIPBULLETHOLE; @@ -484,17 +486,17 @@ static void shootweapon(DDukeActor *actor, int p, int sx, int sy, int sz, int sa wal->picnum == HANDSWITCH || wal->picnum == HANDSWITCH + 1)) { - fi.checkhitswitch(p, hitwall, nullptr); + fi.checkhitswitch(p, wallnum(wal), nullptr); return; } if (wal->hitag != 0 || (wal->nextwall >= 0 && wal->nextWall()->hitag != 0)) goto SKIPBULLETHOLE; - if (hitsect >= 0 && sector[hitsect].lotag == 0) + if (hitsectp && hitsectp->lotag == 0) if (wal->overpicnum != BIGFORCE) if ((wal->nextsector >= 0 && wal->nextSector()->lotag == 0) || - (wal->nextsector == -1 && sector[hitsect].lotag == 0)) + (wal->nextsector == -1 && hitsectp->lotag == 0)) if ((wal->cstat & 16) == 0) { if (wal->nextsector >= 0) @@ -533,7 +535,7 @@ static void shootweapon(DDukeActor *actor, int p, int sx, int sy, int sz, int sa } else { - spark = EGS(hitsect, hitx, hity, hitz, SHOTSPARK1, -15, 24, 24, sa, 0, 0, actor, 4); + spark = EGS(sectnum(hitsectp), hitx, hity, hitz, SHOTSPARK1, -15, 24, 24, sa, 0, 0, actor, 4); spark->s->extra = ScriptCode[gs.actorinfo[atwith].scriptaddress]; if (hitact) @@ -543,8 +545,8 @@ static void shootweapon(DDukeActor *actor, int p, int sx, int sy, int sz, int sa spawn(spark, SMALLSMOKE); else spark->s->xrepeat = spark->s->yrepeat = 0; } - else if (hitwall >= 0) - fi.checkhitwall(spark, &wall[hitwall], hitx, hity, hitz, SHOTSPARK1); + else if (hitwallp) + fi.checkhitwall(spark, hitwallp, hitx, hity, hitz, SHOTSPARK1); } if ((krand() & 255) < 4) @@ -850,7 +852,7 @@ static void shootlaser(DDukeActor* actor, int p, int sx, int sy, int sz, int sa) zvel = -ps[p].horizon.sum().asq16() >> 11; else zvel = 0; - hitscan(sx, sy, sz - ps[p].pyoff, sect, + hitscanw(sx, sy, sz - ps[p].pyoff, sect, bcos(sa), bsin(sa), zvel << 6, &hitsect, &hitwall, &hitsprt, &hitx, &hity, &hitz, CLIPMASK1); @@ -968,7 +970,7 @@ static void shootgrowspark(DDukeActor* actor, int p, int sx, int sy, int sz, int //RESHOOTGROW: s->cstat &= ~257; - hitscan(sx, sy, sz, sect, bcos(sa), bsin(sa), + hitscanw(sx, sy, sz, sect, bcos(sa), bsin(sa), zvel << 6, &hitsect, &hitwall, &hitsprt, &hitx, &hity, &hitz, CLIPMASK1); s->cstat |= 257; @@ -2015,7 +2017,7 @@ int operateTripbomb(int snum) int sect, hw; DDukeActor* hitsprt; - hitscan(p->pos.x, p->pos.y, p->pos.z, + hitscanw(p->pos.x, p->pos.y, p->pos.z, p->cursectnum, p->angle.ang.bcos(), p->angle.ang.bsin(), -p->horizon.sum().asq16() >> 11, §, &hw, &hitsprt, &sx, &sy, &sz, CLIPMASK1); diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp index fbc36fa86..c1a6d688e 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -106,7 +106,7 @@ static void shootmelee(DDukeActor *actor, int p, int sx, int sy, int sz, int sa, sa = getangle(pspr->s->x - sx, pspr->s->y - sy); } - hitscan(sx, sy, sz, sect, + hitscanw(sx, sy, sz, sect, bcos(sa), bsin(sa), zvel << 6, &hitsect, &hitwall, &hitsprt, &hitx, &hity, &hitz, CLIPMASK1); @@ -132,7 +132,7 @@ static void shootmelee(DDukeActor *actor, int p, int sx, int sy, int sz, int sa, { nz = effector->GetOwner()->getSector()->ceilingz; } - hitscan(nx, ny, nz, effector->GetOwner()->s->sectnum, bcos(sa), bsin(sa), zvel << 6, + hitscanw(nx, ny, nz, effector->GetOwner()->s->sectnum, bcos(sa), bsin(sa), zvel << 6, &hitsect, &hitwall, &hitsprt, &hitx, &hity, &hitz, CLIPMASK1); break; } @@ -266,7 +266,7 @@ static void shootweapon(DDukeActor* actor, int p, int sx, int sy, int sz, int sa } s->cstat &= ~257; - hitscan(sx, sy, sz, sect, bcos(sa), bsin(sa), + hitscanw(sx, sy, sz, sect, bcos(sa), bsin(sa), zvel << 6, &hitsect, &hitwall, &hitsprt, &hitx, &hity, &hitz, CLIPMASK1); if (isRRRA() && hitsect >= 0 && (((sector[hitsect].lotag == 160 && zvel > 0) || (sector[hitsect].lotag == 161 && zvel < 0)) @@ -290,7 +290,7 @@ static void shootweapon(DDukeActor* actor, int p, int sx, int sy, int sz, int sa { nz = effector->GetOwner()->getSector()->ceilingz; } - hitscan(nx, ny, nz, effector->GetOwner()->s->sectnum, bcos(sa), bsin(sa), zvel << 6, + hitscanw(nx, ny, nz, effector->GetOwner()->s->sectnum, bcos(sa), bsin(sa), zvel << 6, &hitsect, &hitwall, &hitsprt, &hitx, &hity, &hitz, CLIPMASK1); break; }