コード例 #1
0
 RuleI* RuleMaker::makeRuleFromConsts(const std::string& i_group)
 {
     std::vector<std::string> ruleOutLayers = Consts::get("outputLayers", i_group).toVector<std::string>();
     if(ruleOutLayers.empty())
         AutomapLog::report("Empty output layer list from Consts: "+i_group, AutomapLog::Type::Warning);
     
     std::vector<Param> ruleIndexes = Consts::get("indexes", i_group);
     if(ruleIndexes.empty())
         AutomapLog::report("Empty indexes from Consts: "+i_group, AutomapLog::Type::Warning);
     
     size_t ruleRotations = 0, ruleAnimationFrames = 0, ruleAnimationShift = 0;
     if(Consts::isExist("rotation", i_group))
         ruleRotations = Consts::get("rotation", i_group);
     if(Consts::isExist("animation_frames", i_group))
         ruleAnimationFrames = Consts::get("animation_frames", i_group);
     if(Consts::isExist("animation_shift", i_group))
         ruleAnimationShift = Consts::get("animation_shift", i_group);
     
     RuleI* rule = makeRule(ruleRotations);
     for( size_t i =0; i<ruleOutLayers.size(); ++i )
     {
         rule->assignIndex(i, ruleOutLayers[i]);
     }
     
     for( size_t i =0; i<ruleIndexes.size(); ++i )
     {
         std::vector<Param> tinfo = ruleIndexes.at(i);
         if(tinfo.size()!=5)
         {
             AutomapLog::report("Cannot create TileInfo from Consts"+i_group, AutomapLog::Type::Error);
             continue;
         }
         
         TileInfo info(tinfo[0],tinfo[1],tinfo[2],tinfo[3],tinfo[4]);
         size_t ind = makeInfoGetIndex(i+1, info);
         
         tinfo = ruleIndexes.at(ind-1);
     	if(tinfo.size()!=5)
         {
             AutomapLog::report("Cannot create TileInfo from Consts"+i_group, AutomapLog::Type::Error);
             continue;
         }
         
         info.path = (std::string)tinfo[0];
         info.x = (size_t)tinfo[1];
         info.y = (size_t)tinfo[2];
         info.w = (size_t)tinfo[3];
         info.h = (size_t)tinfo[4];
         
         if(ruleAnimationFrames && ruleAnimationShift)
         {
             std::vector<TileInfo> anim;
             for(size_t frame = 0; frame<ruleAnimationFrames; ++frame)
             {
                 anim.push_back( TileInfo(info.path, info.x + frame*ruleAnimationShift, info.y, info.w, info.h));
             }
             setAnimation(anim, info);
         }
         
         //TileInfo info(tinfo[0], tinfo[1], tinfo[2], tinfo[3], tinfo[4]);
         
         if(info.name()=="")
             AutomapLog::report("Empty name for tileset from Consts: "+i_group, AutomapLog::Type::Error);
         rule->assignIndex(i+1, info);
     }
     return rule;
 }
コード例 #2
0
ファイル: TileGrid.cpp プロジェクト: hnney/webkit
IntRect TileGrid::ensureTilesForRect(const FloatRect& rect, CoverageType newTileType)
{
    if (m_controller.unparentsOffscreenTiles() && !m_controller.isInWindow())
        return IntRect();

    FloatRect scaledRect(rect);
    scaledRect.scale(m_scale);
    IntRect rectInTileCoords(enclosingIntRect(scaledRect));

    TileIndex topLeft;
    TileIndex bottomRight;
    getTileIndexRangeForRect(rectInTileCoords, topLeft, bottomRight);

    TileCohort currCohort = nextTileCohort();
    unsigned tilesInCohort = 0;

    IntRect coverageRect;

    for (int y = topLeft.y(); y <= bottomRight.y(); ++y) {
        for (int x = topLeft.x(); x <= bottomRight.x(); ++x) {
            TileIndex tileIndex(x, y);

            IntRect tileRect = rectForTileIndex(tileIndex);
            TileInfo& tileInfo = m_tiles.add(tileIndex, TileInfo()).iterator->value;

            coverageRect.unite(tileRect);

            bool shouldChangeTileLayerFrame = false;

            if (!tileInfo.layer) {
                tileInfo.layer = m_controller.createTileLayer(tileRect, *this);
                ASSERT(!m_tileRepaintCounts.contains(tileInfo.layer.get()));
            } else {
                // We already have a layer for this tile. Ensure that its size is correct.
                FloatSize tileLayerSize(tileInfo.layer->bounds().size());
                shouldChangeTileLayerFrame = tileLayerSize != FloatSize(tileRect.size());

                if (shouldChangeTileLayerFrame) {
                    tileInfo.layer->setBounds(FloatRect(FloatPoint(), tileRect.size()));
                    tileInfo.layer->setPosition(tileRect.location());
                    tileInfo.layer->setNeedsDisplay();
                }
            }

            if (newTileType == CoverageType::SecondaryTiles && !tileRect.intersects(m_primaryTileCoverageRect)) {
                tileInfo.cohort = currCohort;
                ++tilesInCohort;
            }

            bool shouldParentTileLayer = (!m_controller.unparentsOffscreenTiles() || m_controller.isInWindow()) && !tileInfo.layer->superlayer();

            if (shouldParentTileLayer)
                m_containerLayer.get().appendSublayer(*tileInfo.layer);
        }
    }

    if (tilesInCohort)
        startedNewCohort(currCohort);

    return coverageRect;
}