From 3f8d565dbb63901187596cea82ab336a531f7570 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 31 Dec 2018 12:42:03 +0100 Subject: [PATCH] - split up P_FreeLevelData, so that everything that clears out fields in FLevelLocals is now in a member function of that class. --- src/g_levellocals.h | 2 + src/p_setup.cpp | 161 +++++++++++++++++++++++++++++--------------- src/portal.cpp | 43 ------------ src/portal.h | 1 - 4 files changed, 110 insertions(+), 97 deletions(-) diff --git a/src/g_levellocals.h b/src/g_levellocals.h index 40d1fc6321..e17472dcd5 100644 --- a/src/g_levellocals.h +++ b/src/g_levellocals.h @@ -105,6 +105,8 @@ struct FLevelLocals : public FLevelData void AddScroller(int secnum); void SetInterMusic(const char *nextmap); void SetMusicVolume(float v); + void ClearLevelData(); + void ClearPortals(); uint8_t md5[16]; // for savegame validation. If the MD5 does not match the savegame won't be loaded. int time; // time in the hub diff --git a/src/p_setup.cpp b/src/p_setup.cpp index 418296bbbf..bba370ec2f 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -207,6 +207,113 @@ static void PrecacheLevel(FLevelLocals *Level) } +//============================================================================ +// +// clears all portal data for a new level start +// +//============================================================================ + +void FLevelLocals::ClearPortals() +{ + Displacements.Create(1); + linePortals.Clear(); + linkedPortals.Clear(); + sectorPortals.Resize(2); + PortalBlockmap.Clear(); + + // The first entry must always be the default skybox. This is what every sector gets by default. + memset(§orPortals[0], 0, sizeof(sectorPortals[0])); + sectorPortals[0].mType = PORTS_SKYVIEWPOINT; + sectorPortals[0].mFlags = PORTSF_SKYFLATONLY; + // The second entry will be the default sky. This is for forcing a regular sky through the skybox picker + memset(§orPortals[1], 0, sizeof(sectorPortals[0])); + sectorPortals[1].mType = PORTS_SKYVIEWPOINT; + sectorPortals[1].mFlags = PORTSF_SKYFLATONLY; + + // also clear the render data + for (auto &sub : subsectors) + { + for (int j = 0; j < 2; j++) + { + if (sub.portalcoverage[j].subsectors != nullptr) + { + delete[] sub.portalcoverage[j].subsectors; + sub.portalcoverage[j].subsectors = nullptr; + } + } + } + for (unsigned i = 0; i < portalGroups.Size(); i++) + { + delete portalGroups[i]; + } + portalGroups.Clear(); + linePortalSpans.Clear(); +} + +//========================================================================== +// +// +// +//========================================================================== + +void FLevelLocals::ClearLevelData() +{ + total_monsters = total_items = total_secrets = + killed_monsters = found_items = found_secrets = + wminfo.maxfrags = 0; + + // delete allocated data in the level arrays. + if (sectors.Size() > 0) + { + delete[] sectors[0].e; + } + for (auto &sub : subsectors) + { + if (sub.BSP != nullptr) delete sub.BSP; + } + ClearPortals(); + + canvasTextureInfo.EmptyList(); + sections.Clear(); + segs.Clear(); + sectors.Clear(); + linebuffer.Clear(); + subsectorbuffer.Clear(); + lines.Clear(); + sides.Clear(); + segbuffer.Clear(); + loadsectors.Clear(); + loadlines.Clear(); + loadsides.Clear(); + vertexes.Clear(); + nodes.Clear(); + gamenodes.Reset(); + subsectors.Clear(); + gamesubsectors.Reset(); + rejectmatrix.Clear(); + Zones.Clear(); + blockmap.Clear(); + Polyobjects.Clear(); + + for (auto &pb : PolyBlockMap) + { + polyblock_t *link = pb; + while (link != nullptr) + { + polyblock_t *next = link->next; + delete link; + link = next; + } + } + PolyBlockMap.Reset(); + + deathmatchstarts.Clear(); + AllPlayerStarts.Clear(); + memset(playerstarts, 0, sizeof(playerstarts)); + Scrolls.Clear(); + +} + //========================================================================== // // @@ -236,64 +343,12 @@ void P_FreeLevelData () FPolyObj::ClearAllSubsectorLinks(); // can't be done as part of the polyobj deletion process. SN_StopAllSequences (); DThinker::DestroyAllThinkers (); - P_ClearPortals(); tagManager.Clear(); - level.total_monsters = level.total_items = level.total_secrets = - level.killed_monsters = level.found_items = level.found_secrets = - wminfo.maxfrags = 0; - - // delete allocated data in the level arrays. - if (level.sectors.Size() > 0) - { - delete[] level.sectors[0].e; - } - for (auto &sub : level.subsectors) - { - if (sub.BSP != nullptr) delete sub.BSP; - } FBehavior::StaticUnloadModules (); - level.canvasTextureInfo.EmptyList(); - level.sections.Clear(); - level.segs.Clear(); - level.sectors.Clear(); - level.linebuffer.Clear(); - level.subsectorbuffer.Clear(); - level.lines.Clear(); - level.sides.Clear(); - level.segbuffer.Clear(); - level.loadsectors.Clear(); - level.loadlines.Clear(); - level.loadsides.Clear(); - level.vertexes.Clear(); - level.nodes.Clear(); - level.gamenodes.Reset(); - level.subsectors.Clear(); - level.gamesubsectors.Reset(); - level.rejectmatrix.Clear(); - level.Zones.Clear(); - level.blockmap.Clear(); - level.Polyobjects.Clear(); - - for(auto &pb : level.PolyBlockMap) - { - polyblock_t *link = pb; - while (link != nullptr) - { - polyblock_t *next = link->next; - delete link; - link = next; - } - } - level.PolyBlockMap.Reset(); - - level.deathmatchstarts.Clear(); - level.AllPlayerStarts.Clear(); - memset(level.playerstarts, 0, sizeof(level.playerstarts)); P_FreeStrifeConversations (); - level.Scrolls.Clear(); - P_ClearUDMFKeys(); + level.ClearLevelData(); } //=========================================================================== diff --git a/src/portal.cpp b/src/portal.cpp index f99b05e1f3..b8cf9a0e59 100644 --- a/src/portal.cpp +++ b/src/portal.cpp @@ -492,49 +492,6 @@ bool P_ChangePortal(line_t *ln, int thisid, int destid) return res; } -//============================================================================ -// -// clears all portal data for a new level start -// -//============================================================================ - -void P_ClearPortals() -{ - level.Displacements.Create(1); - level.linePortals.Clear(); - level.linkedPortals.Clear(); - level.sectorPortals.Resize(2); - level.PortalBlockmap.Clear(); - - // The first entry must always be the default skybox. This is what every sector gets by default. - memset(&level.sectorPortals[0], 0, sizeof(level.sectorPortals[0])); - level.sectorPortals[0].mType = PORTS_SKYVIEWPOINT; - level.sectorPortals[0].mFlags = PORTSF_SKYFLATONLY; - // The second entry will be the default sky. This is for forcing a regular sky through the skybox picker - memset(&level.sectorPortals[1], 0, sizeof(level.sectorPortals[0])); - level.sectorPortals[1].mType = PORTS_SKYVIEWPOINT; - level.sectorPortals[1].mFlags = PORTSF_SKYFLATONLY; - - // also clear the render data - for (auto &sub : level.subsectors) - { - for (int j = 0; j<2; j++) - { - if (sub.portalcoverage[j].subsectors != nullptr) - { - delete[] sub.portalcoverage[j].subsectors; - sub.portalcoverage[j].subsectors = nullptr; - } - } - } - for (unsigned i = 0; i