00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 #ifndef _TILECACHE_HXX
00025 #define _TILECACHE_HXX
00026 
00027 #include <map>
00028 
00029 #include <simgear/bucket/newbucket.hxx>
00030 #include <simgear/math/point3d.hxx>
00031 #include <simgear/scene/tgdb/TileEntry.hxx>
00032 
00033 using std::map;
00034 
00035 namespace simgear {
00036 
00037 
00038 class TileCache {
00039 public:
00040     typedef map < long, simgear::TileEntry * > tile_map;
00041     typedef tile_map::iterator tile_map_iterator;
00042     typedef tile_map::const_iterator const_tile_map_iterator;
00043 private:
00044     
00045     tile_map tile_cache;
00046 
00047     
00048     int max_cache_size;
00049 
00050     
00051     tile_map_iterator current;
00052 
00053     
00054     void entry_free( long cache_index );
00055 
00056     double current_time;
00057 
00058 public:
00059     tile_map_iterator begin() { return tile_cache.begin(); }
00060     tile_map_iterator end() { return tile_cache.end(); }
00061     const_tile_map_iterator begin() const { return tile_cache.begin(); }
00062     const_tile_map_iterator end() const { return tile_cache.end(); }
00063 
00064     
00065     TileCache();
00066 
00067     
00068     ~TileCache();
00069 
00070     
00071     void init( void );
00072 
00073     
00074     bool exists( const SGBucket& b ) const;
00075 
00076     
00077     
00078     long get_oldest_tile();
00079 
00080     
00081     
00082     void clear_inner_ring_flags();
00083 
00084     
00085     
00086     void clear_entry( long cache_entry );
00087 
00088     
00089     void clear_cache();
00090 
00091     
00092     inline simgear::TileEntry *get_tile( const long tile_index ) const {
00093         const_tile_map_iterator it = tile_cache.find( tile_index );
00094         if ( it != tile_cache.end() ) {
00095             return it->second;
00096         } else {
00097             return NULL;
00098         }
00099     }
00100 
00101     
00102     inline simgear::TileEntry *get_tile( const SGBucket& b ) const {
00103         return get_tile( b.gen_index() );
00104     }
00105 
00106     
00107     inline size_t get_size() const { return tile_cache.size(); }
00108 
00109     
00110     inline void reset_traversal() { current = tile_cache.begin(); }
00111     inline bool at_end() { return current == tile_cache.end(); }
00112     inline simgear::TileEntry *get_current() const {
00113         
00114         return current->second;
00115     }
00116     inline void next() { ++current; }
00117 
00118     inline int get_max_cache_size() const { return max_cache_size; }
00119     inline void set_max_cache_size( int m ) { max_cache_size = m; }
00120 
00126     bool insert_tile( simgear::TileEntry* e );
00127 
00128     void set_current_time(double val) { current_time = val; }
00129     double get_current_time() const { return current_time; }
00130 };
00131 
00132 }
00133 
00134 #endif // _TILECACHE_HXX