[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdeedu/marble
From:       Torsten Rahn <tackat () kde ! org>
Date:       2008-05-31 23:33:35
Message-ID: 1212276815.128399.22722.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 815026 by rahn:

- Taking cache contents into account when creating fallback
      tiles: preparation for threaded loading



 M  +8 -0      ChangeLog  
 M  +66 -38    src/lib/TextureTile.cpp  
 M  +2 -2      src/lib/TextureTile.h  
 M  +2 -2      src/lib/TileLoader.cpp  


--- trunk/KDE/kdeedu/marble/ChangeLog #815025:815026
@@ -1,3 +1,11 @@
+2008-06-01  Torsten Rahn  <rahn@kde.org> 
+
+    * src/lib/TextureTile.cpp:
+    * src/lib/TileLoader.cpp:
+
+    - Taking cache contents into account when creating fallback
+      tiles: preparation for threaded loading
+
 2008-06-01  Inge Wallin  <inge@lysator.liu.se>
 
 	Fix some issues with the active area in the image.
--- trunk/KDE/kdeedu/marble/src/lib/TextureTile.cpp #815025:815026
@@ -74,23 +74,20 @@
     delete [] jumpTable8;
 }
 
-void TextureTile::loadRawTile( GeoSceneTexture *textureLayer, int level, \
int x, int y, QCache<TileId, TextureTile> *cache ) +void \
TextureTile::loadRawTile( GeoSceneTexture *textureLayer, int level, int x, \
int y, QCache<TileId, TextureTile> *tileCache )  {
     // qDebug() << "TextureTile::loadRawTile" << level << x << y;
+    QImage temptile;
 
     m_used = true; // Needed to avoid frequent deletion of tiles
 
-    // qDebug() << "Entered loadTile( int, int, int) of Tile" << m_id;
-    // m_used = true; // Needed to avoid frequent deletion of tiles
-
     QString  absfilename;
 
-    // qDebug() << "Requested tile level" << level;
-
     // If the tile level offers the requested tile then load it.
     // Otherwise cycle from the requested tilelevel down to one where
     // the requested area is covered.  Then scale the area to create a
     // replacement for the tile that has been requested.
+
     const int levelZeroColumns = textureLayer->levelZeroColumns();
     const int levelZeroRows = textureLayer->levelZeroRows();
     const int rowsRequestedLevel = TileLoaderHelper::levelToRow( \
levelZeroRows, level ); @@ -108,53 +105,84 @@
         double currentX    = normalizedX * (double)( rowsCurrentLevel );
         double currentY    = normalizedY * (double)( columnsCurrentLevel \
);  
-        QString relfilename = TileLoaderHelper::relativeTileFileName( \
                textureLayer, 
-                                                                      \
                currentLevel,
-                                                                      \
                (int)(currentX),
-                                                                      \
                (int)(currentY) );
-        absfilename = MarbleDirs::path( relfilename );
-        const QFileInfo fileInfo( absfilename );
+        const QDateTime now = QDateTime::currentDateTime();
+        QDateTime lastModified;
 
-        const QDateTime now = QDateTime::currentDateTime();
         bool download = false;
+        bool currentTileAvailable = false;
 
-        // - if the file does not exist, we want to download it and search \
                an
-        //   existing tile of a lower zoom level for imediate display
-        // - if the file exists and is expired according to the value of \
                the
-        //   expire element we want to download it again and display the \
                old
-        //   tile until the new one is there. Once the updated tile is
-        //   available, it should get displayed.
+        TextureTile *currentTile = 0;
 
-        if ( !fileInfo.exists() ) {
-            qDebug() << "File does not exist:" << fileInfo.filePath();
-            download = true;
+        // Check whether the current tile id is available in the CACHE:
+        if ( tileCache ) {
+            TileId currentTileId( currentLevel, (int)(currentX), \
(int)(currentY) );     +            currentTile = tileCache->take( \
currentTileId ); +
+            if ( currentTile ) {
+                // the tile was in the cache, but is it up to date?
+                lastModified = currentTile->created();
+                if ( lastModified.secsTo( now ) < textureLayer->expire()) \
{ +                    temptile = currentTile->rawtile();
+                    qDebug() << "FOUND IN CACHE";
+                    currentTileAvailable = true;
+                } else {
+                    delete currentTile;
+                    currentTile = 0;
+                }
+            }
         }
-        else if ( fileInfo.lastModified().secsTo( now ) > \
                textureLayer->expire() ) {
-            qDebug() << "File does exist, but is expired:" << \
                fileInfo.filePath()
-                     << "age (seconds):" << \
                fileInfo.lastModified().secsTo( now )
-                     << "allowed age:" << textureLayer->expire();
-            download = true;
-        }
+        // If the current tile id is not in the cache or if it was 
+        // in the cache but has expired load from DISK:
 
-        if ( fileInfo.exists() ) {
-            // qDebug() << "The image filename does exist: " << \
absfilename ; +        if ( !currentTile ) {
+            QString relfilename = TileLoaderHelper::relativeTileFileName( \
textureLayer,  +                                                            \
currentLevel, +                                                             \
(int)(currentX), +                                                          \
(int)(currentY) ); +            absfilename = MarbleDirs::path( relfilename \
); +            const QFileInfo fileInfo( absfilename );
+            lastModified = fileInfo.lastModified();
 
-            QImage temptile( absfilename );
-            // qDebug() << "TextureTile::loadRawTile "
-            //          << "depth:" << temptile.depth()
-            //          << "format:" << temptile.format()
-            //          << "bytesPerLine:" << temptile.bytesPerLine()
-            //          << "numBytes:" << temptile.numBytes() ;
+            // - if the file does not exist, we want to download it and \
search an +            //   existing tile of a lower zoom level for \
imediate display +            // - if the file exists and is expired \
according to the value of the +            //   expire element we want to \
download it again and display the old +            //   tile until the new \
one is there. Once the updated tile is +            //   available, it \
should get displayed. + 
+            if ( !fileInfo.exists() ) {
+                qDebug() << "File does not exist:" << fileInfo.filePath();
+                download = true;
+            }
+            else if ( lastModified.secsTo( now ) > textureLayer->expire() \
) { +                qDebug() << "File does exist, but is expired:" << \
fileInfo.filePath() +                        << "age (seconds):" << \
lastModified.secsTo( now ) +                        << "allowed age:" << \
textureLayer->expire(); +                download = true;
+            }
 
+            if ( fileInfo.exists() ) {
+
+                temptile.load( absfilename );
+                // qDebug() << "TextureTile::loadRawTile "
+                //          << "depth:" << temptile.depth()
+                //          << "format:" << temptile.format()
+                //          << "bytesPerLine:" << temptile.bytesPerLine()
+                //          << "numBytes:" << temptile.numBytes() ;
+                currentTileAvailable = true;
+            }
+        }
+
+        if ( currentTileAvailable ) {
             if ( !temptile.isNull() ) {
-                // qDebug() << "Image has been successfully loaded.";
 
+                // Don't scale if the current tile isn't a fallback
                 if ( level != currentLevel ) { 
                     scaleTileFrom( textureLayer, temptile, currentX, \
currentY, currentLevel, x, y, level );  }
 
                 m_rawtile = temptile;
-                m_created = fileInfo.lastModified();
+                m_created = lastModified;
                 tileFound = true;
             }
         }
--- trunk/KDE/kdeedu/marble/src/lib/TextureTile.h #815025:815026
@@ -45,7 +45,7 @@
 
     virtual ~TextureTile();
     
-    void loadRawTile( GeoSceneTexture *textureLayer, int level, int x, int \
y, QCache<TileId, TextureTile> *cache = 0 ); +    void loadRawTile( \
GeoSceneTexture *textureLayer, int level, int x, int y, QCache<TileId, \
TextureTile> *tileCache = 0 );  
     TileId const& id() const  { return m_id; }
     int  depth() const        { return m_depth; }
@@ -56,7 +56,7 @@
     int numBytes() const      { return m_rawtile.numBytes(); }
 
     const QImage& rawtile()   { return m_rawtile; }
-    QImage* tile()            { return &m_rawtile; }
+    QImage *tile()            { return &m_rawtile; }
     const QDateTime & created() const;
 
     // Here we retrieve the color value of the requested pixel on the \
                tile.
--- trunk/KDE/kdeedu/marble/src/lib/TileLoader.cpp #815025:815026
@@ -222,7 +222,7 @@
     connect( tile, SIGNAL( tileUpdateDone() ),
              this, SIGNAL( tileUpdateAvailable() ) );
 
-    tile->loadRawTile( d->m_textureLayer, tileLevel, tilx, tily );
+    tile->loadRawTile( d->m_textureLayer, tileLevel, tilx, tily, &( \
d->m_tileCache ) );  tile->loadTile( false );
 
     // TODO should emit signal rather than directly calling paintTile
@@ -355,7 +355,7 @@
 
         // TODO should emit signal rather than directly calling paintTile
 //         emit paintTile( d->m_tileHash[id], x, y, level, d->m_theme, \
                true );
-        (d->m_tileHash[id])->loadRawTile( d->m_textureLayer, level, x, y \
);  +        (d->m_tileHash[id])->loadRawTile( d->m_textureLayer, level, x, \
                y, &( d->m_tileCache ) ); 
         m_parent->paintTile( d->m_tileHash[id], x, y, level, \
d->m_textureLayer, true );  //         (d->m_tileHash[id]) -> reloadTile( \
x, y, level, d->m_theme );  } else {


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic