[Marble-commits] KDE/kdeedu/marble/src/lib

Bernhard Beschow bbeschow at cs.tu-berlin.de
Thu Mar 31 17:31:07 CEST 2011


SVN commit 1226644 by beschow:

StackedTileLoader: merge reloadTile(), tilesOnDisplay(), and reloadCachedTile() into reloadVisibleTiles(). Use reloadVisibleTiles() in TextureLayer::reload().

This patch does not only remove lots of unused and redundant code, but also seems more efficent, since tileUpdatesAvailable() is signalled only once rather than once for each cached tile in reloadCachedTile().

 M  +11 -74    StackedTileLoader.cpp  
 M  +2 -6      StackedTileLoader.h  
 M  +1 -9      TextureLayer.cpp  


--- trunk/KDE/kdeedu/marble/src/lib/StackedTileLoader.cpp #1226643:1226644
@@ -240,55 +240,6 @@
     return stackedTile;
 }
 
-// The tile to be reloaded might be (alternatively):
-// 1) in the "hash" (m_tilesOnDisplay), which means it is currently displayed
-// 2) not in the hash, but in the "cache", which means it is not currently displayed
-// 3) neither in "hash" nor in "cache"
-StackedTile* StackedTileLoader::reloadTile( TileId const & stackedTileId,
-                                            DownloadUsage const usage )
-{
-    StackedTile * const displayedTile = d->m_tilesOnDisplay.value( stackedTileId, 0 );
-    if ( displayedTile ) {
-        reloadCachedTile( displayedTile, usage );
-        return displayedTile;
-    }
-    StackedTile * const cachedTile = d->m_tileCache.object( stackedTileId );
-    if ( cachedTile ) {
-        // It would be more correct to update the cost for the cache also, but let's ignore it at
-        // least for now.
-        // Perhaps more relevant is, that as a consequence of leaving the tile in the cache
-        // reloadCachedTile must not alter the cache to prevent this tile from being deleted.
-        // So, all in all it might be better to take the tile out of the cache before calling
-        // reloadCachedTile and put it in again afterwards.
-        // FIXME: discuss/decide
-        reloadCachedTile( cachedTile, usage );
-        return cachedTile;
-    }
-
-    QVector<QSharedPointer<TextureTile> > tiles;
-    QVector<GeoSceneTexture const *> const textureLayers = d->findRelevantTextureLayers( stackedTileId );
-    QVector<GeoSceneTexture const *>::const_iterator pos = textureLayers.constBegin();
-    QVector<GeoSceneTexture const *>::const_iterator const end = textureLayers.constEnd();
-    for (; pos != end; ++pos ) {
-        GeoSceneTexture const * const textureLayer = *pos;
-        TileId const tileId( textureLayer->sourceDir(), stackedTileId.zoomLevel(),
-                             stackedTileId.x(), stackedTileId.y() );
-        QSharedPointer<TextureTile> const tile = d->m_tileLoader->reloadTile( stackedTileId, tileId,
-                                                                              usage );
-        if ( tile ) {
-            tile->setBlending( textureLayer->blending() );
-            tiles.append( tile );
-        }
-    }
-    Q_ASSERT( !tiles.isEmpty() );
-
-    StackedTile * const stackedTile = new StackedTile( stackedTileId, tiles );
-    d->m_tilesOnDisplay[ stackedTileId ] = stackedTile;
-    mergeDecorations( stackedTile );
-
-    return stackedTile;
-}
-
 void StackedTileLoader::downloadTile( TileId const & stackedTileId )
 {
     QVector<GeoSceneTexture const *> const textureLayers = d->findRelevantTextureLayers( stackedTileId );
@@ -307,17 +258,20 @@
     return d->m_tileCache.maxCost() / 1024;
 }
 
