1
0
Fork 0

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()
This commit is contained in:
curt 2008-02-21 21:36:20 +00:00
parent 2186fdf961
commit c3ee389fe0
3 changed files with 10 additions and 6 deletions

View file

@ -102,7 +102,7 @@ long FGNewCache::get_oldest_tile() {
// we need to free the furthest entry // we need to free the furthest entry
long min_index = -1; long min_index = -1;
double timestamp = 0.0; double timestamp = 0.0;
double max_time = 0; double min_time = DBL_MAX;
tile_map_iterator current = tile_cache.begin(); tile_map_iterator current = tile_cache.begin();
tile_map_iterator end = tile_cache.end(); tile_map_iterator end = tile_cache.end();
@ -113,8 +113,9 @@ long FGNewCache::get_oldest_tile() {
if ( e->is_loaded() ) { if ( e->is_loaded() ) {
timestamp = e->get_timestamp(); timestamp = e->get_timestamp();
if ( timestamp > max_time ) { if ( timestamp < min_time ) {
max_time = timestamp; min_time = timestamp;
min_index = index;
} }
} else { } 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, " 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; return min_index;
} }
@ -182,6 +183,8 @@ void FGNewCache::clear_cache() {
bool FGNewCache::insert_tile( FGTileEntry *e ) { bool FGNewCache::insert_tile( FGTileEntry *e ) {
// register tile in the cache // register tile in the cache
long tile_index = e->get_tile_bucket().gen_index(); 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; tile_cache[tile_index] = e;
return true; return true;

View file

@ -104,7 +104,8 @@ public:
inline FGTileEntry *get_tile( const long tile_index ) const { inline FGTileEntry *get_tile( const long tile_index ) const {
const_tile_map_iterator it = tile_cache.find( tile_index ); const_tile_map_iterator it = tile_cache.find( tile_index );
if ( it != tile_cache.end() ) { 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; return it->second;
} else { } else {
return NULL; return NULL;

View file

@ -99,7 +99,7 @@ namespace
class TileCullCallback : public osg::NodeCallback class TileCullCallback : public osg::NodeCallback
{ {
public: public:
TileCullCallback() : _timeStamp(DBL_MAX) {} TileCullCallback() : _timeStamp(0) {}
TileCullCallback(const TileCullCallback& tc, const osg::CopyOp& copyOp) : TileCullCallback(const TileCullCallback& tc, const osg::CopyOp& copyOp) :
NodeCallback(tc, copyOp), _timeStamp(tc._timeStamp) NodeCallback(tc, copyOp), _timeStamp(tc._timeStamp)
{ {