From 0885ff44a0e9bc1678752ae327b50a4335eb39e2 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Wed, 11 Jan 2017 21:59:26 +0100 Subject: [PATCH] Convert r_flatplane and r_slopeplane into classes --- src/swrenderer/plane/r_flatplane.cpp | 55 +++++++++++-------------- src/swrenderer/plane/r_flatplane.h | 35 +++++++++++++--- src/swrenderer/plane/r_slopeplane.cpp | 16 ++----- src/swrenderer/plane/r_slopeplane.h | 17 +++++++- src/swrenderer/plane/r_visibleplane.cpp | 19 ++++----- src/swrenderer/plane/r_visibleplane.h | 13 +++++- src/swrenderer/r_main.cpp | 2 +- 7 files changed, 92 insertions(+), 65 deletions(-) diff --git a/src/swrenderer/plane/r_flatplane.cpp b/src/swrenderer/plane/r_flatplane.cpp index af98b4169..3a1e3936c 100644 --- a/src/swrenderer/plane/r_flatplane.cpp +++ b/src/swrenderer/plane/r_flatplane.cpp @@ -41,20 +41,7 @@ namespace swrenderer { - namespace - { - double planeheight; - bool plane_shade; - int planeshade; - fixed_t pviewx, pviewy; - float yslope[MAXHEIGHT]; - fixed_t xscale, yscale; - double xstepscale, ystepscale; - double basexfrac, baseyfrac; - visplane_light *ds_light_list; - } - - void R_DrawNormalPlane(visplane_t *pl, double _xscale, double _yscale, fixed_t alpha, bool additive, bool masked) + void RenderFlatPlane::Render(visplane_t *pl, double _xscale, double _yscale, fixed_t alpha, bool additive, bool masked) { using namespace drawerargs; @@ -189,18 +176,12 @@ namespace swrenderer } } - ds_light_list = pl->lights; + light_list = pl->lights; - R_MapVisPlane(pl, R_MapPlane, R_StepPlane); + RenderLines(pl); } - void R_StepPlane() - { - basexfrac -= xstepscale; - baseyfrac -= ystepscale; - } - - void R_MapPlane(int y, int x1, int x2) + void RenderFlatPlane::RenderLine(int y, int x1, int x2) { using namespace drawerargs; @@ -275,7 +256,7 @@ namespace swrenderer // Setup lights for row dc_num_lights = 0; dc_lights = lightbuffer + nextlightindex; - visplane_light *cur_node = ds_light_list; + visplane_light *cur_node = light_list; while (cur_node && nextlightindex < 64 * 1024) { double lightX = cur_node->lightsource->X() - ViewPos.X; @@ -326,17 +307,13 @@ namespace swrenderer (R_Drawers()->*spanfunc)(); } - void R_DrawColoredPlane(visplane_t *pl) + void RenderFlatPlane::StepColumn() { - R_MapVisPlane(pl, R_MapColoredPlane, nullptr); + basexfrac -= xstepscale; + baseyfrac -= ystepscale; } - void R_MapColoredPlane(int y, int x1, int x2) - { - R_Drawers()->DrawColoredSpan(y, x1, x2); - } - - void R_SetupPlaneSlope() + void RenderFlatPlane::SetupSlope() { int e, i; @@ -377,4 +354,18 @@ namespace swrenderer } while (++i < e); } } + + float RenderFlatPlane::yslope[MAXHEIGHT]; + + ///////////////////////////////////////////////////////////////////////// + + void RenderColoredPlane::Render(visplane_t *pl) + { + RenderLines(pl); + } + + void RenderColoredPlane::RenderLine(int y, int x1, int x2) + { + R_Drawers()->DrawColoredSpan(y, x1, x2); + } } diff --git a/src/swrenderer/plane/r_flatplane.h b/src/swrenderer/plane/r_flatplane.h index c922df34e..246087c3d 100644 --- a/src/swrenderer/plane/r_flatplane.h +++ b/src/swrenderer/plane/r_flatplane.h @@ -17,12 +17,35 @@ namespace swrenderer { - void R_SetupPlaneSlope(); + class RenderFlatPlane : PlaneRenderer + { + public: + void Render(visplane_t *pl, double _xscale, double _yscale, fixed_t alpha, bool additive, bool masked); - void R_DrawNormalPlane(visplane_t *pl, double _xscale, double _yscale, fixed_t alpha, bool additive, bool masked); - void R_MapPlane(int y, int x1, int x2); - void R_StepPlane(); + static void SetupSlope(); - void R_DrawColoredPlane(visplane_t *pl); - void R_MapColoredPlane(int y, int x1, int x2); + private: + void RenderLine(int y, int x1, int x2) override; + void StepColumn() override; + + double planeheight; + bool plane_shade; + int planeshade; + fixed_t pviewx, pviewy; + fixed_t xscale, yscale; + double xstepscale, ystepscale; + double basexfrac, baseyfrac; + visplane_light *light_list; + + static float yslope[MAXHEIGHT]; + }; + + class RenderColoredPlane : PlaneRenderer + { + public: + void Render(visplane_t *pl); + + private: + void RenderLine(int y, int x1, int x2) override; + }; } diff --git a/src/swrenderer/plane/r_slopeplane.cpp b/src/swrenderer/plane/r_slopeplane.cpp index be101e2a2..8a5897bb5 100644 --- a/src/swrenderer/plane/r_slopeplane.cpp +++ b/src/swrenderer/plane/r_slopeplane.cpp @@ -45,17 +45,7 @@ namespace swrenderer { - namespace - { - FVector3 plane_sz, plane_su, plane_sv; - float planelightfloat; - bool plane_shade; - int planeshade; - fixed_t pviewx, pviewy; - fixed_t xscale, yscale; - } - - void R_DrawTiltedPlane(visplane_t *pl, double _xscale, double _yscale, fixed_t alpha, bool additive, bool masked) + void RenderSlopePlane::Render(visplane_t *pl, double _xscale, double _yscale, fixed_t alpha, bool additive, bool masked) { using namespace drawerargs; @@ -182,10 +172,10 @@ namespace swrenderer plane_su[2] = plane_su[1] = plane_su[0] = 0; } - R_MapVisPlane(pl, R_MapTiltedPlane, nullptr); + RenderLines(pl); } - void R_MapTiltedPlane(int y, int x1, int x2) + void RenderSlopePlane::RenderLine(int y, int x1, int x2) { R_Drawers()->DrawTiltedSpan(y, x1, x2, plane_sz, plane_su, plane_sv, plane_shade, planeshade, planelightfloat, pviewx, pviewy); } diff --git a/src/swrenderer/plane/r_slopeplane.h b/src/swrenderer/plane/r_slopeplane.h index d366c5fef..9ea635a26 100644 --- a/src/swrenderer/plane/r_slopeplane.h +++ b/src/swrenderer/plane/r_slopeplane.h @@ -17,6 +17,19 @@ namespace swrenderer { - void R_DrawTiltedPlane(visplane_t *pl, double _xscale, double _yscale, fixed_t alpha, bool additive, bool masked); - void R_MapTiltedPlane(int y, int x1, int x2); + class RenderSlopePlane : PlaneRenderer + { + public: + void Render(visplane_t *pl, double _xscale, double _yscale, fixed_t alpha, bool additive, bool masked); + + private: + void RenderLine(int y, int x1, int x2) override; + + FVector3 plane_sz, plane_su, plane_sv; + float planelightfloat; + bool plane_shade; + int planeshade; + fixed_t pviewx, pviewy; + fixed_t xscale, yscale; + }; } diff --git a/src/swrenderer/plane/r_visibleplane.cpp b/src/swrenderer/plane/r_visibleplane.cpp index 948859cb2..a045d7a99 100644 --- a/src/swrenderer/plane/r_visibleplane.cpp +++ b/src/swrenderer/plane/r_visibleplane.cpp @@ -52,8 +52,6 @@ namespace swrenderer enum { max_plane_lights = 32 * 1024 }; visplane_light plane_lights[max_plane_lights]; int next_plane_light = 0; - - short spanend[MAXHEIGHT]; } void R_DeinitPlanes() @@ -509,17 +507,19 @@ namespace swrenderer if (!pl->height.isSlope() && !tilt) { - R_DrawNormalPlane(pl, xscale, yscale, alpha, additive, masked); + RenderFlatPlane renderer; + renderer.Render(pl, xscale, yscale, alpha, additive, masked); } else { - R_DrawTiltedPlane(pl, xscale, yscale, alpha, additive, masked); + RenderSlopePlane renderer; + renderer.Render(pl, xscale, yscale, alpha, additive, masked); } } NetUpdate(); } - void R_MapVisPlane(visplane_t *pl, void(*mapfunc)(int y, int x1, int x2), void(*stepfunc)()) + void PlaneRenderer::RenderLines(visplane_t *pl) { // t1/b1 are at x // t2/b2 are at x+1 @@ -547,14 +547,14 @@ namespace swrenderer { int y = t2++; int x2 = spanend[y]; - mapfunc(y, xr, x2); + RenderLine(y, xr, x2); } stop = MAX(b1, t2); while (b2 > stop) { int y = --b2; int x2 = spanend[y]; - mapfunc(y, xr, x2); + RenderLine(y, xr, x2); } // Mark any spans that have just opened @@ -572,15 +572,14 @@ namespace swrenderer t2 = pl->top[x]; b2 = pl->bottom[x]; - if (stepfunc) - stepfunc(); + StepColumn(); } // Draw any spans that are still open while (t2 < b2) { int y = --b2; int x2 = spanend[y]; - mapfunc(y, pl->left, x2); + RenderLine(y, pl->left, x2); } } } diff --git a/src/swrenderer/plane/r_visibleplane.h b/src/swrenderer/plane/r_visibleplane.h index c201c691a..41f7d7bda 100644 --- a/src/swrenderer/plane/r_visibleplane.h +++ b/src/swrenderer/plane/r_visibleplane.h @@ -87,5 +87,16 @@ namespace swrenderer int R_DrawPlanes(); void R_DrawHeightPlanes(double height); void R_DrawSinglePlane(visplane_t *pl, fixed_t alpha, bool additive, bool masked); - void R_MapVisPlane(visplane_t *pl, void(*mapfunc)(int y, int x1, int x2), void(*stepfunc)()); + + class PlaneRenderer + { + public: + void RenderLines(visplane_t *pl); + + virtual void RenderLine(int y, int x1, int x2) = 0; + virtual void StepColumn() { } + + private: + short spanend[MAXHEIGHT]; + }; } diff --git a/src/swrenderer/r_main.cpp b/src/swrenderer/r_main.cpp index c55303bec..e2f034b4c 100644 --- a/src/swrenderer/r_main.cpp +++ b/src/swrenderer/r_main.cpp @@ -467,7 +467,7 @@ void R_SetupFreelook() globaluclip = -CenterY / InvZtoScale; globaldclip = (viewheight - CenterY) / InvZtoScale; - R_SetupPlaneSlope(); + RenderFlatPlane::SetupSlope(); } //==========================================================================