- some improvements to compatibility scripts:

* use names, not strings, to allow use of switch/case.
* avoid creating the checksum a second time per level.
* do an early-out check for maps that do not have scripted compatibility.
This commit is contained in:
Christoph Oelckers 2018-04-09 22:09:28 +02:00
parent 640948703f
commit 9daad477c3
4 changed files with 44 additions and 32 deletions

View file

@ -466,7 +466,7 @@ void ParseCompatibility()
// //
//========================================================================== //==========================================================================
void CheckCompatibility(MapData *map) FName CheckCompatibility(MapData *map)
{ {
FMD5Holder md5; FMD5Holder md5;
FCompatValues *flags; FCompatValues *flags;
@ -489,13 +489,16 @@ void CheckCompatibility(MapData *map)
flags = BCompatMap.CheckKey(md5); flags = BCompatMap.CheckKey(md5);
FString hash;
for (size_t j = 0; j < sizeof(md5.Bytes); ++j)
{
hash.AppendFormat("%02X", md5.Bytes[j]);
}
if (developer >= DMSG_NOTIFY) if (developer >= DMSG_NOTIFY)
{ {
Printf("MD5 = "); Printf("MD5 = %s", hash.GetChars());
for (size_t j = 0; j < sizeof(md5.Bytes); ++j)
{
Printf("%02X", md5.Bytes[j]);
}
if (flags != NULL) if (flags != NULL)
{ {
Printf(", cflags = %08x, cflags2 = %08x, bflags = %08x\n", Printf(", cflags = %08x, cflags2 = %08x, bflags = %08x\n",
@ -523,6 +526,7 @@ void CheckCompatibility(MapData *map)
{ {
ib_compatflags |= BCOMPATF_FLOATBOB; ib_compatflags |= BCOMPATF_FLOATBOB;
} }
return FName(hash, true); // if this returns NAME_None it means there is no scripted compatibility handler.
} }
//========================================================================== //==========================================================================
@ -531,15 +535,19 @@ void CheckCompatibility(MapData *map)
// //
//========================================================================== //==========================================================================
void SetCompatibilityParams() void SetCompatibilityParams(FName checksum)
{ {
PClass *const cls = PClass::FindClass("LevelCompatibility"); if (checksum != NAME_None)
if (cls != nullptr)
{ {
PFunction *const func = dyn_cast<PFunction>(cls->FindSymbol("Apply", true)); PClass *const cls = PClass::FindClass("LevelCompatibility");
if (func != nullptr) if (cls != nullptr)
{ {
VMCall(func->Variants[0].Implementation, nullptr, 0, nullptr, 0); PFunction *const func = dyn_cast<PFunction>(cls->FindSymbol("Apply", true));
if (func != nullptr)
{
VMValue param = { (int)checksum };
VMCall(func->Variants[0].Implementation, &param, 1, nullptr, 0);
}
} }
} }

View file

@ -36,7 +36,7 @@ struct FMD5HashTraits
extern TMap<FMD5Holder, FCompatValues, FMD5HashTraits> BCompatMap; extern TMap<FMD5Holder, FCompatValues, FMD5HashTraits> BCompatMap;
void ParseCompatibility(); void ParseCompatibility();
void CheckCompatibility(MapData *map); FName CheckCompatibility(MapData *map);
void SetCompatibilityParams(); void SetCompatibilityParams(FName);
#endif #endif

View file

@ -3756,7 +3756,7 @@ void P_SetupLevel (const char *lumpname, int position)
{ {
level.maptype = MAPTYPE_UDMF; level.maptype = MAPTYPE_UDMF;
} }
CheckCompatibility(map); FName checksum = CheckCompatibility(map);
if (ib_compatflags & BCOMPATF_REBUILDNODES) if (ib_compatflags & BCOMPATF_REBUILDNODES)
{ {
ForceNodeBuild = true; ForceNodeBuild = true;
@ -3834,7 +3834,7 @@ void P_SetupLevel (const char *lumpname, int position)
times[0].Unclock(); times[0].Unclock();
} }
SetCompatibilityParams(); SetCompatibilityParams(checksum);
times[6].Clock(); times[6].Clock();
P_LoopSidedefs (true); P_LoopSidedefs (true);

View file

@ -1,24 +1,28 @@
class LevelCompatibility play class LevelCompatibility play
{ {
private static void Apply() private static void Apply(Name checksum)
{ {
string checksum = level.GetChecksum(); switch (checksum)
if ( checksum ~== "AB24AE6E2CB13CBDD04600A4D37F9189" // doom2.wad map02
|| checksum ~== "1EC0AF1E3985650F0C9000319C599D0C") // doom2bfg.wad map02
{ {
// Missing textures case 'AB24AE6E2CB13CBDD04600A4D37F9189': // doom2.wad map02
TextureID stone4 = TexMan.CheckForTexture("STONE4", TexMan.Type_Wall); case '1EC0AF1E3985650F0C9000319C599D0C': // doom2bfg.wad map02
SetWallTextureID(327, Line.front, Side.bottom, stone4); {
SetWallTextureID(328, Line.front, Side.bottom, stone4); // Missing textures
SetWallTextureID(338, Line.front, Side.bottom, stone4); TextureID stone4 = TexMan.CheckForTexture("STONE4", TexMan.Type_Wall);
SetWallTextureID(339, Line.front, Side.bottom, stone4); SetWallTextureID(327, Line.front, Side.bottom, stone4);
} SetWallTextureID(328, Line.front, Side.bottom, stone4);
else if (checksum ~== "66C46385EB1A23D60839D1532522076B") // doom2.wad map08 SetWallTextureID(338, Line.front, Side.bottom, stone4);
{ SetWallTextureID(339, Line.front, Side.bottom, stone4);
// Missing texture break;
SetWallTexture(101, Line.back, Side.top, "BRICK7"); }
case '66C46385EB1A23D60839D1532522076B': // doom2.wad map08
{
// Missing texture
SetWallTexture(101, Line.back, Side.top, "BRICK7");
break;
}
} }
} }