From 5a4499dc48dc67c7ffce27e47cb6c8f37a87bbee Mon Sep 17 00:00:00 2001 From: Tyrann Date: Sun, 19 Aug 2007 20:17:23 +0930 Subject: [PATCH] [PATCH] qbsp: select better non-axial split planes Make ChooseMidPlaneFromList a bit more picky about the non-axial planes it selects. This can matter a lot for maps which have a lot of non-axial-aligned brushwork (e.g. terrain, etc.) The number of clipnodes can skyrocket if planes are not chosen with at least a small amount of care. Signed-off-by: Tyrann --- qbsp/solidbsp.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/qbsp/solidbsp.c b/qbsp/solidbsp.c index ef75744c..2c36d3b6 100644 --- a/qbsp/solidbsp.c +++ b/qbsp/solidbsp.c @@ -243,11 +243,21 @@ ChooseMidPlaneFromList(surface_t *surfaces, vec3_t mins, vec3_t maxs) } if (!bestsurface) { - for (p = surfaces; p; p = p->next) - if (!p->onnode) - return p; // first valid surface - Message(msgError, errNoValidPlanes); + /* Choose based on spatial subdivision again */ + for (p = surfaces; p; p = p->next) { + if (p->onnode) + continue; + + plane = &pPlanes[p->planenum]; + value = SplitPlaneMetric(plane, mins, maxs); + if (value < bestvalue) { + bestvalue = value; + bestsurface = p; + } + } } + if (!bestsurface) + Message(msgError, errNoValidPlanes); return bestsurface; }