mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-24 13:11:33 +00:00
- pass level as an argument to some code being used by the map loader.
This commit is contained in:
parent
eecf3a203a
commit
4d34e5997b
4 changed files with 63 additions and 64 deletions
|
@ -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;
|
||||
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.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->sscount = build.collect.Size();
|
||||
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++)
|
||||
{
|
||||
|
@ -337,12 +337,12 @@ static void CollectPortalSectors(FPortalMap &collection)
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
static void GroupSectorPortals()
|
||||
static void GroupSectorPortals(FLevelLocals *Level)
|
||||
{
|
||||
FPortalMap collection;
|
||||
|
||||
CollectPortalSectors(collection);
|
||||
level.portalGroups.Clear();
|
||||
CollectPortalSectors(Level, collection);
|
||||
Level->portalGroups.Clear();
|
||||
|
||||
FPortalMap::Iterator it(collection);
|
||||
FPortalMap::Pair *pair;
|
||||
|
@ -363,7 +363,7 @@ static void GroupSectorPortals()
|
|||
FSectorPortalGroup *portal = new FSectorPortalGroup;
|
||||
portal->mDisplacement = pair->Key.mDisplacement;
|
||||
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++)
|
||||
{
|
||||
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;
|
||||
|
||||
tempindex.Reserve(level.linePortals.Size());
|
||||
memset(&tempindex[0], -1, level.linePortals.Size() * sizeof(int));
|
||||
tempindex.Reserve(Level->linePortals.Size());
|
||||
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;
|
||||
|
||||
if (tempindex[i] == -1)
|
||||
{
|
||||
tempindex[i] = level.linePortalSpans.Size();
|
||||
line_t *pSrcLine = level.linePortals[i].mOrigin;
|
||||
line_t *pLine = level.linePortals[i].mDestination;
|
||||
FLinePortalSpan &glport = level.linePortalSpans[level.linePortalSpans.Reserve(1)];
|
||||
glport.lines.Push(&level.linePortals[i]);
|
||||
tempindex[i] = Level->linePortalSpans.Size();
|
||||
line_t *pSrcLine = Level->linePortals[i].mOrigin;
|
||||
line_t *pLine = Level->linePortals[i].mDestination;
|
||||
FLinePortalSpan &glport = Level->linePortalSpans[Level->linePortalSpans.Reserve(1)];
|
||||
glport.lines.Push(&Level->linePortals[i]);
|
||||
|
||||
// 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.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
|
||||
gotsome = false;
|
||||
for (unsigned j = 0; j < level.linePortals.Size(); j++)
|
||||
for (unsigned j = 0; j < Level->linePortals.Size(); j++)
|
||||
{
|
||||
if (tempindex[j] == -1)
|
||||
{
|
||||
line_t *pSrcLine2 = level.linePortals[j].mOrigin;
|
||||
line_t *pLine2 = level.linePortals[j].mDestination;
|
||||
line_t *pSrcLine2 = Level->linePortals[j].mOrigin;
|
||||
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.)
|
||||
unsigned srcang = pSrcLine->Delta().Angle().BAMs();
|
||||
unsigned dstang = pLine->Delta().Angle().BAMs();
|
||||
|
@ -442,7 +442,7 @@ static void GroupLinePortals()
|
|||
tempindex[j] = tempindex[i];
|
||||
if (pLine->v1 == pLine2->v2) glport.v1 = pLine2->v1;
|
||||
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.
|
||||
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)
|
||||
GroupSectorPortals();
|
||||
GroupLinePortals();
|
||||
if (Level->nodes.Size() > 0)
|
||||
GroupSectorPortals(Level);
|
||||
GroupLinePortals(Level);
|
||||
}
|
||||
|
||||
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 ydisp = p->mDisplacement.Y;
|
||||
Printf(PRINT_LOG, "Portal #%d, %s, displacement = (%f,%f)\n", i, p->plane==0? "floor":"ceiling",
|
||||
xdisp, ydisp);
|
||||
Printf(PRINT_LOG, "Coverage:\n");
|
||||
for(auto &sub : level.subsectors)
|
||||
for(auto &sub : Level->subsectors)
|
||||
{
|
||||
auto port = sub.render_sector->GetPortalGroup(p->plane);
|
||||
if (port == p)
|
||||
|
@ -490,7 +491,7 @@ CCMD(dumpportals)
|
|||
FPortalCoverage *cov = &sub.portalcoverage[p->plane];
|
||||
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);
|
||||
for(unsigned m = 0;m< csub->numlines; m++)
|
||||
{
|
||||
|
|
|
@ -93,6 +93,7 @@ struct Group
|
|||
|
||||
class FSectionCreator
|
||||
{
|
||||
FLevelLocals *Level;
|
||||
FMemArena allocator;
|
||||
TArray<WorkSectionLine *>AllAllocatedLines;
|
||||
|
||||
|
@ -107,8 +108,9 @@ class FSectionCreator
|
|||
|
||||
public:
|
||||
|
||||
FSectionCreator()
|
||||
FSectionCreator(FLevelLocals *l)
|
||||
{
|
||||
Level = l;
|
||||
// These must be manually destroyed but not deleted.
|
||||
for (auto line : AllAllocatedLines)
|
||||
{
|
||||
|
@ -160,7 +162,7 @@ public:
|
|||
|
||||
void GroupSubsectors()
|
||||
{
|
||||
for (auto &sub : level.subsectors)
|
||||
for (auto &sub : Level->subsectors)
|
||||
{
|
||||
int key = MakeKey(sub);
|
||||
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.
|
||||
// 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)
|
||||
{
|
||||
sector_t *mysector = nullptr;
|
||||
bool missing = false;
|
||||
for (auto num : rawsection)
|
||||
{
|
||||
auto &sub = level.subsectors[num];
|
||||
auto &sub = Level->subsectors[num];
|
||||
if (sub.sector == nullptr) missing = true;
|
||||
else mysector = sub.sector;
|
||||
}
|
||||
|
@ -204,7 +206,7 @@ public:
|
|||
else lastsector = mysector;
|
||||
for (auto num : rawsection)
|
||||
{
|
||||
auto &sub = level.subsectors[num];
|
||||
auto &sub = Level->subsectors[num];
|
||||
if (sub.sector == nullptr)
|
||||
{
|
||||
sub.sector = mysector;
|
||||
|
@ -232,7 +234,7 @@ public:
|
|||
seglist.Clear();
|
||||
int index;
|
||||
list.Pop(index);
|
||||
auto sub = &level.subsectors[index];
|
||||
auto sub = &Level->subsectors[index];
|
||||
|
||||
auto collect = [&](subsector_t *sub)
|
||||
{
|
||||
|
@ -256,7 +258,7 @@ public:
|
|||
{
|
||||
if (subi == list[j])
|
||||
{
|
||||
collect(&level.subsectors[subi]);
|
||||
collect(&Level->subsectors[subi]);
|
||||
list.Delete(j);
|
||||
j--;
|
||||
}
|
||||
|
@ -275,8 +277,8 @@ public:
|
|||
void MakeOutlines()
|
||||
{
|
||||
auto rawsections = CompileSections();
|
||||
TArray<WorkSectionLine *> lineForSeg(level.segs.Size(), true);
|
||||
memset(lineForSeg.Data(), 0, sizeof(WorkSectionLine*) * level.segs.Size());
|
||||
TArray<WorkSectionLine *> lineForSeg(Level->segs.Size(), true);
|
||||
memset(lineForSeg.Data(), 0, sizeof(WorkSectionLine*) * Level->segs.Size());
|
||||
for (auto &list : rawsections)
|
||||
{
|
||||
MakeOutline(list, lineForSeg);
|
||||
|
@ -313,7 +315,7 @@ public:
|
|||
// Collect all the segs that make up the outline of this section.
|
||||
for (auto j : rawsection)
|
||||
{
|
||||
auto sub = &level.subsectors[j];
|
||||
auto sub = &Level->subsectors[j];
|
||||
|
||||
for (unsigned i = 0; i < sub->numlines; i++)
|
||||
{
|
||||
|
@ -661,11 +663,11 @@ public:
|
|||
void ConstructOutput(FSectionContainer &output)
|
||||
{
|
||||
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.numberOfSectionForSectorPtr = &output.allIndices[level.sectors.Size()];
|
||||
memset(output.firstSectionForSectorPtr, -1, sizeof(int) * level.sectors.Size());
|
||||
memset(output.numberOfSectionForSectorPtr, 0, sizeof(int) * level.sectors.Size());
|
||||
output.numberOfSectionForSectorPtr = &output.allIndices[Level->sectors.Size()];
|
||||
memset(output.firstSectionForSectorPtr, -1, sizeof(int) * Level->sectors.Size());
|
||||
memset(output.numberOfSectionForSectorPtr, 0, sizeof(int) * Level->sectors.Size());
|
||||
|
||||
unsigned numsegments = 0;
|
||||
unsigned numsides = 0;
|
||||
|
@ -695,7 +697,7 @@ public:
|
|||
}
|
||||
output.allLines.Resize(numsegments);
|
||||
output.allSides.Resize(numsides);
|
||||
output.allSubsectors.Resize(level.subsectors.Size());
|
||||
output.allSubsectors.Resize(Level->subsectors.Size());
|
||||
|
||||
numsegments = 0;
|
||||
numsides = 0;
|
||||
|
@ -706,7 +708,7 @@ public:
|
|||
for (auto &group : groups)
|
||||
{
|
||||
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.hacked = false;
|
||||
dest.lighthead = nullptr;
|
||||
|
@ -740,12 +742,12 @@ public:
|
|||
TMap<int, bool>::Pair *pair;
|
||||
while (it.NextPair(pair))
|
||||
{
|
||||
output.allSides[numsides++] = &level.sides[pair->Key];
|
||||
output.allSides[numsides++] = &Level->sides[pair->Key];
|
||||
}
|
||||
for (auto ssi : group.subsectors)
|
||||
{
|
||||
output.allSubsectors[numsubsectors++] = &level.subsectors[ssi];
|
||||
level.subsectors[ssi].section = &output.allSections[curgroup];
|
||||
output.allSubsectors[numsubsectors++] = &Level->subsectors[ssi];
|
||||
Level->subsectors[ssi].section = &output.allSections[curgroup];
|
||||
}
|
||||
curgroup++;
|
||||
}
|
||||
|
@ -762,13 +764,13 @@ public:
|
|||
|
||||
void FixMissingReferences()
|
||||
{
|
||||
for (auto &sub : level.subsectors)
|
||||
for (auto &sub : Level->subsectors)
|
||||
{
|
||||
if (sub.section == nullptr)
|
||||
{
|
||||
int sector = sub.sector->Index();
|
||||
int mapsection = sub.mapsection;
|
||||
auto sections = level.sections.SectionsForSector(sector);
|
||||
auto sections = Level->sections.SectionsForSector(sector);
|
||||
FSection *bestfit = nullptr;
|
||||
for (auto §ion : sections)
|
||||
{
|
||||
|
@ -796,7 +798,7 @@ public:
|
|||
}
|
||||
}
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
{
|
||||
PrintSections(level.sections);
|
||||
PrintSections(Level->sections);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -161,6 +161,6 @@ public:
|
|||
};
|
||||
|
||||
|
||||
void CreateSections(FSectionContainer &container);
|
||||
void CreateSections(FLevelLocals *l);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -405,11 +405,7 @@ void S_Start ()
|
|||
if (level.info)
|
||||
{
|
||||
LocalSndInfo = level.info->SoundInfo;
|
||||
}
|
||||
|
||||
if (level.info)
|
||||
{
|
||||
LocalSndSeq = level.info->SndSeq;
|
||||
LocalSndSeq = level.info->SndSeq;
|
||||
}
|
||||
|
||||
bool parse_ss = false;
|
||||
|
|
Loading…
Reference in a new issue