-QList<TileId> StackedTileLoader::tilesOnDisplay() const
+void StackedTileLoader::reloadVisibleTiles()
 {
-    QList<TileId> result;
-    QHash<TileId, StackedTile*>::const_iterator pos = d->m_tilesOnDisplay.constBegin();
-    QHash<TileId, StackedTile*>::const_iterator const end = d->m_tilesOnDisplay.constEnd();
-    for (; pos != end; ++pos ) {
-        if ( pos.value()->used() ) {
-            result.append( pos.key() );
+    foreach ( StackedTile * const displayedTile, d->m_tilesOnDisplay.values() ) {
+        Q_ASSERT( displayedTile != 0 );
+        foreach ( QSharedPointer<TextureTile> const & tile, *displayedTile->tiles() ) {
+            // it's debatable here, whether DownloadBulk or DownloadBrowse should be used
+            // but since "reload" or "refresh" seems to be a common action of a browser and it
+            // allows for more connections (in our model), use "DownloadBrowse"
+            d->m_tileLoader->reloadTile( tile, DownloadBrowse );
         }
+        mergeDecorations( displayedTile );
     }
-    return result;
+
+    emit tileUpdatesAvailable();
 }
 
 int StackedTileLoader::maximumTileLevel() const
@@ -459,23 +413,6 @@
     d->m_layerDecorator.paint( "maps/" + d->m_textureLayers.at( 0 )->sourceDir() );
 }
 
-// This method should not alter m_tileCache, as the given tile is managed
-// by the cache and may be evicted at any time (that is usually when inserting
-// other tiles in the cache)
-void StackedTileLoader::reloadCachedTile( StackedTile * const cachedTile,
-                                          DownloadUsage const usage )
-{
-    Q_ASSERT( cachedTile );
-    QVector<QSharedPointer<TextureTile> > * tiles = cachedTile->tiles();
-    QVector<QSharedPointer<TextureTile> >::const_iterator pos = tiles->constBegin();
-    QVector<QSharedPointer<TextureTile> >::const_iterator const end = tiles->constEnd();
-    for (; pos != end; ++pos ) {
-        d->m_tileLoader->reloadTile( *pos, usage );
     }
-    mergeDecorations( cachedTile );
-    emit tileUpdateAvailable( cachedTile->id() );
-}
 
-}
-
 #include "StackedTileLoader.moc"
--- trunk/KDE/kdeedu/marble/src/lib/StackedTileLoader.h #1226643:1226644
@@ -92,7 +92,6 @@
          *                      and the zoom level.
          */
         StackedTile* loadTile( TileId const &stackedTileId );
-        StackedTile* reloadTile( TileId const & stackedTileId, DownloadUsage const );
         void downloadTile( TileId const & stackedTileId );
 
         /**
@@ -121,11 +120,9 @@
         quint64 volatileCacheLimit() const;
 
         /**
-         * @brief Returns a list of TileIds of the tiles which are currently
-         *        displayed. This is used for example for the map reload
-         *        functionality.
+         * @brief Reloads the tiles that are currently displayed.
          */
-        QList<TileId> tilesOnDisplay() const;
+        void reloadVisibleTiles();
 
         /**
          * Returns the highest level in which some tiles are theoretically
@@ -168,7 +165,6 @@
     private:
         Q_DISABLE_COPY( StackedTileLoader )
         void mergeDecorations( StackedTile * const ) const;
-        void reloadCachedTile( StackedTile * const cachedTile, DownloadUsage const );
 
         StackedTileLoaderPrivate* const d;
 };
--- trunk/KDE/kdeedu/marble/src/lib/TextureLayer.cpp #1226643:1226644
@@ -215,16 +215,8 @@
 
 void TextureLayer::reload()
 {
-    QList<TileId> displayed = d->m_tileLoader.tilesOnDisplay();
-    QList<TileId>::const_iterator pos = displayed.constBegin();
-    QList<TileId>::const_iterator const end = displayed.constEnd();
-    for (; pos != end; ++pos ) {
-        // it's debatable here, whether DownloadBulk or DownloadBrowse should be used
-        // but since "reload" or "refresh" seems to be a common action of a browser and it
-        // allows for more connections (in our model), use "DownloadBrowse"
-        d->m_tileLoader.reloadTile( *pos, DownloadBrowse );
+    d->m_tileLoader.reloadVisibleTiles();
     }
-}
 
 void TextureLayer::downloadTile( const TileId &tileId )
 {


More information about the Marble-commits mailing list