diff --git a/src/actor.h b/src/actor.h index 943f137efb..5d3e85bc8d 100644 --- a/src/actor.h +++ b/src/actor.h @@ -742,13 +742,13 @@ public: // What species am I? virtual FName GetSpecies(); - double GetBobOffset(fixed_t ticfrac = 0) const + double GetBobOffset(double ticfrac = 0) const { if (!(flags2 & MF2_FLOATBOB)) { return 0; } - return BobSin(FloatBobPhase + level.maptime + FIXED2FLOAT(ticfrac)); + return BobSin(FloatBobPhase + level.maptime + ticfrac); } @@ -850,8 +850,8 @@ public: // more precise, but slower version, being used in a few places double Distance2D(AActor *other, bool absolute = false) { - fixedvec3 otherpos = absolute ? other->_f_Pos() : other->_f_PosRelative(this); - return (DVector2(_f_X() - otherpos.x, _f_Y() - otherpos.y).Length())/FRACUNIT; + DVector2 otherpos = absolute ? other->Pos() : other->PosRelative(this); + return (Pos().XY() - otherpos).Length(); } double Distance2D(double x, double y) const @@ -860,10 +860,10 @@ public: } // a full 3D version of the above - fixed_t Distance3D(AActor *other, bool absolute = false) + double Distance3D(AActor *other, bool absolute = false) { - fixedvec3 otherpos = absolute ? other->_f_Pos() : other->_f_PosRelative(this); - return xs_RoundToInt(DVector3(_f_X() - otherpos.x, _f_Y() - otherpos.y, _f_Z() - otherpos.z).Length()); + DVector3 otherpos = absolute ? other->Pos() : other->PosRelative(this); + return (Pos() - otherpos).Length(); } angle_t __f_AngleTo(AActor *other, bool absolute = false) @@ -879,19 +879,20 @@ public: DAngle AngleTo(AActor *other, bool absolute = false) { - fixedvec3 otherpos = absolute ? other->_f_Pos() : other->_f_PosRelative(this); - return VecToAngle(otherpos.x - _f_X(), otherpos.y - _f_Y()); + DVector2 otherpos = absolute ? other->Pos() : other->PosRelative(this); + return VecToAngle(otherpos - Pos().XY()); } DAngle AngleTo(AActor *other, fixed_t oxofs, fixed_t oyofs, bool absolute = false) const { fixedvec3 otherpos = absolute ? other->_f_Pos() : other->_f_PosRelative(this); - return VecToAngle(otherpos.y + oxofs - _f_Y(), otherpos.x + oyofs - _f_X()); + return VecToAngle(otherpos.x + oxofs - _f_X(), otherpos.y + oyofs - _f_Y()); } DAngle AngleTo(AActor *other, double oxofs, double oyofs, bool absolute = false) const { - return FIXED2DBL(AngleTo(other, FLOAT2FIXED(oxofs), FLOAT2FIXED(oyofs), absolute)); + DVector2 otherpos = absolute ? other->Pos() : other->PosRelative(this); + return VecToAngle(otherpos - Pos() + DVector2(oxofs, oyofs)); } fixedvec2 _f_Vec2To(AActor *other) const @@ -910,14 +911,12 @@ public: DVector2 Vec2To(AActor *other) const { - fixedvec3 otherpos = other->_f_PosRelative(this); - return{ FIXED2DBL(otherpos.x - _f_X()), FIXED2DBL(otherpos.y - _f_Y()) }; + return other->PosRelative(this) - Pos(); } DVector3 Vec3To(AActor *other) const { - fixedvec3 otherpos = other->_f_PosRelative(this); - return { FIXED2DBL(otherpos.x - _f_X()), FIXED2DBL(otherpos.y - _f_Y()), FIXED2DBL(otherpos.z - _f_Z()) }; + return other->PosRelative(this) - Pos(); } fixedvec2 Vec2Offset(fixed_t dx, fixed_t dy, bool absolute = false) @@ -1089,14 +1088,7 @@ public: // info for drawing // NOTE: The first member variable *must* be snext. AActor *snext, **sprev; // links in sector (if needed) - DVector3 __Pos; // double underscores so that it won't get used by accident. Access to this should be exclusively through the designated access functions. - - /* - angle_t angle; - fixed_t pitch; - angle_t roll; // This was fixed_t before, which is probably wrong - fixedvec3 vel; - */ + DVector3 __Pos; // double underscores so that it won't get used by accident. Access to this should be exclusively through the designated access functions. DRotator Angles; DVector3 Vel; @@ -1321,8 +1313,7 @@ public: FDecalBase *DecalGenerator; // [RH] Used to interpolate the view to get >35 FPS - fixed_t PrevX, PrevY, PrevZ; - //angle_t PrevAngle; + DVector3 Prev; DRotator PrevAngles; int PrevPortalGroup; @@ -1419,6 +1410,11 @@ public: fixedvec3 _f_PosRelative(sector_t *sec) const; fixedvec3 _f_PosRelative(line_t *line) const; + DVector3 PosRelative(int grp) const; + DVector3 PosRelative(const AActor *other) const; + DVector3 PosRelative(sector_t *sec) const; + DVector3 PosRelative(line_t *line) const; + fixed_t SoundX() const { return _f_X(); @@ -1431,14 +1427,9 @@ public: { return _f_Z(); } - fixedvec3 InterpolatedPosition(fixed_t ticFrac) const + DVector3 InterpolatedPosition(double ticFrac) const { - fixedvec3 ret; - - ret.x = PrevX + FixedMul (ticFrac, _f_X() - PrevX); - ret.y = PrevY + FixedMul (ticFrac, _f_Y() - PrevY); - ret.z = PrevZ + FixedMul (ticFrac, _f_Z() - PrevZ); - return ret; + return Prev + (ticFrac * (Pos() - Prev)); } fixedvec3 PosPlusZ(fixed_t zadd) const { @@ -1480,7 +1471,7 @@ public: void AddZ(double newz, bool moving = true) { __Pos.Z += newz; - if (!moving) PrevZ = _f_Z(); + if (!moving) Prev.Z = Z(); } // These are not for general use as they do not link the actor into the world! diff --git a/src/am_map.cpp b/src/am_map.cpp index 65cc1c5833..48fbe18172 100644 --- a/src/am_map.cpp +++ b/src/am_map.cpp @@ -2429,7 +2429,7 @@ void AM_drawWalls (bool allmap) bool portalmode = numportalgroups > 0 && pg != MapPortalGroup; if (pg == p) { - offset = Displacements.getOffset(pg, MapPortalGroup); + offset = Displacements._f_getOffset(pg, MapPortalGroup); } else if (p == -1 && (pg == MapPortalGroup || !am_portaloverlay)) { diff --git a/src/p_enemy.cpp b/src/p_enemy.cpp index 904b41bf9d..811d8748a5 100644 --- a/src/p_enemy.cpp +++ b/src/p_enemy.cpp @@ -2545,8 +2545,7 @@ void A_DoChase (VMFrameStack *stack, AActor *actor, bool fastchase, FState *mele if ((!fastchase || !actor->FastChaseStrafeCount) && !dontmove) { // CANTLEAVEFLOORPIC handling was completely missing in the non-serpent functions. - fixed_t oldX = actor->_f_X(); - fixed_t oldY = actor->_f_Y(); + DVector2 old = actor->Pos(); int oldgroup = actor->PrevPortalGroup; FTextureID oldFloor = actor->floorpic; @@ -2559,12 +2558,12 @@ void A_DoChase (VMFrameStack *stack, AActor *actor, bool fastchase, FState *mele // (copied from A_SerpentChase - it applies to everything with CANTLEAVEFLOORPIC!) if (actor->flags2&MF2_CANTLEAVEFLOORPIC && actor->floorpic != oldFloor ) { - if (P_TryMove(actor, oldX, oldY, false)) + if (P_TryMove(actor, old, false)) { if (nomonsterinterpolation) { - actor->PrevX = oldX; - actor->PrevY = oldY; + actor->Prev.X = old.X; + actor->Prev.Y = old.Y; actor->PrevPortalGroup = oldgroup; } } diff --git a/src/p_map.cpp b/src/p_map.cpp index 77fceae4e7..c261d1e4c1 100644 --- a/src/p_map.cpp +++ b/src/p_map.cpp @@ -2299,8 +2299,8 @@ bool P_TryMove(AActor *thing, fixed_t x, fixed_t y, { thing->UnlinkFromWorld(); thing->SetXY(tm.x + port->mXDisplacement, tm.y + port->mYDisplacement); - thing->PrevX += port->mXDisplacement; - thing->PrevY += port->mYDisplacement; + thing->Prev.X += FIXED2DBL(port->mXDisplacement); + thing->Prev.Y += FIXED2DBL(port->mYDisplacement); thing->LinkToWorld(); P_FindFloorCeiling(thing); portalcrossed = true; diff --git a/src/p_maputl.cpp b/src/p_maputl.cpp index 488260a7f8..4a36870836 100644 --- a/src/p_maputl.cpp +++ b/src/p_maputl.cpp @@ -870,7 +870,7 @@ bool FMultiBlockLinesIterator::Next(FMultiBlockLinesIterator::CheckResult *item) void FMultiBlockLinesIterator::startIteratorForGroup(int group) { - offset = Displacements.getOffset(basegroup, group); + offset = Displacements._f_getOffset(basegroup, group); offset.x += checkpoint.x; offset.y += checkpoint.y; cursector = group == startsector->PortalGroup ? startsector : P_PointInSector(offset.x, offset.y); @@ -1104,7 +1104,7 @@ bool FMultiBlockThingsIterator::Next(FMultiBlockThingsIterator::CheckResult *ite if (thing != NULL) { item->thing = thing; - item->position = checkpoint + Displacements.getOffset(basegroup, thing->Sector->PortalGroup); + item->position = checkpoint + Displacements._f_getOffset(basegroup, thing->Sector->PortalGroup); item->portalflags = portalflags; // same as above in floating point. This is here so that this stuff can be converted piece by piece. @@ -1146,7 +1146,7 @@ bool FMultiBlockThingsIterator::Next(FMultiBlockThingsIterator::CheckResult *ite void FMultiBlockThingsIterator::startIteratorForGroup(int group) { - fixedvec2 offset = Displacements.getOffset(basegroup, group); + fixedvec2 offset = Displacements._f_getOffset(basegroup, group); offset.x += checkpoint.x; offset.y += checkpoint.y; bbox.setBox(offset.x, offset.y, checkpoint.z); diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index f13d6f3955..8b6c3f4ad7 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -2816,7 +2816,7 @@ void P_NightmareRespawn (AActor *mobj) mo->skillrespawncount = mobj->skillrespawncount; - mo->PrevZ = FLOAT2FIXED(z); // Do not interpolate Z position if we changed it since spawning. + mo->Prev.Z = z; // Do not interpolate Z position if we changed it since spawning. // spawn a teleport fog at old spot because of removal of the body? P_SpawnTeleportFog(mobj, mobj->PosPlusZ(TELEFOGHEIGHT), true, true); @@ -3294,13 +3294,11 @@ void AActor::CheckPortalTransition(bool islinked) AActor *port = Sector->SkyBoxes[sector_t::ceiling]; if (Z() > port->specialf1) { - fixedvec3 oldpos = _f_Pos(); + DVector3 oldpos = Pos(); if (islinked && !moved) UnlinkFromWorld(); - SetXYZ(_f_PosRelative(port->Sector)); - PrevX += _f_X() - oldpos.x; - PrevY += _f_Y() - oldpos.y; - PrevZ += _f_Z() - oldpos.z; - Sector = P_PointInSector(_f_X(), _f_Y()); + SetXYZ(PosRelative(port->Sector)); + Prev = Pos() - oldpos; + Sector = P_PointInSector(Pos()); PrevPortalGroup = Sector->PortalGroup; moved = true; } @@ -3313,13 +3311,11 @@ void AActor::CheckPortalTransition(bool islinked) AActor *port = Sector->SkyBoxes[sector_t::floor]; if (Z() < port->specialf1 && floorz < port->specialf1) { - fixedvec3 oldpos = _f_Pos(); + DVector3 oldpos = Pos(); if (islinked && !moved) UnlinkFromWorld(); - SetXYZ(_f_PosRelative(port->Sector)); - PrevX += _f_X() - oldpos.x; - PrevY += _f_Y() - oldpos.y; - PrevZ += _f_Z() - oldpos.z; - Sector = P_PointInSector(_f_X(), _f_Y()); + SetXYZ(PosRelative(port->Sector)); + Prev = Pos() - oldpos; + Sector = P_PointInSector(Pos()); PrevPortalGroup = Sector->PortalGroup; moved = true; } diff --git a/src/p_things.cpp b/src/p_things.cpp index 1fa0905b1f..3e37135f3f 100644 --- a/src/p_things.cpp +++ b/src/p_things.cpp @@ -757,32 +757,26 @@ int P_Thing_Warp(AActor *caller, AActor *reference, double xofs, double yofs, do caller->Vel.Zero(); } -#if 0 // needs fixing // this is no fun with line portals if (flags & WARPF_WARPINTERPOLATION) { // This just translates the movement but doesn't change the vector - fixedvec3 displacedold = old + Displacements.getOffset(oldpgroup, caller->Sector->PortalGroup); - caller->PrevX += caller->_f_X() - displacedold.x; - caller->PrevY += caller->_f_Y() - displacedold.y; - caller->PrevZ += caller->_f_Z() - displacedold.z; + DVector3 displacedold = old + Displacements.getOffset(oldpgroup, caller->Sector->PortalGroup); + caller->Prev += caller->Pos() - displacedold; caller->PrevPortalGroup = caller->Sector->PortalGroup; } else if (flags & WARPF_COPYINTERPOLATION) { // Map both positions of the reference actor to the current portal group - fixedvec3 displacedold = old + Displacements.getOffset(reference->PrevPortalGroup, caller->Sector->PortalGroup); - fixedvec3 displacedref = old + Displacements.getOffset(reference->Sector->PortalGroup, caller->Sector->PortalGroup); - caller->PrevX = caller->_f_X() + displacedold.x - displacedref.x; - caller->PrevY = caller->_f_Y() + displacedold.y - displacedref.y; - caller->PrevZ = caller->_f_Z() + displacedold.z - displacedref.z; + DVector3 displacedold = old + Displacements.getOffset(reference->PrevPortalGroup, caller->Sector->PortalGroup); + DVector3 displacedref = old + Displacements.getOffset(reference->Sector->PortalGroup, caller->Sector->PortalGroup); + caller->Prev = caller->Pos() + displacedold - displacedref; caller->PrevPortalGroup = caller->Sector->PortalGroup; } else if (!(flags & WARPF_INTERPOLATE)) { caller->ClearInterpolation(); } -#endif if ((flags & WARPF_BOB) && (reference->flags2 & MF2_FLOATBOB)) { diff --git a/src/portal.cpp b/src/portal.cpp index 91a24e2e38..1d7419b668 100644 --- a/src/portal.cpp +++ b/src/portal.cpp @@ -1209,7 +1209,7 @@ bool P_CollectConnectedGroups(int startgroup, const fixedvec3 &position, fixed_t while (!wsec->PortalBlocksMovement(sector_t::ceiling) && upperz > FLOAT2FIXED(wsec->SkyBoxes[sector_t::ceiling]->specialf1)) { sector_t *othersec = wsec->SkyBoxes[sector_t::ceiling]->Sector; - fixedvec2 pos = Displacements.getOffset(startgroup, othersec->PortalGroup); + fixedvec2 pos = Displacements._f_getOffset(startgroup, othersec->PortalGroup); fixed_t dx = position.x + pos.x; fixed_t dy = position.y + pos.y; processMask.setBit(othersec->PortalGroup); @@ -1221,7 +1221,7 @@ bool P_CollectConnectedGroups(int startgroup, const fixedvec3 &position, fixed_t while (!wsec->PortalBlocksMovement(sector_t::floor) && position.z < FLOAT2FIXED(wsec->SkyBoxes[sector_t::floor]->specialf1)) { sector_t *othersec = wsec->SkyBoxes[sector_t::floor]->Sector; - fixedvec2 pos = Displacements.getOffset(startgroup, othersec->PortalGroup); + fixedvec2 pos = Displacements._f_getOffset(startgroup, othersec->PortalGroup); fixed_t dx = position.x + pos.x; fixed_t dy = position.y + pos.y; processMask.setBit(othersec->PortalGroup | FPortalGroupArray::LOWER); @@ -1236,7 +1236,7 @@ bool P_CollectConnectedGroups(int startgroup, const fixedvec3 &position, fixed_t int thisgroup = startgroup; for (unsigned i = 0; i < groupsToCheck.Size();i++) { - fixedvec2 disp = Displacements.getOffset(startgroup, thisgroup & ~FPortalGroupArray::FLAT); + fixedvec2 disp = Displacements._f_getOffset(startgroup, thisgroup & ~FPortalGroupArray::FLAT); FBoundingBox box(position.x + disp.x, position.y + disp.y, checkradius); FBlockLinesIterator it(box); line_t *ld; diff --git a/src/portal.h b/src/portal.h index 582695f065..95fc57a931 100644 --- a/src/portal.h +++ b/src/portal.h @@ -54,7 +54,7 @@ struct FDisplacementTable return data[x + size*y]; } - fixedvec2 getOffset(int x, int y) const + fixedvec2 _f_getOffset(int x, int y) const { if (x == y) { @@ -63,6 +63,18 @@ struct FDisplacementTable } return data[x + size*y].pos; } + + DVector2 getOffset(int x, int y) const + { + if (x == y) + { + DVector2 nulvec = { 0,0 }; + return nulvec; // shortcut for the most common case + } + fixedvec2 &p = data[x + size*y].pos; + return{ FIXED2DBL(p.x), FIXED2DBL(p.y) }; + } + }; extern FDisplacementTable Displacements; diff --git a/src/r_defs.h b/src/r_defs.h index db4a3161fe..a467ba6eea 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -838,12 +838,12 @@ struct sector_t // These may only be called if the portal has been validated fixedvec2 FloorDisplacement() { - return Displacements.getOffset(PortalGroup, SkyBoxes[sector_t::floor]->Sector->PortalGroup); + return Displacements._f_getOffset(PortalGroup, SkyBoxes[sector_t::floor]->Sector->PortalGroup); } fixedvec2 CeilingDisplacement() { - return Displacements.getOffset(PortalGroup, SkyBoxes[sector_t::ceiling]->Sector->PortalGroup); + return Displacements._f_getOffset(PortalGroup, SkyBoxes[sector_t::ceiling]->Sector->PortalGroup); } int GetTerrain(int pos) const; @@ -1336,34 +1336,58 @@ inline sector_t *P_PointInSector(const DVector2 &pos) inline fixedvec3 AActor::_f_PosRelative(int portalgroup) const { - return _f_Pos() + Displacements.getOffset(Sector->PortalGroup, portalgroup); + return _f_Pos() + Displacements._f_getOffset(Sector->PortalGroup, portalgroup); } inline fixedvec3 AActor::_f_PosRelative(const AActor *other) const { - return _f_Pos() + Displacements.getOffset(Sector->PortalGroup, other->Sector->PortalGroup); + return _f_Pos() + Displacements._f_getOffset(Sector->PortalGroup, other->Sector->PortalGroup); } inline fixedvec3 AActor::_f_PosRelative(sector_t *sec) const { - return _f_Pos() + Displacements.getOffset(Sector->PortalGroup, sec->PortalGroup); + return _f_Pos() + Displacements._f_getOffset(Sector->PortalGroup, sec->PortalGroup); } inline fixedvec3 AActor::_f_PosRelative(line_t *line) const { - return _f_Pos() + Displacements.getOffset(Sector->PortalGroup, line->frontsector->PortalGroup); + return _f_Pos() + Displacements._f_getOffset(Sector->PortalGroup, line->frontsector->PortalGroup); } inline fixedvec3 _f_PosRelative(const fixedvec3 &pos, line_t *line, sector_t *refsec = NULL) +{ + return pos + Displacements._f_getOffset(refsec->PortalGroup, line->frontsector->PortalGroup); +} + +inline DVector3 AActor::PosRelative(int portalgroup) const +{ + return Pos() + Displacements.getOffset(Sector->PortalGroup, portalgroup); +} + +inline DVector3 AActor::PosRelative(const AActor *other) const +{ + return Pos() + Displacements.getOffset(Sector->PortalGroup, other->Sector->PortalGroup); +} + +inline DVector3 AActor::PosRelative(sector_t *sec) const +{ + return Pos() + Displacements.getOffset(Sector->PortalGroup, sec->PortalGroup); +} + +inline DVector3 AActor::PosRelative(line_t *line) const +{ + return Pos() + Displacements.getOffset(Sector->PortalGroup, line->frontsector->PortalGroup); +} + +inline DVector3 PosRelative(const DVector3 &pos, line_t *line, sector_t *refsec = NULL) { return pos + Displacements.getOffset(refsec->PortalGroup, line->frontsector->PortalGroup); } + inline void AActor::ClearInterpolation() { - PrevX = _f_X(); - PrevY = _f_Y(); - PrevZ = _f_Z(); + Prev = Pos(); PrevAngles = Angles; if (Sector) PrevPortalGroup = Sector->PortalGroup; else PrevPortalGroup = 0; diff --git a/src/r_plane.cpp b/src/r_plane.cpp index c626473556..e46dfa5fe7 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -1239,10 +1239,10 @@ void R_DrawSkyBoxes () extralight = 0; R_SetVisibility (sky->args[0] * 0.25f); - fixedvec3 viewpos = sky->InterpolatedPosition(r_TicFrac); - viewx = viewpos.x; - viewy = viewpos.y; - viewz = viewpos.z; + DVector3 viewpos = sky->InterpolatedPosition(r_TicFracF); + viewx = FLOAT2FIXED(viewpos.X); + viewy = FLOAT2FIXED(viewpos.Y); + viewz = FLOAT2FIXED(viewpos.Z); viewangle = savedangle + (sky->PrevAngles.Yaw + (sky->Angles.Yaw * r_TicFracF) - sky->PrevAngles.Yaw).BAMs(); R_CopyStackedViewParameters(); @@ -1251,8 +1251,8 @@ void R_DrawSkyBoxes () { extralight = pl->extralight; R_SetVisibility (pl->visibility); - viewx = pl->viewx - sky->Mate->_f_X() + sky->_f_X(); - viewy = pl->viewy - sky->Mate->_f_Y() + sky->_f_Y(); + viewx = pl->viewx - FLOAT2FIXED(sky->Mate->X() + sky->X()); + viewy = pl->viewy - FLOAT2FIXED(sky->Mate->Y() + sky->Y()); viewz = pl->viewz; viewangle = pl->viewangle; } diff --git a/src/r_things.cpp b/src/r_things.cpp index 6313e0cabb..6f99a37905 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -767,10 +767,10 @@ void R_ProjectSprite (AActor *thing, int fakeside, F3DFloor *fakefloor, F3DFloor return; // [RH] Interpolate the sprite's position to make it look smooth - fixedvec3 pos = thing->InterpolatedPosition(r_TicFrac); - fx = pos.x; - fy = pos.y; - fz = pos.z + thing->_f_GetBobOffset(r_TicFrac); + DVector3 pos = thing->InterpolatedPosition(r_TicFracF); + fx = FLOAT2FIXED(pos.X); + fy = FLOAT2FIXED(pos.Y); + fz = FLOAT2FIXED(pos.Z + thing->GetBobOffset(r_TicFracF)); tex = NULL; voxel = NULL; diff --git a/src/r_utility.cpp b/src/r_utility.cpp index 224648770b..810410e08b 100644 --- a/src/r_utility.cpp +++ b/src/r_utility.cpp @@ -652,7 +652,7 @@ void R_InterpolateView (player_t *player, fixed_t frac, InterpolationViewer *ivi } else { - fixedvec2 disp = Displacements.getOffset(oldgroup, newgroup); + fixedvec2 disp = Displacements._f_getOffset(oldgroup, newgroup); viewx = iview->oviewx + FixedMul(frac, iview->nviewx - iview->oviewx - disp.x); viewy = iview->oviewy + FixedMul(frac, iview->nviewy - iview->oviewy - disp.y); viewz = iview->oviewz + FixedMul(frac, iview->nviewz - iview->oviewz);