From 733cd5260ab713733cbaa57f097c2c2d0566f0f1 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 27 Dec 2018 12:10:52 +0100 Subject: [PATCH] - moved slope creation functions and most initialize-time variables into MapLoader class. --- src/compatibility.cpp | 2 -- src/p_glnodes.cpp | 3 --- src/p_setup.cpp | 42 +++++++---------------------- src/p_setup.h | 28 ++++++++++++++----- src/p_slopes.cpp | 63 ++++++++++++++++++++++--------------------- src/p_udmf.cpp | 17 ++++++------ src/r_state.h | 2 -- 7 files changed, 71 insertions(+), 86 deletions(-) diff --git a/src/compatibility.cpp b/src/compatibility.cpp index 012ebd2e31..6fe4bf3138 100644 --- a/src/compatibility.cpp +++ b/src/compatibility.cpp @@ -78,8 +78,6 @@ enum // PRIVATE FUNCTION PROTOTYPES --------------------------------------------- // EXTERNAL DATA DECLARATIONS ---------------------------------------------- -extern TArray MapThingsConverted; -extern bool ForceNodeBuild; // PUBLIC DATA DEFINITIONS ------------------------------------------------- diff --git a/src/p_glnodes.cpp b/src/p_glnodes.cpp index db58b26e50..e77afe8581 100644 --- a/src/p_glnodes.cpp +++ b/src/p_glnodes.cpp @@ -66,9 +66,6 @@ CVAR(Bool, gl_cachenodes, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) CVAR(Float, gl_cachetime, 0.6f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) -static void CreateCachedNodes(MapData *map); - - // fixed 32 bit gl_vert format v2.0+ (glBsp 1.91) struct mapglvertex_t { diff --git a/src/p_setup.cpp b/src/p_setup.cpp index ef8aa34c08..90940f6e0e 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -109,11 +109,13 @@ #include "fragglescript/t_fs.h" +sidei_t *sidetemp; +TArray MapThingsConverted; +bool ForceNodeBuild; + + #define MISSING_TEXTURE_WARN_LIMIT 20 -void P_SpawnSlopeMakers (FMapThing *firstmt, FMapThing *lastmt, const int *oldvertextable); -void P_SetSlopes (); -void P_CopySlopes(); void BloodCrypt (void *data, int key, int len); void P_ClearUDMFKeys(); void InitRenderInfo(); @@ -139,24 +141,6 @@ inline bool P_LoadBuildMap(uint8_t *mapdata, size_t len, FMapThing **things, int return false; } - -// -// MAP related Lookup tables. -// Store VERTEXES, LINEDEFS, SIDEDEFS, etc. -// -TArray vertexdatas; - -TArray MapThingsConverted; -TMap MapThingsUserDataIndex; // from mapthing idx -> user data idx -TArray MapThingsUserData; - -int sidecount; -sidei_t *sidetemp; - -TArray linemap; - -bool ForceNodeBuild; - //=========================================================================== // // Sets a sidedef's texture and prints a message if it's not present. @@ -1235,7 +1219,7 @@ void MapLoader::LoadNodes (MapData * map) // //=========================================================================== -static void SetMapThingUserData(AActor *actor, unsigned udi) +void MapLoader::SetMapThingUserData(AActor *actor, unsigned udi) { if (actor == nullptr) { @@ -2831,7 +2815,7 @@ void MapLoader::GroupLines (bool buildmap) times[5].Clock(); if (!buildmap) { - P_SetSlopes (); + SetSlopes (); } times[5].Unclock(); @@ -3112,9 +3096,6 @@ void P_FreeLevelData () // [ZZ] delete per-map event handlers E_Shutdown(true); MapThingsConverted.Clear(); - MapThingsUserDataIndex.Clear(); - MapThingsUserData.Clear(); - linemap.Clear(); R_FreePastViewers(); P_ClearUDMFKeys(); @@ -3461,9 +3442,6 @@ void P_SetupLevel(const char *lumpname, int position, bool newGame) loader.LoopSidedefs(true); times[6].Unclock(); - linemap.Clear(); - linemap.ShrinkToFit(); - loader.SummarizeMissingTextures(missingtex); } else @@ -3664,8 +3642,8 @@ void P_SetupLevel(const char *lumpname, int position, bool newGame) if (!buildmap) { // [RH] Spawn slope creating things first. - P_SpawnSlopeMakers(&MapThingsConverted[0], &MapThingsConverted[MapThingsConverted.Size()], oldvertextable); - P_CopySlopes(); + loader.SpawnSlopeMakers(&MapThingsConverted[0], &MapThingsConverted[MapThingsConverted.Size()], oldvertextable); + loader.CopySlopes(); // Spawn 3d floors - must be done before spawning things so it can't be done in P_SpawnSpecials P_Spawn3DFloors(); @@ -3881,8 +3859,6 @@ void P_SetupLevel(const char *lumpname, int position, bool newGame) } } MapThingsConverted.Clear(); - MapThingsUserDataIndex.Clear(); - MapThingsUserData.Clear(); // Create a backup of the map data so the savegame code can toss out all fields that haven't changed in order to reduce processing time and file size. // Note that we want binary identity here, so assignment is not sufficient because it won't initialize any padding bytes. diff --git a/src/p_setup.h b/src/p_setup.h index 17dda260dc..1b94c69d0c 100644 --- a/src/p_setup.h +++ b/src/p_setup.h @@ -192,17 +192,15 @@ struct sidei_t // [RH] Only keep BOOM sidedef init stuff around for init }; }; extern sidei_t *sidetemp; +extern TArray MapThingsConverted; +extern bool ForceNodeBuild; struct FMissingCount { - FMissingCount() : Count(0) {} - int Count; + int Count = 0; }; + typedef TMap FMissingTextureTracker; - -extern TMap MapThingsUserDataIndex; // from mapthing idx -> user data idx -extern TArray MapThingsUserData; - struct FLevelLocals; class MapLoader @@ -214,6 +212,20 @@ class MapLoader int firstglvertex; // helpers for loading GL nodes from GWA files. bool format5; + TArray vertexdatas; + + TMap MapThingsUserDataIndex; // from mapthing idx -> user data idx + TArray MapThingsUserData; + int sidecount; + TArray linemap; + + 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); + void SetSlope(secplane_t *plane, bool setCeil, int xyangi, int zangi, const DVector3 &pos); + void VavoomSlope(sector_t * sec, int id, const DVector3 &pos, int which); + void SetSlopesFromVertexHeights(FMapThing *firstmt, FMapThing *lastmt, const int *oldvertextable); + void AlignPlane(sector_t *sec, line_t *line, int which); int checkGLVertex(int num); int checkGLVertex3(int num); @@ -242,6 +254,7 @@ class MapLoader void SetSideNum(side_t **sidenum_p, uint16_t sidenum); void AllocateSideDefs(MapData *map, int count); void ProcessSideTextures(bool checktranmap, side_t *sd, sector_t *sec, intmapsidedef_t *msd, int special, int tag, short *alpha, FMissingTextureTracker &missingtex); + void SetMapThingUserData(AActor *actor, unsigned udi); void CreateBlockMap(); void AddToList(uint8_t *hitlist, FTextureID texid, int bitmask); @@ -278,6 +291,9 @@ public: void ParseTextMap(MapData *map, FMissingTextureTracker &missingtex); void SummarizeMissingTextures(const FMissingTextureTracker &missing); void SetRenderSector(); + void SpawnSlopeMakers(FMapThing *firstmt, FMapThing *lastmt, const int *oldvertextable); + void SetSlopes(); + void CopySlopes(); MapLoader(FLevelLocals *lev) { diff --git a/src/p_slopes.cpp b/src/p_slopes.cpp index de5eeab7f6..2673de0a01 100644 --- a/src/p_slopes.cpp +++ b/src/p_slopes.cpp @@ -40,6 +40,7 @@ #include "p_spec.h" #include "g_levellocals.h" #include "actor.h" +#include "p_setup.h" //=========================================================================== // @@ -47,14 +48,14 @@ // //=========================================================================== -static void P_SlopeLineToPoint (int lineid, const DVector3 &pos, bool slopeCeil) +void MapLoader::SlopeLineToPoint (int lineid, const DVector3 &pos, bool slopeCeil) { int linenum; FLineIdIterator itr(lineid); while ((linenum = itr.Next()) >= 0) { - const line_t *line = &level.lines[linenum]; + const line_t *line = &Level->lines[linenum]; sector_t *sec; secplane_t *plane; @@ -116,7 +117,7 @@ static void P_SlopeLineToPoint (int lineid, const DVector3 &pos, bool slopeCeil) // //=========================================================================== -static void P_CopyPlane (int tag, sector_t *dest, bool copyCeil) +void MapLoader::CopyPlane (int tag, sector_t *dest, bool copyCeil) { sector_t *source; int secnum; @@ -127,7 +128,7 @@ static void P_CopyPlane (int tag, sector_t *dest, bool copyCeil) return; } - source = &level.sectors[secnum]; + source = &Level->sectors[secnum]; if (copyCeil) { @@ -139,10 +140,10 @@ static void P_CopyPlane (int tag, sector_t *dest, bool copyCeil) } } -static void P_CopyPlane (int tag, const DVector2 &pos, bool copyCeil) +void MapLoader::CopyPlane (int tag, const DVector2 &pos, bool copyCeil) { sector_t *dest = P_PointInSector (pos); - P_CopyPlane(tag, dest, copyCeil); + CopyPlane(tag, dest, copyCeil); } //=========================================================================== @@ -151,7 +152,7 @@ static void P_CopyPlane (int tag, const DVector2 &pos, bool copyCeil) // //=========================================================================== -void P_SetSlope (secplane_t *plane, bool setCeil, int xyangi, int zangi, const DVector3 &pos) +void MapLoader::SetSlope (secplane_t *plane, bool setCeil, int xyangi, int zangi, const DVector3 &pos) { DAngle xyang; DAngle zang; @@ -201,7 +202,7 @@ void P_SetSlope (secplane_t *plane, bool setCeil, int xyangi, int zangi, const D // //=========================================================================== -void P_VavoomSlope(sector_t * sec, int id, const DVector3 &pos, int which) +void MapLoader::VavoomSlope(sector_t * sec, int id, const DVector3 &pos, int which) { for(auto l : sec->Lines) { @@ -247,7 +248,7 @@ void P_VavoomSlope(sector_t * sec, int id, const DVector3 &pos, int which) // //========================================================================== -static void P_SetSlopesFromVertexHeights(FMapThing *firstmt, FMapThing *lastmt, const int *oldvertextable) +void MapLoader::SetSlopesFromVertexHeights(FMapThing *firstmt, FMapThing *lastmt, const int *oldvertextable) { TMap vt_heights[2]; FMapThing *mt; @@ -259,9 +260,9 @@ static void P_SetSlopesFromVertexHeights(FMapThing *firstmt, FMapThing *lastmt, { if (mt->info->Special == SMT_VertexFloorZ || mt->info->Special == SMT_VertexCeilingZ) { - for (unsigned i = 0; i < level.vertexes.Size(); i++) + for (unsigned i = 0; i < Level->vertexes.Size(); i++) { - if (level.vertexes[i].fX() == mt->pos.X && level.vertexes[i].fY() == mt->pos.Y) + if (Level->vertexes[i].fX() == mt->pos.X && Level->vertexes[i].fY() == mt->pos.Y) { if (mt->info->Special == SMT_VertexFloorZ) { @@ -302,7 +303,7 @@ static void P_SetSlopesFromVertexHeights(FMapThing *firstmt, FMapThing *lastmt, if (vt_found) { - for (auto &sec : level.sectors) + for (auto &sec : Level->sectors) { if (sec.Lines.Size() != 3) continue; // only works with triangular sectors @@ -315,9 +316,9 @@ static void P_SetSlopesFromVertexHeights(FMapThing *firstmt, FMapThing *lastmt, vi3 = (sec.Lines[1]->v1 == sec.Lines[0]->v1 || sec.Lines[1]->v1 == sec.Lines[0]->v2)? sec.Lines[1]->v2->Index() : sec.Lines[1]->v1->Index(); - vt1 = DVector3(level.vertexes[vi1].fPos(), 0); - vt2 = DVector3(level.vertexes[vi2].fPos(), 0); - vt3 = DVector3(level.vertexes[vi3].fPos(), 0); + vt1 = DVector3(Level->vertexes[vi1].fPos(), 0); + vt2 = DVector3(Level->vertexes[vi2].fPos(), 0); + vt3 = DVector3(Level->vertexes[vi3].fPos(), 0); for(int j=0; j<2; j++) { @@ -330,7 +331,7 @@ static void P_SetSlopesFromVertexHeights(FMapThing *firstmt, FMapThing *lastmt, vt2.Z = h2? *h2 : j==0? sec.GetPlaneTexZ(sector_t::floor) : sec.GetPlaneTexZ(sector_t::ceiling); vt3.Z = h3? *h3 : j==0? sec.GetPlaneTexZ(sector_t::floor) : sec.GetPlaneTexZ(sector_t::ceiling); - if (P_PointOnLineSidePrecise(level.vertexes[vi3].fX(), level.vertexes[vi3].fY(), sec.Lines[0]) == 0) + if (P_PointOnLineSidePrecise(Level->vertexes[vi3].fX(), Level->vertexes[vi3].fY(), sec.Lines[0]) == 0) { vec1 = vt2 - vt3; vec2 = vt1 - vt3; @@ -360,7 +361,7 @@ static void P_SetSlopesFromVertexHeights(FMapThing *firstmt, FMapThing *lastmt, secplane_t *plane = j==0? &sec.floorplane : &sec.ceilingplane; - double dist = -cross[0] * level.vertexes[vi3].fX() - cross[1] * level.vertexes[vi3].fY() - cross[2] * vt3.Z; + double dist = -cross[0] * Level->vertexes[vi3].fX() - cross[1] * Level->vertexes[vi3].fY() - cross[2] * vt3.Z; plane->set(cross[0], cross[1], cross[2], dist); } } @@ -373,7 +374,7 @@ static void P_SetSlopesFromVertexHeights(FMapThing *firstmt, FMapThing *lastmt, // //=========================================================================== -void P_SpawnSlopeMakers (FMapThing *firstmt, FMapThing *lastmt, const int *oldvertextable) +void MapLoader::SpawnSlopeMakers (FMapThing *firstmt, FMapThing *lastmt, const int *oldvertextable) { FMapThing *mt; @@ -402,15 +403,15 @@ void P_SpawnSlopeMakers (FMapThing *firstmt, FMapThing *lastmt, const int *oldve if (mt->info->Special <= SMT_SlopeCeilingPointLine) { // SlopeFloorPointLine and SlopCeilingPointLine - P_SlopeLineToPoint (mt->args[0], pos, ceiling); + SlopeLineToPoint (mt->args[0], pos, ceiling); } else if (mt->info->Special <= SMT_SetCeilingSlope) { // SetFloorSlope and SetCeilingSlope - P_SetSlope (refplane, ceiling, mt->angle, mt->args[0], pos); + SetSlope (refplane, ceiling, mt->angle, mt->args[0], pos); } else { // VavoomFloor and VavoomCeiling (these do not perform any sector height adjustment - z is absolute) - P_VavoomSlope(sec, mt->thingid, mt->pos, ceiling); + VavoomSlope(sec, mt->thingid, mt->pos, ceiling); } mt->EdNum = 0; } @@ -421,12 +422,12 @@ void P_SpawnSlopeMakers (FMapThing *firstmt, FMapThing *lastmt, const int *oldve if (mt->info != NULL && mt->info->Type == NULL && (mt->info->Special == SMT_CopyFloorPlane || mt->info->Special == SMT_CopyCeilingPlane)) { - P_CopyPlane (mt->args[0], mt->pos, mt->info->Special == SMT_CopyCeilingPlane); + CopyPlane (mt->args[0], mt->pos, mt->info->Special == SMT_CopyCeilingPlane); mt->EdNum = 0; } } - P_SetSlopesFromVertexHeights(firstmt, lastmt, oldvertextable); + SetSlopesFromVertexHeights(firstmt, lastmt, oldvertextable); } @@ -445,7 +446,7 @@ void P_SpawnSlopeMakers (FMapThing *firstmt, FMapThing *lastmt, const int *oldve // //=========================================================================== -static void P_AlignPlane(sector_t *sec, line_t *line, int which) +void MapLoader::AlignPlane(sector_t *sec, line_t *line, int which) { sector_t *refsec; double bestdist; @@ -515,11 +516,11 @@ static void P_AlignPlane(sector_t *sec, line_t *line, int which) // //=========================================================================== -void P_SetSlopes () +void MapLoader::SetSlopes () { int s; - for (auto &line : level.lines) + for (auto &line : Level->lines) { if (line.special == Plane_Align) { @@ -538,9 +539,9 @@ void P_SetSlopes () bits = (line.args[0] >> 2) & 3; if (bits == 1) // align front side to back - P_AlignPlane (line.frontsector, &line, s); + AlignPlane (line.frontsector, &line, s); else if (bits == 2) // align back side to front - P_AlignPlane (line.backsector, &line, s); + AlignPlane (line.backsector, &line, s); } } } @@ -553,9 +554,9 @@ void P_SetSlopes () // //=========================================================================== -void P_CopySlopes() +void MapLoader::CopySlopes() { - for (auto &line : level.lines) + for (auto &line : Level->lines) { if (line.special == Plane_Copy) { @@ -569,7 +570,7 @@ void P_CopySlopes() for (int s = 0; s < (line.backsector ? 4 : 2); s++) { if (line.args[s]) - P_CopyPlane(line.args[s], + CopyPlane(line.args[s], (s & 2 ? line.backsector : line.frontsector), s & 1); } diff --git a/src/p_udmf.cpp b/src/p_udmf.cpp index 9621b9b550..4a8c17226b 100644 --- a/src/p_udmf.cpp +++ b/src/p_udmf.cpp @@ -123,7 +123,6 @@ enum extern bool ForceNodeBuild; extern TArray MapThingsConverted; -extern TArray linemap; #define CHECK_N(f) if (!(namespace_bits&(f))) break; @@ -437,7 +436,7 @@ public: UDMFParser(MapLoader *ld, FMissingTextureTracker &missing) : loader(ld), missingTex(missing) { - linemap.Clear(); + loader->linemap.Clear(); } void ReadUserKey(FUDMFKey &ukey) { @@ -770,7 +769,7 @@ public: FUDMFKey ukey; ukey.Key = key; ReadUserKey(ukey); - MapThingsUserData.Push(ukey); + loader->MapThingsUserData.Push(ukey); } break; } @@ -2067,7 +2066,7 @@ public: sidecount++; if (ParsedLines[i].sidedef[1] != NULL) sidecount++; - linemap.Push(i+skipped); + loader->linemap.Push(i+skipped); i++; } } @@ -2216,17 +2215,17 @@ public: if (sc.Compare("thing")) { FMapThing th; - unsigned userdatastart = MapThingsUserData.Size(); + unsigned userdatastart = loader->MapThingsUserData.Size(); ParseThing(&th); MapThingsConverted.Push(th); - if (userdatastart < MapThingsUserData.Size()) + if (userdatastart < loader->MapThingsUserData.Size()) { // User data added - MapThingsUserDataIndex[MapThingsConverted.Size()-1] = userdatastart; + loader->MapThingsUserDataIndex[MapThingsConverted.Size()-1] = userdatastart; // Mark end of the user data for this map thing FUDMFKey ukey; ukey.Key = NAME_None; ukey = 0; - MapThingsUserData.Push(ukey); + loader->MapThingsUserData.Push(ukey); } } else if (sc.Compare("linedef")) @@ -2256,7 +2255,7 @@ public: vertexdata_t vd; ParseVertex(&vt, &vd); ParsedVertices.Push(vt); - vertexdatas.Push(vd); + loader->vertexdatas.Push(vd); } else { diff --git a/src/r_state.h b/src/r_state.h index 5619a15301..6d3c232a69 100644 --- a/src/r_state.h +++ b/src/r_state.h @@ -49,8 +49,6 @@ extern int viewheight; extern TArray sprites; extern uint32_t NumStdSprites; -extern TArray vertexdatas; - // // POV data. //