Did a bit of renaming and reorganizing.
libScenery_a_SOURCES = \
scenery.cxx scenery.hxx \
- tile.cxx tile.hxx \
tilecache.cxx tilecache.hxx \
+ tileentry.cxx tileentry.hxx \
tilemgr.cxx tilemgr.hxx
INCLUDES += \
#include <Misc/fgpath.hxx>
#include <Objects/obj.hxx>
-#include "tile.hxx"
#include "tilecache.hxx"
+#include "tileentry.hxx"
// the tile cache
-fgTILECACHE global_tile_cache;
+FGTileCache global_tile_cache;
// Constructor
-fgTILECACHE::fgTILECACHE( void ) {
+FGTileCache::FGTileCache( void ) {
+ tile_cache.clear();
}
// Initialize the tile cache subsystem
void
-fgTILECACHE::init( void )
+FGTileCache::init( void )
{
int i;
FG_LOG( FG_TERRAIN, FG_INFO, "Initializing the tile cache." );
- for ( i = 0; i < FG_TILE_CACHE_SIZE; i++ ) {
+ // expand cache if needed. For best results ... i.e. to avoid
+ // tile load problems and blank areas:
+ //
+ // target_cache_size >= (current.options.tile_diameter + 1) ** 2
+ //
+ int side = current_options.get_tile_diameter() + 1;
+ int target_cache_size = side * side;
+ FG_LOG( FG_TERRAIN, FG_DEBUG, " target cache size = "
+ << target_cache_size );
+ FG_LOG( FG_TERRAIN, FG_DEBUG, " current cache size = "
+ << tile_cache.size() );
+ FGTileEntry e;
+ FG_LOG( FG_TERRAIN, FG_DEBUG, " size of tile = "
+ << sizeof( e ) );
+ if ( target_cache_size > (int)tile_cache.size() ) {
+ // FGTileEntry e;
+ e.used = false;
+ int expansion_amt = target_cache_size - (int)tile_cache.size();
+ for ( i = 0; i < expansion_amt; ++i ) {
+ tile_cache.push_back( e );
+ FG_LOG( FG_TERRAIN, FG_DEBUG, " expanding cache size = "
+ << tile_cache.size() );
+ }
+ }
+ FG_LOG( FG_TERRAIN, FG_DEBUG, " done expanding cache, size = "
+ << tile_cache.size() );
+
+ for ( i = 0; i < (int)tile_cache.size(); i++ ) {
if ( tile_cache[i].used ) {
entry_free(i);
}
- tile_cache[i].used = 0;
+ tile_cache[i].used = false;
tile_cache[i].tile_bucket.make_bad();
}
+ FG_LOG( FG_TERRAIN, FG_DEBUG, " done with init()" );
}
// Search for the specified "bucket" in the cache
int
-fgTILECACHE::exists( const FGBucket& p )
+FGTileCache::exists( const FGBucket& p )
{
int i;
- for ( i = 0; i < FG_TILE_CACHE_SIZE; i++ ) {
+ for ( i = 0; i < (int)tile_cache.size(); i++ ) {
if ( tile_cache[i].tile_bucket == p ) {
FG_LOG( FG_TERRAIN, FG_DEBUG,
"TILE EXISTS in cache ... index = " << i );
// Fill in a tile cache entry with real data for the specified bucket
void
-fgTILECACHE::fill_in( int index, FGBucket& p )
+FGTileCache::fill_in( int index, FGBucket& p )
{
// Load the appropriate data file and build tile fragment list
FGPath tile_path( current_options.get_fg_root() );
// Free a tile cache entry
void
-fgTILECACHE::entry_free( int index )
+FGTileCache::entry_free( int index )
{
tile_cache[index].release_fragments();
}
// Return index of next available slot in tile cache
int
-fgTILECACHE::next_avail( void )
+FGTileCache::next_avail( void )
{
Point3D delta, abs_view_pos;
int i;
max_dist = 0.0;
max_index = 0;
- for ( i = 0; i < FG_TILE_CACHE_SIZE; i++ ) {
+ for ( i = 0; i < (int)tile_cache.size(); i++ ) {
if ( ! tile_cache[i].used ) {
return(i);
} else {
// Destructor
-fgTILECACHE::~fgTILECACHE( void ) {
+FGTileCache::~FGTileCache( void ) {
}
#include <GL/glut.h>
#include <XGL/xgl.h>
+#include <vector>
+
#include <Bucket/newbucket.hxx>
#include <Math/point3d.hxx>
-#include "tile.hxx"
+#include "tileentry.hxx"
+FG_USING_STD(vector);
-// For best results ... i.e. to avoid tile load problems and blank areas
-//
-// FG_TILE_CACHE_SIZE >= (o->tile_diameter + 1) ** 2
-#define FG_TILE_CACHE_SIZE 121
// A class to store and manage a pile of tiles
-class fgTILECACHE {
-
-// enum
-// {
-// // For best results... i.e. to avoid tile load problems and blank areas
-// // FG_TILE_CACHE_SIZE >= (o->tile_diameter + 1) ** 2
-// FG_TILE_CACHE_SIZE = 121
-// };
+class FGTileCache {
// cache storage space
- fgTILE tile_cache[ FG_TILE_CACHE_SIZE ];
+ tile_list tile_cache;
public:
// Constructor
- fgTILECACHE( void );
+ FGTileCache( void );
// Initialize the tile cache subsystem
void init( void );
void fill_in( int index, FGBucket& p );
// Return a pointer to the specified tile cache entry
- fgTILE *get_tile( int index ) {
+ FGTileEntry *get_tile( int index ) {
return &tile_cache[index];
}
// Destructor
- ~fgTILECACHE( void );
+ ~FGTileCache( void );
};
// the tile cache
-extern fgTILECACHE global_tile_cache;
+extern FGTileCache global_tile_cache;
#endif // _TILECACHE_HXX
#include <Weather/weather.hxx>
#include "scenery.hxx"
-#include "tile.hxx"
#include "tilecache.hxx"
+#include "tileentry.hxx"
#include "tilemgr.hxx"
// load a tile
void fgTileMgrLoadTile( FGBucket& p, int *index) {
- fgTILECACHE *c;
+ FGTileCache *c;
c = &global_tile_cache;
// Returns result in meters.
double
fgTileMgrCurElevNEW( const FGBucket& p ) {
- fgTILE *t;
+ FGTileEntry *t;
fgFRAGMENT *frag_ptr;
Point3D abs_view_pos = current_view.get_abs_view_pos();
Point3D earth_center(0.0);
if ( dist < FG_SQUARE(t->bounding_radius) ) {
// traverse fragment list for tile
- fgTILE::FragmentIterator current = t->begin();
- fgTILE::FragmentIterator last = t->end();
+ FGTileEntry::FragmentIterator current = t->begin();
+ FGTileEntry::FragmentIterator last = t->end();
for ( ; current != last; ++current ) {
frag_ptr = &(*current);
// Returns result in meters.
double
fgTileMgrCurElev( double lon, double lat, const Point3D& abs_view_pos ) {
- fgTILECACHE *c;
- fgTILE *t;
+ FGTileCache *c;
+ FGTileEntry *t;
fgFRAGMENT *frag_ptr;
Point3D earth_center(0.0);
Point3D result;
if ( dist < FG_SQUARE(t->bounding_radius) ) {
// traverse fragment list for tile
- fgTILE::FragmentIterator current = t->begin();
- fgTILE::FragmentIterator last = t->end();
+ FGTileEntry::FragmentIterator current = t->begin();
+ FGTileEntry::FragmentIterator last = t->end();
for ( ; current != last; ++current ) {
frag_ptr = &(*current);
// given the current lon/lat, fill in the array of local chunks. If
// the chunk isn't already in the cache, then read it from disk.
int fgTileMgrUpdate( void ) {
- fgTILECACHE *c;
+ FGTileCache *c;
FGInterface *f;
FGBucket p2;
static FGBucket p_last(false);
// update this tile's geometry for current view
// The Compiler should inline this
static void
-update_tile_geometry( fgTILE *t, GLdouble *MODEL_VIEW)
+update_tile_geometry( FGTileEntry *t, GLdouble *MODEL_VIEW)
{
GLfloat *m;
double x, y, z;
// Render the local tiles
void fgTileMgrRender( void ) {
FGInterface *f;
- fgTILECACHE *c;
- fgTILE *t;
+ FGTileCache *c;
+ FGTileEntry *t;
FGView *v;
Point3D frag_offset;
fgFRAGMENT *frag_ptr;
// Calculate the model_view transformation matrix for this tile
// This is equivalent to doing a glTranslatef(x, y, z);
- t->UpdateViewMatrix( v->get_MODEL_VIEW() );
+ t->update_view_matrix( v->get_MODEL_VIEW() );
// xglPushMatrix();
// xglTranslatef(t->offset.x, t->offset.y, t->offset.z);
// traverse fragment list for tile
- fgTILE::FragmentIterator current = t->begin();
- fgTILE::FragmentIterator last = t->end();
+ FGTileEntry::FragmentIterator current = t->begin();
+ FGTileEntry::FragmentIterator last = t->end();
for ( ; current != last; ++current ) {
frag_ptr = &(*current);