- use floats for ceilingz/floorz storage.

This commit is contained in:
Christoph Oelckers 2022-02-03 19:15:46 +01:00
parent 367a998b40
commit a59a771209
11 changed files with 65 additions and 58 deletions

View file

@ -522,12 +522,13 @@ int inside(double x, double y, const sectortype* sect)
// //
//========================================================================== //==========================================================================
sectortype* nextsectorneighborzptr(sectortype* sectp, int startz, int flags) sectortype* nextsectorneighborzptr(sectortype* sectp, int startz_, int flags)
{ {
int factor = (flags & Find_Up)? -1 : 1; double startz = startz_ * zinttoworld;
double factor = (flags & Find_Up)? -1 : 1;
int bestz = INT_MAX; int bestz = INT_MAX;
sectortype* bestsec = (flags & Find_Safe)? sectp : nullptr; sectortype* bestsec = (flags & Find_Safe)? sectp : nullptr;
const auto planez = (flags & Find_Ceiling)? &sectortype::__int_ceilingz : &sectortype::__int_floorz; const auto planez = (flags & Find_Ceiling)? &sectortype::ceilingz : &sectortype::floorz;
startz *= factor; startz *= factor;
for(auto& wal : wallsofsector(sectp)) for(auto& wal : wallsofsector(sectp))

View file

@ -41,8 +41,8 @@ double Get(int index, DCoreActor* actor, int type)
{ {
switch(type) switch(type)
{ {
case Interp_Sect_Floorz: return sector[index].int_floorz(); case Interp_Sect_Floorz: return sector[index].floorz;
case Interp_Sect_Ceilingz: return sector[index].int_ceilingz(); case Interp_Sect_Ceilingz: return sector[index].ceilingz;
case Interp_Sect_Floorheinum: return sector[index].floorheinum; case Interp_Sect_Floorheinum: return sector[index].floorheinum;
case Interp_Sect_Ceilingheinum: return sector[index].ceilingheinum; case Interp_Sect_Ceilingheinum: return sector[index].ceilingheinum;
case Interp_Sect_FloorPanX: return sector[index].floorxpan_; case Interp_Sect_FloorPanX: return sector[index].floorxpan_;
@ -65,8 +65,8 @@ void Set(int index, DCoreActor* actor, int type, double val)
int old; int old;
switch(type) switch(type)
{ {
case Interp_Sect_Floorz: sector[index].set_int_floorz(xs_CRoundToInt(val)); break; case Interp_Sect_Floorz: sector[index].setfloorz(val); break;
case Interp_Sect_Ceilingz: sector[index].set_int_ceilingz(xs_CRoundToInt(val)); break; case Interp_Sect_Ceilingz: sector[index].setceilingz(val); break;
case Interp_Sect_Floorheinum: sector[index].floorheinum = (short)xs_CRoundToInt(val); break; case Interp_Sect_Floorheinum: sector[index].floorheinum = (short)xs_CRoundToInt(val); break;
case Interp_Sect_Ceilingheinum: sector[index].ceilingheinum = (short)xs_CRoundToInt(val); break; case Interp_Sect_Ceilingheinum: sector[index].ceilingheinum = (short)xs_CRoundToInt(val); break;
case Interp_Sect_FloorPanX: sector[index].floorxpan_ = float(val); break; case Interp_Sect_FloorPanX: sector[index].floorxpan_ = float(val); break;

View file

@ -98,8 +98,9 @@ static void ReadSectorV7(FileReader& fr, sectortype& sect)
{ {
sect.wallptr = fr.ReadInt16(); sect.wallptr = fr.ReadInt16();
sect.wallnum = fr.ReadInt16(); sect.wallnum = fr.ReadInt16();
sect.set_int_ceilingz(fr.ReadInt32(), true); int c = fr.ReadInt32();
sect.set_int_floorz(fr.ReadInt32(), true); int f = fr.ReadInt32();
sect.setzfrommap(c, f);
sect.ceilingstat = ESectorFlags::FromInt(fr.ReadUInt16()); sect.ceilingstat = ESectorFlags::FromInt(fr.ReadUInt16());
sect.floorstat = ESectorFlags::FromInt(fr.ReadUInt16()); sect.floorstat = ESectorFlags::FromInt(fr.ReadUInt16());
sect.ceilingpicnum = fr.ReadUInt16(); sect.ceilingpicnum = fr.ReadUInt16();
@ -129,8 +130,9 @@ static void ReadSectorV6(FileReader& fr, sectortype& sect)
sect.floorpicnum = fr.ReadUInt16(); sect.floorpicnum = fr.ReadUInt16();
sect.ceilingheinum = clamp(fr.ReadInt16() << 5, -32768, 32767); sect.ceilingheinum = clamp(fr.ReadInt16() << 5, -32768, 32767);
sect.floorheinum = clamp(fr.ReadInt16() << 5, -32768, 32767); sect.floorheinum = clamp(fr.ReadInt16() << 5, -32768, 32767);
sect.set_int_ceilingz(fr.ReadInt32(), true); int c = fr.ReadInt32();
sect.set_int_floorz(fr.ReadInt32(), true); int f = fr.ReadInt32();
sect.setzfrommap(c, f);
sect.ceilingshade = fr.ReadInt8(); sect.ceilingshade = fr.ReadInt8();
sect.floorshade = fr.ReadInt8(); sect.floorshade = fr.ReadInt8();
sect.ceilingxpan_ = fr.ReadUInt8(); sect.ceilingxpan_ = fr.ReadUInt8();
@ -156,8 +158,9 @@ static void ReadSectorV5(FileReader& fr, sectortype& sect)
sect.floorpicnum = fr.ReadUInt16(); sect.floorpicnum = fr.ReadUInt16();
sect.ceilingheinum = clamp(fr.ReadInt16() << 5, -32768, 32767); sect.ceilingheinum = clamp(fr.ReadInt16() << 5, -32768, 32767);
sect.floorheinum = clamp(fr.ReadInt16() << 5, -32768, 32767); sect.floorheinum = clamp(fr.ReadInt16() << 5, -32768, 32767);
sect.set_int_ceilingz(fr.ReadInt32(), true); int c = fr.ReadInt32();
sect.set_int_floorz(fr.ReadInt32(), true); int f = fr.ReadInt32();
sect.setzfrommap(c, f);
sect.ceilingshade = fr.ReadInt8(); sect.ceilingshade = fr.ReadInt8();
sect.floorshade = fr.ReadInt8(); sect.floorshade = fr.ReadInt8();
sect.ceilingxpan_ = fr.ReadUInt8(); sect.ceilingxpan_ = fr.ReadUInt8();

View file

@ -227,9 +227,8 @@ struct sectortype
// Debug hack job for finding all places where ceilingz and floorz get written to. // Debug hack job for finding all places where ceilingz and floorz get written to.
// If the engine does not compile with this block on, we got a problem. // If the engine does not compile with this block on, we got a problem.
// Since this is only for compile verification there's no need to provide a working implementation. // Since this is only for compile verification there's no need to provide a working implementation.
const int32_t __int_ceilingz; const double floorz, ceilingz;
const int32_t __int_floorz; sectortype(double a = 0, double b = 0) : ceilingz(a), floorz(b) {}
sectortype(int a = 0, int b = 0) : ceilingz(a), floorz(b) {}
void set_int_ceilingz(int cc, bool temp = false) {} void set_int_ceilingz(int cc, bool temp = false) {}
void set_int_floorz(int cc, bool temp = false) {} void set_int_floorz(int cc, bool temp = false) {}
@ -238,28 +237,30 @@ struct sectortype
#else #else
// Do not change directly! // Do not change directly!
int32_t __int_ceilingz; double floorz, ceilingz;
int32_t __int_floorz;
/*
void setceilingz(double cc, bool temp = false); void setceilingz(double cc, bool temp = false);
void setfloorz(double cc, bool temp = false); void setfloorz(double cc, bool temp = false);
void addceilingz(double cc, bool temp = false); void addceilingz(double cc, bool temp = false);
void addfloorz(double cc, bool temp = false); void addfloorz(double cc, bool temp = false);
*/
void set_int_ceilingz(int cc, bool temp = false) { setceilingz(cc * zinttoworld, temp); }
void set_int_floorz(int cc, bool temp = false) { setfloorz(cc * zinttoworld, temp); }
void add_int_ceilingz(int cc, bool temp = false) { addceilingz(cc * zinttoworld, temp); }
void add_int_floorz(int cc, bool temp = false) { addfloorz(cc * zinttoworld, temp); }
void set_int_ceilingz(int cc, bool temp = false); void setzfrommap(int c, int f)
void set_int_floorz(int cc, bool temp = false); {
void add_int_ceilingz(int cc, bool temp = false); ceilingz = c * zmaptoworld;
void add_int_floorz(int cc, bool temp = false); floorz = f * zmaptoworld;
}
#endif #endif
int int_ceilingz() const { return __int_ceilingz; } int int_ceilingz() const { return ceilingz * zworldtoint; }
int int_floorz() const { return __int_floorz; } int int_floorz() const { return floorz * zworldtoint; }
float render_ceilingz() const { return __int_ceilingz * (float)zinttoworld; } float render_ceilingz() const { return (float)-ceilingz; }
float render_floorz() const { return __int_floorz * (float)zinttoworld; } float render_floorz() const { return (float)-floorz; }
// panning byte fields were promoted to full floats to enable panning interpolation. // panning byte fields were promoted to full floats to enable panning interpolation.
@ -673,24 +674,24 @@ inline int walltype::Length()
#ifndef SECTOR_HACKJOB #ifndef SECTOR_HACKJOB
inline void sectortype::set_int_ceilingz(int cc, bool temp) inline void sectortype::setceilingz(double cc, bool temp)
{ {
__int_ceilingz = cc; ceilingz = cc;
if (!temp) MarkVerticesForSector(sector.IndexOf(this)); if (!temp) MarkVerticesForSector(sector.IndexOf(this));
} }
inline void sectortype::set_int_floorz(int cc, bool temp) inline void sectortype::setfloorz(double cc, bool temp)
{ {
__int_floorz = cc; floorz = cc;
if (!temp) MarkVerticesForSector(sector.IndexOf(this)); if (!temp) MarkVerticesForSector(sector.IndexOf(this));
} }
inline void sectortype::add_int_ceilingz(int cc, bool temp) inline void sectortype::addceilingz(double cc, bool temp)
{ {
__int_ceilingz += cc; ceilingz += cc;
if (!temp) MarkVerticesForSector(sector.IndexOf(this)); if (!temp) MarkVerticesForSector(sector.IndexOf(this));
} }
inline void sectortype::add_int_floorz(int cc, bool temp) inline void sectortype::addfloorz(double cc, bool temp)
{ {
__int_floorz += cc; floorz += cc;
if (!temp) MarkVerticesForSector(sector.IndexOf(this)); if (!temp) MarkVerticesForSector(sector.IndexOf(this));
} }

View file

@ -179,7 +179,7 @@ public:
HWSkyInfo * sky; // for normal sky HWSkyInfo * sky; // for normal sky
//HWHorizonInfo * horizon; // for horizon information //HWHorizonInfo * horizon; // for horizon information
PortalDesc * portal; // stacked sector portals PortalDesc * portal; // stacked sector portals
const int * planemirror; // for plane mirrors const double * planemirror; // for plane mirrors
}; };
unsigned int vertindex; unsigned int vertindex;

View file

@ -114,7 +114,7 @@ void HWWall::SkyPlane(HWDrawInfo *di, sectortype *sector, int plane, bool allowr
ptype = PORTALTYPE_PLANEMIRROR; ptype = PORTALTYPE_PLANEMIRROR;
if (plane == plane_ceiling && (sector->ceilingstat & CSTAT_SECTOR_SLOPE)) return; if (plane == plane_ceiling && (sector->ceilingstat & CSTAT_SECTOR_SLOPE)) return;
if (plane == plane_floor && (sector->floorstat & CSTAT_SECTOR_SLOPE)) return; if (plane == plane_floor && (sector->floorstat & CSTAT_SECTOR_SLOPE)) return;
planemirror = plane == plane_floor ? &sector->__int_floorz : &sector->__int_ceilingz; planemirror = plane == plane_floor ? &sector->floorz : &sector->ceilingz;
PutPortal(di, PORTALTYPE_PLANEMIRROR, plane); PutPortal(di, PORTALTYPE_PLANEMIRROR, plane);
} }
else else

View file

@ -512,8 +512,8 @@ FSerializer &Serialize(FSerializer &arc, const char *key, sectortype &c, sectort
("wallptr", c.wallptr, def->wallptr) ("wallptr", c.wallptr, def->wallptr)
("wallnum", c.wallnum, def->wallnum) ("wallnum", c.wallnum, def->wallnum)
#ifndef SECTOR_HACKJOB // can't save these in test mode... #ifndef SECTOR_HACKJOB // can't save these in test mode...
("ceilingz", c.__int_ceilingz, def->__int_ceilingz) ("ceilingz", c.ceilingz, def->ceilingz)
("floorz", c.__int_floorz, def->__int_floorz) ("floorz", c.floorz, def->floorz)
#endif #endif
("ceilingstat", c.ceilingstat, def->ceilingstat) ("ceilingstat", c.ceilingstat, def->ceilingstat)
("floorstat", c.floorstat, def->floorstat) ("floorstat", c.floorstat, def->floorstat)

View file

@ -61,6 +61,8 @@ DEFINE_FIELD_X(sectortype, sectortype, floorpal)
DEFINE_FIELD_X(sectortype, sectortype, visibility) DEFINE_FIELD_X(sectortype, sectortype, visibility)
DEFINE_FIELD_X(sectortype, sectortype, fogpal) DEFINE_FIELD_X(sectortype, sectortype, fogpal)
DEFINE_FIELD_X(sectortype, sectortype, exflags) DEFINE_FIELD_X(sectortype, sectortype, exflags)
DEFINE_FIELD_X(sectortype, sectortype, floorz)
DEFINE_FIELD_X(sectortype, sectortype, ceilingz)
DEFINE_FIELD_NAMED_X(walltype, walltype, xpan_, xpan) DEFINE_FIELD_NAMED_X(walltype, walltype, xpan_, xpan)
DEFINE_FIELD_NAMED_X(walltype, walltype, ypan_, ypan) DEFINE_FIELD_NAMED_X(walltype, walltype, ypan_, ypan)
@ -107,56 +109,56 @@ DEFINE_GLOBAL(sector)
void sector_setfloorz(sectortype* sect, double val) void sector_setfloorz(sectortype* sect, double val)
{ {
if (!sect) ThrowAbortException(X_READ_NIL, nullptr); if (!sect) ThrowAbortException(X_READ_NIL, nullptr);
sect->set_int_floorz(int(val * zworldtoint)); sect->setfloorz(val);
} }
DEFINE_ACTION_FUNCTION_NATIVE(_sectortype, setfloorz, sector_floorz) DEFINE_ACTION_FUNCTION_NATIVE(_sectortype, setfloorz, sector_setfloorz)
{ {
PARAM_SELF_STRUCT_PROLOGUE(sectortype); PARAM_SELF_STRUCT_PROLOGUE(sectortype);
PARAM_FLOAT(z); PARAM_FLOAT(z);
self->set_int_floorz(z); self->setfloorz(z);
return 0; return 0;
} }
void sector_setceilingz(sectortype* sect, double val) void sector_setceilingz(sectortype* sect, double val)
{ {
if (!sect) ThrowAbortException(X_READ_NIL, nullptr); if (!sect) ThrowAbortException(X_READ_NIL, nullptr);
sect->set_int_ceilingz(int(val * zworldtoint)); sect->setceilingz(val);
} }
DEFINE_ACTION_FUNCTION_NATIVE(_sectortype, setceilingz, sector_ceilingz) DEFINE_ACTION_FUNCTION_NATIVE(_sectortype, setceilingz, sector_setceilingz)
{ {
PARAM_SELF_STRUCT_PROLOGUE(sectortype); PARAM_SELF_STRUCT_PROLOGUE(sectortype);
PARAM_FLOAT(z); PARAM_FLOAT(z);
self->set_int_ceilingz(z); self->setceilingz(z);
return 0; return 0;
} }
void sector_addfloorz(sectortype* sect, double val) void sector_addfloorz(sectortype* sect, double val)
{ {
if (!sect) ThrowAbortException(X_READ_NIL, nullptr); if (!sect) ThrowAbortException(X_READ_NIL, nullptr);
sect->add_int_floorz(int(val * zworldtoint)); sect->addfloorz(val);
} }
DEFINE_ACTION_FUNCTION_NATIVE(_sectortype, addfloorz, sector_floorz) DEFINE_ACTION_FUNCTION_NATIVE(_sectortype, addfloorz, sector_addfloorz)
{ {
PARAM_SELF_STRUCT_PROLOGUE(sectortype); PARAM_SELF_STRUCT_PROLOGUE(sectortype);
PARAM_FLOAT(z); PARAM_FLOAT(z);
self->add_int_floorz(z); self->addfloorz(z);
return 0; return 0;
} }
void sector_addceilingz(sectortype* sect, double val) void sector_addceilingz(sectortype* sect, double val)
{ {
if (!sect) ThrowAbortException(X_READ_NIL, nullptr); if (!sect) ThrowAbortException(X_READ_NIL, nullptr);
sect->add_int_ceilingz(int(val * zworldtoint)); sect->addceilingz(val);
} }
DEFINE_ACTION_FUNCTION_NATIVE(_sectortype, addceilingz, sector_ceilingz) DEFINE_ACTION_FUNCTION_NATIVE(_sectortype, addceilingz, sector_addceilingz)
{ {
PARAM_SELF_STRUCT_PROLOGUE(sectortype); PARAM_SELF_STRUCT_PROLOGUE(sectortype);
PARAM_FLOAT(z); PARAM_FLOAT(z);
self->add_int_ceilingz(z); self->addceilingz(z);
return 0; return 0;
} }

View file

@ -257,8 +257,7 @@ void dbLoadMap(const char* pPath, int* pX, int* pY, int* pZ, short* pAngle, int*
} }
pSector->wallptr = LittleShort(load.wallptr); pSector->wallptr = LittleShort(load.wallptr);
pSector->wallnum = LittleShort(load.wallnum); pSector->wallnum = LittleShort(load.wallnum);
pSector->set_int_ceilingz(LittleLong(load.ceilingz), true); pSector->setzfrommap(LittleLong(load.ceilingz), LittleLong(load.floorz));
pSector->set_int_floorz(LittleLong(load.floorz), true);
pSector->ceilingstat = ESectorFlags::FromInt(LittleShort(load.ceilingstat)); pSector->ceilingstat = ESectorFlags::FromInt(LittleShort(load.ceilingstat));
pSector->floorstat = ESectorFlags::FromInt(LittleShort(load.floorstat)); pSector->floorstat = ESectorFlags::FromInt(LittleShort(load.floorstat));
pSector->ceilingpicnum = LittleShort(load.ceilingpicnum); pSector->ceilingpicnum = LittleShort(load.ceilingpicnum);

View file

@ -99,9 +99,9 @@ static double getvalue(so_interp::interp_data& element)
case soi_wally: case soi_wally:
return wall[index].pos.Y; return wall[index].pos.Y;
case soi_ceil: case soi_ceil:
return sector[index].int_ceilingz(); return sector[index].ceilingz;
case soi_floor: case soi_floor:
return sector[index].int_floorz(); return sector[index].floorz;
case soi_sox: case soi_sox:
return SectorObject[index].pmid.X; return SectorObject[index].pmid.X;
case soi_soy: case soi_soy:
@ -141,10 +141,10 @@ static void setvalue(so_interp::interp_data& element, double value)
wall[index].moved(); wall[index].moved();
break; break;
case soi_ceil: case soi_ceil:
sector[index].set_int_ceilingz((int)value); sector[index].setceilingz(value);
break; break;
case soi_floor: case soi_floor:
sector[index].set_int_floorz((int)value); sector[index].setfloorz(value);
break; break;
case soi_sox: case soi_sox:
SectorObject[index].pmid.X = (int)value; SectorObject[index].pmid.X = (int)value;

View file

@ -114,6 +114,7 @@ struct sectortype native
native readonly float ceilingypan; native readonly float ceilingypan;
native readonly float floorxpan; native readonly float floorxpan;
native readonly float floorypan; native readonly float floorypan;
native readonly double ceilingz, floorz;
native readonly int wallptr; native readonly int wallptr;
native readonly int16 wallnum; native readonly int16 wallnum;