本文整理汇总了C++中Population::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ Population::clear方法的具体用法?C++ Population::clear怎么用?C++ Population::clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Population
的用法示例。
在下文中一共展示了Population::clear方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: genPopulation
void WorldGenerator::genPopulation( Population& population, Level& level, PopulationGenerationRanges& ranges, float blockDimension )
{
struct OpenBlock{
ushort i;
ushort j;
};
//Allocate space for open blocks
ushort numOpens = 0;
OpenBlock* opens = new OpenBlock[ level.getWidth() * level.getDepth() ];
population.clear();
//fill the array with open blocks
for(ushort i = 0; i < level.getWidth(); i++){
for(ushort j = 0; j < level.getDepth(); j++){
if( level.getBlock(i, j).getCollidableType() == Level::Block::Collidable::None ){
opens[ numOpens ].i = i;
opens[ numOpens ].j = j;
numOpens++;
}
}
}
float popDensity = ranges.density.gen( mRand );
int popCount = static_cast<int>( static_cast<float>( numOpens ) * popDensity ) + 1;
int gennedPop = 0;
int attempts = 0;
float halfBlockDimension = blockDimension * 0.5f;
while( gennedPop < popCount ){
if( attempts > WORLD_GEN_ATTEMPTS ){
break;
}
//Generate a spot in the list
ushort genOpen = mRand.gen( 0, numOpens );
//Spawn an entity 0 to start
population.spawn( 0,
XMFLOAT4( static_cast<float>( opens[ genOpen ].i ) * blockDimension + halfBlockDimension,
0.32f,
static_cast<float>( opens[ genOpen ].j ) * blockDimension + halfBlockDimension,
1.0f ) );
//Remove the spot from the list
numOpens--;
if( genOpen < numOpens ){
for(ushort i = genOpen; i < numOpens; i++){
opens[i] = opens[i+1];
}
}
gennedPop++;
}
delete[] opens;
}