Use sphere culling in the base vis.

Base vis was done first for testing. Optimized base vis is down to ~12.4s
from ~16s (29% faster?).
This commit is contained in:
Bill Currie 2013-03-13 21:32:18 +09:00
parent 7753583bfd
commit b9d71218f6
3 changed files with 32 additions and 0 deletions

View file

@ -69,6 +69,7 @@ typedef enum {
typedef struct {
plane_t plane; // normal pointing into neighbor
int cluster; // neighbor
sphere_t sphere; // bounding sphere
winding_t *winding;
vstatus_t status;
set_t *visbits;

View file

@ -86,6 +86,20 @@ SimpleFlood (portal_t *srcportal, int clusternum)
}
}
static inline int
test_sphere (sphere_t *sphere, plane_t *plane, int test_front)
{
float d;
int pass;
d = DotProduct (sphere->center, plane->normal) - plane->dist;
if (test_front)
pass = (d >= -sphere->radius);
else
pass = (d <= sphere->radius);
return pass;
}
void
BasePortalVis (void)
{
@ -93,7 +107,10 @@ BasePortalVis (void)
float d;
portal_t *tp, *portal;
winding_t *winding;
int base_mightsee = 0;
double start, end;
start = Sys_DoubleTime ();
portalsee = set_new_size (numportals * 2);
for (i = 0, portal = portals; i < numportals * 2; i++, portal++) {
portal->mightsee = set_new_size (portalclusters);
@ -104,6 +121,11 @@ BasePortalVis (void)
if (j == i)
continue;
if (!test_sphere (&tp->sphere, &portal->plane, 1))
continue; // entirely behind
if (!test_sphere (&portal->sphere, &tp->plane, 0))
continue; // entirely behind
winding = tp->winding;
for (k = 0; k < winding->numpoints; k++) {
d = DotProduct (winding->points[k],
@ -130,6 +152,10 @@ BasePortalVis (void)
clustersee = 0;
SimpleFlood (portal, portal->cluster);
portal->nummightsee = clustersee;
base_mightsee += clustersee;
}
set_delete (portalsee);
end = Sys_DoubleTime ();
if (options.verbosity > 0)
printf ("base_mightsee: %d %gs\n", base_mightsee, end - start);
}

View file

@ -765,6 +765,7 @@ LoadPortals (char *name)
plane_t plane;
portal_t *portal;
winding_t *winding;
sphere_t sphere;
QFile *f;
if (!strcmp (name, "-"))
@ -884,6 +885,8 @@ LoadPortals (char *name)
// calc plane
PlaneFromWinding (winding, &plane);
sphere = SmallestEnclosingBall((const vec_t(*)[3])winding->points,
winding->numpoints);
// create forward portal
cluster = &clusters[clusternums[0]];
@ -896,6 +899,7 @@ LoadPortals (char *name)
VectorNegate (plane.normal, portal->plane.normal);
portal->plane.dist = -plane.dist;
portal->cluster = clusternums[1];
portal->sphere = sphere;
portal++;
// create backwards portal
@ -908,6 +912,7 @@ LoadPortals (char *name)
portal->winding = winding;
portal->plane = plane;
portal->cluster = clusternums[0];
portal->sphere = sphere;
portal++;
}