Refactor TextmapCount

This commit is contained in:
MascaraSnake 2019-12-30 13:27:05 +01:00
parent e43df2993f
commit 4aee4e3684

View file

@ -1245,36 +1245,50 @@ UINT32 sidesPos[UINT16_MAX];
UINT32 vertexesPos[UINT16_MAX];
UINT32 sectorsPos[UINT16_MAX];
// Determine total amount of map data in TEXTMAP.
static boolean TextmapCount(UINT8 *data, size_t size)
{
char *nsp1 = M_GetToken((char *)data);
boolean ret = true;
char *tkn = M_GetToken((char *)data);
nummapthings = 0;
numlines = 0;
numsides = 0;
numvertexes = 0;
numsectors = 0;
// Determine total amount of map data in TEXTMAP.
// Look for namespace at the beginning.
if (fastcmp(nsp1, "namespace"))
if (!fastcmp(tkn, "namespace"))
{
char *nsp2 = M_GetToken(NULL);
char *tkn = M_GetToken(NULL);
Z_Free(tkn);
CONS_Alert(CONS_WARNING, "No namespace at beginning of lump!\n");
return false;
}
Z_Free(tkn);
// Check if namespace is valid.
if (!fastcmp(nsp2, "srb2"))
CONS_Alert(CONS_WARNING, "Invalid namespace '%s', only 'srb2' is supported.\n", nsp2);
Z_Free(nsp2);
tkn = M_GetToken(NULL);
if (!fastcmp(tkn, "srb2"))
CONS_Alert(CONS_WARNING, "Invalid namespace '%s', only 'srb2' is supported.\n", tkn);
Z_Free(tkn);
while (tkn != NULL && M_GetTokenPos() < size)
tkn = M_GetToken(NULL);
while (tkn && M_GetTokenPos() < size)
{
// Avoid anything inside bracketed stuff, only look for external keywords.
// Assuming there's only one level of bracket nesting.
if (fastcmp(tkn, "{"))
{
Z_Free(tkn);
tkn = M_GetToken(NULL);
while (!fastcmp(tkn, "}"))
do
{
Z_Free(tkn);
tkn = M_GetToken(NULL);
if (!tkn || M_GetTokenPos() >= size)
{
Z_Free(tkn);
CONS_Alert(CONS_WARNING, "Opening bracket not closed!\n");
return false;
}
} while (!fastcmp(tkn, "}"));
}
// Check for valid fields.
else if (fastcmp(tkn, "thing"))
@ -1293,15 +1307,9 @@ static boolean TextmapCount (UINT8 *data, size_t size)
Z_Free(tkn);
tkn = M_GetToken(NULL);
}
}
else
{
CONS_Alert(CONS_WARNING, "No namespace at beginning of lump!\n");
ret = false;
}
Z_Free(nsp1);
return ret;
Z_Free(tkn);
return true;
}
static char* dat;
@ -1597,17 +1605,8 @@ static void P_LoadMapData(const virtres_t *virt)
virtlump_t *textmap = vres_Find(virt, "TEXTMAP");
// Count map data.
if (textmap)
{
nummapthings = 0;
numlines = 0;
numsides = 0;
numvertexes = 0;
numsectors = 0;
// Count how many entries for each type we got in textmap.
if (textmap) // Count how many entries for each type we got in textmap.
TextmapCount(textmap->data, textmap->size);
}
else
{
virtthings = vres_Find(virt, "THINGS");