From 094844898801be3832a56203de7f430c37a0963f Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 17 Feb 2016 02:21:26 +0100 Subject: [PATCH] - some more checking and refactoring of ZatPoint calls. - removed Plane/Floor/CeilingAtPoint functions because they are overkill for the problem they were meant to solve. Calling ZatPoint with adjusted coordinates created with AActor::PosRelative is just as easy in the few places where this is needed. - made P_HitWater and P_CheckSplash portal aware. --- src/g_shared/a_fastprojectile.cpp | 2 +- src/p_enemy.cpp | 6 ++--- src/p_maputl.cpp | 4 +-- src/p_mobj.cpp | 39 ++++++++++++++++++----------- src/p_sectors.cpp | 18 -------------- src/p_spec.cpp | 9 ++++--- src/r_defs.h | 41 ------------------------------- 7 files changed, 35 insertions(+), 84 deletions(-) diff --git a/src/g_shared/a_fastprojectile.cpp b/src/g_shared/a_fastprojectile.cpp index baad73628..3a8e8e5ec 100644 --- a/src/g_shared/a_fastprojectile.cpp +++ b/src/g_shared/a_fastprojectile.cpp @@ -82,7 +82,7 @@ void AFastProjectile::Tick () if (tm.ceilingline && tm.ceilingline->backsector && tm.ceilingline->backsector->GetTexture(sector_t::ceiling) == skyflatnum && - Z() >= tm.ceilingline->backsector->CeilingAtPoint(this)) + Z() >= tm.ceilingline->backsector->ceilingplane.ZatPoint(PosRelative(tm.ceilingline)) { // Hack to prevent missiles exploding against the sky. // Does not handle sky floors. diff --git a/src/p_enemy.cpp b/src/p_enemy.cpp index 49451c5d6..9ffb17c27 100644 --- a/src/p_enemy.cpp +++ b/src/p_enemy.cpp @@ -558,7 +558,7 @@ bool P_Move (AActor *actor) else { // The monster just hit the floor, so trigger any actions. if (actor->floorsector->SecActTarget != NULL && - actor->floorz == actor->floorsector->FloorAtPoint(actor)) + actor->floorz == actor->floorsector->floorplane.ZatPoint(actor->PosRelative(actor->floorsector)) { actor->floorsector->SecActTarget->TriggerAction(actor, SECSPAC_HitFloor); } @@ -868,8 +868,8 @@ void P_NewChaseDir(AActor * actor) box.Bottom() < line->bbox[BOXTOP] && box.BoxOnLineSide(line) == -1) { - fixed_t front = line->frontsector->FloorAtPoint(actor); - fixed_t back = line->backsector->FloorAtPoint(actor); + fixed_t front = line->frontsector->floorplane.ZatPoint(actor->PosRelative(line)); + fixed_t back = line->backsector->floorplane.ZatPoint(actor->PosRelative(line)); angle_t angle; // The monster must contact one of the two floors, diff --git a/src/p_maputl.cpp b/src/p_maputl.cpp index e09c86eb4..53d7d14e9 100644 --- a/src/p_maputl.cpp +++ b/src/p_maputl.cpp @@ -513,8 +513,8 @@ void AActor::SetOrigin (fixed_t ix, fixed_t iy, fixed_t iz, bool moving) SetXYZ(ix, iy, iz); if (moving) SetMovement(ix - X(), iy - Y(), iz - Z()); LinkToWorld (); - floorz = Sector->floorplane.ZatPoint (ix, iy); - ceilingz = Sector->ceilingplane.ZatPoint (ix, iy); + floorz = Sector->LowestFloorAt(ix, iy, &floorsector); + ceilingz = Sector->HighestCeilingAt(ix, iy, &ceilingsector); P_FindFloorCeiling(this, FFCF_ONLYSPAWNPOS); } diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index 82326c39b..60724bbe5 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -2186,7 +2186,7 @@ explode: if (tm.ceilingline && tm.ceilingline->backsector && tm.ceilingline->backsector->GetTexture(sector_t::ceiling) == skyflatnum && - mo->Z() >= tm.ceilingline->backsector->ceilingplane.ZatPoint(mo)) + mo->Z() >= tm.ceilingline->backsector->ceilingplane.ZatPoint(mo->PosRelative(tm.ceilingline))) { // Hack to prevent missiles exploding against the sky. // Does not handle sky floors. @@ -3640,7 +3640,8 @@ void AActor::Tick () { continue; } - height = sec->floorplane.ZatPoint (this); + fixedvec3 pos = PosRelative(sec); + height = sec->floorplane.ZatPoint (pos); if (Z() > height) { if (heightsec == NULL) @@ -3648,7 +3649,7 @@ void AActor::Tick () continue; } - waterheight = heightsec->floorplane.ZatPoint (this); + waterheight = heightsec->floorplane.ZatPoint (pos); if (waterheight > height && Z() >= waterheight) { continue; @@ -3689,7 +3690,7 @@ void AActor::Tick () floorplane = P_FindFloorPlane(floorsector, X(), Y(), floorz); if (floorplane.c < STEEPSLOPE && - floorplane.ZatPoint (this) <= floorz) + floorplane.ZatPoint (PosRelative(floorsector)) <= floorz) { const msecnode_t *node; bool dopush = true; @@ -3701,7 +3702,7 @@ void AActor::Tick () const sector_t *sec = node->m_sector; if (sec->floorplane.c >= STEEPSLOPE) { - if (floorplane.ZatPoint (this) >= Z() - MaxStepHeight) + if (floorplane.ZatPoint (PosRelative(node->m_sector)) >= Z() - MaxStepHeight) { dopush = false; break; @@ -4171,6 +4172,8 @@ AActor *AActor::StaticSpawn (PClassActor *type, fixed_t ix, fixed_t iy, fixed_t // z-coordinate. if (!SpawningMapThing) { + actor->ceilingz = actor->Sector->HighestCeilingAt(actor, &actor->ceilingsector); + actor->dropoffz = actor->floorz = actor->Sector->LowestFloorAt(actor, &actor->floorsector); P_FindFloorCeiling(actor, FFCF_ONLYSPAWNPOS); } else @@ -4477,15 +4480,16 @@ void AActor::AdjustFloorClip () const msecnode_t *m; // possibly standing on a 3D-floor - if (Sector->e->XFloor.ffloors.Size() && Z()>Sector->floorplane.ZatPoint(this)) floorclip=0; + if (Sector->e->XFloor.ffloors.Size() && Z() > Sector->floorplane.ZatPoint(this)) floorclip = 0; // [RH] clip based on shallowest floor player is standing on // If the sector has a deep water effect, then let that effect // do the floorclipping instead of the terrain type. for (m = touching_sectorlist; m; m = m->m_tnext) { + fixedvec3 pos = PosRelative(m->m_sector); sector_t *hsec = m->m_sector->GetHeightSec(); - if (hsec == NULL && m->m_sector->floorplane.ZatPoint (this) == Z()) + if (hsec == NULL && m->m_sector->floorplane.ZatPoint (pos) == Z()) { fixed_t clip = Terrains[m->m_sector->GetTerrain(sector_t::floor)].FootClip; if (clip < shallowestclip) @@ -5523,9 +5527,9 @@ bool P_HitWater (AActor * thing, sector_t * sec, fixed_t x, fixed_t y, fixed_t z fixed_t planez = rover->top.plane->ZatPoint(x, y); if (z > planez - FRACUNIT / 2 && z < planez + FRACUNIT / 2) // allow minor imprecisions { - if (rover->flags & (FF_SOLID | FF_SWIMMABLE)) + if (rover->flags & (FF_SOLID | FF_SWIMMABLE)) { - terrainnum = rover->model->GetTerrain(rover->top.isceiling); + terrainnum = rover->model->GetTerrain(rover->top.isceiling); goto foundone; } } @@ -5638,9 +5642,11 @@ bool P_HitFloor (AActor *thing) return false; // don't splash if landing on the edge above water/lava/etc.... + fixedvec3 pos; for (m = thing->touching_sectorlist; m; m = m->m_tnext) { - if (thing->Z() == m->m_sector->floorplane.ZatPoint(thing)) + pos = thing->PosRelative(m->m_sector); + if (thing->Z() == m->m_sector->floorplane.ZatPoint(pos.x, pos.y)) { break; } @@ -5652,9 +5658,9 @@ bool P_HitFloor (AActor *thing) if (!(rover->flags & FF_EXISTS)) continue; if (rover->flags & (FF_SOLID|FF_SWIMMABLE)) { - if (rover->top.plane->ZatPoint(thing) == thing->Z()) + if (rover->top.plane->ZatPoint(pos.x, pos.y) == thing->Z()) { - return P_HitWater (thing, m->m_sector); + return P_HitWater (thing, m->m_sector, pos.x, pos.y, pos.z); } } } @@ -5664,7 +5670,7 @@ bool P_HitFloor (AActor *thing) return false; } - return P_HitWater (thing, m->m_sector); + return P_HitWater (thing, m->m_sector, pos.x, pos.y, pos.z); } //--------------------------------------------------------------------------- @@ -5677,12 +5683,15 @@ bool P_HitFloor (AActor *thing) void P_CheckSplash(AActor *self, fixed_t distance) { - if (self->Z() <= self->floorz + (distance<floorsector == self->Sector && self->Sector->GetHeightSec() == NULL) + sector_t *floorsec; + self->Sector->LowestFloorAt(self, &floorsec); + if (self->Z() <= self->floorz + (distance<floorsector == floorsec && self->Sector->GetHeightSec() == NULL && floorsec->heightsec == NULL) { // Explosion splashes never alert monsters. This is because A_Explode has // a separate parameter for that so this would get in the way of proper // behavior. - P_HitWater (self, self->Sector, self->X(), self->Y(), self->floorz, false, false); + fixedvec3 pos = self->PosRelative(floorsec); + P_HitWater (self, floorsec, pos.x, pos.y, self->floorz, false, false); } } diff --git a/src/p_sectors.cpp b/src/p_sectors.cpp index 606e85575..f6d126cc0 100644 --- a/src/p_sectors.cpp +++ b/src/p_sectors.cpp @@ -1000,24 +1000,6 @@ fixed_t sector_t::NextLowestFloorAt(fixed_t x, fixed_t y, fixed_t z, sector_t ** } } -//=========================================================================== -// -// Calculates the height of a sector plane, respecting portal offsets -// between two spots -// -//=========================================================================== - -fixed_t sector_t::PlaneAtPoint(const secplane_t &plane, fixed_t x, fixed_t y, int refgroup) const -{ - if (refgroup != PortalGroup) - { - FDisplacement &disp = Displacements(PortalGroup, refgroup); - x += disp.pos.x; - y += disp.pos.y; - } - return plane.ZatPoint(x, y); -} - //=========================================================================== // // diff --git a/src/p_spec.cpp b/src/p_spec.cpp index 45ed51be2..7e57cd0f8 100644 --- a/src/p_spec.cpp +++ b/src/p_spec.cpp @@ -440,7 +440,7 @@ void P_PlayerInSpecialSector (player_t *player, sector_t * sector) { // Falling, not all the way down yet? sector = player->mo->Sector; - if (player->mo->Z() != sector->floorplane.ZatPoint(player->mo) + if (player->mo->Z() != sector->LowestFloorAt(player->mo) && !player->mo->waterlevel) { return; @@ -480,7 +480,7 @@ void P_PlayerInSpecialSector (player_t *player, sector_t * sector) } if (sector->Flags & SECF_DMGTERRAINFX) { - P_HitWater(player->mo, sector, INT_MIN, INT_MIN, INT_MIN, false, true, true); + P_HitWater(player->mo, player->mo->Sector, INT_MIN, INT_MIN, INT_MIN, false, true, true); } } } @@ -2299,6 +2299,7 @@ void DPusher::Tick () continue; sector_t *hsec = sec->GetHeightSec(); + fixedvec2 pos = thing->PosRelative(sec); if (m_Type == p_wind) { if (hsec == NULL) @@ -2316,7 +2317,7 @@ void DPusher::Tick () } else // special water sector { - ht = hsec->floorplane.ZatPoint(thing); + ht = hsec->floorplane.ZatPoint(pos); if (thing->Z() > ht) // above ground { xspeed = m_Xmag; // full force @@ -2345,7 +2346,7 @@ void DPusher::Tick () { // special water sector floor = &hsec->floorplane; } - if (thing->Z() > floor->ZatPoint(thing)) + if (thing->Z() > floor->ZatPoint(pos)) { // above ground xspeed = yspeed = 0; // no force } diff --git a/src/r_defs.h b/src/r_defs.h index eb08cec7b..90d71dcd0 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -778,47 +778,6 @@ struct sector_t return NextLowestFloorAt(a->X(), a->Y(), z, resultsec, resultffloor); } - // ... for ceilings - fixed_t CeilingAtPoint(fixed_t x, fixed_t y, int refgroup) const - { - return PlaneAtPoint(ceilingplane, x, y, refgroup); - } - fixed_t CeilingAtPoint(AActor *actor) const - { - return PlaneAtPoint(ceilingplane, actor->X(), actor->Y(), actor->Sector->PortalGroup); - } - fixed_t CeilingAtPoint(fixed_t x, fixed_t y, sector_t *refsector) const - { - return PlaneAtPoint(ceilingplane, x, y, refsector->PortalGroup); - } - - // ... for floors - fixed_t FloorAtPoint(fixed_t x, fixed_t y, int refgroup) const - { - return PlaneAtPoint(floorplane, x, y, refgroup); - } - fixed_t FloorAtPoint(AActor *actor) const - { - return PlaneAtPoint(floorplane, actor->X(), actor->Y(), actor->Sector->PortalGroup); - } - fixed_t FloorAtPoint(fixed_t x, fixed_t y, sector_t *refsector) const - { - return PlaneAtPoint(floorplane, x, y, refsector->PortalGroup); - } - - // ... for control sectors - fixed_t PlaneAtPoint(const secplane_t &plane, AActor *actor) const - { - return PlaneAtPoint(plane, actor->X(), actor->Y(), actor->Sector->PortalGroup); - } - fixed_t PlaneAtPoint(const secplane_t &plane, fixed_t x, fixed_t y, sector_t *refsector) const - { - return PlaneAtPoint(plane, x, y, refsector->PortalGroup); - } - - // The worker function for all the above. - fixed_t PlaneAtPoint(const secplane_t &plane, fixed_t x, fixed_t y, int refgroup) const; - FDisplacement &FloorDisplacement(); FDisplacement &CeilingDisplacement();