]> git.mxchange.org Git - flightgear.git/commitdiff
Till Busch:
authorcurt <curt>
Thu, 21 Feb 2008 21:36:20 +0000 (21:36 +0000)
committercurt <curt>
Thu, 21 Feb 2008 21:36:20 +0000 (21:36 +0000)
As discussed with Tim on irc: Here is a quick fix for the memory-hungry tile
manager. Due to bugs in FGNewCache, old tiles were never deleted.

I left the timestamp-updates in the cull-traversal. but imho things work
just as well when timestamps are updated in FGNewCache::insert_tile() and
FGNewCache::get_tile()

src/Scenery/newcache.cxx
src/Scenery/newcache.hxx
src/Scenery/tileentry.cxx

index 3c3e569707cf6550aa0934e5f6bf8faca70d2397..a7d1980e3d33dc66a6155a1d74b1a67ab2018712 100644 (file)
@@ -102,7 +102,7 @@ long FGNewCache::get_oldest_tile() {
     // we need to free the furthest entry
     long min_index = -1;
     double timestamp = 0.0;
-    double max_time = 0;
+    double min_time = DBL_MAX;
 
     tile_map_iterator current = tile_cache.begin();
     tile_map_iterator end = tile_cache.end();
@@ -113,8 +113,9 @@ long FGNewCache::get_oldest_tile() {
         if ( e->is_loaded() ) {
             
             timestamp = e->get_timestamp();
-            if ( timestamp > max_time ) {
-                max_time = timestamp;
+            if ( timestamp < min_time ) {
+                min_time = timestamp;
+                min_index = index;
             }
 
         } else {
@@ -124,7 +125,7 @@ long FGNewCache::get_oldest_tile() {
     }
 
     SG_LOG( SG_TERRAIN, SG_DEBUG, "    index = " << min_index );
-    SG_LOG( SG_TERRAIN, SG_DEBUG, "    max_time = " << max_time );
+    SG_LOG( SG_TERRAIN, SG_DEBUG, "    min_time = " << min_time );
 
     return min_index;
 }
@@ -182,6 +183,8 @@ void FGNewCache::clear_cache() {
 bool FGNewCache::insert_tile( FGTileEntry *e ) {
     // register tile in the cache
     long tile_index = e->get_tile_bucket().gen_index();
+    // not needed if timestamps are updated in cull-callback
+    // e->set_timestamp(globals->get_sim_time_sec());
     tile_cache[tile_index] = e;
 
     return true;
index 5713029fda464cabfe8e8895d7b9893cfefc7fbe..1e92978987c6cc05087bc5055dd3399da506a571 100644 (file)
@@ -104,7 +104,8 @@ public:
     inline FGTileEntry *get_tile( const long tile_index ) const {
        const_tile_map_iterator it = tile_cache.find( tile_index );
        if ( it != tile_cache.end() ) {
-           it->second->set_timestamp(globals->get_sim_time_sec());
+           // not needed if timestamps are updated in cull-callback
+           // it->second->set_timestamp(globals->get_sim_time_sec());
            return it->second;
        } else {
            return NULL;
index b1fb3d3fd448924f01c88f747c0ae74478d81560..ab06bf62f15b99823c6f047dd921d03bcc4d8119 100644 (file)
@@ -99,7 +99,7 @@ namespace
 class TileCullCallback : public osg::NodeCallback
 {
 public:
-    TileCullCallback() : _timeStamp(DBL_MAX) {}
+    TileCullCallback() : _timeStamp(0) {}
     TileCullCallback(const TileCullCallback& tc, const osg::CopyOp& copyOp) :
         NodeCallback(tc, copyOp), _timeStamp(tc._timeStamp)
     {