From f6cc75fad58e05d2bf0f332e5fa40e2d47ea2916 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Sun, 15 Jan 2017 22:57:42 +0100 Subject: [PATCH] Convert r_clipsegment into a class --- src/swrenderer/line/r_line.cpp | 6 +++--- src/swrenderer/scene/r_opaque_pass.cpp | 2 +- src/swrenderer/scene/r_portal.cpp | 4 ++-- src/swrenderer/scene/r_scene.cpp | 2 +- src/swrenderer/segments/r_clipsegment.cpp | 19 +++++++------------ src/swrenderer/segments/r_clipsegment.h | 23 +++++++++++++++++++---- 6 files changed, 33 insertions(+), 23 deletions(-) diff --git a/src/swrenderer/line/r_line.cpp b/src/swrenderer/line/r_line.cpp index d7ad75b65..af25166bc 100644 --- a/src/swrenderer/line/r_line.cpp +++ b/src/swrenderer/line/r_line.cpp @@ -91,7 +91,7 @@ namespace swrenderer if (line->linedef == NULL) { - if (R_CheckClipWallSegment(WallC.sx1, WallC.sx2)) + if (RenderClipSegment::Instance()->Check(WallC.sx1, WallC.sx2)) { InSubsector->flags |= SSECF_DRAWN; } @@ -257,7 +257,7 @@ namespace swrenderer // mark their subsectors as visible for automap texturing. if (hasglnodes && !(InSubsector->flags & SSECF_DRAWN)) { - if (R_CheckClipWallSegment(WallC.sx1, WallC.sx2)) + if (RenderClipSegment::Instance()->Check(WallC.sx1, WallC.sx2)) { InSubsector->flags |= SSECF_DRAWN; } @@ -298,7 +298,7 @@ namespace swrenderer } static SWRenderLine *self = this; - bool visible = R_ClipWallSegment(WallC.sx1, WallC.sx2, solid, [](int x1, int x2) -> bool + bool visible = RenderClipSegment::Instance()->Clip(WallC.sx1, WallC.sx2, solid, [](int x1, int x2) -> bool { return self->RenderWallSegment(x1, x2); }); diff --git a/src/swrenderer/scene/r_opaque_pass.cpp b/src/swrenderer/scene/r_opaque_pass.cpp index 7db41d6f8..8c70ab1fe 100644 --- a/src/swrenderer/scene/r_opaque_pass.cpp +++ b/src/swrenderer/scene/r_opaque_pass.cpp @@ -378,7 +378,7 @@ namespace swrenderer // Find the first clippost that touches the source post // (adjacent pixels are touching). - return R_IsWallSegmentVisible(sx1, sx2); + return RenderClipSegment::Instance()->IsVisible(sx1, sx2); } void RenderOpaquePass::AddPolyobjs(subsector_t *sub) diff --git a/src/swrenderer/scene/r_portal.cpp b/src/swrenderer/scene/r_portal.cpp index fbe1ad915..69c921716 100644 --- a/src/swrenderer/scene/r_portal.cpp +++ b/src/swrenderer/scene/r_portal.cpp @@ -179,7 +179,7 @@ namespace swrenderer validcount++; // Make sure we see all sprites planes->Clear(false); - R_ClearClipSegs(pl->left, pl->right); + RenderClipSegment::Instance()->Clear(pl->left, pl->right); WindowLeft = pl->left; WindowRight = pl->right; @@ -429,7 +429,7 @@ namespace swrenderer CurrentPortal = pds; VisiblePlaneList::Instance()->Clear(false); - R_ClearClipSegs(pds->x1, pds->x2); + RenderClipSegment::Instance()->Clear(pds->x1, pds->x2); WindowLeft = pds->x1; WindowRight = pds->x2; diff --git a/src/swrenderer/scene/r_scene.cpp b/src/swrenderer/scene/r_scene.cpp index f33c5fa7c..dfbf63a96 100644 --- a/src/swrenderer/scene/r_scene.cpp +++ b/src/swrenderer/scene/r_scene.cpp @@ -131,7 +131,7 @@ namespace swrenderer RenderPortal::Instance()->CopyStackedViewParameters(); // Clear buffers. - R_ClearClipSegs(0, viewwidth); + RenderClipSegment::Instance()->Clear(0, viewwidth); R_ClearDrawSegs(); VisiblePlaneList::Instance()->Clear(true); RenderTranslucentPass::Clear(); diff --git a/src/swrenderer/segments/r_clipsegment.cpp b/src/swrenderer/segments/r_clipsegment.cpp index 593a253e3..517d2ee07 100644 --- a/src/swrenderer/segments/r_clipsegment.cpp +++ b/src/swrenderer/segments/r_clipsegment.cpp @@ -34,18 +34,13 @@ namespace swrenderer { - namespace + RenderClipSegment *RenderClipSegment::Instance() { - struct cliprange_t - { - short first, last; - }; - - cliprange_t *newend; // newend is one past the last valid seg - cliprange_t solidsegs[MAXWIDTH / 2 + 2]; + static RenderClipSegment instance; + return &instance; } - void R_ClearClipSegs(short left, short right) + void RenderClipSegment::Clear(short left, short right) { solidsegs[0].first = -0x7fff; solidsegs[0].last = left; @@ -54,7 +49,7 @@ namespace swrenderer newend = solidsegs+2; } - bool R_CheckClipWallSegment(int first, int last) + bool RenderClipSegment::Check(int first, int last) { cliprange_t *start; @@ -78,7 +73,7 @@ namespace swrenderer return false; } - bool R_IsWallSegmentVisible(int sx1, int sx2) + bool RenderClipSegment::IsVisible(int sx1, int sx2) { // Does not cross a pixel. if (sx2 <= sx1) @@ -97,7 +92,7 @@ namespace swrenderer return true; } - bool R_ClipWallSegment(int first, int last, bool solid, VisibleSegmentCallback callback) + bool RenderClipSegment::Clip(int first, int last, bool solid, VisibleSegmentCallback callback) { cliprange_t *next, *start; int i, j; diff --git a/src/swrenderer/segments/r_clipsegment.h b/src/swrenderer/segments/r_clipsegment.h index 320453103..33ec0525d 100644 --- a/src/swrenderer/segments/r_clipsegment.h +++ b/src/swrenderer/segments/r_clipsegment.h @@ -17,8 +17,23 @@ namespace swrenderer { typedef bool(*VisibleSegmentCallback)(int x1, int x2); - void R_ClearClipSegs(short left, short right); - bool R_ClipWallSegment(int x1, int x2, bool solid, VisibleSegmentCallback callback); - bool R_CheckClipWallSegment(int first, int last); - bool R_IsWallSegmentVisible(int x1, int x2); + class RenderClipSegment + { + public: + static RenderClipSegment *Instance(); + + void Clear(short left, short right); + bool Clip(int x1, int x2, bool solid, VisibleSegmentCallback callback); + bool Check(int first, int last); + bool IsVisible(int x1, int x2); + + private: + struct cliprange_t + { + short first, last; + }; + + cliprange_t *newend; // newend is one past the last valid seg + cliprange_t solidsegs[MAXWIDTH / 2 + 2]; + }; }