Rename some variables and remove some comments.

The old variable names were confusing ("target" winding comes from
"portal"?), and the comments were from when I really didn't understand
concepts like separating planes. While they weren't wrong, they were quite
inadequate and I want to write new ones.
This commit is contained in:
Bill Currie 2013-03-17 21:52:08 +09:00
parent ccc432a7ea
commit ad247fa12d

View file

@ -135,8 +135,9 @@ test_zero (float d)
and enclosed by the planes is on the front side of the planes. and enclosed by the planes is on the front side of the planes.
*/ */
static sep_t * static sep_t *
FindSeparators (threaddata_t *thread, winding_t *source, const plane_t src_pl, FindSeparators (threaddata_t *thread,
winding_t *pass, int flip) const winding_t *source, const plane_t src_pl,
const winding_t *pass, int flip)
{ {
float d; float d;
int i, j, k, l; int i, j, k, l;
@ -276,9 +277,11 @@ RecursiveClusterFlow (int clusternum, threaddata_t *thread, pstack_t *prevstack)
const set_t *test, *vis; const set_t *test, *vis;
cluster_t *cluster; cluster_t *cluster;
pstack_t *stack; pstack_t *stack;
portal_t *portal; portal_t *target_portal;
plane_t backplane; plane_t backplane;
winding_t *source, *target; const plane_t *source_plane, *pass_plane;
const winding_t *pass_winding;
winding_t *source_winding, *target_winding;
thread->stats.chains++; thread->stats.chains++;
@ -304,57 +307,63 @@ RecursiveClusterFlow (int clusternum, threaddata_t *thread, pstack_t *prevstack)
might = &stack->mightsee; might = &stack->mightsee;
vis = thread->clustervis; vis = thread->clustervis;
source_plane = &thread->pstack_head->pass_plane;
pass_winding = prevstack->pass_winding;
pass_plane = &prevstack->pass_plane;
// check all portals for flowing into other clusters // check all portals for flowing into other clusters
for (i = 0; i < cluster->numportals; i++) { for (i = 0; i < cluster->numportals; i++) {
portal = cluster->portals[i]; target_portal = cluster->portals[i];
if (!set_is_member (&prevstack->mightsee, portal->cluster)) if (!set_is_member (&prevstack->mightsee, target_portal->cluster))
continue; // can't possibly see it continue; // can't possibly see it
// if the portal can't see anything we haven't already seen, skip it // if target_portal can't see anything we haven't already seen, skip it
test = select_test_set (portal, thread); test = select_test_set (target_portal, thread);
if (!mightsee_more (might, &prevstack->mightsee, test, vis)) { if (!mightsee_more (might, &prevstack->mightsee, test, vis)) {
// can't see anything new // can't see anything new
continue; continue;
} }
// get plane of portal, point normal into the neighbor cluster // get plane of target_portal, point normal into the neighbor cluster
VectorNegate (portal->plane.normal, backplane.normal); VectorNegate (target_portal->plane.normal, backplane.normal);
backplane.dist = -portal->plane.dist; backplane.dist = -target_portal->plane.dist;
if (_VectorCompare (prevstack->pass_plane.normal, backplane.normal)) if (_VectorCompare (pass_plane->normal, backplane.normal))
continue; // can't go out a coplanar face continue; // can't go out a coplanar face
thread->stats.portalcheck++; thread->stats.portalcheck++;
target = ClipWinding (portal->winding, target_winding = target_portal->winding;
&thread->pstack_head->pass_plane, false); target_winding = ClipWinding (target_winding, source_plane, false);
if (!target) if (!target_winding)
continue; continue;
if (!prevstack->pass_winding) { if (!pass_winding) {
// the second cluster can be blocked only if coplanar // the second cluster can be blocked only if coplanar
stack->source_winding = prevstack->source_winding; stack->source_winding = prevstack->source_winding;
stack->pass_winding = target;
stack->pass_plane = portal->plane; stack->pass_winding = target_winding;
stack->pass_portal = portal; stack->pass_plane = target_portal->plane;
stack->pass_portal = target_portal;
RecursiveClusterFlow (portal->cluster, thread, stack); RecursiveClusterFlow (target_portal->cluster, thread, stack);
FreeWinding (target); FreeWinding (target_winding);
continue; continue;
} }
target = ClipWinding (target, &prevstack->pass_plane, false); target_winding = ClipWinding (target_winding, pass_plane, false);
if (!target) if (!target_winding)
continue; continue;
source = CopyWinding (prevstack->source_winding); // copy source_winding because it likely is already a copy and thus
// if it gets clipped away, earlier stack levels will get corrupted
source_winding = CopyWinding (prevstack->source_winding);
source = ClipWinding (source, &backplane, false); source_winding = ClipWinding (source_winding, &backplane, false);
if (!source) { if (!source_winding) {
FreeWinding (target); FreeWinding (target_winding);
continue; continue;
} }
@ -362,94 +371,88 @@ RecursiveClusterFlow (int clusternum, threaddata_t *thread, pstack_t *prevstack)
thread->stats.targettested++; thread->stats.targettested++;
if (options.level > 0) { if (options.level > 0) {
// clip target to the image that would be formed by a laser winding_t *old = target_winding;
// pointing from the edges of source passing though the corners of
// pass_winding
winding_t *old = target;
if (!stack->separators[0]) if (!stack->separators[0])
stack->separators[0] = FindSeparators (thread, source, stack->separators[0] = FindSeparators (thread,
thread->pstack_head->pass_plane, source_winding,
prevstack->pass_winding, 0); *source_plane,
target = ClipToSeparators (stack->separators[0], target); pass_winding, 0);
if (!target) { target_winding = ClipToSeparators (stack->separators[0],
target_winding);
if (!target_winding) {
thread->stats.targetclipped++; thread->stats.targetclipped++;
FreeWinding (source); FreeWinding (source_winding);
continue; continue;
} }
if (target != old) if (target_winding != old)
thread->stats.targettrimmed++; thread->stats.targettrimmed++;
} }
if (options.level > 1) { if (options.level > 1) {
// now pass the laser along the edges of pass_winding from the corners of winding_t *old = target_winding;
// source. the resulting image will have a smaller aree. The
// resulting shape will be the light image produced by a backlit
// source shining past pass_winding. eg, if source and pass_winding are equilateral
// triangles rotated 60 (or 180) degrees relative to each other,
// parallel and in line, target will wind up being a hexagon.
winding_t *old = target;
if (!stack->separators[1]) if (!stack->separators[1])
stack->separators[1] = FindSeparators (thread, prevstack->pass_winding, stack->separators[1] = FindSeparators (thread,
prevstack->pass_plane, pass_winding,
source, 1); *pass_plane,
target = ClipToSeparators (stack->separators[1], target); source_winding, 1);
if (!target) { target_winding = ClipToSeparators (stack->separators[1],
target_winding);
if (!target_winding) {
thread->stats.targetclipped++; thread->stats.targetclipped++;
FreeWinding (source); FreeWinding (source_winding);
continue; continue;
} }
if (target != old) if (target_winding != old)
thread->stats.targettrimmed++; thread->stats.targettrimmed++;
} }
thread->stats.sourcetested++; thread->stats.sourcetested++;
// now do the same as for levels 1 and 2, but trimming source using
// the trimmed target
if (options.level > 2) { if (options.level > 2) {
winding_t *old = source; winding_t *old = source_winding;
sep_t *sep; sep_t *sep;
sep = FindSeparators (thread, target, portal->plane, sep = FindSeparators (thread,
prevstack->pass_winding, 0); target_winding, target_portal->plane,
source = ClipToSeparators (sep, source); pass_winding, 0);
source_winding = ClipToSeparators (sep, source_winding);
free_separators (thread, sep); free_separators (thread, sep);
if (!source) { if (!source_winding) {
thread->stats.sourceclipped++; thread->stats.sourceclipped++;
FreeWinding (target); FreeWinding (target_winding);
continue; continue;
} }
if (source != old) if (source_winding != old)
thread->stats.sourcetrimmed++; thread->stats.sourcetrimmed++;
} }
if (options.level > 3) { if (options.level > 3) {
winding_t *old = source; winding_t *old = source_winding;
sep_t *sep; sep_t *sep;
sep = FindSeparators (thread, prevstack->pass_winding, sep = FindSeparators (thread, pass_winding, *pass_plane,
prevstack->pass_plane, target, 1); target_winding, 1);
source = ClipToSeparators (sep, source); source_winding = ClipToSeparators (sep, source_winding);
free_separators (thread, sep); free_separators (thread, sep);
if (!source) { if (!source_winding) {
thread->stats.sourceclipped++; thread->stats.sourceclipped++;
FreeWinding (target); FreeWinding (target_winding);
continue; continue;
} }
if (source != old) if (source_winding != old)
thread->stats.sourcetrimmed++; thread->stats.sourcetrimmed++;
} }
stack->source_winding = source; stack->source_winding = source_winding;
stack->pass_winding = target; stack->pass_winding = target_winding;
stack->pass_plane = portal->plane; stack->pass_plane = target_portal->plane;
stack->pass_portal = portal; stack->pass_portal = target_portal;
thread->stats.portalpass++; thread->stats.portalpass++;
// flow through it for real // flow through it for real
RecursiveClusterFlow (portal->cluster, thread, stack); RecursiveClusterFlow (target_portal->cluster, thread, stack);
FreeWinding (source); FreeWinding (source_winding);
FreeWinding (target); FreeWinding (target_winding);
} }
free_separators (thread, stack->separators[1]); free_separators (thread, stack->separators[1]);
free_separators (thread, stack->separators[0]); free_separators (thread, stack->separators[0]);