- added slope setter methods to sectortype.

To make sure that setting the slope flags is always done properly. (Why are the flags even needed?)
As a nice side effect, this, plus use of other inlines made the align*slope functions implode into virtually nothing.
This commit is contained in:
Christoph Oelckers 2021-12-17 23:33:16 +01:00
parent 24a6d45f97
commit 1edccf1423
12 changed files with 48 additions and 86 deletions

View file

@ -337,9 +337,8 @@ inline void getcorrectzsofslope(int sectnum, int32_t dax, int32_t day, int32_t *
getzsofslopeptr((usectorptr_t)&sector[sectnum], closest.x, closest.y, ceilz, florz);
}
void alignceilslope(int16_t dasect, int32_t x, int32_t y, int32_t z);
void alignflorslope(int16_t dasect, int32_t x, int32_t y, int32_t z);
void setslope(int32_t sectnum, int32_t cf, int16_t slope);
void alignceilslope(sectortype* dasect, int32_t x, int32_t y, int32_t z);
void alignflorslope(sectortype* dasect, int32_t x, int32_t y, int32_t z);
int32_t lintersect(int32_t originX, int32_t originY, int32_t originZ,
int32_t destX, int32_t destY, int32_t destZ,

View file

@ -890,50 +890,6 @@ void renderRestoreTarget()
}
//
// alignceilslope
//
void alignceilslope(int16_t dasect, int32_t x, int32_t y, int32_t z)
{
auto sect = &sector[dasect];
auto const wal = (uwallptr_t)sect->firstWall();
const int32_t dax = wal->point2Wall()->x-wal->x;
const int32_t day = wal->point2Wall()->y-wal->y;
const int32_t i = (y-wal->y)*dax - (x-wal->x)*day;
if (i == 0)
return;
sect->ceilingheinum = Scale((z-sect->ceilingz)<<8,
ksqrt(uhypsq(dax,day)), i);
if (sect->ceilingheinum == 0)
sect->ceilingstat &= ~2;
else sect->ceilingstat |= 2;
}
//
// alignflorslope
//
void alignflorslope(int16_t dasect, int32_t x, int32_t y, int32_t z)
{
auto sect = &sector[dasect];
auto const wal = (uwallptr_t)sect->firstWall();
const int32_t dax = wal->point2Wall()->x-wal->x;
const int32_t day = wal->point2Wall()->y-wal->y;
const int32_t i = (y-wal->y)*dax - (x-wal->x)*day;
if (i == 0)
return;
sect->floorheinum = Scale((z-sect->floorz)<<8,
ksqrt(uhypsq(dax,day)), i);
if (sect->floorheinum == 0)
sect->floorstat &= ~2;
else sect->floorstat |= 2;
}
int tilehasmodelorvoxel(int const tilenume, int pal)
{
return

View file

@ -183,7 +183,7 @@ void calcSlope(const sectortype* sec, float xpos, float ypos, float* pceilz, flo
//
//==========================================================================
void PlanesAtPoint(const sectortype* sec, int dax, int day, float* pceilz, float* pflorz)
void PlanesAtPoint(const sectortype* sec, float dax, float day, float* pceilz, float* pflorz)
{
calcSlope(sec, dax, day, pceilz, pflorz);
if (pceilz) *pceilz *= -(1 / 256.f);
@ -192,7 +192,7 @@ void PlanesAtPoint(const sectortype* sec, int dax, int day, float* pceilz, float
//==========================================================================
//
// for the games
// for the games (these are not inlined so that they can inline calcSlope)
//
//==========================================================================
@ -218,6 +218,20 @@ void getzsofslopeptr(usectorptr_t sec, int32_t dax, int32_t day, int32_t* ceilz,
*florz = int(f);
}
//==========================================================================
//
//
//
//==========================================================================
int getslopeval(sectortype* sect, int x, int y, int z, int basez)
{
auto wal = sect->firstWall();
auto delta = wal->delta();
int i = (y - wal->y) * delta.x - (x - wal->x) * delta.y;
return i == 0? 0 : Scale((z - basez) << 8, wal->Length(), i);
}
//==========================================================================
//

View file

@ -118,11 +118,12 @@ void loaddefinitionsfile(const char* fn, bool cumulative = false, bool maingrp =
bool calcChaseCamPos(int* px, int* py, int* pz, spritetype* pspr, sectortype** psectnum, binangle ang, fixedhoriz horiz, double const smoothratio);
void PlanesAtPoint(const sectortype* sec, int dax, int day, float* ceilz, float* florz);
inline void PlanesAtPoint(const sectortype* sec, float dax, float day, float* ceilz, float* florz) // this is just for warning evasion.
{
PlanesAtPoint(sec, int(dax), int(day), ceilz, florz);
}
void PlanesAtPoint(const sectortype* sec, float dax, float day, float* ceilz, float* florz);
int getslopeval(sectortype* sect, int x, int y, int z, int planez);
void setWallSectors();
void GetWallSpritePosition(const tspritetype* spr, vec2_t pos, vec2_t* out, bool render = false);
void GetFlatSpritePosition(const tspritetype* spr, vec2_t pos, vec2_t* out, bool render = false);
@ -335,15 +336,15 @@ inline void dragpoint(walltype* pointhighlight, int32_t dax, int32_t day)
dragpoint(wallnum(pointhighlight), dax, day);
}
inline void alignceilslope(sectortype* dasect, int32_t x, int32_t y, int32_t z)
inline void alignceilslope(sectortype* sect, int x, int y, int z)
{
alignceilslope(sector.IndexOf(dasect), x, y, z);
}
inline void alignflorslope(sectortype* dasect, int32_t x, int32_t y, int32_t z)
{
alignflorslope(sector.IndexOf(dasect), x, y, z);
sect->setceilingslope(getslopeval(sect, x, y, z, sect->ceilingz));
}
inline void alignflorslope(sectortype* sect, int x, int y, int z)
{
sect->setfloorslope(getslopeval(sect, x, y, z, sect->floorz));
}
inline void updatesectorneighbor(int32_t const x, int32_t const y, sectortype* * const sect, int32_t maxDistance = MAXUPDATESECTORDIST)
{
int sectno = *sect? sector.IndexOf(*sect) : -1;

View file

@ -258,6 +258,8 @@ struct sectortype
void addfloorypan(float add) { floorypan_ = fmodf(floorypan_ + add + 512, 256); } // +512 is for handling negative offsets
void addceilingxpan(float add) { ceilingxpan_ = fmodf(ceilingxpan_ + add + 512, 256); } // +512 is for handling negative offsets
void addceilingypan(float add) { ceilingypan_ = fmodf(ceilingypan_ + add + 512, 256); } // +512 is for handling negative offsets
void setceilingslope(int heinum) { ceilingheinum = heinum; if (heinum) ceilingstat |= CSTAT_SECTOR_SLOPE; else ceilingstat &= ~CSTAT_SECTOR_SLOPE; }
void setfloorslope(int heinum) { floorheinum = heinum; if (heinum) floorstat |= CSTAT_SECTOR_SLOPE; else floorstat &= ~CSTAT_SECTOR_SLOPE; }
walltype* firstWall() const;
walltype* lastWall() const;

View file

@ -6499,14 +6499,11 @@ void useSlopeChanger(DBloodActor* sourceactor, int objType, sectortype* pSect, D
{
case 2:
case 0:
if (slope == 0) pSect->floorstat &= ~0x0002;
else if (!(pSect->floorstat & 0x0002))
pSect->floorstat |= 0x0002;
// just set floor slope
if (flag2)
{
pSect->floorheinum = slope;
pSect->setfloorslope(slope);
}
else
{
@ -6521,7 +6518,7 @@ void useSlopeChanger(DBloodActor* sourceactor, int objType, sectortype* pSect, D
{
sprite2sectorSlope(iactor, pSect, 0, true);
// set new slope of floor
// set temporary slope of floor
pSect->floorheinum = slope;
// force sloped sprites to be on floor slope z
@ -6533,21 +6530,18 @@ void useSlopeChanger(DBloodActor* sourceactor, int objType, sectortype* pSect, D
}
// finally set new slope of floor
pSect->floorheinum = slope;
pSect->setfloorslope(slope);
}
if (pXSource->data1 == 0) break;
[[fallthrough]];
case 1:
if (slope == 0) pSect->ceilingstat &= ~0x0002;
else if (!(pSect->ceilingstat & 0x0002))
pSect->ceilingstat |= 0x0002;
// just set ceiling slope
if (flag2)
{
pSect->ceilingheinum = slope;
pSect->setceilingslope(slope);
}
else
{
@ -6573,7 +6567,7 @@ void useSlopeChanger(DBloodActor* sourceactor, int objType, sectortype* pSect, D
}
// finally set new slope of ceiling
pSect->ceilingheinum = slope;
pSect->setceilingslope(slope);
}
break;

View file

@ -1089,7 +1089,7 @@ void DoSector(bool bSet, int lVar1, int lLabelID, int lVar2, DDukeActor* sActor,
else SetGameVarID(lVar2, sectp->ceilingpicnum, sActor, sPlayer);
break;
case SECTOR_CEILINGSLOPE:
if (bSet) sectp->ceilingheinum = lValue;
if (bSet) sectp->setceilingslope(lValue);
else SetGameVarID(lVar2, sectp->ceilingheinum, sActor, sPlayer);
break;
case SECTOR_CEILINGSHADE:
@ -1113,7 +1113,7 @@ void DoSector(bool bSet, int lVar1, int lLabelID, int lVar2, DDukeActor* sActor,
else SetGameVarID(lVar2, sectp->floorpicnum, sActor, sPlayer);
break;
case SECTOR_FLOORSLOPE:
if (bSet) sectp->floorheinum = lValue;
if (bSet) sectp->setfloorslope(lValue);
else SetGameVarID(lVar2, sectp->floorheinum, sActor, sPlayer);
break;
case SECTOR_FLOORSHADE:

View file

@ -1036,7 +1036,7 @@ void spawneffector(DDukeActor* actor, TArray<DDukeActor*>* actors)
else if (sp->lotag == SE_2_EARTHQUAKE)
{
t[5] = sp->sector()->floorheinum;
sp->sector()->floorheinum = 0;
sp->sector()->setfloorslope(0);
}
}

View file

@ -55,7 +55,7 @@ void DrawOverlapRoom(int tx, int ty, int tz, fixed_t tq16ang, fixed_t tq16horiz,
{
save.sect[i]->floorz = save.zval[i];
save.sect[i]->floorpicnum = save.pic[i];
save.sect[i]->floorheinum = save.slope[i];
save.sect[i]->setfloorslope(save.slope[i]);
}
analyzesprites(pm_tsprite, pm_spritesortcnt, tx, ty, tz, false);
@ -80,7 +80,7 @@ void DrawOverlapRoom(int tx, int ty, int tz, fixed_t tq16ang, fixed_t tq16horiz,
{
save.sect[i]->ceilingz = save.zval[i];
save.sect[i]->ceilingpicnum = save.pic[i];
save.sect[i]->ceilingheinum = save.slope[i];
save.sect[i]->setceilingslope(save.slope[i]);
}
analyzesprites(pm_tsprite, pm_spritesortcnt, tx, ty, tz, false);

View file

@ -764,7 +764,7 @@ bool FindCeilingView(int match, int* x, int* y, int z, sectortype** sect)
// don't change FAF_MIRROR_PIC - ConnectArea
if (sp->sector()->floorpicnum != FAF_MIRROR_PIC)
sp->sector()->floorpicnum = FAF_MIRROR_PIC + 1;
sp->sector()->floorheinum = 0;
sp->sector()->setfloorslope(0);
save.zcount++;
PRODUCTION_ASSERT(save.zcount < ZMAX);
@ -861,7 +861,7 @@ bool FindFloorView(int match, int* x, int* y, int z, sectortype** sect)
// don't change FAF_MIRROR_PIC - ConnectArea
if (sp->sector()->ceilingpicnum != FAF_MIRROR_PIC)
sp->sector()->ceilingpicnum = FAF_MIRROR_PIC + 1;
sp->sector()->ceilingheinum = 0;
sp->sector()->setceilingslope(0);
save.zcount++;
PRODUCTION_ASSERT(save.zcount < ZMAX);

View file

@ -902,14 +902,12 @@ void DoExplodeSector(short match)
if (SP_TAG5(esp))
{
sectp->floorheinum = SP_TAG5(esp);
SET(sectp->floorstat, CSTAT_SECTOR_SLOPE);
sectp->setfloorslope(SP_TAG5(esp));
}
if (SP_TAG6(esp))
{
sectp->ceilingheinum = SP_TAG6(esp);
SET(sectp->ceilingstat, CSTAT_SECTOR_SLOPE);
sectp->setceilingslope(SP_TAG6(esp));
}
for (zh = sectp->ceilingz; zh < sectp->floorz; zh += Z(60))

View file

@ -2516,15 +2516,13 @@ void SpriteSetup(void)
if (TEST(sectp->floorstat, CSTAT_SECTOR_SLOPE))
{
SP_TAG5(sp) = sectp->floorheinum;
RESET(sectp->floorstat, CSTAT_SECTOR_SLOPE);
sectp->floorheinum = 0;
sectp->setfloorslope(0);
}
if (TEST(sectp->ceilingstat, CSTAT_SECTOR_SLOPE))
{
SP_TAG6(sp) = sectp->ceilingheinum;
RESET(sectp->ceilingstat, CSTAT_SECTOR_SLOPE);
sectp->ceilingheinum = 0;
sectp->setceilingslope(0);
}
SP_TAG4(sp) = abs(sectp->ceilingz - sectp->floorz)>>8;