- moved Extradata parser into MapLoader class.

This commit is contained in:
Christoph Oelckers 2018-12-27 12:32:35 +01:00
parent 733cd5260a
commit f351df5c22
6 changed files with 132 additions and 154 deletions

View file

@ -85,72 +85,7 @@ DEFINE_MAP_OPTION(loadacs, false)
opt->acsName = parse.sc.String;
}
struct EDMapthing
{
int recordnum;
int tid;
int type;
double height;
int args[5];
uint16_t skillfilter;
uint32_t flags;
};
struct EDLinedef
{
int recordnum;
int special;
int tag;
int id;
int args[5];
double alpha;
uint32_t flags;
uint32_t activation;
};
struct EDSector
{
int recordnum;
uint32_t flags;
uint32_t flagsRemove;
uint32_t flagsAdd;
int damageamount;
int damageinterval;
FName damagetype;
uint8_t leaky;
uint8_t leakyadd;
uint8_t leakyremove;
int floorterrain;
int ceilingterrain;
uint32_t color;
uint32_t damageflags;
uint32_t damageflagsAdd;
uint32_t damageflagsRemove;
bool flagsSet;
bool damageflagsSet;
bool colorSet;
// colormaptop//bottom cannot be used because ZDoom has no corresponding properties.
double xoffs[2], yoffs[2];
DAngle angle[2];
uint32_t portalflags[2];
double Overlayalpha[2];
};
static FString EDMap;
static TMap<int, EDLinedef> EDLines;
static TMap<int, EDSector> EDSectors;
static TMap<int, EDMapthing> EDThings;
static void parseLinedef(FScanner &sc)
static void parseLinedef(FScanner &sc, TMap<int, EDLinedef> &EDLines)
{
EDLinedef ld;
bool argsset = false;
@ -225,7 +160,7 @@ static void parseLinedef(FScanner &sc)
{
sc.CheckString("=");
sc.MustGetString();
for (const char *tok = strtok(sc.String, ",+ \t"); tok != NULL; tok = strtok(NULL, ",+ \t"))
for (const char *tok = strtok(sc.String, ",+ \t"); tok != nullptr; tok = strtok(nullptr, ",+ \t"))
{
if (!stricmp(tok, "USE")) actmethod |= SPAC_Use | SPAC_MUse;
else if (!stricmp(tok, "CROSS")) actmethod |= SPAC_Cross | SPAC_MCross | SPAC_PCross;
@ -268,7 +203,7 @@ static void parseLinedef(FScanner &sc)
EDLines[ld.recordnum] = ld;
}
static void parseSector(FScanner &sc)
static void parseSector(FScanner &sc, TMap<int, EDSector> &EDSectors)
{
EDSector sec;
@ -288,7 +223,7 @@ static void parseSector(FScanner &sc)
}
else if (sc.Compare("flags"))
{
uint32_t *flagvar = NULL;
uint32_t *flagvar = nullptr;
if (sc.CheckString("."))
{
sc.MustGetString();
@ -314,7 +249,7 @@ static void parseSector(FScanner &sc)
do
{
sc.MustGetString();
for (const char *tok = strtok(sc.String, ",+ \t"); tok != NULL; tok = strtok(NULL, ",+ \t"))
for (const char *tok = strtok(sc.String, ",+ \t"); tok != nullptr; tok = strtok(nullptr, ",+ \t"))
{
if (!stricmp(tok, "SECRET")) *flagvar |= SECF_SECRET | SECF_WASSECRET;
else if (!stricmp(tok, "FRICTION")) *flagvar |= SECF_FRICTION;
@ -345,8 +280,8 @@ static void parseSector(FScanner &sc)
}
else if (sc.Compare("damageflags"))
{
uint32_t *flagvar = NULL;
uint8_t *leakvar = NULL;
uint32_t *flagvar = nullptr;
uint8_t *leakvar = nullptr;
if (sc.CheckString("."))
{
sc.MustGetString();
@ -375,7 +310,7 @@ static void parseSector(FScanner &sc)
do
{
sc.MustGetString();
for (const char *tok = strtok(sc.String, ",+ \t"); tok != NULL; tok = strtok(NULL, ",+ \t"))
for (const char *tok = strtok(sc.String, ",+ \t"); tok != nullptr; tok = strtok(nullptr, ",+ \t"))
{
if (!stricmp(tok, "LEAKYSUIT")) *leakvar |= 1;
else if (!stricmp(tok, "IGNORESUIT")) *leakvar |= 2; // these 2 bits will be used to set 'leakychance', but this can only be done when the sector gets initialized
@ -485,7 +420,7 @@ static void parseSector(FScanner &sc)
do
{
sc.MustGetString();
for (const char *tok = strtok(sc.String, ",+ \t"); tok != NULL; tok = strtok(NULL, ",+ \t"))
for (const char *tok = strtok(sc.String, ",+ \t"); tok != nullptr; tok = strtok(nullptr, ",+ \t"))
{
if (!stricmp(tok, "DISABLED")) sec.portalflags[dest] |= PLANEF_DISABLED;
else if (!stricmp(tok, "NORENDER")) sec.portalflags[dest] |= PLANEF_NORENDER;
@ -506,7 +441,7 @@ static void parseSector(FScanner &sc)
EDSectors[sec.recordnum] = sec;
}
static void parseMapthing(FScanner &sc)
static void parseMapthing(FScanner &sc, TMap<int, EDMapthing> &EDThings)
{
EDMapthing mt;
@ -545,7 +480,7 @@ static void parseMapthing(FScanner &sc)
if (pos) pos++;
else pos = sc.String;
const PClass *cls = PClass::FindClass(pos);
if (cls != NULL)
if (cls != nullptr)
{
FDoomEdMap::Iterator it(DoomEdMap);
FDoomEdMap::Pair *pair;
@ -591,7 +526,7 @@ static void parseMapthing(FScanner &sc)
do
{
sc.MustGetString();
for (const char *tok = strtok(sc.String, ",+ \t"); tok != NULL; tok = strtok(NULL, ",+ \t"))
for (const char *tok = strtok(sc.String, ",+ \t"); tok != nullptr; tok = strtok(nullptr, ",+ \t"))
{
if (!stricmp(tok, "EASY")) mt.skillfilter |= 3;
else if (!stricmp(tok, "NORMAL")) mt.skillfilter |= 4;
@ -614,64 +549,56 @@ static void parseMapthing(FScanner &sc)
EDThings[mt.recordnum] = mt;
}
void InitED()
void MapLoader::InitED()
{
FString filename;
FScanner sc;
if (EDMap.CompareNoCase(level.MapName) != 0)
const char *arg = Args->CheckValue("-edf");
if (arg != nullptr) filename = arg;
else
{
EDLines.Clear();
EDSectors.Clear();
EDThings.Clear();
EDMap = level.MapName;
FEDOptions *opt = Level->info->GetOptData<FEDOptions>("EData", false);
if (opt != nullptr)
{
filename = opt->EDName;
}
}
const char *arg = Args->CheckValue("-edf");
if (filename.IsEmpty()) return;
int lump = Wads.CheckNumForFullName(filename, true, ns_global);
if (lump == -1) return;
sc.OpenLumpNum(lump);
if (arg != NULL) filename = arg;
sc.SetCMode(true);
while (sc.GetString())
{
if (sc.Compare("linedef"))
{
parseLinedef(sc, EDLines);
}
else if (sc.Compare("mapthing"))
{
parseMapthing(sc, EDThings);
}
else if (sc.Compare("sector"))
{
parseSector(sc, EDSectors);
}
else
{
FEDOptions *opt = level.info->GetOptData<FEDOptions>("EData", false);
if (opt != NULL)
{
filename = opt->EDName;
}
}
if (filename.IsEmpty()) return;
int lump = Wads.CheckNumForFullName(filename, true, ns_global);
if (lump == -1) return;
sc.OpenLumpNum(lump);
sc.SetCMode(true);
while (sc.GetString())
{
if (sc.Compare("linedef"))
{
parseLinedef(sc);
}
else if (sc.Compare("mapthing"))
{
parseMapthing(sc);
}
else if (sc.Compare("sector"))
{
parseSector(sc);
}
else
{
sc.ScriptError("Unknown keyword '%s'", sc.String);
}
sc.ScriptError("Unknown keyword '%s'", sc.String);
}
}
}
void ProcessEDMapthing(FMapThing *mt, int recordnum)
void MapLoader::ProcessEDMapthing(FMapThing *mt, int recordnum)
{
InitED();
EDMapthing *emt = EDThings.CheckKey(recordnum);
if (emt == NULL)
if (emt == nullptr)
{
Printf("EDF Mapthing record %d not found\n", recordnum);
mt->EdNum = 0;
@ -686,12 +613,12 @@ void ProcessEDMapthing(FMapThing *mt, int recordnum)
mt->flags = emt->flags;
}
void ProcessEDLinedef(line_t *ld, int recordnum)
void MapLoader::ProcessEDLinedef(line_t *ld, int recordnum)
{
InitED();
EDLinedef *eld = EDLines.CheckKey(recordnum);
if (eld == NULL)
if (eld == nullptr)
{
Printf("EDF Linedef record %d not found\n", recordnum);
ld->special = 0;
@ -706,10 +633,10 @@ void ProcessEDLinedef(line_t *ld, int recordnum)
tagManager.AddLineID(ld->Index(), eld->tag);
}
void ProcessEDSector(sector_t *sec, int recordnum)
void MapLoader::ProcessEDSector(sector_t *sec, int recordnum)
{
EDSector *esec = EDSectors.CheckKey(recordnum);
if (esec == NULL)
if (esec == nullptr)
{
Printf("EDF Sector record %d not found\n", recordnum);
return;
@ -749,16 +676,16 @@ void ProcessEDSector(sector_t *sec, int recordnum)
}
void ProcessEDSectors()
void MapLoader::ProcessEDSectors()
{
InitED();
if (EDSectors.CountUsed() == 0) return; // don't waste time if there's no records.
// collect all Extradata sector records up front so we do not need to search the complete line array for each sector separately.
auto numsectors = level.sectors.Size();
auto numsectors = Level->sectors.Size();
TArray<int> sectorrecord(numsectors, true);
memset(sectorrecord.Data(), -1, numsectors * sizeof(int));
for (auto &line : level.lines)
for (auto &line : Level->lines)
{
if (line.special == Static_Init && line.args[1] == Init_EDSector)
{
@ -770,15 +697,15 @@ void ProcessEDSectors()
{
if (sectorrecord[i] >= 0)
{
ProcessEDSector(&level.sectors[i], sectorrecord[i]);
ProcessEDSector(&Level->sectors[i], sectorrecord[i]);
}
}
}
void LoadMapinfoACSLump()
void MapLoader::LoadMapinfoACSLump()
{
FEDOptions *opt = level.info->GetOptData<FEDOptions>("EData", false);
if (opt != NULL)
FEDOptions *opt = Level->info->GetOptData<FEDOptions>("EData", false);
if (opt != nullptr)
{
int lump = Wads.CheckNumForName(opt->acsName);
if (lump >= 0) FBehavior::StaticLoadModule(lump);

View file

@ -1,12 +0,0 @@
#ifndef EDATA_H
#define EDATA_H
struct FMapThing;
struct line_t;
void ProcessEDMapthing(FMapThing *mt, int recordnum);
void ProcessEDLinedef(line_t *line, int recordnum);
void ProcessEDSectors();
void LoadMapinfoACSLump();
#endif

View file

@ -97,9 +97,6 @@
#include "g_levellocals.h"
#include "c_dispatch.h"
#include "a_dynlight.h"
#ifndef NO_EDATA
#include "edata.h"
#endif
#include "events.h"
#include "p_destructible.h"
#include "types.h"
@ -3386,9 +3383,7 @@ void P_SetupLevel(const char *lumpname, int position, bool newGame)
}
FBehavior::StaticLoadDefaultModules();
#ifndef NO_EDATA
LoadMapinfoACSLump();
#endif
loader.LoadMapinfoACSLump();
P_LoadStrifeConversations(map, lumpname);
@ -3680,7 +3675,7 @@ void P_SetupLevel(const char *lumpname, int position, bool newGame)
}
// set up world state
P_SpawnSpecials();
P_SpawnSpecials(&loader);
// disable reflective planes on sloped sectors.
for (auto &sec : level.sectors)

View file

@ -169,6 +169,64 @@ void FixMinisegReferences();
void FixHoles();
void ReportUnpairedMinisegs();
struct EDMapthing
{
int recordnum;
int tid;
int type;
double height;
int args[5];
uint16_t skillfilter;
uint32_t flags;
};
struct EDLinedef
{
int recordnum;
int special;
int tag;
int id;
int args[5];
double alpha;
uint32_t flags;
uint32_t activation;
};
struct EDSector
{
int recordnum;
uint32_t flags;
uint32_t flagsRemove;
uint32_t flagsAdd;
int damageamount;
int damageinterval;
FName damagetype;
uint8_t leaky;
uint8_t leakyadd;
uint8_t leakyremove;
int floorterrain;
int ceilingterrain;
uint32_t color;
uint32_t damageflags;
uint32_t damageflagsAdd;
uint32_t damageflagsRemove;
bool flagsSet;
bool damageflagsSet;
bool colorSet;
// colormaptop//bottom cannot be used because ZDoom has no corresponding properties.
double xoffs[2], yoffs[2];
DAngle angle[2];
uint32_t portalflags[2];
double Overlayalpha[2];
};
struct sidei_t // [RH] Only keep BOOM sidedef init stuff around for init
{
@ -219,6 +277,10 @@ class MapLoader
int sidecount;
TArray<int> linemap;
TMap<int, EDLinedef> EDLines;
TMap<int, EDSector> EDSectors;
TMap<int, EDMapthing> EDThings;
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);
@ -227,6 +289,11 @@ class MapLoader
void SetSlopesFromVertexHeights(FMapThing *firstmt, FMapThing *lastmt, const int *oldvertextable);
void AlignPlane(sector_t *sec, line_t *line, int which);
void InitED();
void ProcessEDMapthing(FMapThing *mt, int recordnum);
void ProcessEDLinedef(line_t *line, int recordnum);
void ProcessEDSector(sector_t *sec, int recordnum);
int checkGLVertex(int num);
int checkGLVertex3(int num);
int CheckForMissingSegs();
@ -260,6 +327,8 @@ class MapLoader
void AddToList(uint8_t *hitlist, FTextureID texid, int bitmask);
public:
void LoadMapinfoACSLump();
void ProcessEDSectors();
void FloodZones();
void LoadVertexes(MapData * map);

View file

@ -94,10 +94,8 @@
#include "d_player.h"
#include "g_levellocals.h"
#include "actorinlines.h"
#ifndef NO_EDATA
#include "edata.h"
#endif
#include "vm.h"
#include "p_setup.h"
#include "c_console.h"
@ -1299,7 +1297,7 @@ void P_InitSectorSpecial(sector_t *sector, int special)
// After the map has been loaded, scan for specials that spawn thinkers
//
void P_SpawnSpecials (void)
void P_SpawnSpecials (MapLoader *ml)
{
P_SetupPortals();
@ -1312,7 +1310,7 @@ void P_SpawnSpecials (void)
}
#ifndef NO_EDATA
ProcessEDSectors();
ml->ProcessEDSectors();
#endif

View file

@ -92,8 +92,9 @@ const double CARRYFACTOR = 3 / 32.;
// it returns true, and the player is allowed to live.
bool CheckIfExitIsGood (AActor *self, level_info_t *info);
class MapLoader;
// at map load
void P_SpawnSpecials (void);
void P_SpawnSpecials (MapLoader *ml);
// every tic
void P_UpdateSpecials (void);