long FGNewCache::get_oldest_tile() { // we need to free the furthest entry long min_index = -1; double timestamp = 0.0; double min_time = 2419200000.0f; // one month should be enough double max_time = 0; tile_map_iterator current = tile_cache.begin(); tile_map_iterator end = tile_cache.end(); for ( ; current != end; ++current ) { long index = current->first; FGTileEntry *e = current->second; if ( e->is_loaded() && (e->get_pending_models() == 0) ) { timestamp = e->get_timestamp(); if ( timestamp < min_time ) { min_index = index; min_time = timestamp; } if ( timestamp > max_time ) { max_time = timestamp; } } else { SG_LOG( SG_TERRAIN, SG_DEBUG, "loaded = " << e->is_loaded() << " pending models = " << e->get_pending_models() << " time stamp = " << e->get_timestamp() ); } } SG_LOG( SG_TERRAIN, SG_DEBUG, " min_time = " << min_time ); SG_LOG( SG_TERRAIN, SG_DEBUG, " index = " << min_index ); SG_LOG( SG_TERRAIN, SG_DEBUG, " max_time = " << max_time ); return min_index; }