diff --git a/qbsp/globals.c b/qbsp/globals.c index 95b88c9c..5421f7cc 100644 --- a/qbsp/globals.c +++ b/qbsp/globals.c @@ -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", }; diff --git a/qbsp/portals.c b/qbsp/portals.c index c4411531..c5fbaa1e 100644 --- a/qbsp/portals.c +++ b/qbsp/portals.c @@ -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); diff --git a/qbsp/warnerr.h b/qbsp/warnerr.h index 377fac3d..d83d9764 100644 --- a/qbsp/warnerr.h +++ b/qbsp/warnerr.h @@ -112,5 +112,6 @@ enum { errTooManyClipnodes, errBadTXStyle, // 60 errLowMapbrushCount, + errDetailClusterMismatch, cErrors };