]> git.mxchange.org Git - flightgear.git/commitdiff
Fix tile cache resizing bug (which could lead to thrashing.)
authorcurt <curt>
Thu, 1 Aug 2002 06:15:59 +0000 (06:15 +0000)
committercurt <curt>
Thu, 1 Aug 2002 06:15:59 +0000 (06:15 +0000)
src/Scenery/newcache.cxx
src/Scenery/tilemgr.cxx
src/Scenery/tilemgr.hxx

index 9e1040d3d0506961a964fcf06fa3e07c4aabccc9..f9c46b20ad9da3aa27ccf9be8e8878738907ae3f 100644 (file)
@@ -175,7 +175,7 @@ bool FGNewCache::make_space() {
 // nothing available to be removed.
 long FGNewCache::get_oldest_tile() {
     // we need to free the furthest entry
-    long max_index = -1;
+    long min_index = -1;
     double timestamp = 0.0;
     double min_time = 2419200000.0f; // one month should be enough
     double max_time = 0;
@@ -190,7 +190,7 @@ long FGNewCache::get_oldest_tile() {
             
             timestamp = e->get_timestamp();
             if ( timestamp < min_time ) {
-                max_index = index;
+                min_index = index;
                 min_time = timestamp;
             }
             if ( timestamp > max_time ) {
@@ -205,10 +205,10 @@ long FGNewCache::get_oldest_tile() {
     }
 
     SG_LOG( SG_TERRAIN, SG_INFO, "    min_time = " << min_time );
-    SG_LOG( SG_TERRAIN, SG_INFO, "    index = " << max_index );
+    SG_LOG( SG_TERRAIN, SG_INFO, "    index = " << min_index );
     SG_LOG( SG_TERRAIN, SG_INFO, "    max_time = " << max_time );
 
-    return max_index;
+    return min_index;
 }
 
 
@@ -260,6 +260,7 @@ bool FGNewCache::insert_tile( FGTileEntry *e ) {
     }
 }
 
+
 // Note this is the old version of FGNewCache::make_space(), currently disabled
 // It uses distance from a center point to determine tiles to be discarded...
 #if 0
index c9b335249f04545697df4d3b278b436994b6c5de..767fcd8e57883da3074720a1d2e9c13ed2b407ac 100644 (file)
@@ -70,7 +70,6 @@ FGTileMgr::FGTileMgr():
     state( Start ),
     current_tile( NULL ),
     vis( 16000 ),
-    max_cache_size(100),
     counter_hack(0)
 {
 }
@@ -131,7 +130,7 @@ void FGTileMgr::sched_tile( const SGBucket& b ) {
 
     if ( t == NULL ) {
         // make space in the cache
-        while ( (int)tile_cache.get_size() > max_cache_size ) {
+        while ( (int)tile_cache.get_size() > tile_cache.get_max_cache_size() ) {
             long index = tile_cache.get_oldest_tile();
             if ( index >= 0 ) {
                 FGTileEntry *old = tile_cache.get_tile( index );
@@ -173,10 +172,10 @@ void FGTileMgr::schedule_needed( double vis, SGBucket curr_bucket) {
         exit(-1);        
     }
 
-   SG_LOG( SG_TERRAIN, SG_INFO,
-           "scheduling needed tiles for " << longitude << " " << latitude );
+    SG_LOG( SG_TERRAIN, SG_INFO,
+            "scheduling needed tiles for " << longitude << " " << latitude );
 
-//   vis = fgGetDouble("/environment/visibility-m");
+    // vis = fgGetDouble("/environment/visibility-m");
 
     double tile_width = curr_bucket.get_width_m();
     double tile_height = curr_bucket.get_height_m();
@@ -185,12 +184,17 @@ void FGTileMgr::schedule_needed( double vis, SGBucket curr_bucket) {
 
     xrange = (int)(vis / tile_width) + 1;
     yrange = (int)(vis / tile_height) + 1;
-    if ( xrange < 1 ) { xrange = 1; }
+    if ( xrange < 1 ) { xrange /= 1; }
     if ( yrange < 1 ) { yrange = 1; }
-    // cout << "xrange = " << xrange << "  yrange = " << yrange << endl;
 
     // note * 2 at end doubles cache size (for fdm and viewer)
-    max_cache_size = (2*xrange + 2) * (2*yrange + 2) * 2;
+    tile_cache.set_max_cache_size( (2*xrange + 2) * (2*yrange + 2) * 2 );
+
+    /*
+    cout << "xrange = " << xrange << "  yrange = " << yrange << endl;
+    cout << "max cache size = " << tile_cache.get_max_cache_size()
+         << " current cache size = " << tile_cache.get_size() << endl;
+    */
 
     SGBucket b;
 
index 714bafa760cd96e6d5a583be3afe111b6c24679b..d268d4a861d237f71af911892a79c03bd125e0dc 100644 (file)
@@ -105,7 +105,6 @@ private:
     /**
      * tile cache
      */
-    int max_cache_size;
     FGNewCache tile_cache;
 
     /**