本文整理汇总了C++中FileInputStream::getSize方法的典型用法代码示例。如果您正苦于以下问题:C++ FileInputStream::getSize方法的具体用法?C++ FileInputStream::getSize怎么用?C++ FileInputStream::getSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileInputStream
的用法示例。
在下文中一共展示了FileInputStream::getSize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init
bool LayerComponent::init(const std::string& filename, const Vector2f& offset)
{
FileInputStream mapStream;
if (!mapStream.open(filename))
{
err() << "loadMap: could not open file " << filename << endl;
return false;
}
// convert FileInputStream to char* mapBuffer
char* mapBuffer = new char[mapStream.getSize() + 1];
mapStream.read(mapBuffer, mapStream.getSize());
mapBuffer[mapStream.getSize()] = '\0';
// now lets load a NLTmxMap
NLTmxMap* tilemap = NLLoadTmxMap(mapBuffer);
delete mapBuffer;
err() << "Load tilemap with size: " << tilemap->width << ", "
<< tilemap->height << " and tilesize: " << tilemap->tileWidth
<< ", " << tilemap->tileHeight << std::endl;
// load textures for every tileset
for (auto tileset : tilemap->tilesets)
{
err() << "Load tileset: " << tileset->name << " width filename: "
<< tileset->filename << " and tilesize: " << tileset->tileWidth
<< ", " << tileset->tileHeight << std::endl;
auto texture = make_shared<Texture>();
if (!texture->loadFromFile(m_resourcePath + tileset->filename))
err() << "Could not load texture " << m_resourcePath + tileset->filename << endl;
m_tilesetTexture[tileset->name] = texture;
}
// go through all layers
m_layers.resize(tilemap->layers.size());
for (int layerIdx = 0; layerIdx < (int)tilemap->layers.size(); layerIdx++)
{
NLTmxMapLayer* layer = tilemap->layers[layerIdx];
err() << "Load layer: " << layer->name << " with width: "
<< layer->width << " and height: " << layer->height << std::endl;
int size = layer->width * layer->height;
// go over all elements in the layer
for (int i = 0; i < size; i++)
{
int grid = layer->data[i];
if (grid == 0) continue;
// get tileset and tileset texture
NLTmxMapTileset* tileset = tilemap->getTilesetForGrid(grid);
Vector2i tileSize(tilemap->tileWidth, tilemap->tileHeight);
TexturePtr texture = m_tilesetTexture[tileset->name];
assert(texture != nullptr);
// horizontal tile count in tileset texture
int tileCountX = texture->getSize().x / tileSize.x;
// calcualte position of tile
Vector2f position;
position.x = (i % layer->width) * (float)tileSize.x;
position.y = (i / layer->width) * (float)tileSize.y;
position += offset;
// calculate 2d idx of tile in tileset texture
int idx = grid - tileset->firstGid;
int idxX = idx % tileCountX;
int idxY = idx / tileCountX;
// calculate source area of tile in tileset texture
IntRect source(idxX * tileSize.x, idxY * tileSize.y, tileSize.x, tileSize.y);
// TODO create tile and put it into a layer
auto sprite = make_shared<Sprite>();
sprite->setTexture(*texture);
sprite->setTextureRect(source);
sprite->setPosition(position.x, position.y);
m_layers[layerIdx].push_back(sprite);
}
}
// go through all object layers
for (auto group : tilemap->groups)
{
// go over all objects per layer
for (auto object : group->objects)
{
Vector2f position(object->x, object->y);
position += offset;
FloatRect bounds(position.x, position.y, object->width, object->height);
// TODO create object
if (object->type == "Sprite")
//.........这里部分代码省略.........