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


C++ CTokenizer::GetTokens方法代码示例

本文整理汇总了C++中CTokenizer::GetTokens方法的典型用法代码示例。如果您正苦于以下问题:C++ CTokenizer::GetTokens方法的具体用法?C++ CTokenizer::GetTokens怎么用?C++ CTokenizer::GetTokens使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CTokenizer的用法示例。


在下文中一共展示了CTokenizer::GetTokens方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ReadParticleBehaviour

CParticleBehaviour CParticleSystemManager::ReadParticleBehaviour( std::string szEmitterScript, std::string szParticleBehaviourName )
{
    FILE *pFile = fopen( szEmitterScript.c_str(), "rt" );
    if ( !pFile )
        return CParticleBehaviour( "NULL", 0.0f, 0.0f );

    CTokenizer tokenizer;
    std::vector<std::string> tokens;

    std::string in = ReadLine( pFile );
    bool bInBehaviour = false;

    float fEffect, fVelocity;
    fEffect = fVelocity = 0.0f;

    while ( in != "<<<EOF>>>" )
    {
        tokens = tokenizer.GetTokens( in, " ,;:\"" );
        if ( tokens.size() == 0 )
        {
            in = ReadLine( pFile );
            bInBehaviour = false;
            continue;
        }

        if ( tokens[0] == "[emitter]" )
            bInBehaviour = false;
        else if ( tokens[0] == "[particle]" )
            bInBehaviour = false;
        else if ( tokens[0] == "[behaviour]" )
            bInBehaviour = true;

        if ( bInBehaviour )
        {
            if ( tokens[0] == "name" && tokens[2] == szParticleBehaviourName )
            {
                // Read until the next blank line
                in = ReadLine( pFile );
                while ( in != "" && in != "<<<EOF>>>" )
                {
                    tokens = tokenizer.GetTokens(in);
                    if ( tokens[0] == "velocity" )
                        fVelocity = (float)atof( tokens[2].c_str() );
                    else if ( tokens[0] == "move" )
                        fEffect = (float)atof( tokens[2].c_str() );
                    in = ReadLine( pFile );
                }
                fclose( pFile );
                return CParticleBehaviour( szParticleBehaviourName, fEffect, fVelocity );
            }
        }

        in = ReadLine( pFile );
    }
    fclose( pFile );

    return CParticleBehaviour( "NULL", 0.0f, 0.0f );
}
开发者ID:TimToxopeus,项目名称:grapplon2,代码行数:58,代码来源:ParticleSystemManager.cpp

示例2: if

CParticleEmitter *CParticleSystemManager::LoadEmitter( std::string szEmitterScript )
{
    if ( !SETS->PARTICLES_ON )
        return NULL;

    FILE *pFile = fopen( szEmitterScript.c_str(), "rt" );
    if ( !pFile )
        return NULL;

    std::string in = ReadLine( pFile );
    while ( in != "<<<EOF>>>" && in != "[emitter]" )
        in = ReadLine( pFile );

    EmitterType eType = NONE;
    float fTypeParameter = 0.0f;
    unsigned int iMaxParticles = 50;
    unsigned int iLifespan = 6000;
    unsigned int iSpawnrate = 10;
    float fRadius = 0.0f;

    CTokenizer tokenizer;
    std::vector<std::string> tokens;
    std::map<std::string, int> vParticles;
    std::map<std::string,int>::iterator particleIt;

    while ( in != "<<<EOF>>>" && in != "" )
    {
        tokens = tokenizer.GetTokens( in, " ,;:\"" );
        if ( tokens.size() > 0 )
        {
            if ( tokens[0] == "direction" )
            {
                if ( tokens[2] == "arc" )
                {
                    eType = ARC;
                    fTypeParameter = (float)atof(tokens[3].c_str());
                }
                else if ( tokens[2] == "line" )
                {
                    eType = LINE;
                    fTypeParameter = (float)atof(tokens[3].c_str());
                }
                else
                {
                    eType = NONE;
                    fTypeParameter = 0.0f;
                }
            }
            else if ( tokens[0] == "maxparticles" )
                iMaxParticles = atoi(tokens[2].c_str());
            else if ( tokens[0] == "lifespan" )
                iLifespan = atoi(tokens[2].c_str());
            else if ( tokens[0] == "spawnrate" )
                iSpawnrate = atoi(tokens[2].c_str());
            else if ( tokens[0] == "radius" )
                fRadius = (float)atof(tokens[2].c_str());
            else if ( tokens[0] == "particles" )
            {
                int particles = (tokens.size() - 2) / 2;
                for ( int i = 0; i<particles * 2; i+=2 )
                {
                    std::string name = tokens[i + 2];
                    int chance = atoi(tokens[i + 3].c_str());
                    vParticles[name] = chance;
                }
            }
        }
        in = ReadLine( pFile );
    }
    fclose( pFile );

    CParticleEmitter *pEmitter = new CParticleEmitter( eType, fTypeParameter, iMaxParticles, iLifespan, iSpawnrate, fRadius );

    for ( particleIt = vParticles.begin(); particleIt != vParticles.end(); particleIt++ )
    {
        std::string name = (*particleIt).first;
        int chance = (*particleIt).second;

        CParticle *pParticle = ReadParticle( szEmitterScript, name, pEmitter );
        pEmitter->AddToFactory( pParticle, chance );
    }

    m_vEmitters.push_back( pEmitter );
    return pEmitter;
}
开发者ID:TimToxopeus,项目名称:grapplon2,代码行数:85,代码来源:ParticleSystemManager.cpp


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