diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a627e0fdc..46fa671b0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 diff --git a/src/maploader/maploader.cpp b/src/maploader/maploader.cpp index ad38081a9..d9b857004 100644 --- a/src/maploader/maploader.cpp +++ b/src/maploader/maploader.cpp @@ -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) diff --git a/src/maploader/maploader.h b/src/maploader/maploader.h index b9ed0f2f8..14cf61b81 100644 --- a/src/maploader/maploader.h +++ b/src/maploader/maploader.h @@ -114,6 +114,7 @@ class MapLoader // Polyobject init TArray 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); diff --git a/src/r_data/renderinfo.cpp b/src/maploader/renderinfo.cpp similarity index 80% rename from src/r_data/renderinfo.cpp rename to src/maploader/renderinfo.cpp index 753bf7cb4..5ab76fce3 100644 --- a/src/r_data/renderinfo.cpp +++ b/src/maploader/renderinfo.cpp @@ -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 FSectionVertexMap; TArray 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 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++] = ⊂ } // 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 & list) // //========================================================================== -static void InitVertexData() +void MapLoader::InitVertexData() { - TArray> vt_sectorlists(level.vertexes.Size(), true); + TArray> 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;jsectors[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 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 checkmap(level.vertexes.Size()); - memset(checkmap.Data(), -1, sizeof(int)*level.vertexes.Size()); - for(auto &sec : level.sectors) + TArray 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 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 bogussegs; TArray> 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(); -} diff --git a/src/p_setup.cpp b/src/p_setup.cpp index 85e819813..3c5306677 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -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; + } + } + } +} +