X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FScenery%2Ftilecache.hxx;h=a1f43cecf95ac9f6121b1da74c09e4569073c54c;hb=130f581b18711b63138580d306a39c27b891178c;hp=789c0db125e1220955cb1eb72899fdc4224599d7;hpb=a5f19c7a7ca5eee5bf6df01ab78b80d90b5fe8a6;p=flightgear.git diff --git a/src/Scenery/tilecache.hxx b/src/Scenery/tilecache.hxx index 789c0db12..a1f43cecf 100644 --- a/src/Scenery/tilecache.hxx +++ b/src/Scenery/tilecache.hxx @@ -1,8 +1,8 @@ -// tilecache.hxx -- routines to handle scenery tile caching +// TileCache.hxx -- routines to handle scenery tile caching // -// Written by Curtis Olson, started January 1998. +// Written by Curtis Olson, started December 2000. // -// Copyright (C) 1998, 1999 Curtis L. Olson - curt@flightgear.org +// Copyright (C) 2000 Curtis L. Olson - http://www.flightgear.org/~curt // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License as @@ -16,7 +16,7 @@ // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software -// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // // $Id$ @@ -24,76 +24,108 @@ #ifndef _TILECACHE_HXX #define _TILECACHE_HXX +#include -#ifndef __cplusplus -# error This library requires C++ -#endif - - -#ifdef HAVE_CONFIG_H -# include -#endif - -#ifdef HAVE_WINDOWS_H -# include -#endif - -#include -#include - -#include +#include +#include "tileentry.hxx" -#include -#include +using std::map; -#include "tileentry.hxx" +// A class to store and manage a pile of tiles +class TileCache { +public: + typedef map < long, TileEntry * > tile_map; + typedef tile_map::iterator tile_map_iterator; + typedef tile_map::const_iterator const_tile_map_iterator; +private: + // cache storage space + tile_map tile_cache; -FG_USING_STD(vector); + // maximum cache size + int max_cache_size; + // pointers to allow an external linear traversal of cache entries + tile_map_iterator current; -// A class to store and manage a pile of tiles -class FGTileCache { + double current_time; - // cache storage space - tile_list tile_cache; + // Free a tile cache entry + void entry_free( long cache_index ); public: + tile_map_iterator begin() { return tile_cache.begin(); } + tile_map_iterator end() { return tile_cache.end(); } + const_tile_map_iterator begin() const { return tile_cache.begin(); } + const_tile_map_iterator end() const { return tile_cache.end(); } // Constructor - FGTileCache( void ); + TileCache(); - // Initialize the tile cache subsystem - void init( void ); - - // Search for the specified "bucket" in the cache - int exists( const FGBucket& p ); - - // Return index of next available slot in tile cache - int next_avail( void ); + // Destructor + ~TileCache(); - // Free a tile cache entry - void entry_free( int index ); + // Initialize the tile cache subsystem + void init( void ); - // Fill in a tile cache entry with real data for the specified bucket - void fill_in( int index, const FGBucket& p ); + // Check if the specified "bucket" exists in the cache + bool exists( const SGBucket& b ) const; + + // Return the index of a tile to be dropped from the cache, return -1 if + // nothing available to be removed. + long get_drop_tile(); + + // Clear all flags indicating tiles belonging to the current view + void clear_current_view(); + + // Clear a cache entry, note that the cache only holds pointers + // and this does not free the object which is pointed to. + void clear_entry( long cache_entry ); + + // Clear all completely loaded tiles (ignores partially loaded tiles) + void clear_cache(); + + // Return a pointer to the specified tile cache entry + inline TileEntry *get_tile( const long tile_index ) const { + const_tile_map_iterator it = tile_cache.find( tile_index ); + if ( it != tile_cache.end() ) { + return it->second; + } else { + return NULL; + } + } - // Return a pointer to the specified tile cache entry - FGTileEntry *get_tile( int index ) { - return &tile_cache[index]; + // Return a pointer to the specified tile cache entry + inline TileEntry *get_tile( const SGBucket& b ) const { + return get_tile( b.gen_index() ); } // Return the cache size inline size_t get_size() const { return tile_cache.size(); } - // Destructor - ~FGTileCache( void ); -}; - + // External linear traversal of cache + inline void reset_traversal() { current = tile_cache.begin(); } + inline bool at_end() { return current == tile_cache.end(); } + inline TileEntry *get_current() const { + // cout << "index = " << current->first << endl; + return current->second; + } + inline void next() { ++current; } -// the tile cache -extern FGTileCache global_tile_cache; + inline int get_max_cache_size() const { return max_cache_size; } + inline void set_max_cache_size( int m ) { max_cache_size = m; } + /** + * Create a new tile and enqueue it for loading. + * @param b + * @return success/failure + */ + bool insert_tile( TileEntry* e ); -#endif // _TILECACHE_HXX + void set_current_time(double val) { current_time = val; } + double get_current_time() const { return current_time; } + // update tile's priority and expiry time according to current request + void request_tile(TileEntry* t,float priority,bool current_view,double requesttime); +}; +#endif // _TILECACHE_HXX