- handle all of gUpper/gLowerLink.

This completes the removal of all access to the global arrays outside of setup code.
This commit is contained in:
Christoph Oelckers 2021-09-05 09:24:28 +02:00
parent 5b9152abfd
commit 3e452994d8
8 changed files with 49 additions and 58 deletions

View file

@ -138,11 +138,11 @@ void render3DViewPolymost(int nSectnum, int cX, int cY, int cZ, binangle cA, fix
getzsofslope(nSectnum, cX, cY, &ceilingZ, &floorZ); getzsofslope(nSectnum, cX, cY, &ceilingZ, &floorZ);
if (cZ >= floorZ) if (cZ >= floorZ)
{ {
cZ = floorZ - (gUpperLink[nSectnum] >= 0 ? 0 : (8 << 8)); cZ = floorZ - (getUpperLink(nSectnum) ? 0 : (8 << 8));
} }
if (cZ <= ceilingZ) if (cZ <= ceilingZ)
{ {
cZ = ceilingZ + (gLowerLink[nSectnum] >= 0 ? 0 : (8 << 8)); cZ = ceilingZ + (getLowerLink(nSectnum) ? 0 : (8 << 8));
} }
cH = q16horiz(ClipRange(cH.asq16(), gi->playerHorizMin(), gi->playerHorizMax())); cH = q16horiz(ClipRange(cH.asq16(), gi->playerHorizMin(), gi->playerHorizMax()));
RORHACK: RORHACK:

View file

@ -335,14 +335,12 @@ inline DBloodActor* PLAYER::actor()
inline DBloodActor* getUpperLink(int sect) inline DBloodActor* getUpperLink(int sect)
{ {
auto l = gUpperLink[sect]; return gUpperLink[sect];
return l == -1 ? nullptr : &bloodActors[l];
} }
inline DBloodActor* getLowerLink(int sect) inline DBloodActor* getLowerLink(int sect)
{ {
auto l = gLowerLink[sect]; return gLowerLink[sect];
return l == -1 ? nullptr : &bloodActors[l];
} }
inline FSerializer& Serialize(FSerializer& arc, const char* keyname, DBloodActor*& w, DBloodActor** def) inline FSerializer& Serialize(FSerializer& arc, const char* keyname, DBloodActor*& w, DBloodActor** def)

View file

@ -38,8 +38,8 @@ int baseFloor[kMaxSectors];
int baseCeil[kMaxSectors]; int baseCeil[kMaxSectors];
int velFloor[kMaxSectors]; int velFloor[kMaxSectors];
int velCeil[kMaxSectors]; int velCeil[kMaxSectors];
short gUpperLink[kMaxSectors]; DBloodActor* gUpperLink[kMaxSectors];
short gLowerLink[kMaxSectors]; DBloodActor* gLowerLink[kMaxSectors];
HITINFO gHitInfo; HITINFO gHitInfo;
bool AreSectorsNeighbors(int sect1, int sect2) bool AreSectorsNeighbors(int sect1, int sect2)
@ -638,7 +638,6 @@ void GetZRange(DBloodActor *actor, int *ceilZ, Collision *ceilColl, int *floorZ,
auto actor = getUpperLink(nSector); auto actor = getUpperLink(nSector);
if (actor) if (actor)
{ {
int nSprite = gUpperLink[nSector];
auto link = actor->GetOwner(); auto link = actor->GetOwner();
vec3_t lpos = pSprite->pos + link->s().pos - actor->s().pos; vec3_t lpos = pSprite->pos + link->s().pos - actor->s().pos;
getzrange(&lpos, link->s().sectnum, &nTemp1, &nTemp2, (int32_t*)floorZ, &floorHit, nDist, nMask); getzrange(&lpos, link->s().sectnum, &nTemp1, &nTemp2, (int32_t*)floorZ, &floorHit, nDist, nMask);

View file

@ -47,8 +47,8 @@ extern int baseFloor[kMaxSectors];
extern int baseCeil[kMaxSectors]; extern int baseCeil[kMaxSectors];
extern int velFloor[kMaxSectors]; extern int velFloor[kMaxSectors];
extern int velCeil[kMaxSectors]; extern int velCeil[kMaxSectors];
extern short gUpperLink[kMaxSectors]; extern DBloodActor* gUpperLink[kMaxSectors];
extern short gLowerLink[kMaxSectors]; extern DBloodActor* gLowerLink[kMaxSectors];
extern HITINFO gHitInfo; extern HITINFO gHitInfo;
enum { enum {

View file

@ -1457,8 +1457,8 @@ void nnExtProcessSuperSprites()
int fz = getflorzofslope(nSector, pDebris->x, pDebris->y); int fz = getflorzofslope(nSector, pDebris->x, pDebris->y);
GetActorExtents(debrisactor, &top, &bottom); GetActorExtents(debrisactor, &top, &bottom);
if (fz >= bottom && gLowerLink[nSector] < 0 && !(sector[nSector].ceilingstat & 0x1)) pDebris->z += ClipLow(cz - top, 0); if (fz >= bottom && getLowerLink(nSector) == nullptr && !(sector[nSector].ceilingstat & 0x1)) pDebris->z += ClipLow(cz - top, 0);
if (cz <= top && gUpperLink[nSector] < 0 && !(sector[nSector].floorstat & 0x1)) pDebris->z += ClipHigh(fz - bottom, 0); if (cz <= top && getUpperLink(nSector) == nullptr && !(sector[nSector].floorstat & 0x1)) pDebris->z += ClipHigh(fz - bottom, 0);
} }
} }
} }
@ -1822,7 +1822,7 @@ void debrisMove(int listIndex)
int fz = getflorzofslope(nSector, pSprite->x, pSprite->y); int fz = getflorzofslope(nSector, pSprite->x, pSprite->y);
int div = ClipLow(bottom - top, 1); int div = ClipLow(bottom - top, 1);
if (gLowerLink[nSector] >= 0) cz += (cz < 0) ? 0x500 : -0x500; if (getLowerLink(nSector)) cz += (cz < 0) ? 0x500 : -0x500;
if (top > cz && (!(pXSprite->physAttr & kPhysDebrisFloat) || fz <= bottom << 2)) if (top > cz && (!(pXSprite->physAttr & kPhysDebrisFloat) || fz <= bottom << 2))
actor->zvel -= DivScale((bottom - ceilZ) >> 6, mass, 8); actor->zvel -= DivScale((bottom - ceilZ) >> 6, mass, 8);

