From fff12697e5188f1802b27cf3c3cced32a7f00b04 Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Thu, 19 May 2016 15:03:21 -0600 Subject: [PATCH] light: move DicePatch to polylib.c --- common/polylib.c | 49 ++++++++++++++++++++++++++++++++++++++++ include/common/polylib.h | 3 +++ light/light.cc | 46 ------------------------------------- 3 files changed, 52 insertions(+), 46 deletions(-) diff --git a/common/polylib.c b/common/polylib.c index 9d85ac7f..27da6564 100644 --- a/common/polylib.c +++ b/common/polylib.c @@ -418,3 +418,52 @@ CheckWinding(const winding_t * w) } } } + +/* + ============= + DiceWinding + + Chops the winding by a global grid. + Calls save_fn on each subdivided chunk. + Frees w. + + From q3rad (DicePatch) + ============= + */ +void DiceWinding (winding_t *w, vec_t subdiv, save_winding_fn_t save_fn) +{ + winding_t *o1, *o2; + vec3_t mins, maxs; + vec3_t split; + vec_t dist; + int i; + + if (!w) + return; + + WindingBounds (w, mins, maxs); + for (i=0 ; i<3 ; i++) + if (floor((mins[i]+1)/subdiv) < floor((maxs[i]-1)/subdiv)) + break; + if (i == 3) + { + // no splitting needed + save_fn(w); + return; + } + + // + // split the winding + // + VectorCopy (vec3_origin, split); + split[i] = 1; + dist = subdiv*(1+floor((mins[i]+1)/subdiv)); + ClipWinding (w, split, dist, &o1, &o2); + free(w); + + // + // create a new patch + // + DiceWinding(o1, subdiv, save_fn); + DiceWinding(o2, subdiv, save_fn); +} diff --git a/include/common/polylib.h b/include/common/polylib.h index 7f7613a1..076cc967 100644 --- a/include/common/polylib.h +++ b/include/common/polylib.h @@ -28,6 +28,9 @@ void CheckWinding(const winding_t * w); void WindingPlane(const winding_t * w, vec3_t normal, vec_t *dist); void RemoveColinearPoints(winding_t * w); +typedef void (*save_winding_fn_t)(winding_t *w); +void DiceWinding (winding_t *w, vec_t subdiv, save_winding_fn_t save_fn); + #ifdef __cplusplus } #endif diff --git a/light/light.cc b/light/light.cc index c44ccca3..328fdaef 100644 --- a/light/light.cc +++ b/light/light.cc @@ -958,52 +958,6 @@ void SavePatch (const bsp2_t *bsp, const bsp2_dface_t *sourceface, winding_t *w) facenumToPatches[i].push_back(p); } -/* -============= -DicePatch - -Chops the patch by a global grid -From q3rad -============= -*/ -void DicePatch (const bsp2_t *bsp, const bsp2_dface_t *sourceface, winding_t *w, vec_t subdiv) -{ - winding_t *o1, *o2; - vec3_t mins, maxs; - vec3_t split; - vec_t dist; - int i; - - if (!w) - return; - - WindingBounds (w, mins, maxs); - for (i=0 ; i<3 ; i++) - if (floor((mins[i]+1)/subdiv) < floor((maxs[i]-1)/subdiv)) - break; - if (i == 3) - { - // no splitting needed - SavePatch(bsp, sourceface, w); - return; - } - - // - // split the winding - // - VectorCopy (vec3_origin, split); - split[i] = 1; - dist = subdiv*(1+floor((mins[i]+1)/subdiv)); - ClipWinding (w, split, dist, &o1, &o2); - free(w); - - // - // create a new patch - // - DicePatch(bsp, sourceface, o1, subdiv); - DicePatch(bsp, sourceface, o2, subdiv); -} - static void * MakeBounceLightsThread (void *arg) {