1 // newcache.hxx -- routines to handle scenery tile caching
3 // Written by Curtis Olson, started December 2000.
5 // Copyright (C) 2000 Curtis L. Olson - curt@flightgear.org
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., 675 Mass Ave, Cambridge, MA 02139, USA.
29 # error This library requires C++
45 #include <simgear/bucket/newbucket.hxx>
46 #include <simgear/math/point3d.hxx>
48 #include "tileentry.hxx"
49 #include "FGTileLoader.hxx"
53 // A class to store and manage a pile of tiles
56 typedef map < long, FGTileEntry * > tile_map;
57 typedef tile_map::iterator tile_map_iterator;
58 typedef tile_map::const_iterator const_tile_map_iterator;
60 // cache storage space
66 // pointers to allow an external linear traversal of cache entries
67 tile_map_iterator current;
69 // Free a tile cache entry
70 void entry_free( long cache_index );
73 * Queue tiles for loading.
85 // Initialize the tile cache subsystem
88 // Check if the specified "bucket" exists in the cache
89 bool exists( const SGBucket& b ) const;
91 // Ensure at least one entry is free in the cache
94 // Fill in a tile cache entry with real data for the specified bucket
95 // void fill_in( const SGBucket& b );
97 // Return a pointer to the specified tile cache entry
98 inline FGTileEntry *get_tile( const long tile_index ) {
99 tile_map_iterator it = tile_cache.find( tile_index );
100 if ( it != tile_cache.end() ) {
107 // Return a pointer to the specified tile cache entry
108 inline FGTileEntry *get_tile( const SGBucket& b ) {
109 return get_tile( b.gen_index() );
112 // Return the cache size
113 inline size_t get_size() const { return tile_cache.size(); }
115 // External linear traversal of cache
116 inline void reset_traversal() { current = tile_cache.begin(); }
117 inline bool at_end() { return current == tile_cache.end(); }
118 inline FGTileEntry *get_current() {
119 // cout << "index = " << current->first << endl;
120 return current->second;
122 inline void next() { ++current; }
124 inline int get_max_cache_size() const { return max_cache_size; }
125 inline void set_max_cache_size( int m ) { max_cache_size = m; }
128 * Create a new tile and enqueue it for loading.
131 void load_tile( const SGBucket& b );
135 #endif // _NEWCACHE_HXX