Exemple #1
0
void Chunk::save()
{
    std::ofstream file(getPathFromCoords(mCoords));
    if (!file)
    {
        return;
    }

    file << getLayerCount() << std::endl;
    sf::Vector2i coords, size = Properties::getChunkSize();
    for (coords.y = 0; coords.y < size.y; coords.y++)
    {
        for (coords.x = 0; coords.x < size.x; coords.x++)
        {
            for (std::size_t z = 0; z < getLayerCount(); z++)
            {
                file << getTileId(coords,z);
                if (z == getLayerCount() - 1)
                {
                    file << ";";
                }
                else
                {
                    file << "-";
                }
            }
        }
        file << std::endl;
    }
    file.close();
    mNeedSave = false;
}
Exemple #2
0
void MacroTileMgr::enqueue(uint32_t x, uint32_t y, BE_WORK* pWork)
{
    // Should not enqueue more then what we have backing for in the hot tile manager.
    SWR_ASSERT(x < KNOB_NUM_HOT_TILES_X);
    SWR_ASSERT(y < KNOB_NUM_HOT_TILES_Y);

    if ((x & ~(KNOB_NUM_HOT_TILES_X - 1)) | (y & ~(KNOB_NUM_HOT_TILES_Y - 1)))
    {
        return;
    }

    uint32_t id = getTileId(x, y);

    if (id >= mTiles.size())
    {
        mTiles.resize((16 + id) * 2);
    }

    MacroTileQueue* pTile = mTiles[id];
    if (!pTile)
    {
        pTile = mTiles[id] = new MacroTileQueue();
    }
    pTile->mWorkItemsFE++;
    pTile->mId = id;

    if (pTile->mWorkItemsFE == 1)
    {
        pTile->clear(mArena);
        mDirtyTiles.push_back(pTile);
    }

    mWorkItemsProduced++;
    pTile->enqueue_try_nosync(mArena, pWork);
}
Exemple #3
0
TileData Layer::getTileData(int x, int y)
{
    int id = getTileId(x,y);
    if (mMap != nullptr)
    {
        Tileset::Ptr tileset = mMap->getTileset(id);
        if (tileset != nullptr)
        {
            return tileset->getTile(id-1);
        }
    }
    return TileData();
}
Exemple #4
0
void Chunk::writeToPacket(sf::Packet& packet)
{
    packet << mCoords.x << mCoords.y;
    packet << getLayerCount();

    sf::Vector2i p, size = Properties::getChunkSize();
    for (p.x = 0; p.x < size.x; p.x++)
    {
        for (p.y = 0; p.y < size.y; p.y++)
        {
            for (int z = 0; z < (int)getLayerCount(); z++)
            {
                packet << getTileId(p,z);
            }
        }
    }
}
Exemple #5
0
 int getTileId(sf::Vector2i const& coords) const
 {
     sf::Vector2i chunkCoords = NOrthogonal::coordsToChunk(coords);
     sf::Vector2i tileCoords = NOrthogonal::coordsToRelative(coords);
     return getTileId(chunkCoords, tileCoords);
 }