|
发表于 2003-10-11 21:46:00
|
显示全部楼层
Re:Who can explane what is PVS
// link to PVS leafs
//PVS = Potentially Visible Set
SV_BuildEntityClusterList( ent );
--
//-----------------------------------------------------------------------------
// Purpose: Builds the cluster list for an entity
// Input : *pEdict -
//-----------------------------------------------------------------------------
void SV_BuildEntityClusterList( edict_t *pEdict )
{
int i, j;
int topnode;
int leafCount;
int leafs[MAX_TOTAL_ENT_LEAFS], clusters[MAX_TOTAL_ENT_LEAFS];
int area;
IServerEntity *serverEntity = pEdict->GetIServerEntity();
Assert( serverEntity );
if ( !serverEntity )
return;
pEdict->clusterCount = 0;
topnode = -1;
pEdict->areanum = 0;
pEdict->areanum2 = 0;
//get all leafs, including solids
leafCount = CM_BoxLeafnums( serverEntity->GetAbsMins(), serverEntity->GetAbsMaxs(), leafs, MAX_TOTAL_ENT_LEAFS, &topnode );
// set areas
for ( i = 0; i < leafCount; i++ )
{
clusters = CM_LeafCluster( leafs );
area = CM_LeafArea( leafs );
if ( area )
{ // doors may legally straggle two areas,
// but nothing should evern need more than that
if ( pEdict->areanum && pEdict->areanum != area )
{
if ( pEdict->areanum2 && pEdict->areanum2 != area && sv.state == ss_loading )
{
Con_DPrintf ("Object touching 3 areas at %f %f %f\n",
serverEntity->GetAbsMins()[0], serverEntity->GetAbsMins()[1], serverEntity->GetAbsMins()[2]);
}
pEdict->areanum2 = area;
}
else
{
pEdict->areanum = area;
}
}
}
pEdict->headnode = topnode; // save headnode
if ( leafCount >= MAX_TOTAL_ENT_LEAFS )
{ // assume we missed some leafs, and mark by headnode
pEdict->clusterCount = -1;
}
else
{
for ( i = 0; i < leafCount; i++ )
{
if (clusters == -1)
continue; // not a visible leaf
for ( j = 0; j < i; j++ )
{
if (clusters[j] == clusters)
break;
}
if ( j == i )
{
if ( pEdict->clusterCount == MAX_ENT_CLUSTERS )
{ // assume we missed some leafs, and mark by headnode
pEdict->clusterCount = -1;
break;
}
pEdict->clusters[pEdict->clusterCount++] = clusters;
}
}
}
} |
|