From 9eef7f9b323ae4a1e5423720d6d01774358c09ba Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Thu, 19 Jan 2017 03:02:32 +0100 Subject: [PATCH] Make visplanes hash list private --- src/swrenderer/plane/r_visibleplanelist.cpp | 21 +++++++++++++++++++++ src/swrenderer/plane/r_visibleplanelist.h | 10 +++++++--- src/swrenderer/scene/r_portal.cpp | 18 +++++------------- 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/src/swrenderer/plane/r_visibleplanelist.cpp b/src/swrenderer/plane/r_visibleplanelist.cpp index b6e6de1cb..d9849f2cc 100644 --- a/src/swrenderer/plane/r_visibleplanelist.cpp +++ b/src/swrenderer/plane/r_visibleplanelist.cpp @@ -302,6 +302,27 @@ namespace swrenderer return pl; } + bool VisiblePlaneList::HasPortalPlanes() const + { + return visplanes[MAXVISPLANES] != nullptr; + } + + visplane_t *VisiblePlaneList::PopFirstPortalPlane() + { + visplane_t *pl = visplanes[VisiblePlaneList::MAXVISPLANES]; + if (pl) + { + visplanes[VisiblePlaneList::MAXVISPLANES] = pl->next; + pl->next = nullptr; + } + return pl; + } + + void VisiblePlaneList::ClearPortalPlanes() + { + visplanes[VisiblePlaneList::MAXVISPLANES] = nullptr; + } + int VisiblePlaneList::Render() { visplane_t *pl; diff --git a/src/swrenderer/plane/r_visibleplanelist.h b/src/swrenderer/plane/r_visibleplanelist.h index 46197c99c..64266c80d 100644 --- a/src/swrenderer/plane/r_visibleplanelist.h +++ b/src/swrenderer/plane/r_visibleplanelist.h @@ -32,16 +32,20 @@ namespace swrenderer visplane_t *FindPlane(const secplane_t &height, FTextureID picnum, int lightlevel, double Alpha, bool additive, const FTransform &xxform, int sky, FSectorPortal *portal, FDynamicColormap *basecolormap); visplane_t *GetRange(visplane_t *pl, int start, int stop); + bool HasPortalPlanes() const; + visplane_t *PopFirstPortalPlane(); + void ClearPortalPlanes(); + int Render(); void RenderHeight(double height); - enum { MAXVISPLANES = 128 }; // must be a power of 2 - visplane_t *visplanes[MAXVISPLANES + 1]; - private: VisiblePlaneList(); visplane_t *Add(unsigned hash); + enum { MAXVISPLANES = 128 }; // must be a power of 2 + visplane_t *visplanes[MAXVISPLANES + 1]; + static unsigned CalcHash(int picnum, int lightlevel, const secplane_t &height) { return (unsigned)((picnum) * 3 + (lightlevel)+(FLOAT2FIXED((height).fD())) * 7) & (MAXVISPLANES - 1); } }; } diff --git a/src/swrenderer/scene/r_portal.cpp b/src/swrenderer/scene/r_portal.cpp index 0111d74be..d05a8c4ca 100644 --- a/src/swrenderer/scene/r_portal.cpp +++ b/src/swrenderer/scene/r_portal.cpp @@ -94,7 +94,7 @@ namespace swrenderer VisiblePlaneList *planes = VisiblePlaneList::Instance(); - if (planes->visplanes[VisiblePlaneList::MAXVISPLANES] == nullptr) + if (!planes->HasPortalPlanes()) return; Clip3DFloors::Instance()->EnterSkybox(); @@ -109,17 +109,8 @@ namespace swrenderer AActor *savedcamera = camera; sector_t *savedsector = viewsector; - int i; - visplane_t *pl; - - for (pl = planes->visplanes[VisiblePlaneList::MAXVISPLANES]; pl != nullptr; pl = planes->visplanes[VisiblePlaneList::MAXVISPLANES]) + for (visplane_t *pl = planes->PopFirstPortalPlane(); pl != nullptr; pl = planes->PopFirstPortalPlane()) { - // Pop the visplane off the list now so that if this skybox adds more - // skyboxes to the list, they will be drawn instead of skipped (because - // new skyboxes go to the beginning of the list instead of the end). - planes->visplanes[VisiblePlaneList::MAXVISPLANES] = pl->next; - pl->next = nullptr; - if (pl->right < pl->left || !r_skyboxes || numskyboxes == MAX_SKYBOX_PLANES || pl->portal == nullptr) { pl->Render(OPAQUE, false, false); @@ -181,7 +172,7 @@ namespace swrenderer auto ceilingclip = RenderOpaquePass::Instance()->ceilingclip; auto floorclip = RenderOpaquePass::Instance()->floorclip; - for (i = pl->left; i < pl->right; i++) + for (int i = pl->left; i < pl->right; i++) { if (pl->top[i] == 0x7fff) { @@ -253,6 +244,7 @@ namespace swrenderer VisibleSpriteList::Instance()->PopPortal(); + visplane_t *pl; visplaneStack.Pop(pl); if (pl->Alpha > 0 && pl->picnum != skyflatnum) { @@ -277,7 +269,7 @@ namespace swrenderer if (Clip3DFloors::Instance()->fakeActive) return; - planes->visplanes[VisiblePlaneList::MAXVISPLANES] = nullptr; + planes->ClearPortalPlanes(); } void RenderPortal::RenderLinePortals()