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


C++ StringTokenizer::get_next_integer方法代码示例

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


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

示例1: f

Tileset::Tileset (const std::string &name) throw() {
    this->name = name;

    // Load the PNG into the image buffer.
    std::string texture_filename = "tiles/" + name + ".png";
    sfml_image.LoadFromFile (texture_filename);
    texture_width = sfml_image.GetWidth();
    texture_height = sfml_image.GetHeight();

    // Store the image buffer in an OpenGL texture.
    glGenTextures (1, &texture);
    glBindTexture (GL_TEXTURE_2D, texture);
    glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA,
                  texture_width, texture_height,
                  0, GL_RGBA, GL_UNSIGNED_BYTE,
                  sfml_image.GetPixelsPtr());
    glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

    std::string data_filename = "tiles/" + name + ".dat";
    std::ifstream f (data_filename.c_str());
    std::string str;

    // Get the tile width and height in pixels.
    std::getline (f, str);
    StringTokenizer tokens (str);
    tile_size = tokens.get_next_integer();

    tiles_wide = texture_width / tile_size;
    tiles_high = texture_height / tile_size;

    // Get the individual tile data (x index, y index).
    // Storing a tile's position in the tile's graphic file allows the tile to be
    // moved in the tile's graphic file without having to change that tile's index
    // in maps that use it.  If a tile's position in the tile graphic file wasn't
    // stored but rather sequentially calculated, moving it around in the tile
    // graphic file would cause its index to change and the map's that use it
    // would have to be modified to remain the same.  Shuffling tiles around in a
    // tile graphic file is useful because as tiles are added and removed, we may
    // need to arrange them differently so it's easier to see how nearby tiles
    // connect to them.
    while (!f.eof()) {
        int tile_index = tiles.size();

        std::getline (f, str);
        StringTokenizer tokens (str);
        Rectangle src_rect;
        src_rect.x = tokens.get_next_integer() * tile_size;
        src_rect.y = tokens.get_next_integer() * tile_size;
        src_rect.w = tile_size;
        src_rect.h = tile_size;

        bool dark = false;
        bool destructable = false;
        bool deadly = false;
        while (tokens.has_more_tokens()) {
            std::string attribute = tokens.get_next_string();
            if (attribute == "dark") {
                dark = true;
            } else if (attribute == "destructable") {
                destructable = true;
            } else if (attribute == "deadly") {
                deadly = true;
            }
        }

        Tile *tile = new Tile (tile_index, this, src_rect,
                               dark, destructable, deadly);
        tiles.push_back (tile);
    }

    f.close();
}
开发者ID:samuelpauls,项目名称:Xeno-Story,代码行数:73,代码来源:Tileset.cpp


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