From 744f5422030eaa1e8b72371a6e28eddf763c38bc Mon Sep 17 00:00:00 2001 From: Kevin Shanahan Date: Wed, 6 Mar 2013 09:41:15 +1030 Subject: [PATCH] qbsp: fix handling of leak files Previously, leak files would only be written for a leak in hull 2. This is actually pretty bad because a small leak in hull 0 or 1 might not show up in hull 2 and you would never get a leak file to chase it down. Place a flag in the global mapdata to indicate whether we have written a leak file or not so we only write for the first hull that leaks. Hullnum is no longer needed as a parameter to RecursiveFillOutside, so remove that from the fillparms struct. Signed-off-by: Kevin Shanahan --- changelog.txt | 1 + qbsp/outside.c | 59 ++++++++++++++++++++++++++------------------------ qbsp/qbsp.h | 1 + 3 files changed, 33 insertions(+), 28 deletions(-) diff --git a/changelog.txt b/changelog.txt index c0962c14..63bea1e6 100644 --- a/changelog.txt +++ b/changelog.txt @@ -4,6 +4,7 @@ * qbsp: support for Valve's 220 map format used in later Worldcraft/Hammer * qbsp: support func_group entities used by Radiant and similar editors * qbsp: surfaces with the skip texture are now removed from the compiled bsp +* qbsp: fixed a problem where leak files were not written for hull0 or hull1 * light: fixed a race condition in multithreaded coloured light processing * light: fixed bug preventing use of all 4 light styles in a common case * light: implemented attenutation formulae "delay" 4+5, ala Bengt's tools diff --git a/qbsp/outside.c b/qbsp/outside.c index 76a73127..ffd1b593 100644 --- a/qbsp/outside.c +++ b/qbsp/outside.c @@ -29,7 +29,6 @@ typedef struct { typedef struct { bool fill; - int hullnum; int fillmark; int numportals; } fillparms_t; @@ -334,6 +333,7 @@ RecursiveFillOutside(fillstate_t *state, const fillparms_t *parms, node_t *node) { portal_t *p; int side; + bool leak; if (node->contents == CONTENTS_SOLID || node->contents == CONTENTS_SKY) return false; @@ -358,11 +358,11 @@ RecursiveFillOutside(fillstate_t *state, const fillparms_t *parms, node_t *node) for (p = node->portals; p; p = p->next[!side]) { side = (p->nodes[0] == node); - if (RecursiveFillOutside(state, parms, p->nodes[side])) { - /* leaked, so stop filling */ + leak = RecursiveFillOutside(state, parms, p->nodes[side]); + if (leak) { if (state->backdraw) { state->backdraw--; - if (parms->hullnum == 2) /* FIXME!!! */ + if (!map.leakfile) MarkLeakTrail(p, state->hit_occupied, parms->numportals); } return true; @@ -413,7 +413,7 @@ FillOutside(node_t *node, const int hullnum, const int numportals) int side; vec_t *v; int i; - bool inside; + bool inside, leak; fillstate_t fillstate; fillparms_t fillparms; const mapentity_t *entity; @@ -439,7 +439,7 @@ FillOutside(node_t *node, const int hullnum, const int numportals) return false; } - if (hullnum == 2) { + if (!map.leakfile) { pLeaks = AllocMem(OTHER, sizeof(portal_t *) * numportals, true); StripExtension(options.szBSPName); strcat(options.szBSPName, ".pts"); @@ -462,7 +462,6 @@ FillOutside(node_t *node, const int hullnum, const int numportals) } /* Set up state and parameters for the recursive fill */ - fillparms.hullnum = hullnum; fillparms.numportals = numportals; fillstate.outleafs = 0; fillstate.backdraw = 0; @@ -474,35 +473,39 @@ FillOutside(node_t *node, const int hullnum, const int numportals) fillparms.fillmark = ++map.fillmark; side = !(outside_node.portals->nodes[1] == &outside_node); fillnode = outside_node.portals->nodes[side]; - if (RecursiveFillOutside(&fillstate, &fillparms, fillnode)) { + + leak = RecursiveFillOutside(&fillstate, &fillparms, fillnode); + if (leak) { v = map.entities[fillstate.hit_occupied].origin; Message(msgWarning, warnMapLeak, v[0], v[1], v[2]); - if (hullnum == 2) { - if (!options.fOldleak) - SimplifyLeakline(node); + if (map.leakfile) + return false; - // heh slight little kludge thing - StripExtension(options.szBSPName); - Message(msgLiteral, "Leak file written to %s.pts\n", + if (!options.fOldleak) + SimplifyLeakline(node); + + // heh slight little kludge thing + StripExtension(options.szBSPName); + Message(msgLiteral, "Leak file written to %s.pts\n", options.szBSPName); + fclose(LeakFile); + + // Get rid of .prt file if .pts file is generated + strcat(options.szBSPName, ".prt"); + remove(options.szBSPName); + + if (options.fBspleak) { + Message(msgLiteral, "BSP portal file written to %s.por\n", options.szBSPName); - fclose(LeakFile); - - // Get rid of .prt file if .pts file is generated - strcat(options.szBSPName, ".prt"); - remove(options.szBSPName); - - if (options.fBspleak) { - Message(msgLiteral, "BSP portal file written to %s.por\n", - options.szBSPName); - fseek(PorFile, 0, SEEK_SET); - fprintf(PorFile, "%11i", numports); - fclose(PorFile); - } + fseek(PorFile, 0, SEEK_SET); + fprintf(PorFile, "%11i", numports); + fclose(PorFile); } + map.leakfile = true; + return false; } - if (hullnum == 2) { + if (!map.leakfile) { FreeMem(pLeaks, OTHER, sizeof(portal_t *) * numportals); fclose(LeakFile); diff --git a/qbsp/qbsp.h b/qbsp/qbsp.h index 0585fbfa..bfedb194 100644 --- a/qbsp/qbsp.h +++ b/qbsp/qbsp.h @@ -630,6 +630,7 @@ typedef struct mapdata_s { /* Misc other global state for the compile process */ int fillmark; /* For marking leaves while outside filling */ + bool leakfile; /* Flag once we've written a leak (.por/.pts) file */ } mapdata_t; extern mapdata_t map;