From bd43f49c2965bf1828b70b81936f4e8e4d49bcfc Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 19 Nov 2021 23:05:45 +0100 Subject: [PATCH] - replaced half of the remaining SectUser accesses. --- source/games/sw/src/actor.cpp | 2 +- source/games/sw/src/cheats.cpp | 6 +++--- source/games/sw/src/coolie.cpp | 10 ++++------ source/games/sw/src/copysect.cpp | 2 +- source/games/sw/src/draw.cpp | 2 +- source/games/sw/src/game.h | 2 +- source/games/sw/src/player.cpp | 12 +++++++++--- source/games/sw/src/sector.cpp | 18 ++++++++---------- source/games/sw/src/sprite.cpp | 2 +- source/games/sw/src/vator.cpp | 15 ++++++--------- source/games/sw/src/weapon.cpp | 6 +++--- 11 files changed, 38 insertions(+), 39 deletions(-) diff --git a/source/games/sw/src/actor.cpp b/source/games/sw/src/actor.cpp index d33742dc3..c6a12d200 100644 --- a/source/games/sw/src/actor.cpp +++ b/source/games/sw/src/actor.cpp @@ -526,7 +526,7 @@ void KeepActorOnFloor(DSWActor* actor) if (TEST(u->Flags, SPR_JUMPING | SPR_FALLING)) return; - if (u->lo_sectp && SectUser[sectnum(u->lo_sectp)].Data()) + if (u->lo_sectp && u->lo_sectp->hasU()) depth = FixedToInt(u->lo_sectp->u()->depth_fixed); else depth = 0; diff --git a/source/games/sw/src/cheats.cpp b/source/games/sw/src/cheats.cpp index ec4035484..f3640a4c0 100644 --- a/source/games/sw/src/cheats.cpp +++ b/source/games/sw/src/cheats.cpp @@ -239,10 +239,10 @@ static void ItemCheat(int player) PlayerUpdateInventory(p, p->InventoryNum); - for (int i = 0; i < numsectors; i++) + for (auto& sect : sectors()) { - if (SectUser[i].Data() && SectUser[i]->stag == SECT_LOCK_DOOR) - SectUser[i]->number = 0; // unlock all doors of this type + if (sect.hasU() && sect.u()->stag == SECT_LOCK_DOOR) + sect.u()->number = 0; // unlock all doors of this type } } diff --git a/source/games/sw/src/coolie.cpp b/source/games/sw/src/coolie.cpp index 55f0e5542..057ba207f 100644 --- a/source/games/sw/src/coolie.cpp +++ b/source/games/sw/src/coolie.cpp @@ -471,18 +471,16 @@ void EnemyDefaults(DSWActor* actor, ACTOR_ACTION_SETp action, PERSONALITYp perso //KeepActorOnFloor(actor); // for swimming actors // make sure we start in the water if thats where we are - if (u->lo_sectp) // && SectUser[u->lo_sectp - sector]) + if (u->lo_sectp) { - int i; - int sectno = sectnum(u->lo_sectp); - if (SectUser[sectno].Data() && TEST(u->lo_sectp->extra, SECTFX_SINK)) + if (u->lo_sectp->hasU() && TEST(u->lo_sectp->extra, SECTFX_SINK)) { - depth = FixedToInt(SectUser[sectno]->depth_fixed); + depth = FixedToInt(u->lo_sectp->u()->depth_fixed); } else { - SWSectIterator it(sectno); + SWSectIterator it(u->lo_sectp); 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 41bebc85e..c4e54840b 100644 --- a/source/games/sw/src/copysect.cpp +++ b/source/games/sw/src/copysect.cpp @@ -208,7 +208,7 @@ void CopySectorMatch(short match) } // copy sector user if there is one - if (SectUser[src_sp->sectnum].Data() || SectUser[dest_sp->sectnum].Data()) + if (src_sp->sector()->hasU() || dest_sp->sector()->hasU()) { SECT_USERp ssectu = GetSectUser(src_sp->sectnum); SECT_USERp dsectu = GetSectUser(dest_sp->sectnum); diff --git a/source/games/sw/src/draw.cpp b/source/games/sw/src/draw.cpp index 0ba381648..44df99782 100644 --- a/source/games/sw/src/draw.cpp +++ b/source/games/sw/src/draw.cpp @@ -676,7 +676,7 @@ void analyzesprites(spritetype* tsprite, int& spritesortcnt, int viewx, int view else { // if sector pal is something other than default - SECT_USERp sectu = SectUser[tsp->sectnum].Data(); + SECT_USERp sectu = tsp->sector()->u(); uint8_t pal = tsp->sector()->floorpal; bool nosectpal=false; diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index 47bb52d27..b93fbb603 100644 --- a/source/games/sw/src/game.h +++ b/source/games/sw/src/game.h @@ -2292,7 +2292,7 @@ struct ANIMstruct case ANIM_Userz: return animactor->u()->sz; case ANIM_SUdepth: - return SectUser[animindex]->depth_fixed; + return sector[animindex].u()->depth_fixed; default: return animindex; } diff --git a/source/games/sw/src/player.cpp b/source/games/sw/src/player.cpp index 794e4e9eb..d16a98981 100644 --- a/source/games/sw/src/player.cpp +++ b/source/games/sw/src/player.cpp @@ -1596,9 +1596,13 @@ void DoPlayerTurnTurret(PLAYERp pp, float avel) void SlipSlope(PLAYERp pp) { short ang; - SECT_USERp sectu; - if (pp->cursectnum < 0 || !(sectu = SectUser[pp->cursectnum].Data()) || !TEST(sectu->flags, SECTFU_SLIDE_SECTOR) || !TEST(pp->cursector()->floorstat, FLOOR_STAT_SLOPE)) + if (pp->cursectnum < 0 || !pp->cursector()->hasU()) + return; + + SECT_USERp sectu = pp->cursector()->u(); + + if (!TEST(sectu->flags, SECTFU_SLIDE_SECTOR) || !TEST(pp->cursector()->floorstat, FLOOR_STAT_SLOPE)) return; short wallptr = pp->cursector()->wallptr; @@ -3922,8 +3926,10 @@ int GetOverlapSector(int x, int y, short *over, short *under) { int i, found = 0; short sf[2]= {0,0}; // sectors found + auto secto = §or[*over]; + auto sectu = §or[*under]; - if ((SectUser[*under].Data() && SectUser[*under]->number >= 30000) || (SectUser[*over].Data() && SectUser[*over]->number >= 30000)) + if ((sectu->hasU() && sectu->u()->number >= 30000) || (secto->hasU() && secto->u()->number >= 30000)) return GetOverlapSector2(x,y,over,under); // instead of check ALL sectors, just check the two most likely first diff --git a/source/games/sw/src/sector.cpp b/source/games/sw/src/sector.cpp index b544859ff..b2cb529b3 100644 --- a/source/games/sw/src/sector.cpp +++ b/source/games/sw/src/sector.cpp @@ -746,16 +746,18 @@ int OperateSector(short sectnum, short player_is_operating) if (!player_is_operating) { SPRITEp fsp; + auto sect = §or[sectnum]; - if (SectUser[sectnum].Data() && SectUser[sectnum]->stag == SECT_LOCK_DOOR) + if (sect->hasU() && sect->u()->stag == SECT_LOCK_DOOR) return false; SWSectIterator it(sectnum); while (auto actor = it.Next()) { fsp = &actor->s(); + auto fsect = fsp->sector(); - if (SectUser[fsp->sectnum].Data() && SectUser[fsp->sectnum]->stag == SECT_LOCK_DOOR) + if (fsect->hasU() && fsect->u()->stag == SECT_LOCK_DOOR) return false; if (fsp->statnum == STAT_VATOR && SP_TAG1(fsp) == SECT_VATOR && TEST_BOOL7(fsp)) @@ -768,9 +770,6 @@ int OperateSector(short sectnum, short player_is_operating) } } - //CON_Message("Operating sectnum %d",sectnum); - //CON_Message("stag = %d, lock = %d",SectUser[sectnum]->stag,SECT_LOCK_DOOR); - switch (sector[sectnum].lotag) { @@ -1647,11 +1646,10 @@ int OperateSprite(DSWActor* actor, short player_is_operating) key_num = sp->hitag; if (pp->HasKey[key_num - 1]) { - int i; - for (i=0; istag == SECT_LOCK_DOOR && SectUser[i]->number == key_num) - SectUser[i]->number = 0; // unlock all doors of this type + if (sect.hasU() && sect.u()->stag == SECT_LOCK_DOOR && sect.u()->number == key_num) + sect.u()->number = 0; // unlock all doors of this type } UnlockKeyLock(key_num, actor); } @@ -2449,7 +2447,7 @@ void PlayerOperateEnv(PLAYERp pp) // //////////////////////////// SECT_USERp sectu; - if (pp->cursectnum >= 0 && (sectu = SectUser[pp->cursectnum].Data()) && sectu->damage) + if (pp->cursectnum >= 0 && (sectu = pp->cursector()->u()) && sectu->damage) { SECTORp sectp = pp->cursector(); if (TEST(sectu->flags, SECTFU_DAMAGE_ABOVE_SECTOR)) diff --git a/source/games/sw/src/sprite.cpp b/source/games/sw/src/sprite.cpp index dc9ce0fa9..22d1d2e2a 100644 --- a/source/games/sw/src/sprite.cpp +++ b/source/games/sw/src/sprite.cpp @@ -6731,7 +6731,7 @@ int MissileWaterAdjust(DSWActor* actor) if (u->lo_sectp) { - SECT_USERp sectu = SectUser[sectnum(u->lo_sectp)].Data(); + SECT_USERp sectu = u->lo_sectp->u(); if (sectu && FixedToInt(sectu->depth_fixed)) u->loz -= Z(FixedToInt(sectu->depth_fixed)); } diff --git a/source/games/sw/src/vator.cpp b/source/games/sw/src/vator.cpp index 52b85695e..90917cd70 100644 --- a/source/games/sw/src/vator.cpp +++ b/source/games/sw/src/vator.cpp @@ -156,7 +156,7 @@ void DoVatorOperate(PLAYERp pp, short sectnum) if (fsp->statnum == STAT_VATOR && SP_TAG1(fsp) == SECT_VATOR && SP_TAG3(fsp) == 0) { - sectnum = fsp->sectnum; + auto fsect = fsp->sector(); // single play only vator // bool 8 must be set for message to display @@ -174,11 +174,11 @@ void DoVatorOperate(PLAYERp pp, short sectnum) return; } - if (pp && SectUser[sectnum].Data() && SectUser[sectnum]->stag == SECT_LOCK_DOOR && SectUser[sectnum]->number) + if (pp && fsect->hasU() && fsect->u()->stag == SECT_LOCK_DOOR && fsect->u()->number) { short key_num; - key_num = SectUser[sectnum]->number; + key_num = fsect->u()->number; { PutStringInfo(pp, quoteMgr.GetQuote(QUOTE_DOORMSG + key_num - 1)); @@ -198,7 +198,6 @@ void DoVatorMatch(PLAYERp pp, short match) { USERp fu; SPRITEp fsp; - short sectnum; SWStatIterator it(STAT_VATOR); while (auto actor = it.Next()) @@ -218,12 +217,10 @@ void DoVatorMatch(PLAYERp pp, short match) } // lock code - sectnum = fsp->sectnum; - if (pp && SectUser[sectnum].Data() && SectUser[sectnum]->stag == SECT_LOCK_DOOR && SectUser[sectnum]->number) + auto fsect = fsp->sector(); + if (pp && fsect->hasU() && fsect->u()->stag == SECT_LOCK_DOOR && fsect->u()->number) { - short key_num; - - key_num = SectUser[sectnum]->number; + int key_num = fsect->u()->number; { PutStringInfo(pp, quoteMgr.GetQuote(QUOTE_DOORMSG + key_num - 1)); diff --git a/source/games/sw/src/weapon.cpp b/source/games/sw/src/weapon.cpp index 471d2ff23..7f54a4caf 100644 --- a/source/games/sw/src/weapon.cpp +++ b/source/games/sw/src/weapon.cpp @@ -17901,7 +17901,7 @@ int InitEnemyFireball(DSWActor* actor) bool WarpToUnderwater(short *sectnum, int *x, int *y, int *z) { int i; - SECT_USERp sectu = SectUser[*sectnum].Data(); + SECT_USERp sectu = sector[*sectnum].u(); SPRITEp under_sp = nullptr, over_sp = nullptr; bool Found = false; short over, under; @@ -17974,7 +17974,7 @@ bool WarpToUnderwater(short *sectnum, int *x, int *y, int *z) bool WarpToSurface(short *sectnum, int *x, int *y, int *z) { int i; - SECT_USERp sectu = SectUser[*sectnum].Data(); + SECT_USERp sectu = sector[*sectnum].u(); short over, under; int sx, sy; @@ -18251,8 +18251,8 @@ int SpawnSplashXY(int hit_x, int hit_y, int hit_z, int sectnum) if (Prediction) return 0; - sectu = SectUser[sectnum].Data(); sectp = §or[sectnum]; + sectu = sectp->hasU() ? sectp->u() : nullptr; if (sectu && (TEST(sectp->extra, SECTFX_LIQUID_MASK) == SECTFX_LIQUID_NONE)) return 0;