本文整理汇总了C++中CUtlVector::EnsureCapacity方法的典型用法代码示例。如果您正苦于以下问题:C++ CUtlVector::EnsureCapacity方法的具体用法?C++ CUtlVector::EnsureCapacity怎么用?C++ CUtlVector::EnsureCapacity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CUtlVector
的用法示例。
在下文中一共展示了CUtlVector::EnsureCapacity方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LevelInitPreEntity
//-----------------------------------------------------------------------------
// Level init, shutdown
//-----------------------------------------------------------------------------
void CClientLeafSystem::LevelInitPreEntity()
{
MEM_ALLOC_CREDIT();
m_Renderables.EnsureCapacity( 1024 );
m_RenderablesInLeaf.EnsureCapacity( 1024 );
m_ShadowsInLeaf.EnsureCapacity( 256 );
m_ShadowsOnRenderable.EnsureCapacity( 256 );
m_DirtyRenderables.EnsureCapacity( 256 );
// Add all the leaves we'll need
int leafCount = engine->LevelLeafCount();
m_Leaf.EnsureCapacity( leafCount );
ClientLeaf_t newLeaf;
newLeaf.m_FirstElement = m_RenderablesInLeaf.InvalidIndex();
newLeaf.m_FirstShadow = m_ShadowsInLeaf.InvalidIndex();
newLeaf.m_FirstDetailProp = 0;
newLeaf.m_DetailPropCount = 0;
newLeaf.m_DetailPropRenderFrame = -1;
while ( --leafCount >= 0 )
{
m_Leaf.AddToTail( newLeaf );
}
}
示例2: Intersection
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void CDmeSingleIndexedComponent::Intersection( const CDmeSingleIndexedComponent &rhs )
{
const int nLhs = Count();
const int nRhs = rhs.Count();
int l = 0;
int r = 0;
if ( IsComplete() )
{
// TODO
Assert( 0 );
}
else
{
CUtlVector< int > newComponents;
newComponents.EnsureCapacity( nLhs );
CUtlVector< float > newWeights;
newWeights.EnsureCapacity( nLhs );
while ( l < nLhs || r < nRhs )
{
// In LHS but not RHS
while ( l < nLhs && ( r >= nRhs || m_Components[ l ] < rhs.m_Components[ r ] ) )
{
++l;
}
// In RHS but not LHS
while ( r < nRhs && ( l >= nLhs || m_Components[ l ] > rhs.m_Components[ r ] ) )
{
++r;
}
// In Both LHS & RHS
while ( l < nLhs && r < nRhs && m_Components[ l ] == rhs.m_Components[ r ] )
{
newComponents.AddToTail( m_Components[ l ] );
newWeights.AddToTail( m_Weights[ l ] );
++l;
++r;
}
}
m_Components.CopyArray( newComponents.Base(), newComponents.Count() );
m_Weights.CopyArray( newWeights.Base(), newWeights.Count() );
}
m_CompleteCount.Set( 0 );
m_bComplete.Set( false );
}
示例3: ReadStringTable
bool CRunTimeKeyValuesStringTable::ReadStringTable( int numStrings, CUtlBuffer& buf )
{
Assert( m_Strings.Count() == 0 );
CUtlVector< int > offsets;
offsets.EnsureCapacity( numStrings );
offsets.CopyArray( (int *)( buf.PeekGet() ), numStrings );
// Skip over data
buf.SeekGet( CUtlBuffer::SEEK_HEAD, buf.TellGet() + numStrings * sizeof( int ) );
int stringSize = buf.GetInt();
// Read in the string table
m_Strings.EnsureCapacity( numStrings );
int i;
for ( i = 0 ; i < numStrings; ++i )
{
m_Strings.AddToTail( (const char *)buf.PeekGet( offsets[ i ] ) );
}
buf.SeekGet( CUtlBuffer::SEEK_HEAD, buf.TellGet() + stringSize );
return true;
}
示例4: GetTableAndPool
// build the final pool
void GetTableAndPool( CUtlVector< unsigned int > &offsets, CUtlBuffer &buffer )
{
offsets.Purge();
buffer.Purge();
offsets.EnsureCapacity( m_StringMap.GetNumStrings() );
buffer.EnsureCapacity( m_nOffset );
unsigned int currentOffset = 0;
for ( int i = 0; i < m_StringMap.GetNumStrings(); i++ )
{
offsets.AddToTail( currentOffset );
const char *pString = m_StringMap.String( i );
buffer.Put( pString, strlen( pString ) + 1 );
currentOffset += strlen( pString ) + 1;
}
Assert( currentOffset == m_nOffset );
// align string pool to end on dword boundary
while ( buffer.TellMaxPut() & 0x03 )
{
buffer.PutChar( '\0' );
m_nOffset++;
}
}
示例5: ResizeAnimationLayerCallback
void ResizeAnimationLayerCallback( void *pStruct, int offsetToUtlVector, int len )
{
C_BaseAnimatingOverlay *pEnt = (C_BaseAnimatingOverlay*)pStruct;
CUtlVector < CAnimationLayer > *pVec = &pEnt->m_AnimOverlay;
CUtlVector< CInterpolatedVar< CAnimationLayer > > *pVecIV = &pEnt->m_iv_AnimOverlay;
Assert( (char*)pVec - (char*)pEnt == offsetToUtlVector );
Assert( pVec->Count() == pVecIV->Count() );
Assert( pVec->Count() <= C_BaseAnimatingOverlay::MAX_OVERLAYS );
int diff = len - pVec->Count();
if ( diff != 0 )
{
// remove all entries
for ( int i=0; i < pVec->Count(); i++ )
{
pEnt->RemoveVar( &pVec->Element( i ) );
}
pEnt->InvalidatePhysicsRecursive( BOUNDS_CHANGED );
// adjust vector sizes
if ( diff > 0 )
{
for ( int i = 0; i < diff; ++i )
{
int j = pVec->AddToTail( );
(*pVec)[j].SetOwner( pEnt );
}
pVecIV->AddMultipleToTail( diff );
}
else
{
pVec->RemoveMultiple( len, -diff );
pVecIV->RemoveMultiple( len, -diff );
}
// Rebind all the variables in the ent's list.
for ( int i=0; i < len; i++ )
{
IInterpolatedVar *pWatcher = &pVecIV->Element( i );
pWatcher->SetDebugName( s_m_iv_AnimOverlayNames[i] );
pEnt->AddVar( &pVec->Element( i ), pWatcher, LATCH_ANIMATION_VAR, true );
}
}
// FIXME: need to set historical values of nOrder in pVecIV to MAX_OVERLAY
// Ensure capacity
pVec->EnsureCapacity( len );
int nNumAllocated = pVec->NumAllocated();
// This is important to do because EnsureCapacity doesn't actually call the constructors
// on the elements, but we need them to be initialized, otherwise it'll have out-of-range
// values which will piss off the datatable encoder.
UtlVector_InitializeAllocatedElements( pVec->Base() + pVec->Count(), nNumAllocated - pVec->Count() );
}
示例6: FindFiles
//-----------------------------------------------------------------------------
// Purpose: Generate a list of file matching mask
//-----------------------------------------------------------------------------
int CScriptLib::FindFiles( char* pFileMask, bool bRecurse, CUtlVector<fileList_t> &fileList )
{
char dirPath[MAX_PATH];
char pattern[MAX_PATH];
char extension[MAX_PATH];
// get path only
strcpy( dirPath, pFileMask );
V_StripFilename( dirPath );
// get pattern only
V_FileBase( pFileMask, pattern, sizeof( pattern ) );
V_ExtractFileExtension( pFileMask, extension, sizeof( extension ) );
if ( extension[0] )
{
strcat( pattern, "." );
strcat( pattern, extension );
}
if ( !bRecurse )
{
GetFileList( dirPath, pattern, fileList );
}
else
{
// recurse and get the tree
CUtlVector< fileList_t > tempList;
CUtlVector< CUtlString > dirList;
RecurseFileTree_r( dirPath, 0, dirList );
for ( int i=0; i<dirList.Count(); i++ )
{
// iterate each directory found
tempList.Purge();
tempList.EnsureCapacity( dirList.Count() );
GetFileList( dirList[i].String(), pattern, tempList );
int start = fileList.AddMultipleToTail( tempList.Count() );
for ( int j=0; j<tempList.Count(); j++ )
{
fileList[start+j] = tempList[j];
}
}
}
return fileList.Count();
}
示例7: Init
void CBSPTreeData::Init( ISpatialQuery* pBSPTree )
{
Assert( pBSPTree );
m_pBSPTree = pBSPTree;
m_Handles.EnsureCapacity( 1024 );
m_LeafElements.EnsureCapacity( 1024 );
m_HandleLeafList.EnsureCapacity( 1024 );
// Add all the leaves we'll need
int leafCount = m_pBSPTree->LeafCount();
m_Leaf.EnsureCapacity( leafCount );
Leaf_t newLeaf;
newLeaf.m_FirstElement = m_LeafElements.InvalidIndex();
while ( --leafCount >= 0 )
{
m_Leaf.AddToTail( newLeaf );
}
}
示例8: Add
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void CDmeSingleIndexedComponent::Add( const CDmeSingleIndexedComponent &rhs )
{
int nLhs = Count();
const int nRhs = rhs.Count();
int l = 0;
int r = 0;
if ( IsComplete() )
{
if ( rhs.IsComplete() && nRhs > nLhs )
{
m_CompleteCount.Set( nRhs );
}
else
{
while ( r < nRhs )
{
if ( rhs.m_Components[ r ] >= nLhs )
{
// Got one that's greater than the complete count of this one
CUtlVector< int > newComponents;
newComponents.EnsureCapacity( nLhs + nRhs - r );
CUtlVector< float > newWeights;
newWeights.EnsureCapacity( nLhs + nRhs - r );
GetComponents( newComponents, newWeights );
while ( r < nRhs )
{
newComponents.AddToTail( rhs.m_Components[ r ] );
newWeights.AddToTail( rhs.m_Weights[ r ] );
++r;
}
m_Components.CopyArray( newComponents.Base(), newComponents.Count() );
m_Weights.CopyArray( newWeights.Base(), newWeights.Count() );
m_CompleteCount.Set( 0 );
m_bComplete.Set( false );
break;
}
++r;
}
}
}
else
{
CUtlVector< int > newComponents;
newComponents.EnsureCapacity( nLhs + nRhs * 0.5 ); // Just an estimate assuming 50% of the components in rhs aren't in lhs
CUtlVector< float > newWeights;
newWeights.EnsureCapacity( nLhs + nRhs * 0.5 ); // Just an estimate
while ( l < nLhs || r < nRhs )
{
while ( l < nLhs && ( r >= nRhs || m_Components[ l ] < rhs.m_Components[ r ] ) )
{
newComponents.AddToTail( m_Components[ l ] );
newWeights.AddToTail( m_Weights[ l ] );
++l;
}
// In RHS but not LHS
while ( r < nRhs && ( l >= nLhs || m_Components[ l ] > rhs.m_Components[ r ] ) )
{
newComponents.AddToTail( rhs.m_Components[ r ] );
newWeights.AddToTail( rhs.m_Weights[ r ] );
++r;
}
// In Both LHS & RHS
while ( l < nLhs && r < nRhs && m_Components[ l ] == rhs.m_Components[ r ] )
{
newComponents.AddToTail( m_Components[ l ] );
newWeights.AddToTail( m_Weights[ l ] );
++l;
++r;
}
}
m_Components.CopyArray( newComponents.Base(), newComponents.Count() );
m_Weights.CopyArray( newWeights.Base(), newWeights.Count() );
}
m_CompleteCount.Set( 0 );
m_bComplete.Set( false );
}
示例9: BlendCorners
void BlendCorners( CCoreDispInfo **ppListBase, int listSize )
{
CUtlVector<int> nbCornerVerts;
for ( int iDisp=0; iDisp < listSize; iDisp++ )
{
CCoreDispInfo *pDisp = ppListBase[iDisp];
int iNeighbors[512];
int nNeighbors = GetAllNeighbors( pDisp, iNeighbors );
// Make sure we have room for all the neighbors.
nbCornerVerts.RemoveAll();
nbCornerVerts.EnsureCapacity( nNeighbors );
nbCornerVerts.AddMultipleToTail( nNeighbors );
// For each corner.
for ( int iCorner=0; iCorner < 4; iCorner++ )
{
// Has it been touched?
CVertIndex cornerVert = pDisp->GetCornerPointIndex( iCorner );
int iCornerVert = pDisp->VertIndexToInt( cornerVert );
const Vector &vCornerVert = pDisp->GetVert( iCornerVert );
// For each displacement sharing this corner..
Vector vAverage = pDisp->GetNormal( iCornerVert );
for ( int iNeighbor=0; iNeighbor < nNeighbors; iNeighbor++ )
{
int iNBListIndex = iNeighbors[iNeighbor];
CCoreDispInfo *pNeighbor = ppListBase[iNBListIndex];
// Find out which vert it is on the neighbor.
int iNBCorner = FindNeighborCornerVert( pNeighbor, vCornerVert );
if ( iNBCorner == -1 )
{
nbCornerVerts[iNeighbor] = -1; // remove this neighbor from the list.
}
else
{
CVertIndex viNBCornerVert = pNeighbor->GetCornerPointIndex( iNBCorner );
int iNBVert = pNeighbor->VertIndexToInt( viNBCornerVert );
nbCornerVerts[iNeighbor] = iNBVert;
vAverage += pNeighbor->GetNormal( iNBVert );
}
}
// Blend all the neighbor normals with this one.
VectorNormalize( vAverage );
pDisp->SetNormal( iCornerVert, vAverage );
#if defined( USE_SCRATCHPAD )
ScratchPad_DrawArrowSimple(
g_pPad,
pDisp->GetVert( iCornerVert ),
pDisp->GetNormal( iCornerVert ),
Vector( 0, 0, 1 ),
25 );
#endif
for ( int iNeighbor=0; iNeighbor < nNeighbors; iNeighbor++ )
{
int iNBListIndex = iNeighbors[iNeighbor];
if ( nbCornerVerts[iNeighbor] == -1 )
continue;
CCoreDispInfo *pNeighbor = ppListBase[iNBListIndex];
pNeighbor->SetNormal( nbCornerVerts[iNeighbor], vAverage );
}
}
}
}
示例10: CreateSceneImageFile
//.........这里部分代码省略.........
// construct header
SceneImageHeader_t imageHeader = { 0 };
imageHeader.nId = SCENE_IMAGE_ID;
imageHeader.nVersion = SCENE_IMAGE_VERSION;
imageHeader.nNumScenes = g_SceneFiles.Count();
imageHeader.nNumStrings = stringOffsets.Count();
imageHeader.nSceneEntryOffset = sceneEntryStart;
if ( !bLittleEndian )
{
imageHeader.nId = BigLong( imageHeader.nId );
imageHeader.nVersion = BigLong( imageHeader.nVersion );
imageHeader.nNumScenes = BigLong( imageHeader.nNumScenes );
imageHeader.nNumStrings = BigLong( imageHeader.nNumStrings );
imageHeader.nSceneEntryOffset = BigLong( imageHeader.nSceneEntryOffset );
}
targetBuffer.Put( &imageHeader, sizeof( imageHeader ) );
// header is immediately followed by string table and pool
for ( int i = 0; i < stringOffsets.Count(); i++ )
{
unsigned int offset = stringPoolStart + stringOffsets[i];
if ( !bLittleEndian )
{
offset = BigLong( offset );
}
targetBuffer.PutInt( offset );
}
Assert( stringPoolStart == targetBuffer.TellMaxPut() );
targetBuffer.Put( stringPool.Base(), stringPool.TellMaxPut() );
// construct directory
CUtlSortVector< SceneImageEntry_t, CSceneImageEntryLessFunc > imageDirectory;
imageDirectory.EnsureCapacity( g_SceneFiles.Count() );
// build directory
// directory is linear sorted by filename checksum for later binary search
for ( int i = 0; i < g_SceneFiles.Count(); i++ )
{
SceneImageEntry_t imageEntry = { 0 };
// name needs to be normalized for determinstic later CRC name calc
// calc crc based on scenes\anydir\anyscene.vcd
char szCleanName[MAX_PATH];
V_strncpy( szCleanName, g_SceneFiles[i].fileName.String(), sizeof( szCleanName ) );
V_strlower( szCleanName );
V_FixSlashes( szCleanName );
char *pName = V_stristr( szCleanName, "scenes\\" );
if ( !pName )
{
// must have scenes\ in filename
Error( "CreateSceneImageFile: Unexpected lack of scenes prefix on %s\n", g_SceneFiles[i].fileName.String() );
}
CRC32_t crcFilename = CRC32_ProcessSingleBuffer( pName, strlen( pName ) );
imageEntry.crcFilename = crcFilename;
// temp store an index to its file, fixup later, necessary to access post sort
imageEntry.nDataOffset = i;
if ( imageDirectory.Find( imageEntry ) != imageDirectory.InvalidIndex() )
{
// filename checksums must be unique or runtime binary search would be bogus
Error( "CreateSceneImageFile: Unexpected filename checksum collision!\n" );
}
imageDirectory.Insert( imageEntry );