qbsp: implement the clustermap for PRT2 files

Now that I've done this I realise there could be a more compact
representation by just specifying the number of leafs per cluster, since
leaves are sequentially numbered... but this format is okay as well. And
easy to parse, etc.

Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
This commit is contained in:
Kevin Shanahan 2013-02-24 12:35:33 +10:30
parent 0835b01da5
commit 15ab7386ff
3 changed files with 34 additions and 1 deletions

View File

@ -146,4 +146,5 @@ const char *rgszErrors[cErrors] = {
"Clipnodes in map exceed " stringify(MAX_BSP_CLIPNODES),
"Internal error: bad texture coordinate style",
"Internal error: brush count mismatched during map file parsing",
"Internal error: Detail cluster mismatch",
};

View File

@ -136,6 +136,32 @@ WritePortals_r(node_t *node, bool clusters)
}
}
static int
WriteClusters_r(node_t *node, int viscluster)
{
if (!node->contents) {
viscluster = WriteClusters_r(node->children[0], viscluster);
viscluster = WriteClusters_r(node->children[1], viscluster);
return viscluster;
}
if (node->contents == CONTENTS_SOLID)
return viscluster;
/* If we're in the next cluster, start a new line */
if (node->viscluster != viscluster) {
fprintf(PortalFile, "\n");
viscluster++;
}
/* Sanity check */
if (node->viscluster != viscluster)
Error(errDetailClusterMismatch);
fprintf(PortalFile, "%d ", node->visleafnum);
return viscluster;
}
/*
================
NumberLeafs_r
@ -190,6 +216,8 @@ WritePortalfile
static void
WritePortalfile(node_t *headnode)
{
int check;
/*
* Set the visleafnum and viscluster field in every leaf and count the
* total number of portals.
@ -219,7 +247,10 @@ WritePortalfile(node_t *headnode)
fprintf(PortalFile, "%i\n", num_visclusters);
fprintf(PortalFile, "%i\n", num_visportals);
WritePortals_r(headnode, true);
fprintf(PortalFile, "CLUSTERMAP NOT YET IMPLEMENTED\n");
check = WriteClusters_r(headnode, 0);
if (check != num_visclusters - 1)
Error(errDetailClusterMismatch);
fprintf(PortalFile, "\n");
}
fclose(PortalFile);

View File

@ -112,5 +112,6 @@ enum {
errTooManyClipnodes,
errBadTXStyle, // 60
errLowMapbrushCount,
errDetailClusterMismatch,
cErrors
};