FlightGear
next
tilecache.hxx
Go to the documentation of this file.
1
// TileCache.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
#pragma once
25
26
#include <map>
27
28
#include <simgear/bucket/newbucket.hxx>
29
#include "
tileentry.hxx
"
30
31
32
// A class to store and manage a pile of tiles
33
class
TileCache
{
34
public
:
35
typedef
std::map < long, TileEntry * >
tile_map
;
36
typedef
tile_map::iterator
tile_map_iterator
;
37
typedef
tile_map::const_iterator
const_tile_map_iterator
;
38
private
:
39
// cache storage space
40
tile_map
tile_cache;
41
42
// maximum cache size
43
int
max_cache_size;
44
45
// pointers to allow an external linear traversal of cache entries
46
tile_map_iterator
current;
47
48
double
current_time;
49
50
// Free a tile cache entry
51
void
entry_free(
long
cache_index );
52
53
public
:
54
tile_map_iterator
begin
() {
return
tile_cache.begin(); }
55
tile_map_iterator
end
() {
return
tile_cache.end(); }
56
const_tile_map_iterator
begin
()
const
{
return
tile_cache.begin(); }
57
const_tile_map_iterator
end
()
const
{
return
tile_cache.end(); }
58
59
// Constructor
60
TileCache
();
61
62
// Destructor
63
~TileCache
();
64
65
// Initialize the tile cache subsystem
66
void
init
(
void
);
67
68
// Check if the specified "bucket" exists in the cache
69
bool
exists_stg
(
const
SGBucket& b )
const
;
70
bool
exists_vpb
(
const
SGBucket& b )
const
;
71
72
// Return the index of a tile to be dropped from the cache, return -1 if
73
// nothing available to be removed.
74
long
get_drop_tile
();
75
76
long
get_first_expired_tile
()
const
;
77
78
// Clear all flags indicating tiles belonging to the current view
79
void
clear_current_view
();
80
81
// Clear a cache entry, note that the cache only holds pointers
82
// and this does not free the object which is pointed to.
83
void
clear_entry
(
long
cache_entry );
84
85
// Clear all completely loaded tiles (ignores partially loaded tiles)
86
void
clear_cache
();
87
88
// Return a pointer to the specified tile cache entry
89
inline
TileEntry
*
get_tile
(
const
long
tile_index )
const
{
90
const_tile_map_iterator
it = tile_cache.find( tile_index );
91
if
( it != tile_cache.end() ) {
92
return
it->second;
93
}
else
{
94
return
NULL;
95
}
96
}
97
98
STGTileEntry
*
get_stg_tile
(
const
SGBucket& b )
const
;
99
VPBTileEntry
*
get_vpb_tile
(
const
SGBucket& b )
const
;
100
101
// Return the cache size
102
inline
size_t
get_size
()
const
{
return
tile_cache.size(); }
103
104
// External linear traversal of cache
105
inline
void
reset_traversal
() { current = tile_cache.begin(); }
106
inline
bool
at_end
() {
return
current == tile_cache.end(); }
107
inline
TileEntry
*
get_current
()
const
{
108
// cout << "index = " << current->first << endl;
109
return
current->second;
110
}
111
inline
void
next
() { ++current; }
112
113
inline
int
get_max_cache_size
()
const
{
return
max_cache_size; }
114
inline
void
set_max_cache_size
(
int
m ) { max_cache_size = m; }
115
121
bool
insert_tile
(
STGTileEntry
* e );
122
bool
insert_tile
(
VPBTileEntry
* e );
123
124
void
set_current_time
(
double
val) { current_time = val; }
125
double
get_current_time
()
const
{
return
current_time; }
126
127
// update tile's priority and expiry time according to current request
128
void
request_tile
(
TileEntry
* t,
float
priority,
bool
current_view,
double
requesttime);
129
};
STGTileEntry
Definition
tileentry.hxx:156
TileCache::set_max_cache_size
void set_max_cache_size(int m)
Definition
tilecache.hxx:114
TileCache::begin
const_tile_map_iterator begin() const
Definition
tilecache.hxx:56
TileCache::end
const_tile_map_iterator end() const
Definition
tilecache.hxx:57
TileCache::const_tile_map_iterator
tile_map::const_iterator const_tile_map_iterator
Definition
tilecache.hxx:37
TileCache::get_size
size_t get_size() const
Definition
tilecache.hxx:102
TileCache::get_stg_tile
STGTileEntry * get_stg_tile(const SGBucket &b) const
Definition
tilecache.cxx:249
TileCache::request_tile
void request_tile(TileEntry *t, float priority, bool current_view, double requesttime)
Definition
tilecache.cxx:225
TileCache::get_current
TileEntry * get_current() const
Definition
tilecache.hxx:107
TileCache::begin
tile_map_iterator begin()
Definition
tilecache.hxx:54
TileCache::at_end
bool at_end()
Definition
tilecache.hxx:106
TileCache::end
tile_map_iterator end()
Definition
tilecache.hxx:55
TileCache::tile_map_iterator
tile_map::iterator tile_map_iterator
Definition
tilecache.hxx:36
TileCache::get_tile
TileEntry * get_tile(const long tile_index) const
Definition
tilecache.hxx:89
TileCache::next
void next()
Definition
tilecache.hxx:111
TileCache::clear_current_view
void clear_current_view()
Definition
tilecache.cxx:156
TileCache::get_max_cache_size
int get_max_cache_size() const
Definition
tilecache.hxx:113
TileCache::tile_map
std::map< long, TileEntry * > tile_map
Definition
tilecache.hxx:35
TileCache::init
void init(void)
Definition
tilecache.cxx:63
TileCache::get_first_expired_tile
long get_first_expired_tile() const
Definition
tilecache.cxx:138
TileCache::exists_stg
bool exists_stg(const SGBucket &b) const
Definition
tilecache.cxx:78
TileCache::set_current_time
void set_current_time(double val)
Definition
tilecache.hxx:124
TileCache::clear_entry
void clear_entry(long cache_entry)
Definition
tilecache.cxx:174
TileCache::exists_vpb
bool exists_vpb(const SGBucket &b) const
Definition
tilecache.cxx:85
TileCache::clear_cache
void clear_cache()
Definition
tilecache.cxx:180
TileCache::get_drop_tile
long get_drop_tile()
Definition
tilecache.cxx:96
TileCache::get_current_time
double get_current_time() const
Definition
tilecache.hxx:125
TileCache::~TileCache
~TileCache()
Definition
tilecache.cxx:41
TileCache::TileCache
TileCache()
Definition
tilecache.cxx:34
TileCache::reset_traversal
void reset_traversal()
Definition
tilecache.hxx:105
TileCache::get_vpb_tile
VPBTileEntry * get_vpb_tile(const SGBucket &b) const
Definition
tilecache.cxx:263
TileCache::insert_tile
bool insert_tile(STGTileEntry *e)
Create a new tile and enqueue it for loading.
Definition
tilecache.cxx:202
TileEntry
A class to encapsulate everything we need to know about a scenery tile.
Definition
tileentry.hxx:53
VPBTileEntry
Definition
tileentry.hxx:163
tileentry.hxx
src
Scenery
tilecache.hxx
Generated on Tue Jun 3 2025 12:58:41 for FlightGear by
1.13.2