1 // newcache.hxx -- routines to handle scenery tile caching
3 // Written by Curtis Olson, started December 2000.
5 // Copyright (C) 2000 Curtis L. Olson - http://www.flightgear.org/~curt
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 #ifndef _TILECACHE_HXX
25 #define _TILECACHE_HXX
29 #include <simgear/bucket/newbucket.hxx>
30 #include <simgear/scene/tgdb/TileEntry.hxx>
36 // A class to store and manage a pile of tiles
39 typedef map < long, simgear::TileEntry * > tile_map;
40 typedef tile_map::iterator tile_map_iterator;
41 typedef tile_map::const_iterator const_tile_map_iterator;
43 // cache storage space
49 // pointers to allow an external linear traversal of cache entries
50 tile_map_iterator current;
52 // Free a tile cache entry
53 void entry_free( long cache_index );
58 tile_map_iterator begin() { return tile_cache.begin(); }
59 tile_map_iterator end() { return tile_cache.end(); }
60 const_tile_map_iterator begin() const { return tile_cache.begin(); }
61 const_tile_map_iterator end() const { return tile_cache.end(); }
69 // Initialize the tile cache subsystem
72 // Check if the specified "bucket" exists in the cache
73 bool exists( const SGBucket& b ) const;
75 // Return the index of the oldest tile in the cache, return -1 if
76 // nothing available to be removed.
77 long get_oldest_tile();
79 // Clear the inner ring flag for all tiles in the cache so that
80 // the external tile scheduler can flag the inner ring correctly.
81 void clear_inner_ring_flags();
83 // Clear all locked flags for all tiles in the cache.
84 // (Tiles belonging to the current position are locked to
85 // the cache to prevent them from being dropped).
86 void clear_cache_lock_flags();
88 // Clear a cache entry, note that the cache only holds pointers
89 // and this does not free the object which is pointed to.
90 void clear_entry( long cache_entry );
92 // Clear all completely loaded tiles (ignores partially loaded tiles)
95 // Return a pointer to the specified tile cache entry
96 inline simgear::TileEntry *get_tile( const long tile_index ) const {
97 const_tile_map_iterator it = tile_cache.find( tile_index );
98 if ( it != tile_cache.end() ) {
105 // Return a pointer to the specified tile cache entry
106 inline simgear::TileEntry *get_tile( const SGBucket& b ) const {
107 return get_tile( b.gen_index() );
110 // Return the cache size
111 inline size_t get_size() const { return tile_cache.size(); }
113 // External linear traversal of cache
114 inline void reset_traversal() { current = tile_cache.begin(); }
115 inline bool at_end() { return current == tile_cache.end(); }
116 inline simgear::TileEntry *get_current() const {
117 // cout << "index = " << current->first << endl;
118 return current->second;
120 inline void next() { ++current; }
122 inline int get_max_cache_size() const { return max_cache_size; }
123 inline void set_max_cache_size( int m ) { max_cache_size = m; }
126 * Create a new tile and enqueue it for loading.
128 * @return success/failure
130 bool insert_tile( simgear::TileEntry* e );
132 void set_current_time(double val) { current_time = val; }
133 double get_current_time() const { return current_time; }
138 #endif // _TILECACHE_HXX