void LeafFlow (int leafnum) { leaf_t *leaf; byte *outbuffer; byte compressed[MAX_MAP_LEAFS/8]; int i, j; int numvis; byte *dest; portal_t *p; // // flow through all portals, collecting visible bits // outbuffer = uncompressed + leafnum*bitbytes; leaf = &leafs[leafnum]; for (i=0 ; i<leaf->numportals ; i++) { p = leaf->portals[i]; if (p->status != stat_done) Error ("portal not done"); for (j=0 ; j<bitbytes ; j++) outbuffer[j] |= p->visbits[j]; } if (outbuffer[leafnum>>3] & (1<<(leafnum&7))) Error ("Leaf portals saw into leaf"); outbuffer[leafnum>>3] |= (1<<(leafnum&7)); numvis = 0; for (i=0 ; i<portalleafs ; i++) if (outbuffer[i>>3] & (1<<(i&3))) numvis++; // // compress the bit string // if (verbose) printf ("leaf %4i : %4i visible\n", leafnum, numvis); totalvis += numvis; #if 0 i = (portalleafs+7)>>3; memcpy (compressed, outbuffer, i); #else i = CompressRow (outbuffer, compressed); #endif dest = vismap_p; vismap_p += i; if (vismap_p > vismap_end) Error ("Vismap expansion overflow"); dleafs[leafnum+1].visofs = dest-vismap; // leaf 0 is a common solid memcpy (dest, compressed, i); }
/* ClusterFlow Builds the entire visibility list for a cluster */ void ClusterFlow (int clusternum) { byte compressed[MAX_MAP_LEAFS / 8]; byte *outbuffer; int numvis, i, j; cluster_t *cluster; portal_t *portal; outbuffer = uncompressed + clusternum * bitbytes_l; cluster = &clusters[clusternum]; // flow through all portals, collecting visible bits memset (compressed, 0, sizeof (compressed)); for (i = 0; i < cluster->numportals; i++) { portal = cluster->portals[i]; if (portal->status != stat_done) Sys_Error ("portal not done"); for (j = 0; j < bitbytes; j++) compressed[j] |= portal->visbits[j]; } if (compressed[clusternum >> 3] & (1 << (clusternum & 7))) Sys_Error ("Cluster portals saw into cluster"); compressed[clusternum >> 3] |= (1 << (clusternum & 7)); numvis = 0; for (i = 0; i < portalclusters; i++) if (compressed[i >> 3] & (1 << (i & 3))) numvis++; // expand to cluster->leaf PVS ClusterFlowExpand (compressed, outbuffer); // compress the bit string if (options.verbosity > 0) printf ("cluster %4i : %4i visible\n", clusternum, numvis); totalvis += numvis; i = CompressRow (outbuffer, compressed); cluster->visofs = visdata->size; dstring_append (visdata, (char *) compressed, i); }