当前位置: 首页>>代码示例>>C++>>正文


C++ Population::clear方法代码示例

本文整理汇总了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;
}
开发者ID:justy989,项目名称:MultiFall,代码行数:59,代码来源:WorldGenerator.cpp


注:本文中的Population::clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。