From b5f3f63b9327706fd92fe78a02da2903a354105b Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Fri, 16 Dec 2016 20:52:56 +0100 Subject: [PATCH] Minor bug fixes --- src/r_poly.cpp | 2 +- src/r_poly.h | 2 ++ src/r_poly_cull.cpp | 30 ++++++++++++++++++++++++++---- src/r_poly_scene.cpp | 2 +- 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/r_poly.cpp b/src/r_poly.cpp index 2e100b395..f7fa33979 100644 --- a/src/r_poly.cpp +++ b/src/r_poly.cpp @@ -74,7 +74,7 @@ void PolyRenderer::RenderActorView(AActor *actor, bool dontmaplines) { NetUpdate(); - //swrenderer::r_dontmaplines = dontmaplines; + DontMapLines = dontmaplines; P_FindParticleSubsectors(); PO_LinkToSubsectors(); diff --git a/src/r_poly.h b/src/r_poly.h index f34106a4b..10d2e92aa 100644 --- a/src/r_poly.h +++ b/src/r_poly.h @@ -50,6 +50,8 @@ public: bool InsertSeenLinePortal(FLinePortal *portal); bool InsertSeenMirror(line_t *mirrorLine); + bool DontMapLines = false; + private: void ClearBuffers(); void SetSceneViewport(); diff --git a/src/r_poly_cull.cpp b/src/r_poly_cull.cpp index 59b7c0c5a..02a0f2fc5 100644 --- a/src/r_poly_cull.cpp +++ b/src/r_poly_cull.cpp @@ -239,10 +239,31 @@ LineSegmentRange PolyCull::GetSegmentRangeForLine(double x1, double y1, double x { double znear = 5.0; double updownnear = -400.0; + double sidenear = 400.0; - // Cull if entirely behind the portal clip plane (tbd: should we clip the segment?) - if (Vec4f::dot(PortalClipPlane, Vec4f((float)x1, (float)y1, 0.0f, 1.0f)) < 0.0f && Vec4f::dot(PortalClipPlane, Vec4f((float)x2, (float)y2, 0.0f, 1.0f)) < 0.0f) + // Clip line to the portal clip plane + float distance1 = Vec4f::dot(PortalClipPlane, Vec4f((float)x1, (float)y1, 0.0f, 1.0f)); + float distance2 = Vec4f::dot(PortalClipPlane, Vec4f((float)x2, (float)y2, 0.0f, 1.0f)); + if (distance1 < 0.0f && distance2 < 0.0f) + { return LineSegmentRange::NotVisible; + } + else if (distance1 < 0.0f || distance2 < 0.0f) + { + double t1 = 0.0f, t2 = 1.0f; + if (distance1 < 0.0f) + t1 = clamp(distance1 / (distance1 - distance2), 0.0f, 1.0f); + else + t2 = clamp(distance2 / (distance1 - distance2), 0.0f, 1.0f); + double nx1 = x1 * (1.0 - t1) + x2 * t1; + double ny1 = y1 * (1.0 - t1) + y2 * t1; + double nx2 = x1 * (1.0 - t2) + x2 * t2; + double ny2 = y1 * (1.0 - t2) + y2 * t2; + x1 = nx1; + x2 = nx2; + y1 = ny1; + y2 = ny2; + } // Transform to 2D view space: x1 = x1 - ViewPos.X; @@ -255,7 +276,8 @@ LineSegmentRange PolyCull::GetSegmentRangeForLine(double x1, double y1, double x double ry2 = x2 * ViewCos + y2 * ViewSin; // Is it potentially visible when looking straight up or down? - if (!(ry1 < updownnear && ry2 < updownnear) && !(ry1 > znear && ry2 > znear)) + if (!(ry1 < updownnear && ry2 < updownnear) && !(ry1 > znear && ry2 > znear) && + !(rx1 < -sidenear && rx2 < -sidenear) && !(rx1 > sidenear && rx2 > sidenear)) return LineSegmentRange::AlwaysVisible; // Cull if line is entirely behind view @@ -267,7 +289,7 @@ LineSegmentRange PolyCull::GetSegmentRangeForLine(double x1, double y1, double x if (ry1 < znear) t1 = clamp((znear - ry1) / (ry2 - ry1), 0.0, 1.0); if (ry2 < znear) - t2 = clamp((znear - ry1) / (ry2 - ry1), 0.0, 1.0); + t2 = clamp((znear - ry2) / (ry2 - ry1), 0.0, 1.0); if (t1 != 0.0 || t2 != 1.0) { double nx1 = rx1 * (1.0 - t1) + rx2 * t1; diff --git a/src/r_poly_scene.cpp b/src/r_poly_scene.cpp index cfb858e0b..8bf6d1ce9 100644 --- a/src/r_poly_scene.cpp +++ b/src/r_poly_scene.cpp @@ -198,7 +198,7 @@ void RenderPolyScene::RenderLine(subsector_t *sub, seg_t *line, sector_t *fronts return; // Tell automap we saw this - if (!swrenderer::r_dontmaplines && line->linedef && segmentRange != LineSegmentRange::AlwaysVisible) + if (!PolyRenderer::Instance()->DontMapLines && line->linedef && segmentRange != LineSegmentRange::AlwaysVisible) { line->linedef->flags |= ML_MAPPED; sub->flags |= SSECF_DRAWN;