本文整理汇总了C++中CUtlVector::EnsureCount方法的典型用法代码示例。如果您正苦于以下问题:C++ CUtlVector::EnsureCount方法的具体用法?C++ CUtlVector::EnsureCount怎么用?C++ CUtlVector::EnsureCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CUtlVector
的用法示例。
在下文中一共展示了CUtlVector::EnsureCount方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: VMPI_ReceiveDetailPropWU
void VMPI_ReceiveDetailPropWU( int iWorkUnit, MessageBuffer *pBuf, int iWorker )
{
CUtlVector<DetailPropLightstylesLump_t> *pDetailPropLump = s_pDetailPropLightStyleLump;
DetailObjectLump_t& prop = g_pMPIDetailProps[iWorkUnit];
pBuf->read( &prop.m_Lighting, sizeof( prop.m_Lighting ) );
pBuf->read( &prop.m_LightStyleCount, sizeof( prop.m_LightStyleCount ) );
pBuf->read( &prop.m_LightStyles, sizeof( prop.m_LightStyles ) );
pDetailPropLump->EnsureCount( prop.m_LightStyles + prop.m_LightStyleCount );
for ( int i=0; i < prop.m_LightStyleCount; i++ )
{
DetailPropLightstylesLump_t *l = &pDetailPropLump->Element( i + prop.m_LightStyles );
pBuf->read( &l->m_Lighting, sizeof( l->m_Lighting ) );
pBuf->read( &l->m_Style, sizeof( l->m_Style ) );
}
}
示例2: Disp_BuildVirtualMesh
void Disp_BuildVirtualMesh( int contentsMask )
{
CUtlVector<CPhysCollide *> virtualMeshes;
virtualMeshes.EnsureCount( g_CoreDispInfos.Count() );
for ( int i = 0; i < g_CoreDispInfos.Count(); i++ )
{
CCoreDispInfo *pDispInfo = g_CoreDispInfos[ i ];
mapdispinfo_t *pMapDisp = &mapdispinfo[ i ];
virtualMeshes[i] = NULL;
// not solid for this pass
if ( !(pMapDisp->contents & contentsMask) )
continue;
// Build a triangle list. This shares the tesselation code with the engine.
CUtlVector<unsigned short> indices;
CVBSPTesselateHelper helper;
helper.m_pIndices = &indices;
helper.m_pActiveVerts = pDispInfo->GetAllowedVerts().Base();
helper.m_pPowerInfo = pDispInfo->GetPowerInfo();
::TesselateDisplacement( &helper );
// validate the collision data
if ( 1 )
{
int triCount = indices.Count() / 3;
for ( int j = 0; j < triCount; j++ )
{
int index = j * 3;
Vector v0 = pDispInfo->GetVert( indices[index+0] );
Vector v1 = pDispInfo->GetVert( indices[index+1] );
Vector v2 = pDispInfo->GetVert( indices[index+2] );
if ( v0 == v1 || v1 == v2 || v2 == v0 )
{
Warning( "Displacement %d has bad geometry near %.2f %.2f %.2f\n", i, v0.x, v0.y, v0.z );
texinfo_t *pTexInfo = &texinfo[pMapDisp->face.texinfo];
dtexdata_t *pTexData = GetTexData( pTexInfo->texdata );
const char *pMatName = TexDataStringTable_GetString( pTexData->nameStringTableID );
Error( "Can't compile displacement physics, exiting. Texture is %s\n", pMatName );
}
}
}
CDispMeshEvent meshHandler( indices.Base(), indices.Count(), pDispInfo );
virtualmeshparams_t params;
params.buildOuterHull = true;
params.pMeshEventHandler = &meshHandler;
params.userData = &meshHandler;
virtualMeshes[i] = physcollision->CreateVirtualMesh( params );
}
unsigned int totalSize = 0;
CUtlBuffer buf;
dphysdisp_t header;
header.numDisplacements = g_CoreDispInfos.Count();
buf.PutObjects( &header );
CUtlVector<char> dispBuf;
for ( int i = 0; i < header.numDisplacements; i++ )
{
if ( virtualMeshes[i] )
{
unsigned int testSize = physcollision->CollideSize( virtualMeshes[i] );
totalSize += testSize;
buf.PutShort( testSize );
}
else
{
buf.PutShort( -1 );
}
}
for ( int i = 0; i < header.numDisplacements; i++ )
{
if ( virtualMeshes[i] )
{
unsigned int testSize = physcollision->CollideSize( virtualMeshes[i] );
dispBuf.RemoveAll();
dispBuf.EnsureCount(testSize);
unsigned int outSize = physcollision->CollideWrite( dispBuf.Base(), virtualMeshes[i], false );
Assert( outSize == testSize );
buf.Put( dispBuf.Base(), outSize );
}
}
g_PhysDispSize = totalSize + sizeof(dphysdisp_t) + (sizeof(unsigned short) * header.numDisplacements);
Assert( buf.TellMaxPut() == g_PhysDispSize );
g_PhysDispSize = buf.TellMaxPut();
g_pPhysDisp = new byte[g_PhysDispSize];
Q_memcpy( g_pPhysDisp, buf.Base(), g_PhysDispSize );
}
示例3: UtlStrcpy
//-----------------------------------------------------------------------------
// Purpose: Copy a string into a CUtlVector of characters
//-----------------------------------------------------------------------------
void UtlStrcpy( CUtlVector<char> &dest, const char *pSrc )
{
dest.EnsureCount( (int) (strlen( pSrc ) + 1) );
Q_strncpy( dest.Base(), pSrc, dest.Count() );
}
示例4: ComputeLighting
//-----------------------------------------------------------------------------
// Trace rays from each unique vertex, accumulating direct and indirect
// sources at each ray termination. Use the winding data to distribute the unique vertexes
// into the rendering layout.
//-----------------------------------------------------------------------------
void CVradStaticPropMgr::ComputeLighting( CStaticProp &prop, int iThread, int prop_index )
{
Vector samplePosition;
Vector sampleNormal;
CUtlVector<colorVertex_t> colorVerts;
CUtlVector<badVertex_t> badVerts;
StaticPropDict_t &dict = m_StaticPropDict[prop.m_ModelIdx];
studiohdr_t *pStudioHdr = dict.m_pStudioHdr;
OptimizedModel::FileHeader_t *pVtxHdr = (OptimizedModel::FileHeader_t *)dict.m_VtxBuf.Base();
if ( !pStudioHdr || !pVtxHdr )
{
// must have model and its verts for lighting computation
// game will fallback to fullbright
return;
}
// for access to this model's vertexes
SetCurrentModel( pStudioHdr );
for ( int bodyID = 0; bodyID < pStudioHdr->numbodyparts; ++bodyID )
{
OptimizedModel::BodyPartHeader_t* pVtxBodyPart = pVtxHdr->pBodyPart( bodyID );
mstudiobodyparts_t *pBodyPart = pStudioHdr->pBodypart( bodyID );
for ( int modelID = 0; modelID < pBodyPart->nummodels; ++modelID )
{
OptimizedModel::ModelHeader_t* pVtxModel = pVtxBodyPart->pModel( modelID );
mstudiomodel_t *pStudioModel = pBodyPart->pModel( modelID );
// light all unique vertexes
colorVerts.EnsureCount( pStudioModel->numvertices );
memset( colorVerts.Base(), 0, colorVerts.Count() * sizeof(colorVertex_t) );
int numVertexes = 0;
for ( int meshID = 0; meshID < pStudioModel->nummeshes; ++meshID )
{
mstudiomesh_t *pStudioMesh = pStudioModel->pMesh( meshID );
const mstudio_meshvertexdata_t *vertData = pStudioMesh->GetVertexData();
for ( int vertexID = 0; vertexID < pStudioMesh->numvertices; ++vertexID )
{
// transform position and normal into world coordinate system
matrix3x4_t matrix;
AngleMatrix( prop.m_Angles, prop.m_Origin, matrix );
VectorTransform( *vertData->Position( vertexID ), matrix, samplePosition );
AngleMatrix( prop.m_Angles, matrix );
VectorTransform( *vertData->Normal( vertexID ), matrix, sampleNormal );
if ( (! (prop.m_Flags & STATIC_PROP_NO_PER_VERTEX_LIGHTING ) ) &&
PositionInSolid( samplePosition ) )
{
// vertex is in solid, add to the bad list, and recover later
badVertex_t badVertex;
badVertex.m_ColorVertex = numVertexes;
badVertex.m_Position = samplePosition;
badVertex.m_Normal = sampleNormal;
badVerts.AddToTail( badVertex );
}
else
{
Vector direct_pos=samplePosition;
int skip_prop=-1;
Vector directColor(0,0,0);
if (prop.m_Flags & STATIC_PROP_NO_PER_VERTEX_LIGHTING )
{
if (prop.m_bLightingOriginValid)
VectorCopy( prop.m_LightingOrigin, direct_pos );
else
VectorCopy( prop.m_Origin, direct_pos );
skip_prop = prop_index;
}
if ( prop.m_Flags & STATIC_PROP_NO_SELF_SHADOWING )
skip_prop = prop_index;
ComputeDirectLightingAtPoint( direct_pos,
sampleNormal, directColor, iThread,
skip_prop );
Vector indirectColor(0,0,0);
if (g_bShowStaticPropNormals)
{
directColor= sampleNormal;
directColor += Vector(1.0,1.0,1.0);
directColor *= 50.0;
}
else
if (numbounce >= 1)
ComputeIndirectLightingAtPoint( samplePosition, sampleNormal,
indirectColor, iThread, true );
colorVerts[numVertexes].m_bValid = true;
colorVerts[numVertexes].m_Position = samplePosition;
VectorAdd( directColor, indirectColor, colorVerts[numVertexes].m_Color );
//.........这里部分代码省略.........