View file

@ -366,7 +366,7 @@ void SEQINST::Update()
spritetype* pSprite = &actor->s(); spritetype* pSprite = &actor->s();
if (!VanillaMode() && pSequence->frames[frameIndex].surfaceSound && actor->zvel == 0 && actor->xvel != 0) { if (!VanillaMode() && pSequence->frames[frameIndex].surfaceSound && actor->zvel == 0 && actor->xvel != 0) {
if (gUpperLink[pSprite->sectnum] >= 0) break; // don't play surface sound for stacked sectors if (getUpperLink(pSprite->sectnum)) break; // don't play surface sound for stacked sectors
int surf = tileGetSurfType(sector[pSprite->sectnum].floorpicnum); int surf = tileGetSurfType(sector[pSprite->sectnum].floorpicnum);
if (!surf) break; if (!surf) break;
static int surfSfxMove[15][4] = { static int surfSfxMove[15][4] = {

View file

@ -649,11 +649,11 @@ void viewDrawScreen(bool sceneonly)
getzsofslope(nSectnum, cX, cY, &ceilingZ, &floorZ); getzsofslope(nSectnum, cX, cY, &ceilingZ, &floorZ);
if (cZ >= floorZ) if (cZ >= floorZ)
{ {
cZ = floorZ - (gUpperLink[nSectnum] >= 0 ? 0 : (8 << 8)); cZ = floorZ - (getUpperLink(nSectnum) ? 0 : (8 << 8));
} }
if (cZ <= ceilingZ) if (cZ <= ceilingZ)
{ {
cZ = ceilingZ + (gLowerLink[nSectnum] >= 0 ? 0 : (8 << 8)); cZ = ceilingZ + (getLowerLink(nSectnum) ? 0 : (8 << 8));
} }
cH = q16horiz(ClipRange(cH.asq16(), gi->playerHorizMin(), gi->playerHorizMax())); cH = q16horiz(ClipRange(cH.asq16(), gi->playerHorizMin(), gi->playerHorizMax()));

View file

@ -39,19 +39,18 @@ void warpInit(void)
{ {
for (int i = 0; i < kMaxSectors; i++) for (int i = 0; i < kMaxSectors; i++)
{ {
gUpperLink[i] = -1; gUpperLink[i] = nullptr;
gLowerLink[i] = -1; gLowerLink[i] = nullptr;
} }
#ifdef NOONE_EXTENSIONS #ifdef NOONE_EXTENSIONS
int team1 = 0; int team2 = 0; gTeamsSpawnUsed = false; // increment if team start positions specified. int team1 = 0; int team2 = 0; gTeamsSpawnUsed = false; // increment if team start positions specified.
#endif #endif
for (int nSprite = 0; nSprite < kMaxSprites; nSprite++) BloodLinearSpriteIterator it;
while (auto actor = it.Next())
{ {
if (sprite[nSprite].statnum < kMaxStatus) { spritetype* pSprite = &actor->s();
spritetype *pSprite = &sprite[nSprite]; if (actor->hasX()) {
int nXSprite = pSprite->extra; XSPRITE *pXSprite = &actor->x();
if (nXSprite > 0) {
XSPRITE *pXSprite = &xsprite[nXSprite];
switch (pSprite->type) { switch (pSprite->type) {
case kMarkerSPStart: case kMarkerSPStart:
if (gGameOptions.nGameType < 2 && pXSprite->data1 >= 0 && pXSprite->data1 < kMaxPlayers) { if (gGameOptions.nGameType < 2 && pXSprite->data1 >= 0 && pXSprite->data1 < kMaxPlayers) {
@ -62,7 +61,7 @@ void warpInit(void)
pZone->sectnum = pSprite->sectnum; pZone->sectnum = pSprite->sectnum;
pZone->ang = pSprite->ang; pZone->ang = pSprite->ang;
} }
DeleteSprite(nSprite); DeleteSprite(actor);
break; break;
case kMarkerMPStart: case kMarkerMPStart:
if (pXSprite->data1 >= 0 && pXSprite->data2 < kMaxPlayers) { if (pXSprite->data1 >= 0 && pXSprite->data2 < kMaxPlayers) {
@ -100,23 +99,23 @@ void warpInit(void)
#endif #endif
} }
DeleteSprite(nSprite); DeleteSprite(actor);
} }
break; break;
case kMarkerUpLink: case kMarkerUpLink:
gUpperLink[pSprite->sectnum] = nSprite; gUpperLink[pSprite->sectnum] = actor;
pSprite->cstat |= 32768; pSprite->cstat |= 32768;
pSprite->cstat &= ~257; pSprite->cstat &= ~257;
break; break;
case kMarkerLowLink: case kMarkerLowLink:
gLowerLink[pSprite->sectnum] = nSprite; gLowerLink[pSprite->sectnum] = actor;
pSprite->cstat |= 32768; pSprite->cstat |= 32768;
pSprite->cstat &= ~257; pSprite->cstat &= ~257;
break; break;
case kMarkerUpWater: case kMarkerUpWater:
case kMarkerUpStack: case kMarkerUpStack:
case kMarkerUpGoo: case kMarkerUpGoo:
gUpperLink[pSprite->sectnum] = nSprite; gUpperLink[pSprite->sectnum] = actor;
pSprite->cstat |= 32768; pSprite->cstat |= 32768;
pSprite->cstat &= ~257; pSprite->cstat &= ~257;
pSprite->z = getflorzofslope(pSprite->sectnum, pSprite->x, pSprite->y); pSprite->z = getflorzofslope(pSprite->sectnum, pSprite->x, pSprite->y);
@ -124,14 +123,13 @@ void warpInit(void)
case kMarkerLowWater: case kMarkerLowWater:
case kMarkerLowStack: case kMarkerLowStack:
case kMarkerLowGoo: case kMarkerLowGoo:
gLowerLink[pSprite->sectnum] = nSprite; gLowerLink[pSprite->sectnum] = actor;
pSprite->cstat |= 32768; pSprite->cstat |= 32768;
pSprite->cstat &= ~257; pSprite->cstat &= ~257;
pSprite->z = getceilzofslope(pSprite->sectnum, pSprite->x, pSprite->y); pSprite->z = getceilzofslope(pSprite->sectnum, pSprite->x, pSprite->y);
break; break;
} }
} }
}
} }
#ifdef NOONE_EXTENSIONS #ifdef NOONE_EXTENSIONS
@ -147,27 +145,23 @@ void warpInit(void)
for (int i = 0; i < kMaxSectors; i++) for (int i = 0; i < kMaxSectors; i++)
{ {
int nSprite = gUpperLink[i]; auto actor = getUpperLink(i);
if (nSprite >= 0) if (actor && actor->hasX())
{ {
spritetype *pSprite = &sprite[nSprite]; spritetype *pSprite = &actor->s();
int nXSprite = pSprite->extra; XSPRITE *pXSprite = &actor->x();
assert(nXSprite > 0 && nXSprite < kMaxXSprites);
XSPRITE *pXSprite = &xsprite[nXSprite];
int nLink = pXSprite->data1; int nLink = pXSprite->data1;
for (int j = 0; j < kMaxSectors; j++) for (int j = 0; j < kMaxSectors; j++)
{ {
int nSprite2 = gLowerLink[j]; auto actor2 = getLowerLink(j);
if (nSprite2 >= 0) if (actor2 && actor2->hasX())
{ {
spritetype *pSprite2 = &sprite[nSprite2]; spritetype *pSprite2 = &actor2->s();
int nXSprite = pSprite2->extra; XSPRITE *pXSprite2 = &actor2->x();
assert(nXSprite > 0 && nXSprite < kMaxXSprites);
XSPRITE *pXSprite2 = &xsprite[nXSprite];
if (pXSprite2->data1 == nLink) if (pXSprite2->data1 == nLink)
{ {
pSprite->owner = gLowerLink[j]; actor->SetOwner(actor2);
pSprite2->owner = gUpperLink[i]; actor2->SetOwner(actor);
} }
} }
} }
@ -240,11 +234,11 @@ int CheckLink(DBloodActor *actor)
int CheckLink(int *x, int *y, int *z, int *nSector) int CheckLink(int *x, int *y, int *z, int *nSector)
{ {
int nUpper = gUpperLink[*nSector]; auto upper = getUpperLink(*nSector);
int nLower = gLowerLink[*nSector]; auto lower = getLowerLink(*nSector);
if (nUpper >= 0) if (upper)
{ {
spritetype *pUpper = &sprite[nUpper]; spritetype *pUpper = &upper->s();
int z1; int z1;
if (pUpper->type == kMarkerUpLink) if (pUpper->type == kMarkerUpLink)
z1 = pUpper->z; z1 = pUpper->z;
@ -252,9 +246,9 @@ int CheckLink(int *x, int *y, int *z, int *nSector)
z1 = getflorzofslope(*nSector, *x, *y); z1 = getflorzofslope(*nSector, *x, *y);
if (z1 <= *z) if (z1 <= *z)
{ {
nLower = pUpper->owner; lower = upper->GetOwner();
assert(nLower >= 0 && nLower < kMaxSprites); assert(lower);
spritetype *pLower = &sprite[nLower]; spritetype *pLower = &lower->s();
assert(pLower->sectnum >= 0 && pLower->sectnum < kMaxSectors); assert(pLower->sectnum >= 0 && pLower->sectnum < kMaxSectors);
*nSector = pLower->sectnum; *nSector = pLower->sectnum;
*x += pLower->x-pUpper->x; *x += pLower->x-pUpper->x;
@ -268,9 +262,9 @@ int CheckLink(int *x, int *y, int *z, int *nSector)
return pUpper->type; return pUpper->type;
} }
} }
if (nLower >= 0) if (lower)
{ {
spritetype *pLower = &sprite[nLower]; spritetype *pLower = &lower->s();
int z1; int z1;
if (pLower->type == kMarkerLowLink) if (pLower->type == kMarkerLowLink)
z1 = pLower->z; z1 = pLower->z;
@ -278,9 +272,9 @@ int CheckLink(int *x, int *y, int *z, int *nSector)
z1 = getceilzofslope(*nSector, *x, *y); z1 = getceilzofslope(*nSector, *x, *y);
if (z1 >= *z) if (z1 >= *z)
{ {
nUpper = pLower->owner; upper = lower->GetOwner();
assert(nUpper >= 0 && nUpper < kMaxSprites); assert(upper);
spritetype *pUpper = &sprite[nUpper]; spritetype *pUpper = &upper->s();
assert(pUpper->sectnum >= 0 && pUpper->sectnum < kMaxSectors); assert(pUpper->sectnum >= 0 && pUpper->sectnum < kMaxSectors);
*nSector = pUpper->sectnum; *nSector = pUpper->sectnum;
*x += pUpper->x-pLower->x; *x += pUpper->x-pLower->x;