- moved renderinfo.cpp entriely into the map loader.

This commit is contained in:
Christoph Oelckers 2018-12-28 15:51:32 +01:00
parent e66e594dd0
commit 0e904286e8
5 changed files with 109 additions and 120 deletions

View file

@ -1080,6 +1080,7 @@ set (PCH_SOURCES
maploader/glnodes.cpp
maploader/udmf.cpp
maploader/polyobjects.cpp
maploader/renderinfo.cpp
menu/joystickmenu.cpp
menu/loadsavemenu.cpp
menu/menu.cpp
@ -1146,7 +1147,6 @@ set (PCH_SOURCES
r_data/sprites.cpp
r_data/portalgroups.cpp
r_data/voxels.cpp
r_data/renderinfo.cpp
r_data/renderstyle.cpp
r_data/r_canvastexture.cpp
r_data/r_interpolate.cpp

View file

@ -3206,11 +3206,8 @@ void MapLoader::LoadLevel(MapData *map, const char *lumpname, int position)
node.len = (float)g_sqrt(fdx * fdx + fdy * fdy);
}
// CreateVBO must be run on the plain 3D floor data.
P_ClearDynamic3DFloorData();
// This must be done BEFORE the PolyObj Spawn!!!
InitRenderInfo(); // create hardware independent renderer resources for the Level->
InitRenderInfo(); // create hardware independent renderer resources for the level. This must be done BEFORE the PolyObj Spawn!!!
P_ClearDynamic3DFloorData(); // CreateVBO must be run on the plain 3D floor data.
screen->mVertexData->CreateVBO();
for (auto &sec : Level->sectors)

View file

@ -114,6 +114,7 @@ class MapLoader
// Polyobject init
TArray<int32_t> KnownPolySides;
// Slopes
void SlopeLineToPoint(int lineid, const DVector3 &pos, bool slopeCeil);
void CopyPlane(int tag, sector_t *dest, bool copyCeil);
void CopyPlane(int tag, const DVector2 &pos, bool copyCeil);
@ -122,17 +123,20 @@ class MapLoader
void SetSlopesFromVertexHeights(FMapThing *firstmt, FMapThing *lastmt, const int *oldvertextable);
void AlignPlane(sector_t *sec, line_t *line, int which);
// Extradata
void InitED();
void ProcessEDMapthing(FMapThing *mt, int recordnum);
void ProcessEDLinedef(line_t *line, int recordnum);
void ProcessEDSector(sector_t *sec, int recordnum);
// Polyobjects
void InitSideLists();
void IterFindPolySides(FPolyObj *po, side_t *side);
void SpawnPolyobj(int index, int tag, int type);
void TranslateToStartSpot(int tag, const DVector2 &origin);
void InitPolyBlockMap(void);
// GL nodes
int checkGLVertex(int num);
int checkGLVertex3(int num);
int CheckForMissingSegs();
@ -143,6 +147,17 @@ class MapLoader
bool DoLoadGLNodes(FileReader * lumps);
void CreateCachedNodes(MapData *map);
// Render info
void PrepareSectorData();
void PrepareTransparentDoors(sector_t * sector);
void InitVertexData();
void GetSideVertices(int sdnum, DVector2 *v1, DVector2 *v2);
void PrepareSegs();
void InitRenderInfo();
void FixMinisegReferences();
void FixHoles();
void ReportUnpairedMinisegs();
void SetTexture(side_t *side, int position, const char *name, FMissingTextureTracker &track);
void SetTexture(sector_t *sector, int index, int position, const char *name, FMissingTextureTracker &track, bool truncate);
void SetTexture(side_t *side, int position, uint32_t *blend, const char *name);

View file

@ -34,6 +34,7 @@
#include "r_sky.h"
#include "p_setup.h"
#include "g_levellocals.h"
#include "maploader.h"
//==========================================================================
//
@ -54,9 +55,15 @@ struct MapSectionGenerator
bool operator!= (const cvertex_t &other) const { return fabs(X - other.X) >= EQUAL_EPSILON || fabs(Y - other.Y) >= EQUAL_EPSILON; }
cvertex_t& operator =(const vertex_t *v) { X = v->fX(); Y = v->fY(); return *this; }
};
MapSectionGenerator(FLevelLocals *l)
{
Level = l;
}
typedef TMap<cvertex_t, int> FSectionVertexMap;
TArray<subsector_t *> MapSectionCollector;
FLevelLocals *Level;
//==========================================================================
//
@ -121,7 +128,7 @@ struct MapSectionGenerator
cvertex_t vt;
// first step: Set mapsection for all vertex positions.
for (auto &seg : level.segs)
for (auto &seg : Level->segs)
{
int section = seg.Subsector->mapsection;
for (int j = 0; j < 2; j++)
@ -132,7 +139,7 @@ struct MapSectionGenerator
}
// second step: Check if any seg references more than one mapsection, either by subsector or by vertex
for (auto &seg : level.segs)
for (auto &seg : Level->segs)
{
int section = seg.Subsector->mapsection;
for (int j = 0; j < 2; j++)
@ -143,7 +150,7 @@ struct MapSectionGenerator
if (vsection != section)
{
// These 2 sections should be merged
for (auto &sub : level.subsectors)
for (auto &sub : Level->subsectors)
{
if (sub.mapsection == vsection) sub.mapsection = section;
}
@ -160,7 +167,7 @@ struct MapSectionGenerator
{
if (sectvalid[i]) sectmap[i] = mergecount++;
}
for (auto &sub : level.subsectors)
for (auto &sub : Level->subsectors)
{
sub.mapsection = sectmap[sub.mapsection - 1];
assert(sub.mapsection != -1);
@ -181,7 +188,7 @@ struct MapSectionGenerator
do
{
set = false;
for (auto &sub : level.subsectors)
for (auto &sub : Level->subsectors)
{
if (sub.mapsection == 0)
{
@ -194,7 +201,7 @@ struct MapSectionGenerator
}
while (set);
num = MergeMapSections(num);
level.NumMapSections = num;
Level->NumMapSections = num;
#ifdef DEBUG
Printf("%d map sections found\n", num);
#endif
@ -238,33 +245,33 @@ static void SpreadHackedFlag(subsector_t * sub)
//
//==========================================================================
static void PrepareSectorData()
void MapLoader::PrepareSectorData()
{
TArray<subsector_t *> undetermined;
// now group the subsectors by sector
level.subsectorbuffer.Resize(level.subsectors.Size());
Level->subsectorbuffer.Resize(Level->subsectors.Size());
for (auto &sub : level.subsectors)
for (auto &sub : Level->subsectors)
{
sub.render_sector->subsectorcount++;
}
auto subsectorbuffer = level.subsectorbuffer.Data();
for (auto &sec : level.sectors)
auto subsectorbuffer = Level->subsectorbuffer.Data();
for (auto &sec : Level->sectors)
{
sec.subsectors = subsectorbuffer;
subsectorbuffer += sec.subsectorcount;
sec.subsectorcount = 0;
}
for (auto &sub : level.subsectors)
for (auto &sub : Level->subsectors)
{
sub.render_sector->subsectors[sub.render_sector->subsectorcount++] = &sub;
}
// marks all malformed subsectors so rendering tricks using them can be handled more easily
for (auto &sub : level.subsectors)
for (auto &sub : Level->subsectors)
{
if (sub.sector == sub.render_sector)
{
@ -283,7 +290,7 @@ static void PrepareSectorData()
}
}
}
MapSectionGenerator msg;
MapSectionGenerator msg(Level);
msg.SetMapSections();
}
@ -294,7 +301,7 @@ static void PrepareSectorData()
//
//==========================================================================
static void PrepareTransparentDoors(sector_t * sector)
void MapLoader::PrepareTransparentDoors(sector_t * sector)
{
bool solidwall=false;
unsigned int notextures=0;
@ -302,7 +309,6 @@ static void PrepareTransparentDoors(sector_t * sector)
unsigned int selfref=0;
sector_t * nextsec=NULL;
P_Recalculate3DFloors(sector);
if (sector->subsectorcount==0) return;
sector->transdoorheight=sector->GetPlaneTexZ(sector_t::floor);
@ -391,11 +397,11 @@ static void AddToVertex(const sector_t * sec, TArray<int> & list)
//
//==========================================================================
static void InitVertexData()
void MapLoader::InitVertexData()
{
TArray<TArray<int>> vt_sectorlists(level.vertexes.Size(), true);
TArray<TArray<int>> vt_sectorlists(Level->vertexes.Size(), true);
for(auto &line : level.lines)
for(auto &line : Level->lines)
{
for(int j = 0; j < 2; ++j)
{
@ -416,9 +422,9 @@ static void InitVertexData()
}
}
for(unsigned i = 0; i < level.vertexes.Size(); ++i)
for(unsigned i = 0; i < Level->vertexes.Size(); ++i)
{
auto &vert = level.vertexes[i];
auto &vert = Level->vertexes[i];
int cnt = vt_sectorlists[i].Size();
vert.dirty = true;
@ -430,7 +436,7 @@ static void InitVertexData()
vert.heightlist = new float[cnt*2];
for(int j=0;j<cnt;j++)
{
vert.sectors[j] = &level.sectors[vt_sectorlists[i][j]];
vert.sectors[j] = &Level->sectors[vt_sectorlists[i][j]];
}
}
else
@ -446,10 +452,10 @@ static void InitVertexData()
//
//==========================================================================
static void GetSideVertices(int sdnum, DVector2 *v1, DVector2 *v2)
void MapLoader::GetSideVertices(int sdnum, DVector2 *v1, DVector2 *v2)
{
line_t *ln = level.sides[sdnum].linedef;
if (ln->sidedef[0] == &level.sides[sdnum])
line_t *ln = Level->sides[sdnum].linedef;
if (ln->sidedef[0] == &Level->sides[sdnum])
{
*v1 = ln->v1->fPos();
*v2 = ln->v2->fPos();
@ -474,16 +480,16 @@ static int segcmp(const void *a, const void *b)
//
//==========================================================================
static void PrepareSegs()
void MapLoader::PrepareSegs()
{
auto numsides = level.sides.Size();
auto numsides = Level->sides.Size();
TArray<int> segcount(numsides, true);
int realsegs = 0;
// count the segs
memset(segcount.Data(), 0, numsides * sizeof(int));
for(auto &seg : level.segs)
for(auto &seg : Level->segs)
{
if (seg.sidedef == nullptr) continue; // miniseg
int sidenum = seg.sidedef->Index();
@ -500,18 +506,18 @@ static void PrepareSegs()
}
// allocate memory
level.segbuffer.Resize(realsegs);
level.sides[0].segs = level.segbuffer.Data();
level.sides[0].numsegs = 0;
Level->segbuffer.Resize(realsegs);
Level->sides[0].segs = Level->segbuffer.Data();
Level->sides[0].numsegs = 0;
for(unsigned i = 1; i < numsides; i++)
{
level.sides[i].segs = level.sides[i-1].segs + segcount[i-1];
level.sides[i].numsegs = 0;
Level->sides[i].segs = Level->sides[i-1].segs + segcount[i-1];
Level->sides[i].numsegs = 0;
}
// assign the segs
for (auto &seg : level.segs)
for (auto &seg : Level->segs)
{
if (seg.sidedef != NULL) seg.sidedef->segs[seg.sidedef->numsegs++] = &seg;
}
@ -519,7 +525,7 @@ static void PrepareSegs()
// sort the segs
for(unsigned i = 0; i < numsides; i++)
{
if (level.sides[i].numsegs > 1) qsort(level.sides[i].segs, level.sides[i].numsegs, sizeof(seg_t*), segcmp);
if (Level->sides[i].numsegs > 1) qsort(Level->sides[i].segs, Level->sides[i].numsegs, sizeof(seg_t*), segcmp);
}
}
@ -529,14 +535,14 @@ static void PrepareSegs()
//
//==========================================================================
void InitRenderInfo()
void MapLoader::InitRenderInfo()
{
PrepareSegs();
PrepareSectorData();
InitVertexData();
TArray<int> checkmap(level.vertexes.Size());
memset(checkmap.Data(), -1, sizeof(int)*level.vertexes.Size());
for(auto &sec : level.sectors)
TArray<int> checkmap(Level->vertexes.Size());
memset(checkmap.Data(), -1, sizeof(int)*Level->vertexes.Size());
for(auto &sec : Level->sectors)
{
int i = sec.sectornum;
PrepareTransparentDoors(&sec);
@ -552,15 +558,15 @@ void InitRenderInfo()
if (checkmap[vtnum1] < i)
{
checkmap[vtnum1] = i;
sec.e->vertices.Push(&level.vertexes[vtnum1]);
level.vertexes[vtnum1].dirty = true;
sec.e->vertices.Push(&Level->vertexes[vtnum1]);
Level->vertexes[vtnum1].dirty = true;
}
if (checkmap[vtnum2] < i)
{
checkmap[vtnum2] = i;
sec.e->vertices.Push(&level.vertexes[vtnum2]);
level.vertexes[vtnum2].dirty = true;
sec.e->vertices.Push(&Level->vertexes[vtnum2]);
Level->vertexes[vtnum2].dirty = true;
}
}
}
@ -576,15 +582,15 @@ void InitRenderInfo()
//
//==========================================================================
void FixMinisegReferences()
void MapLoader::FixMinisegReferences()
{
TArray<seg_t *> bogussegs;
for (unsigned i = 0; i < level.segs.Size(); i++)
for (unsigned i = 0; i < Level->segs.Size(); i++)
{
if (level.segs[i].sidedef == nullptr && level.segs[i].PartnerSeg == nullptr)
if (Level->segs[i].sidedef == nullptr && Level->segs[i].PartnerSeg == nullptr)
{
bogussegs.Push(&level.segs[i]);
bogussegs.Push(&Level->segs[i]);
}
}
@ -628,16 +634,16 @@ void FixMinisegReferences()
//
//==========================================================================
void FixHoles()
void MapLoader::FixHoles()
{
TArray<seg_t *> bogussegs;
TArray<TArray<seg_t *>> segloops;
for (unsigned i = 0; i < level.segs.Size(); i++)
for (unsigned i = 0; i < Level->segs.Size(); i++)
{
if (level.segs[i].sidedef == nullptr && level.segs[i].PartnerSeg == nullptr)
if (Level->segs[i].sidedef == nullptr && Level->segs[i].PartnerSeg == nullptr)
{
bogussegs.Push(&level.segs[i]);
bogussegs.Push(&Level->segs[i]);
}
}
@ -704,27 +710,27 @@ void FixHoles()
for (auto &segloop : segloops)
segcount += segloop.Size();
seg_t *oldsegstartptr = &level.segs[0];
subsector_t *oldssstartptr = &level.subsectors[0];
seg_t *oldsegstartptr = &Level->segs[0];
subsector_t *oldssstartptr = &Level->subsectors[0];
unsigned newsegstart = level.segs.Reserve(segcount);
unsigned newssstart = level.subsectors.Reserve(segloops.Size());
unsigned newsegstart = Level->segs.Reserve(segcount);
unsigned newssstart = Level->subsectors.Reserve(segloops.Size());
seg_t *newsegstartptr = &level.segs[0];
subsector_t *newssstartptr = &level.subsectors[0];
seg_t *newsegstartptr = &Level->segs[0];
subsector_t *newssstartptr = &Level->subsectors[0];
// Now fix all references to these in the level data.
// Note that the Index() method does not work here due to the reallocation.
for (auto &seg : level.segs)
for (auto &seg : Level->segs)
{
if (seg.PartnerSeg) seg.PartnerSeg = newsegstartptr + (seg.PartnerSeg - oldsegstartptr);
seg.Subsector = newssstartptr + (seg.Subsector - oldssstartptr);
}
for (auto &sub : level.subsectors)
for (auto &sub : Level->subsectors)
{
sub.firstline = newsegstartptr + (sub.firstline - oldsegstartptr);
}
for (auto &node : level.nodes)
for (auto &node : Level->nodes)
{
// How hideous... :(
for (auto & p : node.children)
@ -754,18 +760,18 @@ void FixHoles()
{
DPrintf(DMSG_NOTIFY, "Adding dummy subsector for sector %d\n", segloop[0]->Subsector->render_sector->Index());
subsector_t &sub = level.subsectors[newssstart++];
subsector_t &sub = Level->subsectors[newssstart++];
memset(&sub, 0, sizeof(sub));
sub.sector = segloop[0]->frontsector;
sub.render_sector = segloop[0]->Subsector->render_sector;
sub.numlines = segloop.Size();
sub.firstline = &level.segs[newsegstart];
sub.firstline = &Level->segs[newsegstart];
sub.flags = SSECF_HOLE;
for (auto otherseg : segloop)
{
DPrintf(DMSG_NOTIFY, " Adding seg from (%2.3f, %2.3f) -> (%2.3f, %2.3f)\n", otherseg->v2->fX(), otherseg->v2->fY(), otherseg->v1->fX(), otherseg->v1->fY());
seg_t &seg = level.segs[newsegstart++];
seg_t &seg = Level->segs[newsegstart++];
memset(&seg, 0, sizeof(seg));
seg.v1 = otherseg->v2;
seg.v2 = otherseg->v1;
@ -779,54 +785,3 @@ void FixHoles()
}
}
//==========================================================================
//
// ReportUnpairedMinisegs
//
// Debug routine
// reports all unpaired minisegs that couldn't be fixed by either
// explicitly pairing them or combining them to a dummy subsector
//
//==========================================================================
void ReportUnpairedMinisegs()
{
int bogus = 0;
for (unsigned i = 0; i < level.segs.Size(); i++)
{
if (level.segs[i].sidedef == nullptr && level.segs[i].PartnerSeg == nullptr)
{
Printf("Unpaired miniseg %d, sector %d, (%d: %2.6f, %2.6f) -> (%d: %2.6f, %2.6f)\n",
i, level.segs[i].Subsector->render_sector->Index(),
level.segs[i].v1->Index(), level.segs[i].v1->fX(), level.segs[i].v1->fY(),
level.segs[i].v2->Index(), level.segs[i].v2->fX(), level.segs[i].v2->fY());
bogus++;
}
}
if (bogus > 0) Printf("%d unpaired minisegs found\n", bogus);
}
//==========================================================================
//
//
//
//==========================================================================
CCMD(listmapsections)
{
for (int i = 0; i < 100; i++)
{
for (auto &sub : level.subsectors)
{
if (sub.mapsection == i)
{
Printf("Mapsection %d, sector %d, line %d\n", i, sub.render_sector->Index(), sub.firstline->linedef->Index());
break;
}
}
}
}
CCMD(listbadminisegs)
{
ReportUnpairedMinisegs();
}

View file

@ -567,3 +567,25 @@ CCMD(dumpgeometry)
}
}
}
//==========================================================================
//
//
//
//==========================================================================
CCMD(listmapsections)
{
for (int i = 0; i < 100; i++)
{
for (auto &sub : level.subsectors)
{
if (sub.mapsection == i)
{
Printf("Mapsection %d, sector %d, line %d\n", i, sub.render_sector->Index(), sub.firstline->linedef->Index());
break;
}
}
}
}