diff --git a/source/build/include/build.h b/source/build/include/build.h index 246cfcb43..9ff83de6c 100644 --- a/source/build/include/build.h +++ b/source/build/include/build.h @@ -370,6 +370,13 @@ class F2DDrawer; void getzrange(const vec3_t *pos, int16_t sectnum, int32_t *ceilz, int32_t *ceilhit, int32_t *florz, int32_t *florhit, int32_t walldist, uint32_t cliptype) ATTRIBUTE((nonnull(1,3,4,5,6))); + +inline void getzrange(const vec3_t* pos, sectortype* sect, int32_t* ceilz, int32_t* ceilhit, int32_t* florz, + int32_t* florhit, int32_t walldist, uint32_t cliptype) +{ + getzrange(pos, sector.IndexOf(sect), ceilz, ceilhit, florz, florhit, walldist, cliptype); +} + inline void getzrange(int x, int y, int z, int16_t sectnum, int32_t* ceilz, int32_t* ceilhit, int32_t* florz, int32_t* florhit, int32_t walldist, uint32_t cliptype) { diff --git a/source/games/blood/src/actor.cpp b/source/games/blood/src/actor.cpp index a7efdf942..b522a1bf1 100644 --- a/source/games/blood/src/actor.cpp +++ b/source/games/blood/src/actor.cpp @@ -5340,18 +5340,18 @@ int MoveMissile(DBloodActor* actor) while (1) { vec3_t pos = pSprite->pos; - int nSector2 = pSprite->sectnum; + auto pSector2 = pSprite->sector(); const auto bakSpriteCstat = pSprite->cstat; if (pOwner && !isFlameSprite && !cl_bloodvanillaexplosions && !VanillaMode()) { enginecompatibility_mode = ENGINECOMPATIBILITY_NONE; // improved clipmove accuracy pSprite->cstat &= ~257; // remove self collisions for accurate clipmove } - Collision clipmoveresult = ClipMove(&pos, &nSector2, vx, vy, pSprite->clipdist << 2, (pos.z - top) / 4, (bottom - pos.z) / 4, CLIPMASK0, 1); + Collision clipmoveresult = ClipMove(&pos, &pSector2, vx, vy, pSprite->clipdist << 2, (pos.z - top) / 4, (bottom - pos.z) / 4, CLIPMASK0, 1); enginecompatibility_mode = bakCompat; // restore pSprite->cstat = bakSpriteCstat; - int nSector = nSector2; - if (nSector2 < 0) + auto pSector = pSector2; + if (pSector2 == nullptr) { cliptype = -1; break; @@ -5368,7 +5368,7 @@ int MoveMissile(DBloodActor* actor) else { int32_t fz, cz; - getzsofslope(clipmoveresult.wall()->nextsector, pos.x, pos.y, &cz, &fz); + getzsofslopeptr(clipmoveresult.wall()->nextSector(), pos.x, pos.y, &cz, &fz); if (pos.z <= cz || pos.z >= fz) cliptype = 0; else cliptype = 4; } @@ -5400,12 +5400,12 @@ int MoveMissile(DBloodActor* actor) pos.y -= MulScale(Sin(nAngle), 16, 30); int nVel = approxDist(actor->xvel, actor->yvel); vz -= scale(0x100, actor->zvel, nVel); - updatesector(pos.x, pos.y, &nSector); - nSector2 = nSector; + updatesector(pos.x, pos.y, &pSector); + pSector2 = pSector; } int ceilZ, floorZ; Collision ceilColl, floorColl; - GetZRangeAtXYZ(pos.x, pos.y, pos.z, nSector2, &ceilZ, &ceilColl, &floorZ, &floorColl, pSprite->clipdist << 2, CLIPMASK0); + GetZRangeAtXYZ(pos.x, pos.y, pos.z, pSector2, &ceilZ, &ceilColl, &floorZ, &floorColl, pSprite->clipdist << 2, CLIPMASK0); GetActorExtents(actor, &top, &bottom); top += vz; bottom += vz; @@ -5423,11 +5423,11 @@ int MoveMissile(DBloodActor* actor) } pSprite->pos = pos; pSprite->z += vz; - updatesector(pos.x, pos.y, &nSector); - if (nSector >= 0 && nSector != pSprite->sectnum) + updatesector(pos.x, pos.y, &pSector); + if (pSector != nullptr && pSector != pSprite->sector()) { - assert(validSectorIndex(nSector)); - ChangeActorSect(actor, nSector); + assert(pSector); + ChangeActorSect(actor, pSector); } CheckLink(actor); gHitInfo.hitSect = pSprite->sector(); diff --git a/source/games/blood/src/gameutil.cpp b/source/games/blood/src/gameutil.cpp index 69a7060cc..7032f1fd6 100644 --- a/source/games/blood/src/gameutil.cpp +++ b/source/games/blood/src/gameutil.cpp @@ -624,40 +624,40 @@ void GetZRange(DBloodActor *actor, int *ceilZ, Collision *ceilColl, int *floorZ, pSprite->cstat = bakCstat; } -void GetZRangeAtXYZ(int x, int y, int z, int nSector, int *ceilZ, Collision* ceilColl, int* floorZ, Collision* floorColl, int nDist, unsigned int nMask, unsigned int nClipParallax) +void GetZRangeAtXYZ(int x, int y, int z, sectortype* pSector, int *ceilZ, Collision* ceilColl, int* floorZ, Collision* floorColl, int nDist, unsigned int nMask, unsigned int nClipParallax) { int ceilHit, floorHit; int32_t nTemp1, nTemp2; vec3_t lpos = { x, y, z }; - getzrange(&lpos, nSector, (int32_t*)ceilZ, &ceilHit, (int32_t*)floorZ, &floorHit, nDist, nMask); + getzrange(&lpos, pSector, (int32_t*)ceilZ, &ceilHit, (int32_t*)floorZ, &floorHit, nDist, nMask); ceilColl->setFromEngine(ceilHit); floorColl->setFromEngine(floorHit); if (floorColl->type == kHitSector) { - int nSector = floorColl->index; - if ((nClipParallax & PARALLAXCLIP_FLOOR) == 0 && (sector[nSector].floorstat & 1)) + auto pSector = floorColl->sector(); + if ((nClipParallax & PARALLAXCLIP_FLOOR) == 0 && (pSector->floorstat & 1)) *floorZ = 0x7fffffff; - if (sector[nSector].hasX()) + if (pSector->hasX()) { - XSECTOR* pXSector = §or[nSector].xs(); + XSECTOR* pXSector = &pSector->xs(); *floorZ += pXSector->Depth << 10; } - auto actor = getUpperLink(nSector); + auto actor = pSector->upperLink; if (actor) { auto link = actor->GetOwner(); vec3_t newpos = lpos + link->s().pos - actor->s().pos; - getzrange(&newpos, link->s().sectnum, &nTemp1, &nTemp2, (int32_t*)floorZ, &floorHit, nDist, nMask); + getzrange(&newpos, link->s().sector(), &nTemp1, &nTemp2, (int32_t*)floorZ, &floorHit, nDist, nMask); floorColl->setFromEngine(floorHit); *floorZ -= link->s().z - actor->s().z; } } if (ceilColl->type == kHitSector) { - int nSector = ceilColl->index; - if ((nClipParallax & PARALLAXCLIP_CEILING) == 0 && (sector[nSector].ceilingstat & 1)) + auto pSector = ceilColl->sector(); + if ((nClipParallax & PARALLAXCLIP_CEILING) == 0 && (pSector->ceilingstat & 1)) *ceilZ = 0x80000000; - auto actor = getLowerLink(nSector); + auto actor = pSector->lowerLink; if (actor) { auto link = actor->GetOwner(); diff --git a/source/games/blood/src/gameutil.h b/source/games/blood/src/gameutil.h index fc3abeb11..33b30183c 100644 --- a/source/games/blood/src/gameutil.h +++ b/source/games/blood/src/gameutil.h @@ -77,7 +77,7 @@ bool IntersectRay(int wx, int wy, int wdx, int wdy, int x1, int y1, int z1, int int HitScan(DBloodActor *pSprite, int z, int dx, int dy, int dz, unsigned int nMask, int a8); int VectorScan(DBloodActor *pSprite, int nOffset, int nZOffset, int dx, int dy, int dz, int nRange, int ac); void GetZRange(DBloodActor *pSprite, int *ceilZ, Collision *ceilHit, int *floorZ, Collision *floorHit, int nDist, unsigned int nMask, unsigned int nClipParallax = 0); -void GetZRangeAtXYZ(int x, int y, int z, int nSector, int *ceilZ, Collision *ceilHit, int *floorZ, Collision *floorHit, int nDist, unsigned int nMask, unsigned int nClipParallax = 0); +void GetZRangeAtXYZ(int x, int y, int z, sectortype* pSector, int *ceilZ, Collision *ceilHit, int *floorZ, Collision *floorHit, int nDist, unsigned int nMask, unsigned int nClipParallax = 0); int GetDistToLine(int x1, int y1, int x2, int y2, int x3, int y3); [[deprecated]] unsigned int ClipMove(vec3_t* pos, int *nSector, int xv, int yv, int wd, int cd, int fd, unsigned int nMask, int tracecount = 3); unsigned int ClipMove(vec3_t* pos, sectortype** pSector, int xv, int yv, int wd, int cd, int fd, unsigned int nMask, int tracecount = 3);