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/math/point3d.hxx>
31 #include <simgear/scene/tgdb/TileEntry.hxx>
37 // A class to store and manage a pile of tiles
40 typedef map < long, simgear::TileEntry * > tile_map;
41 typedef tile_map::iterator tile_map_iterator;
42 typedef tile_map::const_iterator const_tile_map_iterator;
44 // cache storage space
50 // pointers to allow an external linear traversal of cache entries
51 tile_map_iterator current;
53 // Free a tile cache entry
54 void entry_free( long cache_index );
59 tile_map_iterator begin() { return tile_cache.begin(); }
60 tile_map_iterator end() { return tile_cache.end(); }
61 const_tile_map_iterator begin() const { return tile_cache.begin(); }
62 const_tile_map_iterator end() const { return tile_cache.end(); }
70 // Initialize the tile cache subsystem
73 // Check if the specified "bucket" exists in the cache
74 bool exists( const SGBucket& b ) const;
76 // Return the index of the oldest tile in the cache, return -1 if
77 // nothing available to be removed.
78 long get_oldest_tile();
80 // Clear the inner ring flag for all tiles in the cache so that
81 // the external tile scheduler can flag the inner ring correctly.
82 void clear_inner_ring_flags();
84 // Clear a cache entry, note that the cache only holds pointers
85 // and this does not free the object which is pointed to.
86 void clear_entry( long cache_entry );
88 // Clear all completely loaded tiles (ignores partially loaded tiles)
91 // Return a pointer to the specified tile cache entry
92 inline simgear::TileEntry *get_tile( const long tile_index ) const {
93 const_tile_map_iterator it = tile_cache.find( tile_index );
94 if ( it != tile_cache.end() ) {
101 // Return a pointer to the specified tile cache entry
102 inline simgear::TileEntry *get_tile( const SGBucket& b ) const {
103 return get_tile( b.gen_index() );
106 // Return the cache size
107 inline size_t get_size() const { return tile_cache.size(); }
109 // External linear traversal of cache
110 inline void reset_traversal() { current = tile_cache.begin(); }
111 inline bool at_end() { return current == tile_cache.end(); }
112 inline simgear::TileEntry *get_current() const {
113 // cout << "index = " << current->first << endl;
114 return current->second;
116 inline void next() { ++current; }
118 inline int get_max_cache_size() const { return max_cache_size; }
119 inline void set_max_cache_size( int m ) { max_cache_size = m; }
122 * Create a new tile and enqueue it for loading.
124 * @return success/failure
126 bool insert_tile( simgear::TileEntry* e );
128 void set_current_time(double val) { current_time = val; }
129 double get_current_time() const { return current_time; }
134 #endif // _TILECACHE_HXX