From 2c7761926e045352beea6511d48f06cc29d66089 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 14 Jul 2022 10:39:11 +0200 Subject: [PATCH] - removed volatile type punning for clipping against line portals. This now uses a common base for line_t and HWLinePortal. --- src/gamedata/r_defs.h | 28 +++++++++++--------- src/playsim/p_maputl.h | 4 +-- src/playsim/portal.cpp | 4 +-- src/playsim/portal.h | 3 ++- src/rendering/hwrenderer/scene/hw_bsp.cpp | 6 ++--- src/rendering/hwrenderer/scene/hw_drawinfo.h | 2 +- src/rendering/hwrenderer/scene/hw_portal.cpp | 6 ++--- src/rendering/hwrenderer/scene/hw_portal.h | 18 +++---------- 8 files changed, 32 insertions(+), 39 deletions(-) diff --git a/src/gamedata/r_defs.h b/src/gamedata/r_defs.h index 377418d92..273ffebfc 100644 --- a/src/gamedata/r_defs.h +++ b/src/gamedata/r_defs.h @@ -1456,10 +1456,24 @@ enum AutomapLineStyle : int AMLS_COUNT }; -struct line_t +struct linebase_t { - vertex_t *v1, *v2; // vertices, from v1 to v2 + vertex_t* v1, * v2; // vertices, from v1 to v2 DVector2 delta; // precalculated v2 - v1 for side checking + + DVector2 Delta() const + { + return delta; + } + + void setDelta(double x, double y) + { + delta = { x, y }; + } +}; + +struct line_t : public linebase_t +{ uint32_t flags, flags2; uint32_t activation; // activation type int special; @@ -1477,16 +1491,6 @@ struct line_t int healthgroup; // [ZZ] this is the "destructible object" id int linenum; - DVector2 Delta() const - { - return delta; - } - - void setDelta(double x, double y) - { - delta = { x, y }; - } - void setAlpha(double a) { alpha = a; diff --git a/src/playsim/p_maputl.h b/src/playsim/p_maputl.h index 0c93ab445..53984f1d3 100644 --- a/src/playsim/p_maputl.h +++ b/src/playsim/p_maputl.h @@ -39,12 +39,12 @@ struct intercept_t // //========================================================================== -inline int P_PointOnLineSidePrecise(double x, double y, const line_t *line) +inline int P_PointOnLineSidePrecise(double x, double y, const linebase_t *line) { return (y - line->v1->fY()) * line->Delta().X + (line->v1->fX() - x) * line->Delta().Y > EQUAL_EPSILON; } -inline int P_PointOnLineSidePrecise(const DVector2 &pt, const line_t *line) +inline int P_PointOnLineSidePrecise(const DVector2 &pt, const linebase_t *line) { return (pt.Y - line->v1->fY()) * line->Delta().X + (line->v1->fX() - pt.X) * line->Delta().Y > EQUAL_EPSILON; } diff --git a/src/playsim/portal.cpp b/src/playsim/portal.cpp index bc5a170cc..1086315ed 100644 --- a/src/playsim/portal.cpp +++ b/src/playsim/portal.cpp @@ -388,13 +388,13 @@ bool FLevelLocals::ChangePortal(line_t *ln, int thisid, int destid) // //============================================================================ -inline int P_GetLineSide(const DVector2 &pos, const line_t *line) +inline int P_GetLineSide(const DVector2 &pos, const linebase_t *line) { double v = (pos.Y - line->v1->fY()) * line->Delta().X + (line->v1->fX() - pos.X) * line->Delta().Y; return v < -1. / 65536. ? -1 : v > 1. / 65536 ? 1 : 0; } -bool P_ClipLineToPortal(line_t* line, line_t* portal, DVector2 view, bool partial, bool samebehind) +bool P_ClipLineToPortal(linebase_t* line, linebase_t* portal, DVector2 view, bool partial, bool samebehind) { int behind1 = P_GetLineSide(line->v1->fPos(), portal); int behind2 = P_GetLineSide(line->v2->fPos(), portal); diff --git a/src/playsim/portal.h b/src/playsim/portal.h index 164593daf..ca5e98427 100644 --- a/src/playsim/portal.h +++ b/src/playsim/portal.h @@ -4,6 +4,7 @@ #include "basics.h" #include "m_bbox.h" +struct linebase_t; struct line_t; struct sector_t; @@ -278,7 +279,7 @@ struct FSectorPortalGroup /* code ported from prototype */ -bool P_ClipLineToPortal(line_t* line, line_t* portal, DVector2 view, bool partial = true, bool samebehind = true); +bool P_ClipLineToPortal(linebase_t* line, linebase_t* portal, DVector2 view, bool partial = true, bool samebehind = true); void P_TranslatePortalXY(line_t* src, double& vx, double& vy); void P_TranslatePortalVXVY(line_t* src, double &velx, double &vely); void P_TranslatePortalAngle(line_t* src, DAngle& angle); diff --git a/src/rendering/hwrenderer/scene/hw_bsp.cpp b/src/rendering/hwrenderer/scene/hw_bsp.cpp index 8f6f1e194..822f7c2ca 100644 --- a/src/rendering/hwrenderer/scene/hw_bsp.cpp +++ b/src/rendering/hwrenderer/scene/hw_bsp.cpp @@ -485,13 +485,13 @@ void HWDrawInfo::AddLines(subsector_t * sub, sector_t * sector) // //========================================================================== -inline bool PointOnLine(const DVector2 &pos, const line_t *line) +inline bool PointOnLine(const DVector2 &pos, const linebase_t *line) { double v = (pos.Y - line->v1->fY()) * line->Delta().X + (line->v1->fX() - pos.X) * line->Delta().Y; return fabs(v) <= EQUAL_EPSILON; } -void HWDrawInfo::AddSpecialPortalLines(subsector_t * sub, sector_t * sector, line_t *line) +void HWDrawInfo::AddSpecialPortalLines(subsector_t * sub, sector_t * sector, linebase_t *line) { currentsector = sector; currentsubsector = sub; @@ -653,7 +653,7 @@ void HWDrawInfo::DoSubsector(subsector_t * sub) int clipres = mClipPortal->ClipSubsector(sub); if (clipres == PClip_InFront) { - line_t *line = mClipPortal->ClipLine(); + auto line = mClipPortal->ClipLine(); // The subsector is out of range, but we still have to check lines that lie directly on the boundary and may expose their upper or lower parts. if (line) AddSpecialPortalLines(sub, fakesector, line); return; diff --git a/src/rendering/hwrenderer/scene/hw_drawinfo.h b/src/rendering/hwrenderer/scene/hw_drawinfo.h index 4d92c1cbc..52f397dcc 100644 --- a/src/rendering/hwrenderer/scene/hw_drawinfo.h +++ b/src/rendering/hwrenderer/scene/hw_drawinfo.h @@ -197,7 +197,7 @@ private: void RenderPolyBSPNode(void *node); void AddPolyobjs(subsector_t *sub); void AddLines(subsector_t * sub, sector_t * sector); - void AddSpecialPortalLines(subsector_t * sub, sector_t * sector, line_t *line); + void AddSpecialPortalLines(subsector_t * sub, sector_t * sector, linebase_t *line); public: void RenderThings(subsector_t * sub, sector_t * sector); void RenderParticles(subsector_t *sub, sector_t *front); diff --git a/src/rendering/hwrenderer/scene/hw_portal.cpp b/src/rendering/hwrenderer/scene/hw_portal.cpp index c5efff0ab..8573bede1 100644 --- a/src/rendering/hwrenderer/scene/hw_portal.cpp +++ b/src/rendering/hwrenderer/scene/hw_portal.cpp @@ -447,7 +447,7 @@ int HWLinePortal::ClipSeg(seg_t *seg, const DVector3 &viewpos) { return PClip_Inside; // should be handled properly. } - return P_ClipLineToPortal(linedef, line(), viewpos) ? PClip_InFront : PClip_Inside; + return P_ClipLineToPortal(linedef, this, viewpos) ? PClip_InFront : PClip_Inside; } int HWLinePortal::ClipSubsector(subsector_t *sub) @@ -455,14 +455,14 @@ int HWLinePortal::ClipSubsector(subsector_t *sub) // this seg is completely behind the mirror for (unsigned int i = 0; inumlines; i++) { - if (P_PointOnLineSidePrecise(sub->firstline[i].v1->fPos(), line()) == 0) return PClip_Inside; + if (P_PointOnLineSidePrecise(sub->firstline[i].v1->fPos(), this) == 0) return PClip_Inside; } return PClip_InFront; } int HWLinePortal::ClipPoint(const DVector2 &pos) { - if (P_PointOnLineSidePrecise(pos, line())) + if (P_PointOnLineSidePrecise(pos, this)) { return PClip_InFront; } diff --git a/src/rendering/hwrenderer/scene/hw_portal.h b/src/rendering/hwrenderer/scene/hw_portal.h index 6a3b46170..3eebaee2d 100644 --- a/src/rendering/hwrenderer/scene/hw_portal.h +++ b/src/rendering/hwrenderer/scene/hw_portal.h @@ -74,7 +74,7 @@ public: virtual int ClipSeg(seg_t *seg, const DVector3 &viewpos) { return PClip_Inside; } virtual int ClipSubsector(subsector_t *sub) { return PClip_Inside; } virtual int ClipPoint(const DVector2 &pos) { return PClip_Inside; } - virtual line_t *ClipLine() { return nullptr; } + virtual linebase_t *ClipLine() { return nullptr; } virtual void * GetSource() const = 0; // GetSource MUST be implemented! virtual const char *GetName() = 0; virtual bool AllowSSAO() { return true; } @@ -156,14 +156,8 @@ public: virtual void Shutdown(HWDrawInfo *di, FRenderState &rstate) {} }; -struct HWLinePortal : public HWScenePortalBase +struct HWLinePortal : public HWScenePortalBase, public linebase_t { - uint32_t PAD; // This fixes walls not being drawn in portals in 32bit machines..seems to be OK this is here for 64bit also.. - - // this must be the same as at the start of line_t, so that we can pass in this structure directly to P_ClipLineToPortal. - vertex_t *v1, *v2; // vertices, from v1 to v2 - DVector2 delta; // precalculated v2 - v1 for side checking - angle_t angv1, angv2; // for quick comparisons with a line or subsector HWLinePortal(FPortalSceneState *state, line_t *line) : HWScenePortalBase(state) @@ -196,12 +190,6 @@ struct HWLinePortal : public HWScenePortalBase delta = v2->fPos() - v1->fPos(); } - line_t *line() - { - vertex_t **pv = &v1; - return reinterpret_cast(pv); - } - int ClipSeg(seg_t *seg, const DVector3 &viewpos) override; int ClipSubsector(subsector_t *sub) override; int ClipPoint(const DVector2 &pos); @@ -236,7 +224,7 @@ protected: bool Setup(HWDrawInfo *di, FRenderState &rstate, Clipper *clipper) override; virtual void * GetSource() const override { return glport; } virtual const char *GetName() override; - virtual line_t *ClipLine() override { return line(); } + virtual linebase_t *ClipLine() override { return this; } virtual void RenderAttached(HWDrawInfo *di) override; public: