From adf3133fdcde08cad60168004e798b026822809a Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 11 Nov 2021 20:20:00 +0100 Subject: [PATCH] - use sectnum and wallnum to get an index from pointers instead of subtracting the array base. --- source/build/include/clip.h | 2 +- source/build/src/clip.cpp | 14 +++++------ source/core/gamefuncs.h | 8 +++--- source/core/rendering/scene/hw_flats.cpp | 4 +-- source/core/rendering/scene/hw_walls.cpp | 10 ++++---- source/core/savegamehelp.h | 9 ++++--- source/games/blood/src/triggers.cpp | 4 +-- source/games/sw/src/actor.cpp | 8 +++--- source/games/sw/src/break.cpp | 2 +- source/games/sw/src/cache.cpp | 4 +-- source/games/sw/src/coolg.cpp | 4 +-- source/games/sw/src/coolie.cpp | 8 +++--- source/games/sw/src/copysect.cpp | 2 +- source/games/sw/src/eel.cpp | 4 +-- source/games/sw/src/hornet.cpp | 4 +-- source/games/sw/src/interpso.cpp | 4 +-- source/games/sw/src/morph.cpp | 32 ++++++++++++------------ source/games/sw/src/player.cpp | 4 +-- source/games/sw/src/sector.cpp | 4 +-- source/games/sw/src/sprite.cpp | 2 +- source/games/sw/src/swactor.h | 4 +++ source/games/sw/src/track.cpp | 16 ++++++------ source/games/sw/src/wallmove.cpp | 4 +-- source/games/sw/src/weapon.cpp | 2 +- 24 files changed, 81 insertions(+), 78 deletions(-) diff --git a/source/build/include/clip.h b/source/build/include/clip.h index 6c1761614..0f1251636 100644 --- a/source/build/include/clip.h +++ b/source/build/include/clip.h @@ -19,7 +19,7 @@ typedef struct int32_t x1, y1, x2, y2; } linetype; -extern int16_t clipsectorlist[MAXCLIPSECTORS]; +extern int clipsectorlist[MAXCLIPSECTORS]; int clipinsidebox(vec2_t *vect, int wallnum, int walldist); inline int clipinsidebox(int x, int y, int wall, int dist) diff --git a/source/build/src/clip.cpp b/source/build/src/clip.cpp index dc7d7a00b..343604de0 100644 --- a/source/build/src/clip.cpp +++ b/source/build/src/clip.cpp @@ -14,11 +14,11 @@ enum { MAXCLIPDIST = 1024 }; -static int16_t clipnum; +static int clipnum; static linetype clipit[MAXCLIPNUM]; static int32_t clipsectnum, origclipsectnum, clipspritenum; -int16_t clipsectorlist[MAXCLIPSECTORS]; -static int16_t origclipsectorlist[MAXCLIPSECTORS]; +int clipsectorlist[MAXCLIPSECTORS]; +static int origclipsectorlist[MAXCLIPSECTORS]; static uint8_t clipsectormap[(MAXSECTORS+7)>>3]; static uint8_t origclipsectormap[(MAXSECTORS+7)>>3]; static int16_t clipobjectval[MAXCLIPNUM]; @@ -1047,7 +1047,7 @@ void getzrange(const vec3_t *pos, int16_t sectnum, for (bssize_t i=0; i= 0) { @@ -1233,9 +1233,9 @@ static int32_t hitscan_trysector(const vec3_t *sv, usectorptr_t sec, hitdata_t * { if (tmp==NULL) { - if (inside(x1,y1,int(sec-sector)) == 1) + if (inside(x1,y1,sectnum(sec)) == 1) { - hit_set(hit, int(sec-sector), -1, -1, x1, y1, z1); + hit_set(hit, sectnum(sec), -1, -1, x1, y1, z1); hitscan_hitsectcf = (how+1)>>1; } } @@ -1247,7 +1247,7 @@ static int32_t hitscan_trysector(const vec3_t *sv, usectorptr_t sec, hitdata_t * if (!thislastsec) { - if (inside(x1,y1,int(sec-sector)) == 1) + if (inside(x1,y1,sectnum(sec)) == 1) hit_set(hit, int(curspr->sectnum), -1, int(curspr-sprite), x1, y1, z1); } } diff --git a/source/core/gamefuncs.h b/source/core/gamefuncs.h index cb855307a..41941c3b4 100644 --- a/source/core/gamefuncs.h +++ b/source/core/gamefuncs.h @@ -237,12 +237,12 @@ inline int32_t getangle(walltype* wal) inline TArrayView sectors() { - return TArrayView(sector, numsectors); + return TArrayView(§or[0], numsectors); } inline TArrayView walls() { - return TArrayView(wall, numwalls); + return TArrayView(&wall[0], numwalls); } inline TArrayView wallsofsector(sectortype* sec) @@ -256,12 +256,12 @@ inline TArrayView wallsofsector(int sec) } // these are mainly meant as refactoring aids to mark function calls to work on. -inline int wallnum(walltype* wal) +inline int wallnum(const walltype* wal) { return int(wal - wall); } -inline int sectnum(sectortype* sect) +inline int sectnum(const sectortype* sect) { return int(sect - sector); } diff --git a/source/core/rendering/scene/hw_flats.cpp b/source/core/rendering/scene/hw_flats.cpp index 0e0d6d4c9..b829a06a1 100644 --- a/source/core/rendering/scene/hw_flats.cpp +++ b/source/core/rendering/scene/hw_flats.cpp @@ -150,7 +150,7 @@ void HWFlat::DrawFlat(HWDrawInfo *di, FRenderState &state, bool translucent) } #ifdef _DEBUG - if (sec - sector == gl_breaksec) + if (sectnum(sec) == gl_breaksec) { int a = 0; } @@ -241,7 +241,7 @@ void HWFlat::PutFlat(HWDrawInfo *di, int whichplane) void HWFlat::ProcessSector(HWDrawInfo *di, sectortype * frontsector, int section_, int which) { #ifdef _DEBUG - if (frontsector - sector == gl_breaksec) + if (sectnum(sec) == gl_breaksec) { int a = 0; } diff --git a/source/core/rendering/scene/hw_walls.cpp b/source/core/rendering/scene/hw_walls.cpp index a201ddb57..a2f3ee2d4 100644 --- a/source/core/rendering/scene/hw_walls.cpp +++ b/source/core/rendering/scene/hw_walls.cpp @@ -968,7 +968,7 @@ void HWWall::Process(HWDrawInfo* di, walltype* wal, sectortype* frontsector, sec #ifdef _DEBUG - if (wal - wall == 6468) + if (wallnum(wal) == 6468) { int a = 0; } @@ -1036,7 +1036,7 @@ void HWWall::Process(HWDrawInfo* di, walltype* wal, sectortype* frontsector, sec int tilenum = ((wal->cstat & CSTAT_WALL_1WAY) && wal->nextwall != -1) ? wal->overpicnum : wal->picnum; setgotpic(tilenum); - tileUpdatePicnum(&tilenum, int(wal-wall) + 16384, wal->cstat); + tileUpdatePicnum(&tilenum, wallnum(wal) + 16384, wal->cstat); texture = tileGetTexture(tilenum); if (texture && texture->isValid()) { @@ -1074,7 +1074,7 @@ void HWWall::Process(HWDrawInfo* di, walltype* wal, sectortype* frontsector, sec { int tilenum = wal->picnum; setgotpic(tilenum); - tileUpdatePicnum(&tilenum, int(wal - wall) + 16384, wal->cstat); + tileUpdatePicnum(&tilenum, wallnum(wal) + 16384, wal->cstat); texture = tileGetTexture(tilenum); if (texture && texture->isValid()) { @@ -1087,7 +1087,7 @@ void HWWall::Process(HWDrawInfo* di, walltype* wal, sectortype* frontsector, sec { int tilenum = wal->overpicnum; setgotpic(tilenum); - tileUpdatePicnum(&tilenum, int(wal - wall) + 16384, wal->cstat); + tileUpdatePicnum(&tilenum, wallnum(wal) + 16384, wal->cstat); texture = tileGetTexture(tilenum); if (texture && texture->isValid()) { @@ -1113,7 +1113,7 @@ void HWWall::Process(HWDrawInfo* di, walltype* wal, sectortype* frontsector, sec auto w = (wal->cstat & CSTAT_WALL_BOTTOM_SWAP) ? backwall : wal; int tilenum = w->picnum; setgotpic(tilenum); - tileUpdatePicnum(&tilenum, int(wal - wall) + 16384, w->cstat); + tileUpdatePicnum(&tilenum, wallnum(wal) + 16384, w->cstat); texture = tileGetTexture(tilenum); if (texture && texture->isValid()) { diff --git a/source/core/savegamehelp.h b/source/core/savegamehelp.h index 98db88944..561c71d03 100644 --- a/source/core/savegamehelp.h +++ b/source/core/savegamehelp.h @@ -2,6 +2,7 @@ #include "resourcefile.h" #include "build.h" +#include "gamefuncs.h" extern FixedBitArray activeSprites; @@ -32,17 +33,17 @@ inline FSerializer& Serialize(FSerializer& arc, const char* keyname, spritetype* inline FSerializer& Serialize(FSerializer& arc, const char* keyname, sectortype*& w, sectortype** def) { - int ndx = w ? int(w - sector) : -1; + int ndx = w ? sectnum(w) : -1; arc(keyname, ndx); - w = ndx == -1 ? nullptr : sector + ndx; + w = ndx == -1 ? nullptr : §or[ndx]; return arc; } inline FSerializer& Serialize(FSerializer& arc, const char* keyname, walltype*& w, walltype** def) { - int ndx = w ? int(w - wall) : -1; + int ndx = w ? wallnum(w) : -1; arc(keyname, ndx); - w = ndx == -1 ? nullptr : wall + ndx; + w = ndx == -1 ? nullptr : &wall[ndx]; return arc; } diff --git a/source/games/blood/src/triggers.cpp b/source/games/blood/src/triggers.cpp index db21f65a9..2b95c7321 100644 --- a/source/games/blood/src/triggers.cpp +++ b/source/games/blood/src/triggers.cpp @@ -1850,7 +1850,7 @@ void ProcessMotion(void) { sectortype *pSector; int nSector; - for (pSector = sector, nSector = 0; nSector < numsectors; nSector++, pSector++) + for (pSector = §or[0], nSector = 0; nSector < numsectors; nSector++, pSector++) { int nXSector = pSector->extra; if (nXSector <= 0) @@ -1927,7 +1927,7 @@ void AlignSlopes(void) { sectortype *pSector; int nSector; - for (pSector = sector, nSector = 0; nSector < numsectors; nSector++, pSector++) + for (pSector = §or[0], nSector = 0; nSector < numsectors; nSector++, pSector++) { if (qsector_filler[nSector]) { diff --git a/source/games/sw/src/actor.cpp b/source/games/sw/src/actor.cpp index 31b579c9b..70adc4672 100644 --- a/source/games/sw/src/actor.cpp +++ b/source/games/sw/src/actor.cpp @@ -38,6 +38,7 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms #include "tags.h" #include "weapon.h" #include "sprite.h" +#include "gamefuncs.h" BEGIN_SW_NS @@ -525,8 +526,8 @@ void KeepActorOnFloor(DSWActor* actor) if (TEST(u->Flags, SPR_JUMPING | SPR_FALLING)) return; - if (u->lo_sectp && SectUser[u->lo_sectp - sector].Data()) - depth = FixedToInt(SectUser[u->lo_sectp - sector]->depth_fixed); + if (u->lo_sectp && SectUser[sectnum(u->lo_sectp)].Data()) + depth = FixedToInt(SectUser[sectnum(u->lo_sectp)]->depth_fixed); else depth = 0; @@ -690,9 +691,6 @@ int DoActorJump(DSWActor* actor) // have started falling if ((u->jump_speed += jump_adj) > 0) { - //DSPRINTF(ds,"Actor Jump Height %d", labs(sp->z - sector[sp->sectnum].floorz)>>8 ); - MONO_PRINT(ds); - // Start falling DoActorBeginFall(actor); return 0; diff --git a/source/games/sw/src/break.cpp b/source/games/sw/src/break.cpp index 8372e4523..3aa2abccb 100644 --- a/source/games/sw/src/break.cpp +++ b/source/games/sw/src/break.cpp @@ -809,7 +809,7 @@ bool HitBreakWall(WALLp wp, int hit_x, int hit_y, int hit_z, short ang, short ty //if (hit_x == INT32_MAX) { int sectnum; - WallBreakPosition(short(wp - wall), §num, &hit_x, &hit_y, &hit_z, &ang); + WallBreakPosition(wallnum(wp), §num, &hit_x, &hit_y, &hit_z, &ang); } AutoBreakWall(wp, hit_x, hit_y, hit_z, ang, type); diff --git a/source/games/sw/src/cache.cpp b/source/games/sw/src/cache.cpp index 353eaf52a..55373df85 100644 --- a/source/games/sw/src/cache.cpp +++ b/source/games/sw/src/cache.cpp @@ -77,7 +77,7 @@ void precacheMap(void) WALLp wp; SPRITEp sp; - for (sectp = sector; sectp < §or[numsectors]; sectp++) + for (sectp = §or[0]; sectp < §or[numsectors]; sectp++) { j = sectp->ceilingpicnum; markTileForPrecache(j, sectp->ceilingpal); @@ -104,7 +104,7 @@ void precacheMap(void) } - for (wp = wall; wp < &wall[numwalls]; wp++) + for (wp = &wall[0]; wp < &wall[numwalls]; wp++) { j = wp->picnum; diff --git a/source/games/sw/src/coolg.cpp b/source/games/sw/src/coolg.cpp index ce4315054..8527b4baf 100644 --- a/source/games/sw/src/coolg.cpp +++ b/source/games/sw/src/coolg.cpp @@ -654,8 +654,8 @@ int DoCoolgMatchPlayerZ(DSWActor* actor) hiz = u->hiz; // adjust loz/hiz for water depth - if (u->lo_sectp && SectUser[u->lo_sectp - sector].Data() && FixedToInt(SectUser[u->lo_sectp - sector]->depth_fixed)) - loz -= Z(FixedToInt(SectUser[u->lo_sectp - sector]->depth_fixed)) - Z(8); + if (u->lo_sectp && SectUser[sectnum(u->lo_sectp)].Data() && FixedToInt(SectUser[sectnum(u->lo_sectp)]->depth_fixed)) + loz -= Z(FixedToInt(SectUser[sectnum(u->lo_sectp)]->depth_fixed)) - Z(8); // lower bound if (u->lowActor) diff --git a/source/games/sw/src/coolie.cpp b/source/games/sw/src/coolie.cpp index 7cb3a2e15..55f0e5542 100644 --- a/source/games/sw/src/coolie.cpp +++ b/source/games/sw/src/coolie.cpp @@ -474,15 +474,15 @@ void EnemyDefaults(DSWActor* actor, ACTOR_ACTION_SETp action, PERSONALITYp perso if (u->lo_sectp) // && SectUser[u->lo_sectp - sector]) { int i; - short sectnum = short(u->lo_sectp - sector); + int sectno = sectnum(u->lo_sectp); - if (SectUser[sectnum].Data() && TEST(u->lo_sectp->extra, SECTFX_SINK)) + if (SectUser[sectno].Data() && TEST(u->lo_sectp->extra, SECTFX_SINK)) { - depth = FixedToInt(SectUser[sectnum]->depth_fixed); + depth = FixedToInt(SectUser[sectno]->depth_fixed); } else { - SWSectIterator it(sectnum); + SWSectIterator it(sectno); while (auto itActor = it.Next()) { SPRITEp np = &itActor->s(); diff --git a/source/games/sw/src/copysect.cpp b/source/games/sw/src/copysect.cpp index e50101641..02b63d1e1 100644 --- a/source/games/sw/src/copysect.cpp +++ b/source/games/sw/src/copysect.cpp @@ -98,7 +98,7 @@ void CopySectorWalls(short dest_sectnum, short src_sectnum) continue; for (sectp = sop->sectp; *sectp; sectp++) - if (*sectp - sector == dest_sectnum) + if (sectnum(*sectp) == dest_sectnum) { so_setinterpolationtics(sop, 0); break; diff --git a/source/games/sw/src/eel.cpp b/source/games/sw/src/eel.cpp index 2b7bb39cf..19a23d1cb 100644 --- a/source/games/sw/src/eel.cpp +++ b/source/games/sw/src/eel.cpp @@ -471,8 +471,8 @@ int DoEelMatchPlayerZ(DSWActor* actor) hiz = u->hiz; // adjust loz/hiz for water depth - if (u->lo_sectp && SectUser[u->lo_sectp - sector].Data() && FixedToInt(SectUser[u->lo_sectp - sector]->depth_fixed)) - loz -= Z(FixedToInt(SectUser[u->lo_sectp - sector]->depth_fixed)) - Z(8); + if (u->lo_sectp && SectUser[sectnum(u->lo_sectp)].Data() && FixedToInt(SectUser[sectnum(u->lo_sectp)]->depth_fixed)) + loz -= Z(FixedToInt(SectUser[sectnum(u->lo_sectp)]->depth_fixed)) - Z(8); // lower bound if (u->lowActor && u->targetActor == u->highActor) // this doesn't look right... diff --git a/source/games/sw/src/hornet.cpp b/source/games/sw/src/hornet.cpp index d6698ce84..cc39cfc0f 100644 --- a/source/games/sw/src/hornet.cpp +++ b/source/games/sw/src/hornet.cpp @@ -377,8 +377,8 @@ int DoHornetMatchPlayerZ(DSWActor* actor) hiz = u->hiz; // adjust loz/hiz for water depth - if (u->lo_sectp && SectUser[u->lo_sectp - sector].Data() && FixedToInt(SectUser[u->lo_sectp - sector]->depth_fixed)) - loz -= Z(FixedToInt(SectUser[u->lo_sectp - sector]->depth_fixed)) - Z(8); + if (u->lo_sectp && SectUser[sectnum(u->lo_sectp)].Data() && FixedToInt(SectUser[sectnum(u->lo_sectp)]->depth_fixed)) + loz -= Z(FixedToInt(SectUser[sectnum(u->lo_sectp)]->depth_fixed)) - Z(8); // lower bound if (u->lowActor) diff --git a/source/games/sw/src/interpso.cpp b/source/games/sw/src/interpso.cpp index 95fafe0ff..67cbcdbfd 100644 --- a/source/games/sw/src/interpso.cpp +++ b/source/games/sw/src/interpso.cpp @@ -206,8 +206,8 @@ void so_addinterpolation(SECTOR_OBJECTp sop) if (!interp->hasvator) for (sectp = sop->sectp; *sectp; sectp++) { - so_setpointinterpolation(interp, int(*sectp - sector) | soi_floor); - so_setpointinterpolation(interp, int(*sectp - sector) | soi_ceil); + so_setpointinterpolation(interp, sectnum(*sectp) | soi_floor); + so_setpointinterpolation(interp, sectnum(*sectp) | soi_ceil); } // interpolate midpoint, for aiming at a remote controlled SO diff --git a/source/games/sw/src/morph.cpp b/source/games/sw/src/morph.cpp index 3175b2df2..cc0956d58 100644 --- a/source/games/sw/src/morph.cpp +++ b/source/games/sw/src/morph.cpp @@ -357,8 +357,8 @@ MorphTornado(SECTOR_OBJECTp sop) for (sectp = sop->sectp, j = 0; *sectp; sectp++, j++) { - if (SectUser[*sectp - sector].Data() && - TEST(SectUser[*sectp - sector]->flags, SECTFU_SO_SLOPE_CEILING_TO_POINT)) + if (SectUser[sectnum(*sectp)].Data() && + TEST(SectUser[sectnum(*sectp)]->flags, SECTFU_SO_SLOPE_CEILING_TO_POINT)) { #define TOR_LOW (floorz) if (sop->morph_z > TOR_LOW) @@ -372,7 +372,7 @@ MorphTornado(SECTOR_OBJECTp sop) sop->morph_z = ceilingz; } - alignceilslope(int16_t(*sectp - sector), mx, my, sop->morph_z); + alignceilslope(sectnum(*sectp), mx, my, sop->morph_z); } } } @@ -450,10 +450,10 @@ MorphFloor(SECTOR_OBJECTp sop) for (sectp = sop->sectp, j = 0; *sectp; sectp++, j++) { - if (SectUser[*sectp - sector].Data() && - TEST(SectUser[*sectp - sector]->flags, SECTFU_SO_SLOPE_CEILING_TO_POINT)) + if (SectUser[sectnum(*sectp)].Data() && + TEST(SectUser[sectnum(*sectp)]->flags, SECTFU_SO_SLOPE_CEILING_TO_POINT)) { - alignflorslope(int16_t(*sectp - sector), mx, my, floorz + sop->morph_z); + alignflorslope(sectnum(*sectp), mx, my, floorz + sop->morph_z); } } } @@ -466,10 +466,10 @@ SOBJ_AlignFloorToPoint(SECTOR_OBJECTp sop, int x, int y, int z) for (sectp = sop->sectp, j = 0; *sectp; sectp++, j++) { - if (SectUser[*sectp - sector].Data() && - TEST(SectUser[*sectp - sector]->flags, SECTFU_SO_SLOPE_CEILING_TO_POINT)) + if (SectUser[sectnum(*sectp)].Data() && + TEST(SectUser[sectnum(*sectp)]->flags, SECTFU_SO_SLOPE_CEILING_TO_POINT)) { - alignflorslope(int16_t(*sectp - sector), x, y, z); + alignflorslope(int16_t(sectnum(*sectp)), x, y, z); } } } @@ -482,10 +482,10 @@ SOBJ_AlignCeilingToPoint(SECTOR_OBJECTp sop, int x, int y, int z) for (sectp = sop->sectp, j = 0; *sectp; sectp++, j++) { - if (SectUser[*sectp - sector].Data() && - TEST(SectUser[*sectp - sector]->flags, SECTFU_SO_SLOPE_CEILING_TO_POINT)) + if (SectUser[sectnum(*sectp)].Data() && + TEST(SectUser[sectnum(*sectp)]->flags, SECTFU_SO_SLOPE_CEILING_TO_POINT)) { - alignceilslope(int16_t(*sectp - sector), x, y, z); + alignceilslope(int16_t(sectnum(*sectp)), x, y, z); } } } @@ -498,11 +498,11 @@ SOBJ_AlignFloorCeilingToPoint(SECTOR_OBJECTp sop, int x, int y, int z) for (sectp = sop->sectp, j = 0; *sectp; sectp++, j++) { - if (SectUser[*sectp - sector].Data() && - TEST(SectUser[*sectp - sector]->flags, SECTFU_SO_SLOPE_CEILING_TO_POINT)) + if (SectUser[sectnum(*sectp)].Data() && + TEST(SectUser[sectnum(*sectp)]->flags, SECTFU_SO_SLOPE_CEILING_TO_POINT)) { - alignflorslope(int16_t(*sectp - sector), x, y, z); - alignceilslope(int16_t(*sectp - sector), x, y, z); + alignflorslope(sectnum(*sectp), x, y, z); + alignceilslope(sectnum(*sectp), x, y, z); } } } diff --git a/source/games/sw/src/player.cpp b/source/games/sw/src/player.cpp index f6c965ea5..a4773e0b4 100644 --- a/source/games/sw/src/player.cpp +++ b/source/games/sw/src/player.cpp @@ -1442,8 +1442,8 @@ void DoPlayerSetWadeDepth(PLAYERp pp) if (TEST(sectp->extra, SECTFX_SINK)) { // make sure your even in the water - if (pp->posz + PLAYER_HEIGHT > pp->lo_sectp->floorz - Z(FixedToInt(SectUser[pp->lo_sectp - sector]->depth_fixed))) - pp->WadeDepth = FixedToInt(SectUser[pp->lo_sectp - sector]->depth_fixed); + if (pp->posz + PLAYER_HEIGHT > pp->lo_sectp->floorz - Z(FixedToInt(SectUser[sectnum(pp->lo_sectp)]->depth_fixed))) + pp->WadeDepth = FixedToInt(SectUser[sectnum(pp->lo_sectp)]->depth_fixed); } } diff --git a/source/games/sw/src/sector.cpp b/source/games/sw/src/sector.cpp index 8c809e095..19b2fef85 100644 --- a/source/games/sw/src/sector.cpp +++ b/source/games/sw/src/sector.cpp @@ -131,7 +131,7 @@ void WallSetupDontMove(void) if (spu->lotag == spl->lotag) { - for (wallp = wall; wallp < &wall[numwalls]; wallp++) + for (wallp = &wall[0]; wallp < &wall[numwalls]; wallp++) { if (wallp->x < spl->x && wallp->x > spu->x && wallp->y < spl->y && wallp->y > spu->y) { @@ -177,7 +177,7 @@ void WallSetup(void) extern int x_min_bound, y_min_bound, x_max_bound, y_max_bound; - for (wp = wall, i = 0; i < numwalls; i++, wp++) + for (wp = &wall[0]; wp < &wall[numwalls]; wp++) { if (wp->picnum == FAF_PLACE_MIRROR_PIC) wp->picnum = FAF_MIRROR_PIC; diff --git a/source/games/sw/src/sprite.cpp b/source/games/sw/src/sprite.cpp index 9f54ab260..1d5a9c768 100644 --- a/source/games/sw/src/sprite.cpp +++ b/source/games/sw/src/sprite.cpp @@ -6730,7 +6730,7 @@ int MissileWaterAdjust(DSWActor* actor) if (u->lo_sectp) { - SECT_USERp sectu = SectUser[u->lo_sectp - sector].Data(); + SECT_USERp sectu = SectUser[sectnum(u->lo_sectp)].Data(); if (sectu && FixedToInt(sectu->depth_fixed)) u->loz -= Z(FixedToInt(sectu->depth_fixed)); } diff --git a/source/games/sw/src/swactor.h b/source/games/sw/src/swactor.h index 4f67c59ee..f271ae07d 100644 --- a/source/games/sw/src/swactor.h +++ b/source/games/sw/src/swactor.h @@ -80,6 +80,10 @@ public: { } + SWSectIterator(sectortype* stat) : SectIterator(stat) + { + } + DSWActor* Next() { int n = NextIndex(); diff --git a/source/games/sw/src/track.cpp b/source/games/sw/src/track.cpp index 2f8c26cdd..84eaa65a7 100644 --- a/source/games/sw/src/track.cpp +++ b/source/games/sw/src/track.cpp @@ -1753,13 +1753,13 @@ PlayerPart: if (!pp->lo_sectp) continue; - if (TEST(sector[pp->lo_sectp - sector].extra, SECTFX_NO_RIDE)) + if (TEST(sector[sectnum(pp->lo_sectp)].extra, SECTFX_NO_RIDE)) { continue; } // move the player - if (pp->lo_sectp - sector == sop->sector[j]) + if (sectnum(pp->lo_sectp) == sop->sector[j]) { if (PlayerMove) MovePlayer(pp, sop, nx, ny); @@ -2169,7 +2169,7 @@ void MoveZ(SECTOR_OBJECTp sop) { for (i = 0, sectp = &sop->sectp[0]; *sectp; sectp++, i++) { - AnimSet(ANIM_Floorz, int(*sectp - sector), nullptr, sop->zorig_floor[i] + sop->z_tgt, sop->z_rate); + AnimSet(ANIM_Floorz, sectnum(*sectp), nullptr, sop->zorig_floor[i] + sop->z_tgt, sop->z_rate); } RESET(sop->flags, SOBJ_ZDOWN); @@ -2178,7 +2178,7 @@ void MoveZ(SECTOR_OBJECTp sop) { for (i = 0, sectp = &sop->sectp[0]; *sectp; sectp++, i++) { - AnimSet(ANIM_Floorz, int(*sectp - sector), nullptr, sop->zorig_floor[i] + sop->z_tgt, sop->z_rate); + AnimSet(ANIM_Floorz, sectnum(*sectp), nullptr, sop->zorig_floor[i] + sop->z_tgt, sop->z_rate); } RESET(sop->flags, SOBJ_ZUP); @@ -2514,7 +2514,7 @@ void DoTrack(SECTOR_OBJECTp sop, short locktics, int *nx, int *ny) if (SectUser[sop->sector[i]].Data() && TEST(SectUser[sop->sector[i]]->flags, SECTFU_SO_DONT_SINK)) continue; - ndx = AnimSet(ANIM_Floorz, int(*sectp-sector), nullptr, sector[dest_sector].floorz, tpoint->tag_high); + ndx = AnimSet(ANIM_Floorz, sectnum(*sectp), nullptr, sector[dest_sector].floorz, tpoint->tag_high); AnimSetCallback(ndx, CallbackSOsink, sop); AnimSetVelAdj(ndx, 6); } @@ -2531,11 +2531,11 @@ void DoTrack(SECTOR_OBJECTp sop, short locktics, int *nx, int *ny) for (i = 0, sectp = &sop->sectp[0]; *sectp; sectp++, i++) { - sectu = SectUser[*sectp - sector].Data(); + sectu = SectUser[sectnum(*sectp)].Data(); if (sectu && sectu->stag == SECT_SO_FORM_WHIRLPOOL) { - AnimSet(ANIM_Floorz, int(*sectp - sector), nullptr, (*sectp)->floorz + Z(sectu->height), 128); + AnimSet(ANIM_Floorz, sectnum(*sectp), nullptr, (*sectp)->floorz + Z(sectu->height), 128); (*sectp)->floorshade += sectu->height/6; RESET((*sectp)->extra, SECTFX_NO_RIDE); @@ -2760,7 +2760,7 @@ void VehicleSetSmoke(SECTOR_OBJECTp sop, ANIMATORp animator) for (sectp = sop->sectp; *sectp; sectp++) { - SWSectIterator it(int(*sectp - sector)); + SWSectIterator it(*sectp); while (auto actor = it.Next()) { USERp u = actor->u(); diff --git a/source/games/sw/src/wallmove.cpp b/source/games/sw/src/wallmove.cpp index 3e3813c0f..8a6b9f536 100644 --- a/source/games/sw/src/wallmove.cpp +++ b/source/games/sw/src/wallmove.cpp @@ -106,7 +106,7 @@ int DoWallMove(DSWActor* actor) nx = MulScale(dist, bcos(ang), 14); ny = MulScale(dist, bsin(ang), 14); - for (wallp = wall; wallp < &wall[numwalls]; wallp++) + for (wallp = &wall[0]; wallp < &wall[numwalls]; wallp++) { if (wallp->x == sp->x && wallp->y == sp->y) { @@ -134,7 +134,7 @@ int DoWallMove(DSWActor* actor) wallp->picnum = picnum1; // find the previous wall - prev_wall = PrevWall(short(wallp - wall)); + prev_wall = PrevWall(wallnum(wallp)); if (shade2) wall[prev_wall].shade = int8_t(shade2); if (picnum2) diff --git a/source/games/sw/src/weapon.cpp b/source/games/sw/src/weapon.cpp index 33fa8a6c1..fd9dbbb1d 100644 --- a/source/games/sw/src/weapon.cpp +++ b/source/games/sw/src/weapon.cpp @@ -18479,7 +18479,7 @@ int DoBubble(DSWActor* actor) if (sp->z < sector[sp->sectnum].ceilingz) { - if (SectorIsUnderwaterArea(int(u->hi_sectp - sector))) + if (SectorIsUnderwaterArea(sectnum(u->hi_sectp))) { if (!SpriteWarpToSurface(actor)) {