- XSECTOR::reference is gone.

This commit is contained in:
Christoph Oelckers 2021-11-19 17:29:49 +01:00
parent 576a473ec8
commit 32f141ad39
8 changed files with 49 additions and 62 deletions

View file

@ -99,6 +99,7 @@ struct sectortype
// These will unfortunately have to be within the base struct to refactor Blood properly. They can later be removed again, once everything is done.
Blood::XSECTOR& xs() const;
bool hasX() const { return extra > 0; } // 0 is invalid!
void addX();
};

View file

@ -5772,16 +5772,9 @@ static void actCheckThings()
if (!actor->hasX()) continue;
auto pXSprite = &actor->x();
int nSector = pSprite->sectnum;
auto pSector = pSprite->sector();
int nXSector = sector[nSector].extra;
XSECTOR* pXSector = NULL;
if (nXSector > 0)
{
assert(nXSector > 0 && nXSector < kMaxXSectors);
assert(xsector[nXSector].reference == nSector);
pXSector = &xsector[nXSector];
}
XSECTOR* pXSector = pSector->hasX()? &pSector->xs() : nullptr;
if (pXSector && pXSector->panVel && (pXSector->panAlways || pXSector->state || pXSector->busy))
{
int nType = pSprite->type - kThingBase;
@ -5797,7 +5790,7 @@ static void actCheckThings()
{
int top, bottom;
GetActorExtents(actor, &top, &bottom);
if (getflorzofslope(nSector, pSprite->x, pSprite->y) <= bottom)
if (getflorzofslopeptr(pSector, pSprite->x, pSprite->y) <= bottom)
{
int angle = pXSector->panAngle;
int speed = 0;
@ -5806,7 +5799,7 @@ static void actCheckThings()
speed = pXSector->panVel << 9;
if (!pXSector->panAlways && pXSector->busy) speed = MulScale(speed, pXSector->busy, 16);
}
if (sector[nSector].floorstat & 64) angle = (angle + GetWallAngle(sector[nSector].wallptr) + 512) & 2047;
if (pSector->floorstat & 64) angle = (angle + GetWallAngle(pSector->wallptr) + 512) & 2047;
actor->xvel += MulScale(speed, Cos(angle), 30);
actor->yvel += MulScale(speed, Sin(angle), 30);
@ -6237,22 +6230,15 @@ static void actCheckDudes()
spritetype* pSprite = &actor->s();
if (pSprite->flags & 32 || !actor->hasX()) continue;
int nSector = pSprite->sectnum;
auto pSector = pSprite->sector();
viewBackupSpriteLoc(actor);
int nXSector = sector[nSector].extra;
XSECTOR* pXSector = NULL;
XSECTOR* pXSector = pSector->hasX()? &pSector->xs() : nullptr;
if (nXSector > 0)
{
assert(nXSector > 0 && nXSector < kMaxXSectors);
assert(xsector[nXSector].reference == nSector);
pXSector = &xsector[nXSector];
}
if (pXSector)
{
int top, bottom;
GetActorExtents(actor, &top, &bottom);
if (getflorzofslope(nSector, pSprite->x, pSprite->y) <= bottom)
if (getflorzofslopeptr(pSector, pSprite->x, pSprite->y) <= bottom)
{
int angle = pXSector->panAngle;
int speed = 0;
@ -6262,8 +6248,8 @@ static void actCheckDudes()
if (!pXSector->panAlways && pXSector->busy)
speed = MulScale(speed, pXSector->busy, 16);
}
if (sector[nSector].floorstat & 64)
angle = (angle + GetWallAngle(sector[nSector].wallptr) + 512) & 2047;
if (pSector->floorstat & 64)
angle = (angle + GetWallAngle(pSector->wallptr) + 512) & 2047;
int dx = MulScale(speed, Cos(angle), 30);
int dy = MulScale(speed, Sin(angle), 30);
actor->xvel += dx;

View file

@ -251,6 +251,11 @@ public:
return true;
}
}
sectortype* sector()
{
return s().sector();
}
};
extern DBloodActor bloodActors[kMaxSprites];

View file

@ -612,7 +612,7 @@ void dbLoadMap(const char *pPath, int *pX, int *pY, int *pZ, short *pAngle, int
assert(nCount <= nXSectorSize);
fr.Read(pBuffer, nCount);
BitReader bitReader(pBuffer, nCount);
pXSector->reference = bitReader.readSigned(14);
/*pXSector->reference =*/ bitReader.readSigned(14);
pXSector->state = bitReader.readUnsigned(1);
pXSector->busy = bitReader.readUnsigned(17);
pXSector->data = bitReader.readUnsigned(16);
@ -770,7 +770,7 @@ void dbLoadMap(const char *pPath, int *pX, int *pY, int *pZ, short *pAngle, int
pXWall->dudeLockout = bitReader.readUnsigned(1);
bitReader.readUnsigned(4);
bitReader.readUnsigned(32);
xwall[wall[i].extra].busy = IntToFixed(xwall[wall[i].extra].state);
pXWall->busy = IntToFixed(pXWall->state);
}
}

View file

@ -367,3 +367,9 @@ inline Blood::XSECTOR& sectortype::xs() const
{
return Blood::xsector[extra];
}
[[deprecated]]
inline void sectortype::addX()
{
extra = Blood::dbInsertXSector(sectnum(this));
}

View file

@ -560,7 +560,6 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, XSECTOR& w, XSECTO
{
arc("flags", w.flags, def->flags)
("busy", w.busy, def->busy)
("reference", w.reference, def->reference)
("data", w.data, def->data)
("txid", w.txID, def->txID)
("rxid", w.rxID, def->rxID)

View file

@ -847,16 +847,16 @@ void nnExtInitModernStuff()
pCond->obj[count++].cmd = (uint8_t)pXSpr->command;
}
for (int i = 0; i < kMaxXSectors; i++)
for (auto& sect : sectors())
{
if (!sectRangeIsFine(xsector[i].reference) || xsector[i].txID != pXSprite->rxID) continue;
if (!sect.hasX() || sect.xs().txID != pXSprite->rxID) continue;
else if (count >= kMaxTracedObjects)
condError(iactor, "Max(%d) objects to track reached for condition #%d, RXID: %d!");
pCond->obj[count].type = OBJ_SECTOR;
pCond->obj[count].actor = nullptr;
pCond->obj[count].index_ = xsector[i].reference;
pCond->obj[count++].cmd = xsector[i].command;
pCond->obj[count].index_ = sectnum(&sect);
pCond->obj[count++].cmd = sect.xs().command;
}
for(auto& wal : walls())
@ -3225,22 +3225,22 @@ void useSectorWindGen(DBloodActor* sourceactor, sectortype* pSector)
auto pXSource = &sourceactor->x();
XSECTOR* pXSector = nullptr;
int nXSector = 0;
if (pSector != nullptr)
{
pXSector = &xsector[pSector->extra];
nXSector = sector[pXSector->reference].extra;
pXSector = &pSector->xs();
}
else if (xsectRangeIsFine(sector[pSource->sectnum].extra))
else if (pSource->sector()->hasX())
{
pXSector = &xsector[sector[pSource->sectnum].extra];
nXSector = sector[pXSector->reference].extra;
pSector = pSource->sector();
pXSector = &pSector->xs();
}
else
{
nXSector = dbInsertXSector(pSource->sectnum);
pXSector = &xsector[nXSector]; pXSector->windAlways = 1;
pSector = pSource->sector();
pSector->addX();
pXSector = &pSector->xs();
pXSector->windAlways = 1;
}
int windVel = ClipRange(pXSource->data2, 0, 32767);
@ -3301,13 +3301,13 @@ void useSectorWindGen(DBloodActor* sourceactor, sectortype* pSector)
}
if (pXSector->panCeiling)
{
StartInterpolation(pXSector->reference, Interp_Sect_CeilingPanX);
StartInterpolation(pXSector->reference, Interp_Sect_CeilingPanY);
StartInterpolation(pSector, Interp_Sect_CeilingPanX);
StartInterpolation(pSector, Interp_Sect_CeilingPanY);
}
if (pXSector->panFloor)
{
StartInterpolation(pXSector->reference, Interp_Sect_FloorPanX);
StartInterpolation(pXSector->reference, Interp_Sect_FloorPanY);
StartInterpolation(pSector, Interp_Sect_FloorPanX);
StartInterpolation(pSector, Interp_Sect_FloorPanY);
}
int oldPan = pXSector->panVel;
@ -3317,9 +3317,8 @@ void useSectorWindGen(DBloodActor* sourceactor, sectortype* pSector)
// add to panList if panVel was set to 0 previously
if (oldPan == 0 && pXSector->panVel != 0)
{
auto newSect = &sector[pXSector->reference];
if (!panList.Contains(newSect))
panList.Push(newSect);
if (!panList.Contains(pSector))
panList.Push(pSector);
}
}
}

View file

@ -570,14 +570,11 @@ static void fakeActAirDrag(spritetype *, int num)
{
int xvec = 0;
int yvec = 0;
int nSector = predict.sectnum;
assert(validSectorIndex(nSector));
sectortype *pSector = &sector[nSector];
int nXSector = pSector->extra;
if (nXSector > 0)
assert(validSectorIndex(predict.sectnum));
sectortype *pSector = &sector[predict.sectnum];
if (pSector->hasX())
{
assert(nXSector < kMaxXSectors);
XSECTOR *pXSector = &xsector[nXSector];
XSECTOR *pXSector = &pSector->xs();
if (pXSector->windVel && (pXSector->windAlways || pXSector->busy))
{
int vel = pXSector->windVel<<12;
@ -598,14 +595,8 @@ void fakeActProcessSprites(void)
if (pSprite->statnum == kStatDude)
{
int nSector = predict.sectnum;
int nXSector = sector[nSector].extra;
XSECTOR *pXSector = NULL;
if (nXSector > 0)
{
assert(nXSector > 0 && nXSector < kMaxXSectors);
assert(xsector[nXSector].reference == nSector);
pXSector = &xsector[nXSector];
}
auto pSector = &sector[predict.sectnum];
auto pXSector = pSector->hasX()? &pSector->xs() : nullptr;
if (pXSector)
{
int top, bottom;
@ -622,8 +613,8 @@ void fakeActProcessSprites(void)
if (!pXSector->panAlways && pXSector->busy)
speed = MulScale(speed, pXSector->busy, 16);
}
if (sector[nSector].floorstat&64)
angle = (GetWallAngle(sector[nSector].wallptr)+512)&2047;
if (pSector->floorstat&64)
angle = (GetWallAngle(pSector->wallptr)+512)&2047;
predict.xvel += MulScale(speed,Cos(angle), 30);
predict.yvel += MulScale(speed,Sin(angle), 30);
}