1
0
Fork 0

Fix tile cache resizing bug (which could lead to thrashing.)

This commit is contained in:
curt 2002-08-01 06:15:59 +00:00
parent acdd550a2f
commit 2619106044
3 changed files with 17 additions and 13 deletions

View 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

View 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;

View file

@ -105,7 +105,6 @@ private:
/**
* tile cache
*/
int max_cache_size;
FGNewCache tile_cache;
/**