diff --git a/src/doomstat.h b/src/doomstat.h index 7c3c7afed..7c1ce5491 100644 --- a/src/doomstat.h +++ b/src/doomstat.h @@ -46,7 +46,6 @@ extern UINT8 mapmusrng; // Use other bits if necessary. extern UINT32 maptol; -extern boolean mapcompat; extern INT32 cursaveslot; //extern INT16 lastmapsaved; diff --git a/src/g_game.c b/src/g_game.c index d84bd426d..0a203217c 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -92,7 +92,6 @@ UINT8 mapmusrng; // Random selection result INT16 gamemap = 1; UINT32 maptol; -boolean mapcompat = false; preciptype_t globalweather = PRECIP_NONE; preciptype_t curWeather = PRECIP_NONE; diff --git a/src/lua_script.c b/src/lua_script.c index 60b3bf447..368d0725e 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -401,8 +401,8 @@ int LUA_PushGlobals(lua_State *L, const char *word) } else if (fastcmp(word, "compatmode")) { lua_pushboolean(L, lua_compatmode); return 1; - } else if (fastcmp(word, "mapcompat")) { - lua_pushboolean(L, mapcompat); + } else if (fastcmp(word, "mapnamespace")) { + lua_pushstring(L, P_MapNamespaceString(mapnamespace)); return 1; } diff --git a/src/p_floor.c b/src/p_floor.c index 8661cc25e..f3bf5100b 100644 --- a/src/p_floor.c +++ b/src/p_floor.c @@ -1805,7 +1805,7 @@ static floormove_t *CreateFloorThinker(sector_t *sec) } dofloor = Z_Calloc(sizeof (*dofloor), PU_LEVSPEC, NULL); - P_AddThinker(mapcompat ? THINK_FLOORS : THINK_MAIN, &dofloor->thinker); + P_AddThinker(mapnamespace == MNS_SRB2KART ? THINK_FLOORS : THINK_MAIN, &dofloor->thinker); // make sure another floor thinker won't get started over this one sec->floordata = dofloor; diff --git a/src/p_mobj.c b/src/p_mobj.c index 500f6aa97..f8a564c23 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -11094,7 +11094,7 @@ static boolean P_SetupMace(mapthing_t *mthing, mobj_t *mobj, boolean *doangle) mnumspokes = mthing->args[1] + 1; mspokeangle = FixedAngle((360*FRACUNIT)/mnumspokes) >> ANGLETOFINESHIFT; mwidth = max(0, mthing->args[2]); - mspeed = abs(mthing->args[3] << (mapcompat ? 0 : 4)); + mspeed = abs(mthing->args[3] << (mapnamespace == MNS_SRB2KART ? 0 : 4)); mphase = mthing->args[4] % 360; mpinch = mthing->args[5] % 360; mnumnospokes = mthing->args[6]; @@ -12007,7 +12007,7 @@ static boolean P_SetupSpawnedMapThing(mapthing_t *mthing, mobj_t *mobj, boolean case MT_YELLOWSPRING: case MT_INVISSPRING: { - if (mapcompat) + if (mapnamespace == MNS_SRB2KART) mobj->flags ^= MF_NOGRAVITY; } default: diff --git a/src/p_setup.c b/src/p_setup.c index b42780ca9..a128db053 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -124,7 +124,7 @@ unsigned char mapmd5[16]; boolean udmf; INT32 udmf_version; -char *udmf_namespace; +mapnamespace_t mapnamespace = MNS_UNKNOWN; size_t numvertexes, numsegs, numsectors, numsubsectors, numnodes, numlines, numsides, nummapthings; size_t num_orig_vertexes; vertex_t *vertexes; @@ -1449,34 +1449,9 @@ static boolean TextmapCount(size_t size) numvertexes = 0; numsectors = 0; - // Look for namespace at the beginning. - if (!fastcmp(tkn, "namespace")) - { - CONS_Alert(CONS_ERROR, "No namespace at beginning of lump!\n"); - return false; - } + // skip namespace, it's checked by P_SetMapNamespace + M_TokenizerRead(0); - // Check if namespace is valid and copy it into memory. - tkn = M_TokenizerRead(0); - if (fastcmp(tkn, "blankart")) - { - udmf_namespace = "blankart"; - } - else if(fastcmp(tkn, "ringracers")) - { - udmf_namespace = "ringracers"; - } - else if (fastcmp(tkn, "srb2")) - { - udmf_namespace = "srb2"; - } - else - { - udmf_namespace = "unknown"; - CONS_Alert(CONS_WARNING, "Invalid namespace '%s', only 'srb2' or 'ringracers' or 'srb2kart' or 'blankart' is supported.\n", tkn); - return false; - } - // Check for version tkn = M_TokenizerRead(0); if (fastcmp(tkn, "version")) @@ -2091,7 +2066,7 @@ static void ParseTextmapThingParameter(UINT32 i, const char *param, const char * mapthings[i].layer = atol(val); else if (fastncmp(param, "stringarg", 9) && strlen(param) > 9) { - if (!strcmp(udmf_namespace,"ringracers") && udmf_version > 0) + if (mapnamespace == MNS_RINGRACERS && udmf_version > 0) { size_t argnum = atol(param + 9); if (argnum >= NUM_SCRIPT_STRINGARGS) @@ -2114,7 +2089,7 @@ static void ParseTextmapThingParameter(UINT32 i, const char *param, const char * } else if (fastncmp(param, "arg", 3) && strlen(param) > 3) { - if (!strcmp(udmf_namespace,"ringracers") && udmf_version > 0) + if (mapnamespace == MNS_RINGRACERS && udmf_version > 0) { size_t argnum = atol(param + 3); if (argnum >= NUM_SCRIPT_ARGS) @@ -5275,7 +5250,7 @@ static void P_ConvertBinaryLinedefTypes(void) //Alpha if (lines[i].special == 141 || lines[i].special == 142 || lines[i].special == 144 || lines[i].special == 145) { - if (!mapcompat && lines[i].flags & ML_NOCLIMB) + if (mapnamespace != MNS_SRB2KART && lines[i].flags & ML_NOCLIMB) lines[i].args[3] |= TMFA_INSIDES; P_SetBinaryFOFAlpha(&lines[i]); @@ -7260,7 +7235,7 @@ static void P_ConvertBinaryThingTypes(void) break; } - if (!mapcompat) + if (mapnamespace != MNS_SRB2KART) { mapthings[i].angle = lines[j].frontsector->ceilingheight >> FRACBITS; mapthings[i].pitch = lines[j].frontsector->floorheight >> FRACBITS; @@ -7381,7 +7356,7 @@ static void P_ConvertBinaryThingTypes(void) mapthings[i].args[0] = mapthings[i].angle >> 13; mapthings[i].args[1] = (mapthings[i].angle >> 10) & 7; mapthings[i].args[3] = !!(mapthings[i].options & MTF_AMBUSH); - if (!mapcompat) + if (mapnamespace != MNS_SRB2KART) { mapthings[i].args[0] = mapthings[i].args[0]*TICRATE/2; mapthings[i].args[1] = mapthings[i].args[1]*TICRATE/2; @@ -7678,11 +7653,63 @@ static void P_MakeMapMD5(virtres_t *virt, void *dest) M_Memcpy(dest, &resmd5, 16); } -static void P_SetMapCompat(void) +static boolean P_SetMapNamespace(void) { - // choose wisely... - mapcompat = vres_Find(curmapvirt, "TEXTMAP") == NULL; - //mapcompat = wadfiles[WADFILENUM(mapheaderinfo[gamemap-1]->lumpnum)]->compatmode; + virtlump_t *textmap = vres_Find(curmapvirt, "TEXTMAP"); + if (textmap != NULL) + { + M_TokenizerOpen((char *)textmap->data, textmap->size); + const char *tkn = M_TokenizerRead(0); + + // Look for namespace at the beginning. + if (!fastcmp(tkn, "namespace")) + { + CONS_Alert(CONS_ERROR, "No namespace at beginning of lump!\n"); + return false; + } + + // Check if namespace is valid and copy it into memory. + tkn = M_TokenizerRead(0); + if (fastcmp(tkn, "blankart")) + { + mapnamespace = MNS_BLANKART; + } + else if(fastcmp(tkn, "ringracers")) + { + mapnamespace = MNS_RINGRACERS; + } + else if (fastcmp(tkn, "srb2")) + { + mapnamespace = MNS_SRB2; + } + else + { + CONS_Alert(CONS_WARNING, "Invalid namespace '%s'. Only 'srb2', 'ringracers' and 'blankart' are supported.\n", tkn); + return false; + } + + M_TokenizerClose(); + } + else + { + // binary maps are kart only. don't need more than one binary format + mapnamespace = MNS_SRB2KART; + } + return true; +} + +// name that namespace! +const char *P_MapNamespaceString(mapnamespace_t mns) +{ + static const char *names[MNS__MAX] = { + [MNS_UNKNOWN] = "unknown", + [MNS_SRB2KART] = "srb2kart", + [MNS_BLANKART] = "blankart", + [MNS_RINGRACERS] = "ringracers", + [MNS_SRB2] = "srb2", + }; + + return names[mns]; } static boolean P_LoadMapFromFile(void) @@ -7691,7 +7718,6 @@ static boolean P_LoadMapFromFile(void) size_t i; udmf = textmap != NULL; udmf_version = 0; - udmf_namespace = NULL; if (!P_LoadMapData(curmapvirt)) return false; @@ -8513,7 +8539,8 @@ boolean P_LoadLevel(boolean fromnetsave, boolean reloadinggamestate) curmapvirt = vres_GetMap(lastloadedmaplumpnum); // set this as early as possible, to fix palette texture skyboxes - P_SetMapCompat(); + if (!P_SetMapNamespace()) + return false; if (mapheaderinfo[gamemap-1]) { diff --git a/src/p_setup.h b/src/p_setup.h index 70b93d532..d5d60c55b 100644 --- a/src/p_setup.h +++ b/src/p_setup.h @@ -38,6 +38,18 @@ extern UINT8 levelfadecol; extern lumpnum_t lastloadedmaplumpnum; // for comparative savegame extern virtres_t *curmapvirt; +typedef enum +{ + MNS_UNKNOWN, + MNS_SRB2KART, + MNS_BLANKART, + MNS_RINGRACERS, + MNS_SRB2, + MNS__MAX, +} mapnamespace_t; + +extern mapnamespace_t mapnamespace; + /* for levelflat type */ enum { @@ -102,6 +114,7 @@ INT32 P_CheckLevelFlat(const char *flatname); extern size_t nummapthings; extern mapthing_t *mapthings; +const char *P_MapNamespaceString(mapnamespace_t mns); void P_SetupLevelSky(const char *skytexname, boolean global); void P_RespawnThings(void); boolean P_LoadLevel(boolean fromnetsave, boolean reloadinggamestate); diff --git a/src/p_slopes.c b/src/p_slopes.c index 21937a7a1..0fc309e8e 100644 --- a/src/p_slopes.c +++ b/src/p_slopes.c @@ -862,7 +862,7 @@ void P_SpawnSlopes(const boolean fromsave) { // end of jart // in kart, copied slopes are created AFTER spawning mapthings - if (mapcompat) + if (mapnamespace == MNS_SRB2KART) return; /// Copies slopes from tagged sectors via line specials. diff --git a/src/p_spec.c b/src/p_spec.c index c2d78875b..e01429503 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -1412,7 +1412,7 @@ static boolean P_CheckRaceLapSpecial(line_t *triggerline, player_t *player) { lap = P_FindLowestLap(); - if (!mapcompat && lap <= lastLowestLap) + if (mapnamespace != MNS_SRB2KART && lap <= lastLowestLap) { // Need to be able to search for MIDSOLID linedefs return false; @@ -1420,7 +1420,7 @@ static boolean P_CheckRaceLapSpecial(line_t *triggerline, player_t *player) } // kart laps are zero-based - if (lap && mapcompat) + if (lap && mapnamespace == MNS_SRB2KART) lap--; UINT16 threshold = sides[triggerline->sidenum[0]].textureoffset >> FRACBITS; @@ -7853,7 +7853,7 @@ void P_SpawnSpecialsThatRequireObjects(boolean fromnetsave) for (i = 0; i < numlines; i++) { - if (mapcompat && lines[i].special == 720) + if (mapnamespace == MNS_SRB2KART && lines[i].special == 720) P_CopySectorSlope(&lines[i]); if (P_IsLineDisabled(&lines[i])) diff --git a/src/r_textures.c b/src/r_textures.c index 66d346f29..42729e5d1 100644 --- a/src/r_textures.c +++ b/src/r_textures.c @@ -2033,7 +2033,7 @@ void R_ParseTEXTURESLump(UINT16 wadNum, UINT16 lumpNum, INT32 *texindex) static void PaletteTextureHack(const char **name) { static char uberhack[5]; - if (mapcompat) + if (mapnamespace == MNS_SRB2KART) { unsigned num; if (sscanf(*name, "~%03u", &num) && num < 256)