From 961a4c852476e7513028612568276b2c760c409f Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 18 Apr 2016 13:38:56 +0200 Subject: [PATCH] - optimized sector portal checks. All the PortalBlocks* functions were turned into real function calls which for such a frequent check should be avoided. So now any linked portal sets a flag in the attached sectors so that it isn't necessary to check the skybox pointer each time which makes the functions subject to inlining again. --- src/portal.cpp | 7 +++++-- src/r_defs.h | 10 ++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/portal.cpp b/src/portal.cpp index 1be08fc857..12c40e47d2 100644 --- a/src/portal.cpp +++ b/src/portal.cpp @@ -932,7 +932,7 @@ void P_CreateLinkedPortals() { // The engine cannot deal with portals on a sloped plane. sectors[i].SkyBoxes[j] = NULL; - Printf("Portal on %s of sector %d is sloped and will be disabled\n", j == 0 ? "floor" : "ceiling", i); + Printf("Portal on %s of sector %d is sloped and will be disabled\n", j == 0 ? "floor" : "ceiling", i); } } } @@ -1057,7 +1057,7 @@ void P_CreateLinkedPortals() // This is a fatal condition. We have to remove one of the two portals. Choose the one that doesn't match the current plane Printf("Error in sector %d: Ceiling portal at z=%f is below floor portal at z=%f\n", i, cz, fz); double cp = -sectors[i].ceilingplane.fD(); - double fp = -sectors[i].ceilingplane.fD(); + double fp = sectors[i].floorplane.fD(); if (cp < fp || fz == fp) { sectors[i].SkyBoxes[sector_t::ceiling] = NULL; @@ -1068,6 +1068,9 @@ void P_CreateLinkedPortals() } } } + // mark all sector planes that check out ok for everything. + if (sectors[i].PortalIsLinked(sector_t::floor)) sectors[i].planes[sector_t::floor].Flags |= PLANEF_LINKED; + if (sectors[i].PortalIsLinked(sector_t::ceiling)) sectors[i].planes[sector_t::ceiling].Flags |= PLANEF_LINKED; } if (linkedPortals.Size() > 0) { diff --git a/src/r_defs.h b/src/r_defs.h index 9be31e1843..bfb521a277 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -484,6 +484,7 @@ enum PLANEF_BLOCKSOUND = 32, PLANEF_DISABLED = 64, PLANEF_OBSTRUCTED = 128, // if the portal plane is beyond the sector's floor or ceiling. + PLANEF_LINKED = 256 // plane is flagged as a linked portal }; // Internal sector flags @@ -936,20 +937,17 @@ public: bool PortalBlocksSight(int plane) { - if (SkyBoxes[plane] == NULL || SkyBoxes[plane]->special1 != SKYBOX_LINKEDPORTAL) return true; - return !!(planes[plane].Flags & (PLANEF_NORENDER | PLANEF_NOPASS | PLANEF_DISABLED | PLANEF_OBSTRUCTED)); + return PLANEF_LINKED != (planes[plane].Flags & (PLANEF_NORENDER | PLANEF_NOPASS | PLANEF_DISABLED | PLANEF_OBSTRUCTED | PLANEF_LINKED)); } bool PortalBlocksMovement(int plane) { - if (SkyBoxes[plane] == NULL || SkyBoxes[plane]->special1 != SKYBOX_LINKEDPORTAL) return true; - return !!(planes[plane].Flags & (PLANEF_NOPASS | PLANEF_DISABLED | PLANEF_OBSTRUCTED)); + return PLANEF_LINKED != (planes[plane].Flags & (PLANEF_NOPASS | PLANEF_DISABLED | PLANEF_OBSTRUCTED | PLANEF_LINKED)); } bool PortalBlocksSound(int plane) { - if (SkyBoxes[plane] == NULL || SkyBoxes[plane]->special1 != SKYBOX_LINKEDPORTAL) return true; - return !!(planes[plane].Flags & (PLANEF_BLOCKSOUND | PLANEF_DISABLED | PLANEF_OBSTRUCTED)); + return PLANEF_LINKED != (planes[plane].Flags & (PLANEF_BLOCKSOUND | PLANEF_DISABLED | PLANEF_OBSTRUCTED | PLANEF_LINKED)); } bool PortalIsLinked(int plane)