From c3ee389fe0ad9fbc94e71a0ef95cff626b2d2ec6 Mon Sep 17 00:00:00 2001 From: curt Date: Thu, 21 Feb 2008 21:36:20 +0000 Subject: [PATCH] Till Busch: 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 | 11 +++++++---- src/Scenery/newcache.hxx | 3 ++- src/Scenery/tileentry.cxx | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Scenery/newcache.cxx b/src/Scenery/newcache.cxx index 3c3e56970..a7d1980e3 100644 --- a/src/Scenery/newcache.cxx +++ b/src/Scenery/newcache.cxx @@ -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; diff --git a/src/Scenery/newcache.hxx b/src/Scenery/newcache.hxx index 5713029fd..1e9297898 100644 --- a/src/Scenery/newcache.hxx +++ b/src/Scenery/newcache.hxx @@ -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; diff --git a/src/Scenery/tileentry.cxx b/src/Scenery/tileentry.cxx index b1fb3d3fd..ab06bf62f 100644 --- a/src/Scenery/tileentry.cxx +++ b/src/Scenery/tileentry.cxx @@ -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) { -- 2.39.5