std::vector<dimension_size_type> TileInfo::tileCoverage(PlaneRegion region) const { std::vector<dimension_size_type> ret; dimension_size_type samplelimit = 1; if (impl->planarconfig == SEPARATE) // planar samplelimit = impl->samples; // Iterate over all samples for (dimension_size_type sample = 0; sample < samplelimit; ++sample) { // Compute row and column subrange for the covered region dimension_size_type tile1 = tileIndex(region.x, region.y, sample); dimension_size_type tile2 = tileIndex(region.x + region.w - 1, region.y, sample); dimension_size_type tile3 = tileIndex(region.x, region.y + region.h - 1, sample); dimension_size_type colstart = tileColumn(tile1); dimension_size_type collimit = tileColumn(tile2) + 1; dimension_size_type rowstart = tileRow(tile1); dimension_size_type rowlimit = tileRow(tile3) + 1; // Iterate over row and column subranges for (dimension_size_type row = rowstart; row < rowlimit; ++row) for (dimension_size_type col = colstart; col < collimit; ++col) { // Compute tile index for the row/column/sample indexes dimension_size_type index = (sample * impl->ntiles) + (row * impl->ncols) + col; ret.push_back(index); } } return ret; }
void TileGrid::setNeedsDisplayInRect(const IntRect& rect) { if (m_tiles.isEmpty()) return; FloatRect scaledRect(rect); scaledRect.scale(m_scale); IntRect repaintRectInTileCoords(enclosingIntRect(scaledRect)); IntSize tileSize = m_controller.tileSize(); // For small invalidations, lookup the covered tiles. if (repaintRectInTileCoords.height() < 2 * tileSize.height() && repaintRectInTileCoords.width() < 2 * tileSize.width()) { TileIndex topLeft; TileIndex bottomRight; getTileIndexRangeForRect(repaintRectInTileCoords, topLeft, bottomRight); for (int y = topLeft.y(); y <= bottomRight.y(); ++y) { for (int x = topLeft.x(); x <= bottomRight.x(); ++x) { TileIndex tileIndex(x, y); TileMap::iterator it = m_tiles.find(tileIndex); if (it != m_tiles.end()) setTileNeedsDisplayInRect(tileIndex, it->value, repaintRectInTileCoords, m_primaryTileCoverageRect); } } return; } for (TileMap::iterator it = m_tiles.begin(), end = m_tiles.end(); it != end; ++it) setTileNeedsDisplayInRect(it->key, it->value, repaintRectInTileCoords, m_primaryTileCoverageRect); }
// returns the correct tile index' to search for, returns them in a vector Vector2 AOImanager::GetTileRegion(Vector2 position, Maze * maze) { Vector2 tileIndex(0,0); float currentX = 0; float xGap = m_worldDimensions.X / VERTICAL_SPLITS; for(int i = 0; i < VERTICAL_SPLITS; i++) { if( position.X >= currentX && position.X <= currentX+xGap) { //tileIndex.X = //break; } currentX += xGap; } return tileIndex; }
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; }