+ // set time of insertion for tracking age of tiles...
+ e->set_timestamp(globals->get_sim_time_sec());
+
+ // register it in the cache
+ long tile_index = e->get_tile_bucket().gen_index();
+ tile_cache[tile_index] = e;
+
+ return true;
+}
+
+
+// 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
+// Ensure at least one entry is free in the cache
+bool FGNewCache::make_space() {
+ SG_LOG( SG_TERRAIN, SG_DEBUG, "Make space in cache" );
+ SG_LOG( SG_TERRAIN, SG_DEBUG, "cache entries = " << tile_cache.size() );
+ SG_LOG( SG_TERRAIN, SG_DEBUG, "max size = " << max_cache_size );
+
+ if ( (int)tile_cache.size() < max_cache_size ) {
+ // space in the cache, return
+ return true;
+ }
+
+ while ( (int)tile_cache.size() >= max_cache_size ) {
+ sgdVec3 abs_view_pos;
+ float dist;
+ float max_dist = 0.0;
+ int max_index = -1;
+
+ // we need to free the furthest entry
+ 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) ) {
+ // calculate approximate distance from view point
+ sgdCopyVec3( abs_view_pos,
+ globals->get_current_view()->get_absolute_view_pos() );
+
+ SG_LOG( SG_TERRAIN, SG_DEBUG, "DIST Abs view pos = "
+ << abs_view_pos[0] << ","
+ << abs_view_pos[1] << ","
+ << abs_view_pos[2] );
+ SG_LOG( SG_TERRAIN, SG_DEBUG,
+ " ref point = " << e->center );
+
+ sgdVec3 center;
+ sgdSetVec3( center,
+ e->center.x(), e->center.y(), e->center.z() );
+ dist = sgdDistanceVec3( center, abs_view_pos );
+
+ SG_LOG( SG_TERRAIN, SG_DEBUG, " distance = " << dist );