Esempio n. 1
0
/*
   ===============
   ClusterMerge

   Merges the portal visibility for a leaf
   ===============
 */
void ClusterMerge( int leafnum ){
	leaf_t      *leaf;
	byte portalvector[MAX_PORTALS / 8];
	byte uncompressed[MAX_MAP_LEAFS / 8];
	byte compressed[MAX_MAP_LEAFS / 8];
	int i, j;
	int numvis;
	byte        *dest;
	portal_t    *p;
	int pnum;

	// OR together all the portalvis bits

	memset( portalvector, 0, portalbytes );
	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 < portallongs ; j++ )
			( (long *)portalvector )[j] |= ( (long *)p->portalvis )[j];
		pnum = p - portals;
		portalvector[pnum >> 3] |= 1 << ( pnum & 7 );
	}

	// convert portal bits to leaf bits
	numvis = LeafVectorFromPortalVector( portalvector, uncompressed );

	if ( uncompressed[leafnum >> 3] & ( 1 << ( leafnum & 7 ) ) ) {
		Sys_Printf( "WARNING: Leaf portals saw into leaf\n" );
	}

	uncompressed[leafnum >> 3] |= ( 1 << ( leafnum & 7 ) );
	numvis++;       // count the leaf itself

	// save uncompressed for PHS calculation
	memcpy( uncompressedvis + leafnum * leafbytes, uncompressed, leafbytes );

//
// compress the bit string
//
	Sys_FPrintf( SYS_VRB, "cluster %4i : %4i visible\n", leafnum, numvis );
	totalvis += numvis;

	i = CompressVis( uncompressed, compressed );

	dest = vismap_p;
	vismap_p += i;

	if ( vismap_p > vismap_end ) {
		Error( "Vismap expansion overflow" );
	}

	dvis->bitofs[leafnum][DVIS_PVS] = dest - vismap;

	memcpy( dest, compressed, i );
}
Esempio n. 2
0
/*
 * @brief Merges the portal visibility for a leaf.
 */
static void ClusterMerge(uint32_t leaf_num) {
	leaf_t *leaf;
	byte portalvector[MAX_BSP_PORTALS / 8];
	byte uncompressed[MAX_BSP_LEAFS / 8];
	byte compressed[MAX_BSP_LEAFS / 8];
	uint32_t i, j;
	int32_t numvis;
	byte *dest;
	portal_t *p;
	int32_t pnum;

	if (map_vis.portal_bytes > sizeof(portalvector)) {
		Com_Error(ERR_FATAL, "VIS overflow. Try making more brushes CONTENTS_DETAIL.\n");
	}

	// OR together all the portal vis bits
	memset(portalvector, 0, map_vis.portal_bytes);
	leaf = &map_vis.leafs[leaf_num];
	for (i = 0; i < leaf->num_portals; i++) {
		p = leaf->portals[i];
		if (p->status != stat_done)
			Com_Error(ERR_FATAL, "Portal not done\n");
		for (j = 0; j < map_vis.portal_longs; j++)
			((long *) portalvector)[j] |= ((long *) p->vis)[j];
		pnum = p - map_vis.portals;
		portalvector[pnum >> 3] |= 1 << (pnum & 7);
	}

	// convert portal bits to leaf bits
	numvis = LeafVectorFromPortalVector(portalvector, uncompressed);

	if (uncompressed[leaf_num >> 3] & (1 << (leaf_num & 7))) {
		Com_Warn("Leaf portals saw into leaf\n");
	}

	uncompressed[leaf_num >> 3] |= (1 << (leaf_num & 7));
	numvis++; // count the leaf itself

	// save uncompressed for PHS calculation
	memcpy(map_vis.uncompressed + leaf_num * map_vis.leaf_bytes, uncompressed, map_vis.leaf_bytes);

	// compress the bit string
	Com_Debug("Cluster %4i : %4i visible\n", leaf_num, numvis);
	visibility_count += numvis;

	i = CompressVis(uncompressed, compressed);

	dest = map_vis.pointer;
	map_vis.pointer += i;

	if (map_vis.pointer > map_vis.end)
		Com_Error(ERR_FATAL, "VIS expansion overflow\n");

	d_vis->bit_offsets[leaf_num][DVIS_PVS] = dest - map_vis.base;

	memcpy(dest, compressed, i);
}
Esempio n. 3
0
/*
   ===============
   ClusterMerge

   Merges the portal visibility for a leaf
   ===============
 */
void ClusterMerge( int leafnum ){
	leaf_t      *leaf;
	byte portalvector[MAX_PORTALS / 8];
	byte uncompressed[MAX_MAP_LEAFS / 8];
	int i, j;
	int numvis, mergedleafnum;
	vportal_t   *p;
	int pnum;

	// OR together all the portalvis bits

	mergedleafnum = leafnum;
	while ( leafs[mergedleafnum].merged >= 0 )
		mergedleafnum = leafs[mergedleafnum].merged;

	memset( portalvector, 0, portalbytes );
	leaf = &leafs[mergedleafnum];
	for ( i = 0; i < leaf->numportals; i++ )
	{
		p = leaf->portals[i];
		if ( p->removed ) {
			continue;
		}

		if ( p->status != stat_done ) {
			Error( "portal not done" );
		}
		for ( j = 0 ; j < portallongs ; j++ )
			( (long *)portalvector )[j] |= ( (long *)p->portalvis )[j];
		pnum = p - portals;
		portalvector[pnum >> 3] |= 1 << ( pnum & 7 );
	}

	memset( uncompressed, 0, leafbytes );

	uncompressed[mergedleafnum >> 3] |= ( 1 << ( mergedleafnum & 7 ) );
	// convert portal bits to leaf bits
	numvis = LeafVectorFromPortalVector( portalvector, uncompressed );

//	if (uncompressed[leafnum>>3] & (1<<(leafnum&7)))
//		Sys_Printf ("WARNING: Leaf portals saw into leaf\n");

//	uncompressed[leafnum>>3] |= (1<<(leafnum&7));

	numvis++;       // count the leaf itself

	totalvis += numvis;

	Sys_FPrintf( SYS_VRB,"cluster %4i : %4i visible\n", leafnum, numvis );

	memcpy( bspVisBytes + VIS_HEADER_SIZE + leafnum * leafbytes, uncompressed, leafbytes );
}
Esempio n. 4
0
/*
===============
ClusterMerge

Merges the portal visibility for a leaf
===============
*/
void ClusterMerge (int clusternum)
{
    leaf_t		*leaf;
//	byte		portalvector[MAX_PORTALS/8];
    byte		portalvector[MAX_PORTALS/4];      // 4 because portal bytes is * 2
    byte		uncompressed[MAX_MAP_LEAFS/8];
    int			i, j;
    int			numvis;
    portal_t	*p;
    int			pnum;

    // OR together all the portalvis bits

    memset (portalvector, 0, portalbytes);
    leaf = &leafs[clusternum];
    for (i=0 ; i<leaf->numportals ; i++)
    {
        p = leaf->portals[i];
        if (p->status != stat_done)
            Error ("portal not done %d %d %d\n", i, p, portals);
        for (j=0 ; j<portallongs ; j++)
            ((long *)portalvector)[j] |= ((long *)p->portalvis)[j];
        pnum = p - portals;
        SetBit( portalvector, pnum );
    }

    // convert portal bits to leaf bits
    numvis = LeafVectorFromPortalVector (portalvector, uncompressed);

    if ( CheckBit( uncompressed, clusternum ) )
        Warning("WARNING: Cluster portals saw into cluster\n");

    SetBit( uncompressed, clusternum );
    numvis++;		// count the leaf itself

    // save uncompressed for PHS calculation
    memcpy (uncompressedvis + clusternum*leafbytes, uncompressed, leafbytes);

    qprintf ("cluster %4i : %4i visible\n", clusternum, numvis);
    totalvis += numvis;
}