- moved most content of p_setup.cpp into a MapLoader class.

This commit is contained in:
Christoph Oelckers 2018-12-27 09:44:49 +01:00
parent 071347d7fb
commit 2e22c01d45
10 changed files with 511 additions and 451 deletions

View file

@ -34,6 +34,7 @@
**---------------------------------------------------------------------------
**
*/
#pragma once
#include "doomdata.h"
#include "tarray.h"

View file

@ -73,7 +73,7 @@ struct FBlockmap
return blockmaplump + *(blockmap + offset) + 1;
}
bool VerifyBlockMap(int count);
bool VerifyBlockMap(int count, unsigned numlines);
void Clear()
{

View file

@ -63,13 +63,9 @@
#include "g_levellocals.h"
#include "i_time.h"
void P_GetPolySpots (MapData * lump, TArray<FNodeBuilder::FPolyStart> &spots, TArray<FNodeBuilder::FPolyStart> &anchors);
CVAR(Bool, gl_cachenodes, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR(Float, gl_cachetime, 0.6f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
void P_LoadZNodes (FileReader &dalump, uint32_t id);
static bool CheckCachedNodes(MapData *map);
static void CreateCachedNodes(MapData *map);
@ -775,7 +771,7 @@ static int FindGLNodesInFile(FResourceFile * f, const char * label)
//
//==========================================================================
bool P_LoadGLNodes(MapData * map)
bool MapLoader::LoadGLNodes(MapData * map)
{
if (map->Size(ML_GLZNODES) != 0)
{
@ -794,17 +790,17 @@ bool P_LoadGLNodes(MapData * map)
{
try
{
level.subsectors.Clear();
level.segs.Clear();
level.nodes.Clear();
P_LoadZNodes (file, id);
Level->subsectors.Clear();
Level->segs.Clear();
Level->nodes.Clear();
LoadExtendedNodes (file, id);
return true;
}
catch (CRecoverableError &)
{
level.subsectors.Clear();
level.segs.Clear();
level.nodes.Clear();
Level->subsectors.Clear();
Level->segs.Clear();
Level->nodes.Clear();
}
}
}
@ -883,7 +879,7 @@ bool P_LoadGLNodes(MapData * map)
//
//==========================================================================
bool P_CheckNodes(MapData * map, bool rebuilt, int buildtime)
bool MapLoader::CheckNodes(MapData * map, bool rebuilt, int buildtime)
{
bool ret = false;
bool loaded = false;
@ -892,18 +888,18 @@ bool P_CheckNodes(MapData * map, bool rebuilt, int buildtime)
if (!rebuilt && !P_CheckForGLNodes())
{
ret = true; // we are not using the level's original nodes if we get here.
for (auto &sub : level.subsectors)
for (auto &sub : Level->subsectors)
{
sub.sector = sub.firstline->sidedef->sector;
}
// The nodes and subsectors need to be preserved for gameplay related purposes.
level.gamenodes = std::move(level.nodes);
level.gamesubsectors = std::move(level.subsectors);
level.segs.Clear();
Level->gamenodes = std::move(Level->nodes);
Level->gamesubsectors = std::move(Level->subsectors);
Level->segs.Clear();
// Try to load GL nodes (cached or GWA)
loaded = P_LoadGLNodes(map);
loaded = LoadGLNodes(map);
if (!loaded)
{
// none found - we have to build new ones!
@ -911,20 +907,20 @@ bool P_CheckNodes(MapData * map, bool rebuilt, int buildtime)
startTime = I_msTime ();
TArray<FNodeBuilder::FPolyStart> polyspots, anchors;
P_GetPolySpots (map, polyspots, anchors);
GetPolySpots (map, polyspots, anchors);
FNodeBuilder::FLevel leveldata =
{
&level.vertexes[0], (int)level.vertexes.Size(),
&level.sides[0], (int)level.sides.Size(),
&level.lines[0], (int)level.lines.Size(),
&Level->vertexes[0], (int)Level->vertexes.Size(),
&Level->sides[0], (int)Level->sides.Size(),
&Level->lines[0], (int)Level->lines.Size(),
0, 0, 0, 0
};
leveldata.FindMapBounds ();
FNodeBuilder builder (leveldata, polyspots, anchors, true);
builder.Extract (level);
builder.Extract (*Level);
endTime = I_msTime ();
DPrintf (DMSG_NOTIFY, "BSP generation took %.3f sec (%u segs)\n", (endTime - startTime) * 0.001, level.segs.Size());
DPrintf (DMSG_NOTIFY, "BSP generation took %.3f sec (%u segs)\n", (endTime - startTime) * 0.001, Level->segs.Size());
buildtime = (int32_t)(endTime - startTime);
}
}
@ -935,7 +931,7 @@ bool P_CheckNodes(MapData * map, bool rebuilt, int buildtime)
// Building nodes in debug is much slower so let's cache them only if cachetime is 0
buildtime = 0;
#endif
if (level.maptype != MAPTYPE_BUILD && gl_cachenodes && buildtime/1000.f >= gl_cachetime)
if (Level->maptype != MAPTYPE_BUILD && gl_cachenodes && buildtime/1000.f >= gl_cachetime)
{
DPrintf(DMSG_NOTIFY, "Caching nodes\n");
CreateCachedNodes(map);
@ -1102,7 +1098,7 @@ static void CreateCachedNodes(MapData *map)
}
static bool CheckCachedNodes(MapData *map)
bool MapLoader::CheckCachedNodes(MapData *map)
{
char magic[4] = {0,0,0,0};
uint8_t md5[16];
@ -1120,7 +1116,7 @@ static bool CheckCachedNodes(MapData *map)
if (fr.Read(&numlin, 4) != 4) return false;
numlin = LittleLong(numlin);
if (numlin != level.lines.Size()) return false;
if (numlin != Level->lines.Size()) return false;
if (fr.Read(md5, 16) != 16) return false;
map->GetChecksum(md5map);
@ -1135,23 +1131,23 @@ static bool CheckCachedNodes(MapData *map)
try
{
P_LoadZNodes (fr, MAKE_ID(magic[0],magic[1],magic[2],magic[3]));
LoadExtendedNodes (fr, MAKE_ID(magic[0],magic[1],magic[2],magic[3]));
}
catch (CRecoverableError &error)
{
Printf ("Error loading nodes: %s\n", error.GetMessage());
level.subsectors.Clear();
level.segs.Clear();
level.nodes.Clear();
Level->subsectors.Clear();
Level->segs.Clear();
Level->nodes.Clear();
return false;
}
for(auto &line : level.lines)
for(auto &line : Level->lines)
{
int i = line.Index();
line.v1 = &level.vertexes[LittleLong(verts[i*2])];
line.v2 = &level.vertexes[LittleLong(verts[i*2+1])];
line.v1 = &Level->vertexes[LittleLong(verts[i*2])];
line.v2 = &Level->vertexes[LittleLong(verts[i*2+1])];
}
return true;
}

View file

@ -98,6 +98,7 @@
#include "events.h"
#include "actorinlines.h"
#include "a_dynlight.h"
#include "fragglescript/t_fs.h"
// MACROS ------------------------------------------------------------------
@ -5577,6 +5578,26 @@ AActor *P_SpawnMapThing (FMapThing *mthing, int position)
return mobj;
}
//===========================================================================
//
// SpawnMapThing
//
//===========================================================================
CVAR(Bool, dumpspawnedthings, false, 0)
AActor *SpawnMapThing(int index, FMapThing *mt, int position)
{
AActor *spawned = P_SpawnMapThing(mt, position);
if (dumpspawnedthings)
{
Printf("%5d: (%5f, %5f, %5f), doomednum = %5d, flags = %04x, type = %s\n",
index, mt->pos.X, mt->pos.Y, mt->pos.Z, mt->EdNum, mt->flags,
spawned ? spawned->GetClass()->TypeName.GetChars() : "(none)");
}
T_AddSpawnedThing(spawned);
return spawned;
}
//

View file

@ -1477,6 +1477,39 @@ CUSTOM_CVAR(Int, r_fakecontrast, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
else if (self > 2) self = 2;
}
//===========================================================================
//
//
//
//===========================================================================
void line_t::AdjustLine()
{
setDelta(v2->fX() - v1->fX(), v2->fY() - v1->fY());
if (v1->fX() < v2->fX())
{
bbox[BOXLEFT] = v1->fX();
bbox[BOXRIGHT] = v2->fX();
}
else
{
bbox[BOXLEFT] = v2->fX();
bbox[BOXRIGHT] = v1->fX();
}
if (v1->fY() < v2->fY())
{
bbox[BOXBOTTOM] = v1->fY();
bbox[BOXTOP] = v2->fY();
}
else
{
bbox[BOXBOTTOM] = v2->fY();
bbox[BOXTOP] = v1->fY();
}
}
//==========================================================================
//
//

File diff suppressed because it is too large Load diff

View file

@ -31,6 +31,7 @@
#include "resourcefiles/resourcefile.h"
#include "doomdata.h"
#include "r_defs.h"
#include "nodebuild.h"
struct MapData
@ -131,7 +132,7 @@ public:
void GetChecksum(uint8_t cksum[16]);
friend bool P_LoadGLNodes(MapData * map);
friend class MapLoader;
friend MapData *P_OpenMapData(const char * mapname, bool justcheck);
};
@ -164,8 +165,6 @@ int GetUDMFInt(int type, int index, FName key);
double GetUDMFFloat(int type, int index, FName key);
FString GetUDMFString(int type, int index, FName key);
bool P_LoadGLNodes(MapData * map);
bool P_CheckNodes(MapData * map, bool rebuilt, int buildtime);
bool P_CheckForGLNodes();
void P_SetRenderSector();
void FixMinisegReferences();
@ -206,5 +205,70 @@ typedef TMap<FString,FMissingCount> FMissingTextureTracker;
extern TMap<unsigned,unsigned> MapThingsUserDataIndex; // from mapthing idx -> user data idx
extern TArray<FUDMFKey> MapThingsUserData;
struct FLevelLocals;
class MapLoader
{
friend class UDMFParser;
void *level; // this is to hide the global variable and produce an error for referencing it.
FLevelLocals *Level;
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);
void SetTextureNoErr(side_t *side, int position, uint32_t *color, const char *name, bool *validcolor, bool isFog);
void FloodZone(sector_t *sec, int zonenum);
void LoadGLZSegs(FileReader &data, int type);
void LoadZSegs(FileReader &data);
void LoadZNodes(FileReader &data, int glnodes);
int DetermineTranslucency(int lumpnum);
void SetLineID(int i, line_t *ld);
void SaveLineSpecial(line_t *ld);
void FinishLoadingLineDef(line_t *ld, int alpha);
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 CreateBlockMap();
void AddToList(uint8_t *hitlist, FTextureID texid, int bitmask);
public:
void FloodZones();
void LoadVertexes(MapData * map);
void LoadExtendedNodes(FileReader &dalump, uint32_t id);
template<class segtype> void LoadSegs(MapData * map);
template<class subsectortype, class segtype> void LoadSubsectors(MapData * map);
template<class nodetype, class subsectortype> void LoadNodes(MapData * map);
bool LoadGLNodes(MapData * map);
bool CheckCachedNodes(MapData *map);
bool CheckNodes(MapData * map, bool rebuilt, int buildtime);
void LoadSectors(MapData *map, FMissingTextureTracker &missingtex);
void LoadThings(MapData * map);
void LoadThings2(MapData * map);
void SpawnThings(int position);
void FinishLoadingLineDefs();
void LoadLineDefs(MapData * map);
void LoadLineDefs2(MapData * map);
void LoopSidedefs(bool firstloop);
void LoadSideDefs2(MapData *map, FMissingTextureTracker &missingtex);
void LoadBlockMap(MapData * map);
void LoadReject(MapData * map, bool junk);
void LoadBehavior(MapData * map);
void GetPolySpots(MapData * map, TArray<FNodeBuilder::FPolyStart> &spots, TArray<FNodeBuilder::FPolyStart> &anchors);
void GroupLines(bool buildmap);
void PrecacheLevel();
void ParseTextMap(MapData *map, FMissingTextureTracker &missingtex);
void SummarizeMissingTextures(const FMissingTextureTracker &missing);
MapLoader(FLevelLocals *lev)
{
Level = lev;
}
};
#endif

View file

@ -121,11 +121,6 @@ enum
// namespace for each game
};
void SetTexture (sector_t *sector, int index, int position, const char *name, FMissingTextureTracker &, bool truncate);
void P_ProcessSideTextures(bool checktranmap, side_t *sd, sector_t *sec, intmapsidedef_t *msd, int special, int tag, short *alpha, FMissingTextureTracker &);
void P_AdjustLine (line_t *ld);
void P_FinishLoadingLineDef(line_t *ld, int alpha);
void SpawnMapThing(int index, FMapThing *mt, int position);
extern bool ForceNodeBuild;
extern TArray<FMapThing> MapThingsConverted;
extern TArray<int> linemap;
@ -426,6 +421,7 @@ class UDMFParser : public UDMFParserBase
bool isTranslated;
bool isExtended;
bool floordrop;
MapLoader *loader;
TArray<line_t> ParsedLines;
TArray<side_t> ParsedSides;
@ -438,8 +434,8 @@ class UDMFParser : public UDMFParserBase
FMissingTextureTracker &missingTex;
public:
UDMFParser(FMissingTextureTracker &missing)
: missingTex(missing)
UDMFParser(MapLoader *ld, FMissingTextureTracker &missing)
: loader(ld), missingTex(missing)
{
linemap.Clear();
}
@ -1499,11 +1495,11 @@ public:
continue;
case NAME_Texturefloor:
SetTexture(sec, index, sector_t::floor, CheckString(key), missingTex, false);
loader->SetTexture(sec, index, sector_t::floor, CheckString(key), missingTex, false);
continue;
case NAME_Textureceiling:
SetTexture(sec, index, sector_t::ceiling, CheckString(key), missingTex, false);
loader->SetTexture(sec, index, sector_t::ceiling, CheckString(key), missingTex, false);
continue;
case NAME_Lightlevel:
@ -2100,7 +2096,7 @@ public:
sides[side].sector = &level.sectors[intptr_t(sides[side].sector)];
lines[line].sidedef[sd] = &sides[side];
P_ProcessSideTextures(!isExtended, &sides[side], sides[side].sector, &ParsedSideTextures[mapside],
loader->ProcessSideTextures(!isExtended, &sides[side], sides[side].sector, &ParsedSideTextures[mapside],
lines[line].special, lines[line].args[0], &tempalpha[sd], missingTex);
side++;
@ -2112,8 +2108,8 @@ public:
}
}
P_AdjustLine(&lines[line]);
P_FinishLoadingLineDef(&lines[line], tempalpha[0]);
lines[line].AdjustLine();
loader->FinishLoadingLineDef(&lines[line], tempalpha[0]);
}
const int sideDelta = level.sides.Size() - side;
@ -2307,9 +2303,9 @@ public:
}
};
void P_ParseTextMap(MapData *map, FMissingTextureTracker &missingtex)
void MapLoader::ParseTextMap(MapData *map, FMissingTextureTracker &missingtex)
{
UDMFParser parse(missingtex);
UDMFParser parse(this, missingtex);
parse.ParseTextMap(map);
}

View file

@ -124,7 +124,6 @@ public:
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
void PO_Init (void);
void P_AdjustLine(line_t *ld);
// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
@ -912,7 +911,7 @@ void FPolyObj::UpdateBBox ()
{
for(unsigned i=0;i<Linedefs.Size(); i++)
{
P_AdjustLine(Linedefs[i]);
Linedefs[i]->AdjustLine();
}
CalcCenter();
}

View file

@ -1406,6 +1406,7 @@ struct line_t
}
FSectorPortal *GetTransferredPortal();
void AdjustLine();
inline FLinePortal *getPortal() const;
inline bool isLinePortal() const;