Merge branch 'xgl2' into 'next'

Implement support for ZDoom GL2 nodes

See merge request STJr/SRB2!2474
This commit is contained in:
sphere 2024-06-07 13:28:17 +00:00
commit 3d4ab0279f

View file

@ -3449,13 +3449,13 @@ typedef enum {
} nodetype_t; } nodetype_t;
// Find out the BSP format. // Find out the BSP format.
static nodetype_t P_GetNodetype(const virtres_t *virt, UINT8 **nodedata) static nodetype_t P_GetNodetype(const virtres_t *virt, UINT8 **nodedata, char signature[4 + 1])
{ {
boolean supported[NUMNODETYPES] = {0}; boolean supported[NUMNODETYPES] = {0};
nodetype_t nodetype = NT_UNSUPPORTED; nodetype_t nodetype = NT_UNSUPPORTED;
char signature[4 + 1];
*nodedata = NULL; *nodedata = NULL;
signature[0] = signature[4] = '\0';
if (udmf) if (udmf)
{ {
@ -3464,7 +3464,7 @@ static nodetype_t P_GetNodetype(const virtres_t *virt, UINT8 **nodedata)
if (virtznodes && virtznodes->size) if (virtznodes && virtznodes->size)
{ {
*nodedata = virtznodes->data; *nodedata = virtznodes->data;
supported[NT_XGLN] = supported[NT_XGL3] = true; supported[NT_XGLN] = supported[NT_XGL2] = supported[NT_XGL3] = true;
} }
} }
else else
@ -3486,9 +3486,9 @@ static nodetype_t P_GetNodetype(const virtres_t *virt, UINT8 **nodedata)
virtssectors = vres_Find(virt, "SSECTORS"); virtssectors = vres_Find(virt, "SSECTORS");
if (virtssectors && virtssectors->size) if (virtssectors && virtssectors->size)
{ // Possibly GL nodes: NODES ignored, SSECTORS takes precedence as nodes lump, (It is confusing yeah) and has a signature. { // Possibly GL nodes: NODES ignored, SSECTORS takes precedence as nodes lump (it is confusing, yeah), and has a signature.
*nodedata = virtssectors->data; *nodedata = virtssectors->data;
supported[NT_XGLN] = supported[NT_ZGLN] = supported[NT_XGL3] = true; supported[NT_XGLN] = supported[NT_ZGLN] = supported[NT_XGL2] = supported[NT_XGL3] = true;
} }
else else
{ // Possibly ZDoom extended nodes: SSECTORS is empty, NODES has a signature. { // Possibly ZDoom extended nodes: SSECTORS is empty, NODES has a signature.
@ -3508,19 +3508,42 @@ static nodetype_t P_GetNodetype(const virtres_t *virt, UINT8 **nodedata)
} }
M_Memcpy(signature, *nodedata, 4); M_Memcpy(signature, *nodedata, 4);
signature[4] = '\0';
(*nodedata) += 4; (*nodedata) += 4;
if (!strcmp(signature, "XNOD")) // Identify node format from its starting signature.
nodetype = NT_XNOD; if (memcmp(&signature[1], "NOD", 3) == 0) // ZDoom extended nodes
else if (!strcmp(signature, "ZNOD")) {
nodetype = NT_ZNOD; if (signature[0] == 'X')
else if (!strcmp(signature, "XGLN")) {
nodetype = NT_XGLN; nodetype = NT_XNOD; // Uncompressed
else if (!strcmp(signature, "ZGLN")) }
nodetype = NT_ZGLN; else if (signature[0] == 'Z')
else if (!strcmp(signature, "XGL3")) {
nodetype = NT_XGL3; nodetype = NT_ZNOD; // Compressed
}
}
else if (memcmp(&signature[1], "GL", 2) == 0) // GL nodes
{
switch (signature[0])
{
case 'X': // Uncompressed
switch (signature[3])
{
case 'N': nodetype = NT_XGLN; break; // GL nodes
case '2': nodetype = NT_XGL2; break; // Version 2 GL nodes
case '3': nodetype = NT_XGL3; break; // Version 3 GL nodes
}
break;
case 'Z': // Compressed
switch (signature[3])
{
case 'N': nodetype = NT_ZGLN; break; // GL nodes (compressed)
case '2': nodetype = NT_ZGL2; break; // Version 2 GL nodes (compressed)
case '3': nodetype = NT_ZGL3; break; // Version 3 GL nodes (compressed)
}
break;
}
}
return supported[nodetype] ? nodetype : NT_UNSUPPORTED; return supported[nodetype] ? nodetype : NT_UNSUPPORTED;
} }
@ -3588,6 +3611,7 @@ static boolean P_LoadExtendedSubsectorsAndSegs(UINT8 **data, nodetype_t nodetype
switch (nodetype) switch (nodetype)
{ {
case NT_XGLN: case NT_XGLN:
case NT_XGL2:
case NT_XGL3: case NT_XGL3:
for (m = 0; m < (size_t)subsectors[i].numlines; m++, k++) for (m = 0; m < (size_t)subsectors[i].numlines; m++, k++)
{ {
@ -3599,7 +3623,7 @@ static boolean P_LoadExtendedSubsectorsAndSegs(UINT8 **data, nodetype_t nodetype
READUINT32((*data)); // partner, can be ignored by software renderer READUINT32((*data)); // partner, can be ignored by software renderer
if (nodetype == NT_XGL3) if (nodetype != NT_XGLN)
{ {
UINT32 linenum = READUINT32((*data)); UINT32 linenum = READUINT32((*data));
if (linenum != 0xFFFFFFFF && linenum >= numlines) if (linenum != 0xFFFFFFFF && linenum >= numlines)
@ -3710,8 +3734,9 @@ static void P_LoadExtendedNodes(UINT8 **data, nodetype_t nodetype)
static void P_LoadMapBSP(const virtres_t *virt) static void P_LoadMapBSP(const virtres_t *virt)
{ {
char signature[4 + 1];
UINT8 *nodedata = NULL; UINT8 *nodedata = NULL;
nodetype_t nodetype = P_GetNodetype(virt, &nodedata); nodetype_t nodetype = P_GetNodetype(virt, &nodedata, signature);
switch (nodetype) switch (nodetype)
{ {
@ -3743,6 +3768,7 @@ static void P_LoadMapBSP(const virtres_t *virt)
} }
case NT_XNOD: case NT_XNOD:
case NT_XGLN: case NT_XGLN:
case NT_XGL2:
case NT_XGL3: case NT_XGL3:
if (!P_LoadExtraVertices(&nodedata)) if (!P_LoadExtraVertices(&nodedata))
return; return;
@ -3751,10 +3777,13 @@ static void P_LoadMapBSP(const virtres_t *virt)
P_LoadExtendedNodes(&nodedata, nodetype); P_LoadExtendedNodes(&nodedata, nodetype);
break; break;
default: default:
CONS_Alert(CONS_WARNING, "Unsupported BSP format detected.\n"); if (isprint(signature[0]) && isprint(signature[1]) && isprint(signature[2]) && isprint(signature[3]))
{
I_Error("Unsupported BSP format '%s' detected!\n", signature);
return; return;
} }
return; I_Error("Unknown BSP format detected!\n");
}
} }
// Split from P_LoadBlockMap for convenience // Split from P_LoadBlockMap for convenience