]> git.mxchange.org Git - flightgear.git/blob - src/Scenery/newcache.hxx
Clear chat messages when an aircraft becomes inactive in the property tree.
[flightgear.git] / src / Scenery / newcache.hxx
1 // newcache.hxx -- routines to handle scenery tile caching
2 //
3 // Written by Curtis Olson, started December 2000.
4 //
5 // Copyright (C) 2000  Curtis L. Olson  - http://www.flightgear.org/~curt
6 //
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.
11 //
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.
16 //
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.
20 //
21 // $Id$
22
23
24 #ifndef _NEWCACHE_HXX
25 #define _NEWCACHE_HXX
26
27
28 #ifndef __cplusplus                                                          
29 # error This library requires C++
30 #endif                                   
31
32
33 #ifdef HAVE_CONFIG_H
34 #  include <config.h>
35 #endif
36
37 #include <map>
38
39 #include <simgear/bucket/newbucket.hxx>
40 #include <simgear/math/point3d.hxx>
41
42 #include "tileentry.hxx"
43
44 SG_USING_STD(map);
45
46 // A class to store and manage a pile of tiles
47 class FGNewCache {
48 public:
49     typedef map < long, FGTileEntry * > tile_map;
50     typedef tile_map::iterator tile_map_iterator;
51     typedef tile_map::const_iterator const_tile_map_iterator;
52 private:
53     // cache storage space
54     tile_map tile_cache;
55
56     // maximum cache size
57     int max_cache_size;
58
59     // pointers to allow an external linear traversal of cache entries
60     tile_map_iterator current;
61
62     // Free a tile cache entry
63     void entry_free( long cache_index );
64
65 public:
66     tile_map_iterator begin() { return tile_cache.begin(); }
67     tile_map_iterator end() { return tile_cache.end(); }
68     const_tile_map_iterator begin() const { return tile_cache.begin(); }
69     const_tile_map_iterator end() const { return tile_cache.end(); }
70     
71     // Constructor
72     FGNewCache();
73
74     // Destructor
75     ~FGNewCache();
76
77     // Initialize the tile cache subsystem 
78     void init( void );
79
80     // Check if the specified "bucket" exists in the cache
81     bool exists( const SGBucket& b ) const;
82
83 #if 0
84     // Ensure at least one entry is free in the cache
85     bool make_space();
86 #endif
87
88     // Return the index of the oldest tile in the cache, return -1 if
89     // nothing available to be removed.
90     long get_oldest_tile();
91
92     // Clear the inner ring flag for all tiles in the cache so that
93     // the external tile scheduler can flag the inner ring correctly.
94     void clear_inner_ring_flags();
95
96     // Clear a cache entry, note that the cache only holds pointers
97     // and this does not free the object which is pointed to.
98     void clear_entry( long cache_entry );
99
100     // Clear all completely loaded tiles (ignores partially loaded tiles)
101     void clear_cache();
102
103     // Return a pointer to the specified tile cache entry 
104     inline FGTileEntry *get_tile( const long tile_index ) const {
105         const_tile_map_iterator it = tile_cache.find( tile_index );
106         if ( it != tile_cache.end() ) {
107             it->second->set_timestamp(globals->get_sim_time_sec());
108             return it->second;
109         } else {
110             return NULL;
111         }
112     }
113
114     // Return a pointer to the specified tile cache entry 
115     inline FGTileEntry *get_tile( const SGBucket& b ) const {
116         return get_tile( b.gen_index() );
117     }
118
119     // Return the cache size
120     inline size_t get_size() const { return tile_cache.size(); }
121
122     // External linear traversal of cache
123     inline void reset_traversal() { current = tile_cache.begin(); }
124     inline bool at_end() { return current == tile_cache.end(); }
125     inline FGTileEntry *get_current() const {
126         // cout << "index = " << current->first << endl;
127         return current->second;
128     }
129     inline void next() { ++current; }
130
131     inline int get_max_cache_size() const { return max_cache_size; }
132     inline void set_max_cache_size( int m ) { max_cache_size = m; }
133
134     /**
135      * Create a new tile and enqueue it for loading.
136      * @param b 
137      * @return success/failure
138      */
139     bool insert_tile( FGTileEntry* e );
140 };
141
142
143 #endif // _NEWCACHE_HXX