- fixed some places in p_pillar.cpp where sector plane z's were calculated at (0, 0) which could cause overflows if the actual plane is too far away from the origin.

- renamed sector_t::soundorg in centerspot, changed the type to a fixedvec2 and removed the CenterSpot #define.

Since this thing was used in lots of places that have nothing to do with sound the name made no sense. Having it as a fixed_t array also made it clumsy to use and the CenterSpot #define used a potentially dangerous type cast.
This commit is contained in:
Christoph Oelckers 2016-02-24 14:49:59 +01:00
parent 81cca69303
commit 58d3b04590
11 changed files with 63 additions and 61 deletions

View File

@ -1974,8 +1974,8 @@ void AM_drawSubsectors()
} }
else else
{ {
secx = FIXED2DBL(sec->soundorg[0]); secx = FIXED2DBL(sec->centerspot.x);
secy = FIXED2DBL(sec->soundorg[1]); secy = FIXED2DBL(sec->centerspot.y);
} }
seczb = floorplane->ZatPoint(secx, secy); seczb = floorplane->ZatPoint(secx, secy);
seczt = sec->ceilingplane.ZatPoint(secx, secy); seczt = sec->ceilingplane.ZatPoint(secx, secy);

View File

@ -1615,7 +1615,7 @@ void FParser::SF_FloorHeight(void)
DFloorChanger * f = new DFloorChanger(&sectors[i]); DFloorChanger * f = new DFloorChanger(&sectors[i]);
if (!f->Move( if (!f->Move(
abs(dest - sectors[i].CenterFloor()), abs(dest - sectors[i].CenterFloor()),
sectors[i].floorplane.PointToDist (CenterSpot(&sectors[i]), dest), sectors[i].floorplane.PointToDist (sectors[i].centerspot, dest),
crush? 10:-1, crush? 10:-1,
(dest > sectors[i].CenterFloor()) ? 1 : -1)) (dest > sectors[i].CenterFloor()) ? 1 : -1))
{ {
@ -1699,7 +1699,7 @@ void FParser::SF_MoveFloor(void)
// Don't start a second thinker on the same floor // Don't start a second thinker on the same floor
if (sec->floordata) continue; if (sec->floordata) continue;
new DMoveFloor(sec,sec->floorplane.PointToDist(CenterSpot(sec),destheight), new DMoveFloor(sec,sec->floorplane.PointToDist(sec->centerspot,destheight),
destheight < sec->CenterFloor() ? -1:1,crush,platspeed); destheight < sec->CenterFloor() ? -1:1,crush,platspeed);
} }
} }
@ -1763,7 +1763,7 @@ void FParser::SF_CeilingHeight(void)
DCeilingChanger * c = new DCeilingChanger(&sectors[i]); DCeilingChanger * c = new DCeilingChanger(&sectors[i]);
if (!c->Move( if (!c->Move(
abs(dest - sectors[i].CenterCeiling()), abs(dest - sectors[i].CenterCeiling()),
sectors[i].ceilingplane.PointToDist (CenterSpot(&sectors[i]), dest), sectors[i].ceilingplane.PointToDist (sectors[i].centerspot, dest),
crush? 10:-1, crush? 10:-1,
(dest > sectors[i].CenterCeiling()) ? 1 : -1)) (dest > sectors[i].CenterCeiling()) ? 1 : -1))
{ {
@ -1807,8 +1807,7 @@ public:
m_Silent = silent; m_Silent = silent;
m_Type = DCeiling::ceilLowerByValue; // doesn't really matter as long as it's no special value m_Type = DCeiling::ceilLowerByValue; // doesn't really matter as long as it's no special value
m_Tag=tag; m_Tag=tag;
vertex_t * spot=CenterSpot(sec); m_TopHeight=m_BottomHeight=sec->ceilingplane.PointToDist(sec->centerspot,destheight);
m_TopHeight=m_BottomHeight=sec->ceilingplane.PointToDist(spot,destheight);
m_Direction=destheight>sec->GetPlaneTexZ(sector_t::ceiling)? 1:-1; m_Direction=destheight>sec->GetPlaneTexZ(sector_t::ceiling)? 1:-1;
// Do not interpolate instant movement ceilings. // Do not interpolate instant movement ceilings.

View File

@ -476,13 +476,13 @@ void P_Recalculate3DFloors(sector_t * sector)
while (oldlist.Size()) while (oldlist.Size())
{ {
pick=oldlist[0]; pick=oldlist[0];
fixed_t height=pick->top.plane->ZatPoint(CenterSpot(sector)); fixed_t height=pick->top.plane->ZatPoint(sector->centerspot);
// find highest starting ffloor - intersections are not supported! // find highest starting ffloor - intersections are not supported!
pickindex=0; pickindex=0;
for (j=1;j<oldlist.Size();j++) for (j=1;j<oldlist.Size();j++)
{ {
fixed_t h2=oldlist[j]->top.plane->ZatPoint(CenterSpot(sector)); fixed_t h2=oldlist[j]->top.plane->ZatPoint(sector->centerspot);
if (h2>height) if (h2>height)
{ {
@ -493,7 +493,7 @@ void P_Recalculate3DFloors(sector_t * sector)
} }
oldlist.Delete(pickindex); oldlist.Delete(pickindex);
fixed_t pick_bottom=pick->bottom.plane->ZatPoint(CenterSpot(sector)); fixed_t pick_bottom=pick->bottom.plane->ZatPoint(sector->centerspot);
if (pick->flags & FF_THISINSIDE) if (pick->flags & FF_THISINSIDE)
{ {
@ -607,7 +607,7 @@ void P_Recalculate3DFloors(sector_t * sector)
if ( !(rover->flags & FF_EXISTS) || rover->flags & FF_NOSHADE ) if ( !(rover->flags & FF_EXISTS) || rover->flags & FF_NOSHADE )
continue; continue;
fixed_t ff_top=rover->top.plane->ZatPoint(CenterSpot(sector)); fixed_t ff_top=rover->top.plane->ZatPoint(sector->centerspot);
if (ff_top < minheight) break; // reached the floor if (ff_top < minheight) break; // reached the floor
if (ff_top < maxheight) if (ff_top < maxheight)
{ {
@ -622,7 +622,7 @@ void P_Recalculate3DFloors(sector_t * sector)
} }
else else
{ {
fixed_t ff_bottom=rover->bottom.plane->ZatPoint(CenterSpot(sector)); fixed_t ff_bottom=rover->bottom.plane->ZatPoint(sector->centerspot);
if (ff_bottom<maxheight) if (ff_bottom<maxheight)
{ {
// this segment begins over the ceiling and extends beyond it // this segment begins over the ceiling and extends beyond it
@ -648,7 +648,7 @@ void P_Recalculate3DFloors(sector_t * sector)
if (rover->flags&FF_DOUBLESHADOW) if (rover->flags&FF_DOUBLESHADOW)
{ {
fixed_t ff_bottom=rover->bottom.plane->ZatPoint(CenterSpot(sector)); fixed_t ff_bottom=rover->bottom.plane->ZatPoint(sector->centerspot);
if(ff_bottom < maxheight && ff_bottom>minheight) if(ff_bottom < maxheight && ff_bottom>minheight)
{ {
newlight.caster = rover; newlight.caster = rover;
@ -736,11 +736,11 @@ lightlist_t * P_GetPlaneLight(sector_t * sector, secplane_t * plane, bool unders
unsigned i; unsigned i;
TArray<lightlist_t> &lightlist = sector->e->XFloor.lightlist; TArray<lightlist_t> &lightlist = sector->e->XFloor.lightlist;
fixed_t planeheight=plane->ZatPoint(CenterSpot(sector)); fixed_t planeheight=plane->ZatPoint(sector->centerspot);
if(underside) planeheight--; if(underside) planeheight--;
for(i = 1; i < lightlist.Size(); i++) for(i = 1; i < lightlist.Size(); i++)
if (lightlist[i].plane.ZatPoint(CenterSpot(sector)) <= planeheight) if (lightlist[i].plane.ZatPoint(sector->centerspot) <= planeheight)
return &lightlist[i - 1]; return &lightlist[i - 1];
return &lightlist[lightlist.Size() - 1]; return &lightlist[lightlist.Size() - 1];
@ -1000,8 +1000,8 @@ CCMD (dump3df)
for (unsigned int i = 0; i < ffloors.Size(); i++) for (unsigned int i = 0; i < ffloors.Size(); i++)
{ {
fixed_t height=ffloors[i]->top.plane->ZatPoint(CenterSpot(sector)); fixed_t height=ffloors[i]->top.plane->ZatPoint(sector->centerspot);
fixed_t bheight=ffloors[i]->bottom.plane->ZatPoint(CenterSpot(sector)); fixed_t bheight=ffloors[i]->bottom.plane->ZatPoint(sector->centerspot);
IGNORE_FORMAT_PRE IGNORE_FORMAT_PRE
Printf("FFloor %d @ top = %f (model = %d), bottom = %f (model = %d), flags = %B, alpha = %d %s %s\n", Printf("FFloor %d @ top = %f (model = %d), bottom = %f (model = %d), flags = %B, alpha = %d %s %s\n",

View File

@ -2,8 +2,6 @@
#define __SECTORE_H #define __SECTORE_H
#define CenterSpot(sec) (vertex_t*)&(sec)->soundorg[0]
// 3D floor flags. Most are the same as in Legacy but I added some for EDGE's and Vavoom's features as well. // 3D floor flags. Most are the same as in Legacy but I added some for EDGE's and Vavoom's features as well.
typedef enum typedef enum
{ {

View File

@ -343,16 +343,16 @@ bool EV_DoFloor (DFloor::EFloor floortype, line_t *line, int tag,
floor->m_Speed = height; floor->m_Speed = height;
case DFloor::floorLowerByValue: case DFloor::floorLowerByValue:
floor->m_Direction = -1; floor->m_Direction = -1;
newheight = sec->floorplane.ZatPoint (sec->soundorg[0], sec->soundorg[1]) - height; newheight = sec->CenterFloor() - height;
floor->m_FloorDestDist = sec->floorplane.PointToDist (sec->soundorg[0], sec->soundorg[1], newheight); floor->m_FloorDestDist = sec->floorplane.PointToDist (sec->centerspot, newheight);
break; break;
case DFloor::floorRaiseInstant: case DFloor::floorRaiseInstant:
floor->m_Speed = height; floor->m_Speed = height;
case DFloor::floorRaiseByValue: case DFloor::floorRaiseByValue:
floor->m_Direction = 1; floor->m_Direction = 1;
newheight = sec->floorplane.ZatPoint (sec->soundorg[0], sec->soundorg[1]) + height; newheight = sec->CenterFloor() + height;
floor->m_FloorDestDist = sec->floorplane.PointToDist (sec->soundorg[0], sec->soundorg[1], newheight); floor->m_FloorDestDist = sec->floorplane.PointToDist (sec->centerspot, newheight);
break; break;
case DFloor::floorMoveToValue: case DFloor::floorMoveToValue:
@ -412,8 +412,8 @@ bool EV_DoFloor (DFloor::EFloor floortype, line_t *line, int tag,
case DFloor::floorLowerByTexture: case DFloor::floorLowerByTexture:
floor->m_Direction = -1; floor->m_Direction = -1;
newheight = sec->floorplane.ZatPoint (sec->soundorg[0], sec->soundorg[1]) - sec->FindShortestTextureAround (); newheight = sec->CenterFloor() - sec->FindShortestTextureAround ();
floor->m_FloorDestDist = sec->floorplane.PointToDist (sec->soundorg[0], sec->soundorg[1], newheight); floor->m_FloorDestDist = sec->floorplane.PointToDist (sec->centerspot, newheight);
break; break;
case DFloor::floorLowerToCeiling: case DFloor::floorLowerToCeiling:
@ -429,14 +429,14 @@ bool EV_DoFloor (DFloor::EFloor floortype, line_t *line, int tag,
// since the code is identical to what was here. (Oddly // since the code is identical to what was here. (Oddly
// enough, BOOM preserved the code here even though it // enough, BOOM preserved the code here even though it
// also had this function.) // also had this function.)
newheight = sec->floorplane.ZatPoint (sec->soundorg[0], sec->soundorg[1]) + sec->FindShortestTextureAround (); newheight = sec->CenterFloor() + sec->FindShortestTextureAround ();
floor->m_FloorDestDist = sec->floorplane.PointToDist (sec->soundorg[0], sec->soundorg[1], newheight); floor->m_FloorDestDist = sec->floorplane.PointToDist (sec->centerspot, newheight);
break; break;
case DFloor::floorRaiseAndChange: case DFloor::floorRaiseAndChange:
floor->m_Direction = 1; floor->m_Direction = 1;
newheight = sec->floorplane.ZatPoint (sec->soundorg[0], sec->soundorg[1]) + height; newheight = sec->CenterFloor() + height;
floor->m_FloorDestDist = sec->floorplane.PointToDist (sec->soundorg[0], sec->soundorg[1], newheight); floor->m_FloorDestDist = sec->floorplane.PointToDist (sec->centerspot, newheight);
if (line != NULL) if (line != NULL)
{ {
FTextureID oldpic = sec->GetTexture(sector_t::floor); FTextureID oldpic = sec->GetTexture(sector_t::floor);
@ -619,8 +619,8 @@ bool EV_BuildStairs (int tag, DFloor::EStair type, line_t *line,
floor->m_Hexencrush = false; floor->m_Hexencrush = false;
floor->m_Speed = speed; floor->m_Speed = speed;
height = sec->floorplane.ZatPoint (sec->soundorg[0], sec->soundorg[1]) + stairstep; height = sec->CenterFloor() + stairstep;
floor->m_FloorDestDist = sec->floorplane.PointToDist (sec->soundorg[0], sec->soundorg[1], height); floor->m_FloorDestDist = sec->floorplane.PointToDist (sec->centerspot, height);
texture = sec->GetTexture(sector_t::floor); texture = sec->GetTexture(sector_t::floor);
osecnum = secnum; //jff 3/4/98 preserve loop index osecnum = secnum; //jff 3/4/98 preserve loop index
@ -1037,15 +1037,15 @@ bool EV_DoElevator (line_t *line, DElevator::EElevator elevtype,
// [RH] elevate up by a specific amount // [RH] elevate up by a specific amount
case DElevator::elevateRaise: case DElevator::elevateRaise:
elevator->m_Direction = 1; elevator->m_Direction = 1;
elevator->m_FloorDestDist = sec->floorplane.PointToDist (sec->soundorg[0], sec->soundorg[1], floorheight + height); elevator->m_FloorDestDist = sec->floorplane.PointToDist (sec->centerspot, floorheight + height);
elevator->m_CeilingDestDist = sec->ceilingplane.PointToDist (sec->soundorg[0], sec->soundorg[1], ceilingheight + height); elevator->m_CeilingDestDist = sec->ceilingplane.PointToDist (sec->centerspot, ceilingheight + height);
break; break;
// [RH] elevate down by a specific amount // [RH] elevate down by a specific amount
case DElevator::elevateLower: case DElevator::elevateLower:
elevator->m_Direction = -1; elevator->m_Direction = -1;
elevator->m_FloorDestDist = sec->floorplane.PointToDist (sec->soundorg[0], sec->soundorg[1], floorheight - height); elevator->m_FloorDestDist = sec->floorplane.PointToDist (sec->centerspot, floorheight - height);
elevator->m_CeilingDestDist = sec->ceilingplane.PointToDist (sec->soundorg[0], sec->soundorg[1], ceilingheight - height); elevator->m_CeilingDestDist = sec->ceilingplane.PointToDist (sec->centerspot, ceilingheight - height);
break; break;
} }
} }

View File

@ -3273,8 +3273,8 @@ FUNC(LS_GlassBreak)
x = ln->v1->x + ln->dx/2; x = ln->v1->x + ln->dx/2;
y = ln->v1->y + ln->dy/2; y = ln->v1->y + ln->dy/2;
x += (ln->frontsector->soundorg[0] - x) / 5; x += (ln->frontsector->centerspot.x - x) / 5;
y += (ln->frontsector->soundorg[1] - y) / 5; y += (ln->frontsector->centerspot.y - y) / 5;
for (int i = 0; i < 7; ++i) for (int i = 0; i < 7; ++i)
{ {

View File

@ -144,15 +144,15 @@ DPillar::DPillar (sector_t *sector, EPillar type, fixed_t speed,
if (floordist == 0) if (floordist == 0)
{ {
newheight = (sector->CenterFloor () + sector->CenterCeiling ()) / 2; newheight = (sector->CenterFloor () + sector->CenterCeiling ()) / 2;
m_FloorTarget = sector->floorplane.PointToDist (sector->soundorg[0], sector->soundorg[1], newheight); m_FloorTarget = sector->floorplane.PointToDist (sector->centerspot, newheight);
m_CeilingTarget = sector->ceilingplane.PointToDist (sector->soundorg[0], sector->soundorg[1], newheight); m_CeilingTarget = sector->ceilingplane.PointToDist (sector->centerspot, newheight);
floordist = newheight - sector->CenterFloor (); floordist = newheight - sector->CenterFloor ();
} }
else else
{ {
newheight = sector->CenterFloor () + floordist; newheight = sector->CenterFloor () + floordist;
m_FloorTarget = sector->floorplane.PointToDist (sector->soundorg[0], sector->soundorg[1], newheight); m_FloorTarget = sector->floorplane.PointToDist (sector->centerspot, newheight);
m_CeilingTarget = sector->ceilingplane.PointToDist (sector->soundorg[0], sector->soundorg[1], newheight); m_CeilingTarget = sector->ceilingplane.PointToDist (sector->centerspot, newheight);
} }
ceilingdist = sector->CenterCeiling () - newheight; ceilingdist = sector->CenterCeiling () - newheight;
} }
@ -168,8 +168,8 @@ DPillar::DPillar (sector_t *sector, EPillar type, fixed_t speed,
} }
else else
{ {
newheight = sector->floorplane.ZatPoint (0, 0) - floordist; newheight = sector->CenterFloor() - floordist;
m_FloorTarget = sector->floorplane.PointToDist (0, 0, newheight); m_FloorTarget = sector->floorplane.PointToDist (sector->centerspot, newheight);
} }
if (ceilingdist == 0) if (ceilingdist == 0)
{ {
@ -179,8 +179,8 @@ DPillar::DPillar (sector_t *sector, EPillar type, fixed_t speed,
} }
else else
{ {
newheight = sector->ceilingplane.ZatPoint (0, 0) + ceilingdist; newheight = sector->CenterCeiling() + ceilingdist;
m_CeilingTarget = sector->ceilingplane.PointToDist (0, 0, newheight); m_CeilingTarget = sector->ceilingplane.PointToDist (sector->centerspot, newheight);
} }
} }

View File

@ -3221,9 +3221,9 @@ static void P_GroupLines (bool buildmap)
} }
} }
// set the soundorg to the middle of the bounding box // set the center to the middle of the bounding box
sector->soundorg[0] = bbox.Right()/2 + bbox.Left()/2; sector->centerspot.x = bbox.Right()/2 + bbox.Left()/2;
sector->soundorg[1] = bbox.Top()/2 + bbox.Bottom()/2; sector->centerspot.y = bbox.Top()/2 + bbox.Bottom()/2;
// For triangular sectors the above does not calculate good points unless the longest of the triangle's lines is perfectly horizontal and vertical // For triangular sectors the above does not calculate good points unless the longest of the triangle's lines is perfectly horizontal and vertical
if (sector->linecount == 3) if (sector->linecount == 3)
@ -3245,8 +3245,8 @@ static void P_GroupLines (bool buildmap)
if (DMulScale32 (v->y - Triangle[0]->y, dx, if (DMulScale32 (v->y - Triangle[0]->y, dx,
Triangle[0]->x - v->x, dy) != 0) Triangle[0]->x - v->x, dy) != 0)
{ {
sector->soundorg[0] = Triangle[0]->x / 3 + Triangle[1]->x / 3 + v->x / 3; sector->centerspot.x = Triangle[0]->x / 3 + Triangle[1]->x / 3 + v->x / 3;
sector->soundorg[1] = Triangle[0]->y / 3 + Triangle[1]->y / 3 + v->y / 3; sector->centerspot.y = Triangle[0]->y / 3 + Triangle[1]->y / 3 + v->y / 3;
break; break;
} }
} }

View File

@ -1182,9 +1182,9 @@ void R_Subsector (subsector_t *sub)
fakeFloor->validcount = validcount; fakeFloor->validcount = validcount;
R_3D_NewClip(); R_3D_NewClip();
} }
fakeHeight = fakeFloor->top.plane->ZatPoint(frontsector->soundorg[0], frontsector->soundorg[0]); fakeHeight = fakeFloor->top.plane->ZatPoint(frontsector->centerspot);
if (fakeHeight < viewz && if (fakeHeight < viewz &&
fakeHeight > frontsector->floorplane.ZatPoint(frontsector->soundorg[0], frontsector->soundorg[1])) fakeHeight > frontsector->floorplane.ZatPoint(frontsector->centerspot))
{ {
fake3D = FAKE3D_FAKEFLOOR; fake3D = FAKE3D_FAKEFLOOR;
tempsec = *fakeFloor->model; tempsec = *fakeFloor->model;
@ -1244,9 +1244,9 @@ void R_Subsector (subsector_t *sub)
fakeFloor->validcount = validcount; fakeFloor->validcount = validcount;
R_3D_NewClip(); R_3D_NewClip();
} }
fakeHeight = fakeFloor->bottom.plane->ZatPoint(frontsector->soundorg[0], frontsector->soundorg[1]); fakeHeight = fakeFloor->bottom.plane->ZatPoint(frontsector->centerspot);
if (fakeHeight > viewz && if (fakeHeight > viewz &&
fakeHeight < frontsector->ceilingplane.ZatPoint(frontsector->soundorg[0], frontsector->soundorg[1])) fakeHeight < frontsector->ceilingplane.ZatPoint(frontsector->centerspot))
{ {
fake3D = FAKE3D_FAKECEILING; fake3D = FAKE3D_FAKECEILING;
tempsec = *fakeFloor->model; tempsec = *fakeFloor->model;

View File

@ -340,6 +340,11 @@ struct secplane_t
return -TMulScale16 (a, x, y, b, z, c); return -TMulScale16 (a, x, y, b, z, c);
} }
fixed_t PointToDist(fixedvec2 xy, fixed_t z) const
{
return -TMulScale16(a, xy.x, xy.y, b, z, c);
}
fixed_t PointToDist (const vertex_t *v, fixed_t z) const fixed_t PointToDist (const vertex_t *v, fixed_t z) const
{ {
return -TMulScale16 (a, v->x, b, v->y, z, c); return -TMulScale16 (a, v->x, b, v->y, z, c);
@ -825,8 +830,8 @@ struct sector_t
} }
// Member variables // Member variables
fixed_t CenterFloor () const { return floorplane.ZatPoint (soundorg[0], soundorg[1]); } fixed_t CenterFloor () const { return floorplane.ZatPoint (centerspot); }
fixed_t CenterCeiling () const { return ceilingplane.ZatPoint (soundorg[0], soundorg[1]); } fixed_t CenterCeiling () const { return ceilingplane.ZatPoint (centerspot); }
// [RH] store floor and ceiling planes instead of heights // [RH] store floor and ceiling planes instead of heights
secplane_t floorplane, ceilingplane; secplane_t floorplane, ceilingplane;
@ -844,7 +849,7 @@ struct sector_t
int sky; int sky;
FNameNoInit SeqName; // Sound sequence name. Setting seqType non-negative will override this. FNameNoInit SeqName; // Sound sequence name. Setting seqType non-negative will override this.
fixed_t soundorg[2]; // origin for any sounds played by the sector fixedvec2 centerspot; // origin for any sounds played by the sector
int validcount; // if == validcount, already checked int validcount; // if == validcount, already checked
AActor* thinglist; // list of mobjs in sector AActor* thinglist; // list of mobjs in sector

View File

@ -709,8 +709,8 @@ static void CalcPosVel(int type, const AActor *actor, const sector_t *sector,
} }
else else
{ {
x = sector->soundorg[0]; x = sector->centerspot.x;
z = sector->soundorg[1]; z = sector->centerspot.y;
chanflags |= CHAN_LISTENERZ; chanflags |= CHAN_LISTENERZ;
} }
} }
@ -776,8 +776,8 @@ static void CalcSectorSoundOrg(const sector_t *sec, int channum, fixed_t *x, fix
} }
else else
{ {
*x = sec->soundorg[0]; *x = sec->centerspot.x;
*y = sec->soundorg[1]; *y = sec->centerspot.y;
} }
// Set sound vertical position based on channel. // Set sound vertical position based on channel.