- pass level as an argument to some code being used by the map loader.

This commit is contained in:
Christoph Oelckers 2018-12-29 16:19:38 +01:00
parent eecf3a203a
commit 4d34e5997b
4 changed files with 63 additions and 64 deletions

View file

@ -282,7 +282,7 @@ struct FCoverageBuilder
// //
//========================================================================== //==========================================================================
void BuildPortalCoverage(FPortalCoverage *coverage, subsector_t *subsector, const DVector2 &displacement) void BuildPortalCoverage(FLevelLocals *Level, FPortalCoverage *coverage, subsector_t *subsector, const DVector2 &displacement)
{ {
TArray<FCoverageVertex> shape; TArray<FCoverageVertex> shape;
double centerx=0, centery=0; double centerx=0, centery=0;
@ -298,7 +298,7 @@ void BuildPortalCoverage(FPortalCoverage *coverage, subsector_t *subsector, cons
build.center.x = xs_CRoundToInt(centerx / subsector->numlines); build.center.x = xs_CRoundToInt(centerx / subsector->numlines);
build.center.y = xs_CRoundToInt(centery / subsector->numlines); build.center.y = xs_CRoundToInt(centery / subsector->numlines);
build.CollectNode(level.HeadNode(), shape); build.CollectNode(Level->HeadNode(), shape);
coverage->subsectors = new uint32_t[build.collect.Size()]; coverage->subsectors = new uint32_t[build.collect.Size()];
coverage->sscount = build.collect.Size(); coverage->sscount = build.collect.Size();
memcpy(coverage->subsectors, &build.collect[0], build.collect.Size() * sizeof(uint32_t)); memcpy(coverage->subsectors, &build.collect[0], build.collect.Size() * sizeof(uint32_t));
@ -310,9 +310,9 @@ void BuildPortalCoverage(FPortalCoverage *coverage, subsector_t *subsector, cons
// //
//========================================================================== //==========================================================================
static void CollectPortalSectors(FPortalMap &collection) static void CollectPortalSectors(FLevelLocals *Level, FPortalMap &collection)
{ {
for (auto &sec : level.sectors) for (auto &sec : Level->sectors)
{ {
for (int j = 0; j < 2; j++) for (int j = 0; j < 2; j++)
{ {
@ -337,12 +337,12 @@ static void CollectPortalSectors(FPortalMap &collection)
// //
//========================================================================== //==========================================================================
static void GroupSectorPortals() static void GroupSectorPortals(FLevelLocals *Level)
{ {
FPortalMap collection; FPortalMap collection;
CollectPortalSectors(collection); CollectPortalSectors(Level, collection);
level.portalGroups.Clear(); Level->portalGroups.Clear();
FPortalMap::Iterator it(collection); FPortalMap::Iterator it(collection);
FPortalMap::Pair *pair; FPortalMap::Pair *pair;
@ -363,7 +363,7 @@ static void GroupSectorPortals()
FSectorPortalGroup *portal = new FSectorPortalGroup; FSectorPortalGroup *portal = new FSectorPortalGroup;
portal->mDisplacement = pair->Key.mDisplacement; portal->mDisplacement = pair->Key.mDisplacement;
portal->plane = (i == 1 ? sector_t::floor : sector_t::ceiling); /**/ portal->plane = (i == 1 ? sector_t::floor : sector_t::ceiling); /**/
level.portalGroups.Push(portal); Level->portalGroups.Push(portal);
for (unsigned j = 0; j < pair->Value.Size(); j++) for (unsigned j = 0; j < pair->Value.Size(); j++)
{ {
sector_t *sec = pair->Value[j].mSub; sector_t *sec = pair->Value[j].mSub;
@ -390,29 +390,29 @@ static void GroupSectorPortals()
// //
//========================================================================== //==========================================================================
static void GroupLinePortals() static void GroupLinePortals(FLevelLocals *Level)
{ {
level.linePortalSpans.Clear(); Level->linePortalSpans.Clear();
TArray<int> tempindex; TArray<int> tempindex;
tempindex.Reserve(level.linePortals.Size()); tempindex.Reserve(Level->linePortals.Size());
memset(&tempindex[0], -1, level.linePortals.Size() * sizeof(int)); memset(&tempindex[0], -1, Level->linePortals.Size() * sizeof(int));
for (unsigned i = 0; i < level.linePortals.Size(); i++) for (unsigned i = 0; i < Level->linePortals.Size(); i++)
{ {
auto port = level.linePortals[i]; auto port = Level->linePortals[i];
bool gotsome; bool gotsome;
if (tempindex[i] == -1) if (tempindex[i] == -1)
{ {
tempindex[i] = level.linePortalSpans.Size(); tempindex[i] = Level->linePortalSpans.Size();
line_t *pSrcLine = level.linePortals[i].mOrigin; line_t *pSrcLine = Level->linePortals[i].mOrigin;
line_t *pLine = level.linePortals[i].mDestination; line_t *pLine = Level->linePortals[i].mDestination;
FLinePortalSpan &glport = level.linePortalSpans[level.linePortalSpans.Reserve(1)]; FLinePortalSpan &glport = Level->linePortalSpans[Level->linePortalSpans.Reserve(1)];
glport.lines.Push(&level.linePortals[i]); glport.lines.Push(&Level->linePortals[i]);
// We cannot do this grouping for non-linked portals because they can be changed at run time. // We cannot do this grouping for non-linked portals because they can be changed at run time.
if (level.linePortals[i].mType == PORTT_LINKED && pLine != nullptr) if (Level->linePortals[i].mType == PORTT_LINKED && pLine != nullptr)
{ {
glport.v1 = pLine->v1; glport.v1 = pLine->v1;
glport.v2 = pLine->v2; glport.v2 = pLine->v2;
@ -420,12 +420,12 @@ static void GroupLinePortals()
{ {
// now collect all other colinear lines connected to this one. We run this loop as long as it still finds a match // now collect all other colinear lines connected to this one. We run this loop as long as it still finds a match
gotsome = false; gotsome = false;
for (unsigned j = 0; j < level.linePortals.Size(); j++) for (unsigned j = 0; j < Level->linePortals.Size(); j++)
{ {
if (tempindex[j] == -1) if (tempindex[j] == -1)
{ {
line_t *pSrcLine2 = level.linePortals[j].mOrigin; line_t *pSrcLine2 = Level->linePortals[j].mOrigin;
line_t *pLine2 = level.linePortals[j].mDestination; line_t *pLine2 = Level->linePortals[j].mDestination;
// angular precision is intentionally reduced to 32 bit BAM to account for precision problems (otherwise many not perfectly horizontal or vertical portals aren't found here.) // angular precision is intentionally reduced to 32 bit BAM to account for precision problems (otherwise many not perfectly horizontal or vertical portals aren't found here.)
unsigned srcang = pSrcLine->Delta().Angle().BAMs(); unsigned srcang = pSrcLine->Delta().Angle().BAMs();
unsigned dstang = pLine->Delta().Angle().BAMs(); unsigned dstang = pLine->Delta().Angle().BAMs();
@ -442,7 +442,7 @@ static void GroupLinePortals()
tempindex[j] = tempindex[i]; tempindex[j] = tempindex[i];
if (pLine->v1 == pLine2->v2) glport.v1 = pLine2->v1; if (pLine->v1 == pLine2->v2) glport.v1 = pLine2->v1;
else glport.v2 = pLine2->v2; else glport.v2 = pLine2->v2;
glport.lines.Push(&level.linePortals[j]); glport.lines.Push(&Level->linePortals[j]);
} }
} }
} }
@ -453,30 +453,31 @@ static void GroupLinePortals()
} }
// Final assignment can only be done when all allocations are finished. Otherwise the array may be moved. // Final assignment can only be done when all allocations are finished. Otherwise the array may be moved.
for (unsigned i = 0; i < level.linePortals.Size(); i++) for (unsigned i = 0; i < Level->linePortals.Size(); i++)
{ {
level.linePortals[i].mGroup = &level.linePortalSpans[tempindex[i]]; Level->linePortals[i].mGroup = &Level->linePortalSpans[tempindex[i]];
} }
} }
void InitPortalGroups() void InitPortalGroups(FLevelLocals *Level)
{ {
if (level.nodes.Size() > 0) if (Level->nodes.Size() > 0)
GroupSectorPortals(); GroupSectorPortals(Level);
GroupLinePortals(); GroupLinePortals(Level);
} }
CCMD(dumpportals) CCMD(dumpportals)
{ {
for(unsigned i=0;i<level.portalGroups.Size(); i++) auto Level = &level;
for(unsigned i=0;i<Level->portalGroups.Size(); i++)
{ {
auto p = level.portalGroups[i]; auto p = Level->portalGroups[i];
double xdisp = p->mDisplacement.X; double xdisp = p->mDisplacement.X;
double ydisp = p->mDisplacement.Y; double ydisp = p->mDisplacement.Y;
Printf(PRINT_LOG, "Portal #%d, %s, displacement = (%f,%f)\n", i, p->plane==0? "floor":"ceiling", Printf(PRINT_LOG, "Portal #%d, %s, displacement = (%f,%f)\n", i, p->plane==0? "floor":"ceiling",
xdisp, ydisp); xdisp, ydisp);
Printf(PRINT_LOG, "Coverage:\n"); Printf(PRINT_LOG, "Coverage:\n");
for(auto &sub : level.subsectors) for(auto &sub : Level->subsectors)
{ {
auto port = sub.render_sector->GetPortalGroup(p->plane); auto port = sub.render_sector->GetPortalGroup(p->plane);
if (port == p) if (port == p)
@ -490,7 +491,7 @@ CCMD(dumpportals)
FPortalCoverage *cov = &sub.portalcoverage[p->plane]; FPortalCoverage *cov = &sub.portalcoverage[p->plane];
for(int l = 0;l< cov->sscount; l++) for(int l = 0;l< cov->sscount; l++)
{ {
subsector_t *csub = &level.subsectors[cov->subsectors[l]]; subsector_t *csub = &Level->subsectors[cov->subsectors[l]];
Printf(PRINT_LOG, "\t\t\t%5d (%4d): ", cov->subsectors[l], csub->render_sector->sectornum); Printf(PRINT_LOG, "\t\t\t%5d (%4d): ", cov->subsectors[l], csub->render_sector->sectornum);
for(unsigned m = 0;m< csub->numlines; m++) for(unsigned m = 0;m< csub->numlines; m++)
{ {

View file

@ -93,6 +93,7 @@ struct Group
class FSectionCreator class FSectionCreator
{ {
FLevelLocals *Level;
FMemArena allocator; FMemArena allocator;
TArray<WorkSectionLine *>AllAllocatedLines; TArray<WorkSectionLine *>AllAllocatedLines;
@ -107,8 +108,9 @@ class FSectionCreator
public: public:
FSectionCreator() FSectionCreator(FLevelLocals *l)
{ {
Level = l;
// These must be manually destroyed but not deleted. // These must be manually destroyed but not deleted.
for (auto line : AllAllocatedLines) for (auto line : AllAllocatedLines)
{ {
@ -160,7 +162,7 @@ public:
void GroupSubsectors() void GroupSubsectors()
{ {
for (auto &sub : level.subsectors) for (auto &sub : Level->subsectors)
{ {
int key = MakeKey(sub); int key = MakeKey(sub);
auto &array = subsectormap[key]; auto &array = subsectormap[key];
@ -188,14 +190,14 @@ public:
// Make sure that all subsectors have a sector. In some degenerate cases a subsector may come up empty. // Make sure that all subsectors have a sector. In some degenerate cases a subsector may come up empty.
// An example is in Doom.wad E3M4 near linedef 1087. With the grouping data here this is relatively easy to fix. // An example is in Doom.wad E3M4 near linedef 1087. With the grouping data here this is relatively easy to fix.
sector_t *lastsector = &level.sectors[0]; sector_t *lastsector = &Level->sectors[0];
for (auto &rawsection : rawsections) for (auto &rawsection : rawsections)
{ {
sector_t *mysector = nullptr; sector_t *mysector = nullptr;
bool missing = false; bool missing = false;
for (auto num : rawsection) for (auto num : rawsection)
{ {
auto &sub = level.subsectors[num]; auto &sub = Level->subsectors[num];
if (sub.sector == nullptr) missing = true; if (sub.sector == nullptr) missing = true;
else mysector = sub.sector; else mysector = sub.sector;
} }
@ -204,7 +206,7 @@ public:
else lastsector = mysector; else lastsector = mysector;
for (auto num : rawsection) for (auto num : rawsection)
{ {
auto &sub = level.subsectors[num]; auto &sub = Level->subsectors[num];
if (sub.sector == nullptr) if (sub.sector == nullptr)
{ {
sub.sector = mysector; sub.sector = mysector;
@ -232,7 +234,7 @@ public:
seglist.Clear(); seglist.Clear();
int index; int index;
list.Pop(index); list.Pop(index);
auto sub = &level.subsectors[index]; auto sub = &Level->subsectors[index];
auto collect = [&](subsector_t *sub) auto collect = [&](subsector_t *sub)
{ {
@ -256,7 +258,7 @@ public:
{ {
if (subi == list[j]) if (subi == list[j])
{ {
collect(&level.subsectors[subi]); collect(&Level->subsectors[subi]);
list.Delete(j); list.Delete(j);
j--; j--;
} }
@ -275,8 +277,8 @@ public:
void MakeOutlines() void MakeOutlines()
{ {
auto rawsections = CompileSections(); auto rawsections = CompileSections();
TArray<WorkSectionLine *> lineForSeg(level.segs.Size(), true); TArray<WorkSectionLine *> lineForSeg(Level->segs.Size(), true);
memset(lineForSeg.Data(), 0, sizeof(WorkSectionLine*) * level.segs.Size()); memset(lineForSeg.Data(), 0, sizeof(WorkSectionLine*) * Level->segs.Size());
for (auto &list : rawsections) for (auto &list : rawsections)
{ {
MakeOutline(list, lineForSeg); MakeOutline(list, lineForSeg);
@ -313,7 +315,7 @@ public:
// Collect all the segs that make up the outline of this section. // Collect all the segs that make up the outline of this section.
for (auto j : rawsection) for (auto j : rawsection)
{ {
auto sub = &level.subsectors[j]; auto sub = &Level->subsectors[j];
for (unsigned i = 0; i < sub->numlines; i++) for (unsigned i = 0; i < sub->numlines; i++)
{ {
@ -661,11 +663,11 @@ public:
void ConstructOutput(FSectionContainer &output) void ConstructOutput(FSectionContainer &output)
{ {
output.allSections.Resize(groups.Size()); output.allSections.Resize(groups.Size());
output.allIndices.Resize(2*level.sectors.Size()); output.allIndices.Resize(2*Level->sectors.Size());
output.firstSectionForSectorPtr = &output.allIndices[0]; output.firstSectionForSectorPtr = &output.allIndices[0];
output.numberOfSectionForSectorPtr = &output.allIndices[level.sectors.Size()]; output.numberOfSectionForSectorPtr = &output.allIndices[Level->sectors.Size()];
memset(output.firstSectionForSectorPtr, -1, sizeof(int) * level.sectors.Size()); memset(output.firstSectionForSectorPtr, -1, sizeof(int) * Level->sectors.Size());
memset(output.numberOfSectionForSectorPtr, 0, sizeof(int) * level.sectors.Size()); memset(output.numberOfSectionForSectorPtr, 0, sizeof(int) * Level->sectors.Size());
unsigned numsegments = 0; unsigned numsegments = 0;
unsigned numsides = 0; unsigned numsides = 0;
@ -695,7 +697,7 @@ public:
} }
output.allLines.Resize(numsegments); output.allLines.Resize(numsegments);
output.allSides.Resize(numsides); output.allSides.Resize(numsides);
output.allSubsectors.Resize(level.subsectors.Size()); output.allSubsectors.Resize(Level->subsectors.Size());
numsegments = 0; numsegments = 0;
numsides = 0; numsides = 0;
@ -706,7 +708,7 @@ public:
for (auto &group : groups) for (auto &group : groups)
{ {
FSection &dest = output.allSections[curgroup]; FSection &dest = output.allSections[curgroup];
dest.sector = &level.sectors[group.groupedSections[0].section->sectorindex]; dest.sector = &Level->sectors[group.groupedSections[0].section->sectorindex];
dest.mapsection = (short)group.groupedSections[0].section->mapsection; dest.mapsection = (short)group.groupedSections[0].section->mapsection;
dest.hacked = false; dest.hacked = false;
dest.lighthead = nullptr; dest.lighthead = nullptr;
@ -740,12 +742,12 @@ public:
TMap<int, bool>::Pair *pair; TMap<int, bool>::Pair *pair;
while (it.NextPair(pair)) while (it.NextPair(pair))
{ {
output.allSides[numsides++] = &level.sides[pair->Key]; output.allSides[numsides++] = &Level->sides[pair->Key];
} }
for (auto ssi : group.subsectors) for (auto ssi : group.subsectors)
{ {
output.allSubsectors[numsubsectors++] = &level.subsectors[ssi]; output.allSubsectors[numsubsectors++] = &Level->subsectors[ssi];
level.subsectors[ssi].section = &output.allSections[curgroup]; Level->subsectors[ssi].section = &output.allSections[curgroup];
} }
curgroup++; curgroup++;
} }
@ -762,13 +764,13 @@ public:
void FixMissingReferences() void FixMissingReferences()
{ {
for (auto &sub : level.subsectors) for (auto &sub : Level->subsectors)
{ {
if (sub.section == nullptr) if (sub.section == nullptr)
{ {
int sector = sub.sector->Index(); int sector = sub.sector->Index();
int mapsection = sub.mapsection; int mapsection = sub.mapsection;
auto sections = level.sections.SectionsForSector(sector); auto sections = Level->sections.SectionsForSector(sector);
FSection *bestfit = nullptr; FSection *bestfit = nullptr;
for (auto &section : sections) for (auto &section : sections)
{ {
@ -796,7 +798,7 @@ public:
} }
} }
// This should really never happen, but better be safe than sorry and assign at least something. // This should really never happen, but better be safe than sorry and assign at least something.
if (bestfit == nullptr) bestfit = &level.sections.allSections[0]; if (bestfit == nullptr) bestfit = &Level->sections.allSections[0];
sub.section = bestfit; sub.section = bestfit;
} }
} }
@ -849,7 +851,7 @@ void PrintSections(FSectionContainer &container)
} }
} }
} }
Printf(PRINT_LOG, "%d sectors, %d subsectors, %d sections\n", level.sectors.Size(), level.subsectors.Size(), container.allSections.Size()); Printf(PRINT_LOG, "%d sectors, %d subsectors, %d sections\n", Level->sectors.Size(), Level->subsectors.Size(), container.allSections.Size());
} }
@ -873,7 +875,7 @@ void CreateSections(FSectionContainer &container)
CCMD(printsections) CCMD(printsections)
{ {
PrintSections(level.sections); PrintSections(Level->sections);
} }

View file

@ -161,6 +161,6 @@ public:
}; };
void CreateSections(FSectionContainer &container); void CreateSections(FLevelLocals *l);
#endif #endif

View file

@ -405,11 +405,7 @@ void S_Start ()
if (level.info) if (level.info)
{ {
LocalSndInfo = level.info->SoundInfo; LocalSndInfo = level.info->SoundInfo;
} LocalSndSeq = level.info->SndSeq;
if (level.info)
{
LocalSndSeq = level.info->SndSeq;
} }
bool parse_ss = false; bool parse_ss = false;