From 3ed7a25d61e5c4594cb1134c5cccdd62c75de2d4 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 17 Apr 2016 17:10:11 +0200 Subject: [PATCH] - added polyportal offset updates. - removed the nodebuilder message for splitting polyobject subsectors because it is no longer relevant. --- src/nodebuild.cpp | 9 ------- src/p_saveg.cpp | 10 +++++++- src/po_man.cpp | 61 +++++++++++++++++++++++++++++++++++++++++++++++ src/po_man.h | 2 ++ src/portal.cpp | 3 +-- src/portal.h | 8 +++++++ src/version.h | 2 +- 7 files changed, 82 insertions(+), 13 deletions(-) diff --git a/src/nodebuild.cpp b/src/nodebuild.cpp index c56ee697e..d1a8737ec 100644 --- a/src/nodebuild.cpp +++ b/src/nodebuild.cpp @@ -811,15 +811,6 @@ void FNodeBuilder::SplitSegs (DWORD set, node_t &node, DWORD splitseg, DWORD &ou unsigned int vertnum; int seg2; - if (seg->loopnum) - { - Printf (" Split seg %u (%d,%d)-(%d,%d) of sector %td in loop %d\n", - set, - Vertices[seg->v1].x>>16, Vertices[seg->v1].y>>16, - Vertices[seg->v2].x>>16, Vertices[seg->v2].y>>16, - seg->frontsector - sectors, seg->loopnum); - } - frac = InterceptVector (node, *seg); newvert.x = Vertices[seg->v1].x; newvert.y = Vertices[seg->v1].y; diff --git a/src/p_saveg.cpp b/src/p_saveg.cpp index 8744ec740..81218640a 100644 --- a/src/p_saveg.cpp +++ b/src/p_saveg.cpp @@ -539,7 +539,7 @@ void P_SerializePolyobjs (FArchive &arc) arc << seg << po_NumPolyobjs; for(i = 0, po = polyobjs; i < po_NumPolyobjs; i++, po++) { - arc << po->tag << po->Angle << po->StartSpot.pos << po->interpolation << po->bBlocked; + arc << po->tag << po->Angle << po->StartSpot.pos << po->interpolation << po->bBlocked << po->bHasPortals; } } else @@ -573,6 +573,14 @@ void P_SerializePolyobjs (FArchive &arc) { po->bBlocked = false; } + if (SaveVersion >= 4538) + { + arc << po->bHasPortals; + } + else + { + po->bHasPortals = 0; + } po->RotatePolyobj (angle, true); delta -= po->StartSpot.pos; diff --git a/src/po_man.cpp b/src/po_man.cpp index f2029026d..d2faa6690 100644 --- a/src/po_man.cpp +++ b/src/po_man.cpp @@ -425,6 +425,11 @@ bool EV_RotatePoly (line_t *line, int polyNum, int speed, int byteAngle, { // poly is already in motion break; } + if (poly->bHasPortals == 2) + { + // cannot do rotations on linked polyportals. + break; + } pe = new DRotatePoly(poly->tag); poly->specialdata = pe; poly->bBlocked = false; @@ -476,6 +481,7 @@ void DMovePoly::Tick () m_Speed = m_Dist * (m_Speed < 0 ? -1 : 1); m_Speedv = m_Angle.ToVector(m_Speed); } + poly->UpdateLinks(); } } } @@ -555,6 +561,7 @@ void DMovePolyTo::Tick () m_Speed = m_Dist * (m_Speed < 0 ? -1 : 1); m_Speedv = m_Target - poly->StartSpot.pos; } + poly->UpdateLinks(); } } } @@ -649,6 +656,7 @@ void DPolyDoor::Tick () Destroy (); } } + poly->UpdateLinks(); } else { @@ -735,6 +743,12 @@ bool EV_OpenPolyDoor(line_t *line, int polyNum, double speed, DAngle angle, int { // poly is already moving break; } + if (poly->bHasPortals == 2 && type == PODOOR_SWING) + { + // cannot do rotations on linked polyportals. + break; + } + pd = new DPolyDoor(poly->tag, type); poly->specialdata = pd; if (type == PODOOR_SLIDE) @@ -899,6 +913,36 @@ void FPolyObj::ThrustMobj (AActor *actor, side_t *side) // //========================================================================== +void FPolyObj::UpdateLinks() +{ + if (bHasPortals == 2) + { + TMap processed; + for (unsigned i = 0; i < Linedefs.Size(); i++) + { + if (Linedefs[i]->isLinePortal()) + { + FLinePortal *port = Linedefs[i]->getPortal(); + if (port->mType == PORTT_LINKED) + { + DVector2 old = port->mDisplacement; + port->mDisplacement = port->mDestination->v2->fPos() - port->mOrigin->v1->fPos(); + FLinePortal *port2 = port->mDestination->getPortal(); + if (port2) port2->mDisplacement = -port->mDisplacement; + int destgroup = port->mDestination->frontsector->PortalGroup; + bool *done = processed.CheckKey(destgroup); + if (!done || !*done) + { + processed[destgroup] = true; + DVector2 delta = port->mDisplacement - old; + Displacements.MoveGroup(destgroup, delta); + } + } + } + } + } +} + void FPolyObj::UpdateBBox () { for(unsigned i=0;iisLinePortal()) + { + // Fixme: this still needs to figure out if the polyobject move made the player cross the portal line. + if (P_TryMove(mobj, mobj->Pos(), false)) + { + continue; + } + } // We have a two-sided linedef so we should only check one side // so that the thrust from both sides doesn't cancel each other out. // Best use the one facing the player and ignore the back side. @@ -1496,6 +1549,8 @@ static void SpawnPolyobj (int index, int tag, int type) { continue; } + po->bBlocked = false; + po->bHasPortals = 0; side_t *sd = &sides[i]; @@ -1563,6 +1618,12 @@ static void SpawnPolyobj (int index, int tag, int type) if (l->validcount != validcount) { + FLinePortal *port = l->getPortal(); + if (port && (port->mDefFlags & PORTF_PASSABLE)) + { + int type = port->mType == PORTT_LINKED ? 2 : 1; + if (po->bHasPortals < type) po->bHasPortals = (BYTE)type; + } l->validcount = validcount; po->Linedefs.Push(l); diff --git a/src/po_man.h b/src/po_man.h index 2b9c8afef..9bc853255 100644 --- a/src/po_man.h +++ b/src/po_man.h @@ -63,6 +63,7 @@ struct FPolyObj int crush; // should the polyobj attempt to crush mobjs? bool bHurtOnTouch; // should the polyobj hurt anything it touches? bool bBlocked; + BYTE bHasPortals; // 1 for any portal, 2 for a linked portal (2 must block rotations.) int seqType; double Size; // polyobj size (area of POLY_AREAUNIT == size of FRACUNIT) FPolyNode *subsectorlinks; @@ -82,6 +83,7 @@ struct FPolyObj void CreateSubsectorLinks(); void ClearSubsectorLinks(); void CalcCenter(); + void UpdateLinks(); static void ClearAllSubsectorLinks(); private: diff --git a/src/portal.cpp b/src/portal.cpp index 3ce45c636..1be08fc85 100644 --- a/src/portal.cpp +++ b/src/portal.cpp @@ -384,8 +384,7 @@ void P_UpdatePortal(FLinePortal *port) } else { - port->mDisplacement.X = port->mDestination->v2->fX() - port->mOrigin->v1->fX(); - port->mDisplacement.Y = port->mDestination->v2->fY() - port->mOrigin->v1->fY(); + port->mDisplacement = port->mDestination->v2->fPos() - port->mOrigin->v1->fPos(); } } } diff --git a/src/portal.h b/src/portal.h index 2868521bc..0aa9a2ef2 100644 --- a/src/portal.h +++ b/src/portal.h @@ -64,6 +64,14 @@ struct FDisplacementTable return data[x + size*y].pos; } + void MoveGroup(int grp, DVector2 delta) + { + for (int i = 1; i < size; i++) + { + data[grp + size*i].pos -= delta; + data[i + grp*size].pos += delta; + } + } }; extern FDisplacementTable Displacements; diff --git a/src/version.h b/src/version.h index a824525c9..14da98c1a 100644 --- a/src/version.h +++ b/src/version.h @@ -76,7 +76,7 @@ const char *GetVersionString(); // Use 4500 as the base git save version, since it's higher than the // SVN revision ever got. -#define SAVEVER 4537 +#define SAVEVER 4538 #define SAVEVERSTRINGIFY2(x) #x #define SAVEVERSTRINGIFY(x) SAVEVERSTRINGIFY2(x)