- moved Extradata parser into MapLoader class.
This commit is contained in:
parent
733cd5260a
commit
f351df5c22
6 changed files with 131 additions and 153 deletions
185
src/edata.cpp
185
src/edata.cpp
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue