+ tile_cache.set_current_time( current_time );
+ tile_cache.reset_traversal();
+
+ while ( ! tile_cache.at_end() )
+ {
+ e = tile_cache.get_current();
+ // cout << "processing a tile" << endl;
+ if ( e )
+ {
+ // Prepare the ssg nodes corresponding to each tile.
+ // Set the ssg transform and update it's range selector
+ // based on current visibilty
+ e->prep_ssg_node(vis);
+
+ if (( !e->is_loaded() )&&
+ ((!e->is_expired(current_time))||
+ e->is_current_view() ))
+ {
+ // schedule tile for loading with osg pager
+ pager->queueRequest(e->tileFileName,
+ e->getNode(),
+ e->get_priority(),
+ framestamp,
+ e->getDatabaseRequest(),
+ _options.get());
+ loading++;
+ }
+ } else
+ {
+ SG_LOG(SG_TERRAIN, SG_ALERT, "Warning: empty tile in cache!");
+ }
+ tile_cache.next();
+ sz++;
+ }
+
+ int drop_count = sz - tile_cache.get_max_cache_size();
+ if (( drop_count > 0 )&&
+ ((loading==0)||(drop_count > 10)))
+ {
+ long drop_index = tile_cache.get_drop_tile();
+ while ( drop_index > -1 )
+ {
+ // schedule tile for deletion with osg pager
+ TileEntry* old = tile_cache.get_tile(drop_index);
+ tile_cache.clear_entry(drop_index);
+
+ osg::ref_ptr<osg::Object> subgraph = old->getNode();
+ old->removeFromSceneGraph();
+ delete old;
+ // zeros out subgraph ref_ptr, so subgraph is owned by
+ // the pager and will be deleted in the pager thread.
+ pager->queueDeleteRequest(subgraph);
+
+ if (--drop_count > 0)
+ drop_index = tile_cache.get_drop_tile();
+ else
+ drop_index = -1;
+ }
+ }
+}