]> git.mxchange.org Git - flightgear.git/commitdiff
Started work on a dynamic tile cache.
authorcurt <curt>
Sat, 12 Jun 1999 21:12:13 +0000 (21:12 +0000)
committercurt <curt>
Sat, 12 Jun 1999 21:12:13 +0000 (21:12 +0000)
Did a bit of renaming and reorganizing.

Simulator/Scenery/Makefile.am
Simulator/Scenery/tilecache.cxx
Simulator/Scenery/tilecache.hxx
Simulator/Scenery/tilemgr.cxx

index 6e8da5051beb7535b27254409baa440d7c06d7ac..699a4442e0c0f8cc86ffcc5fcec561b021e9eb3c 100644 (file)
@@ -2,8 +2,8 @@ noinst_LIBRARIES = libScenery.a
 
 libScenery_a_SOURCES = \
        scenery.cxx scenery.hxx \
-       tile.cxx tile.hxx \
        tilecache.cxx tilecache.hxx \
+       tileentry.cxx tileentry.hxx \
        tilemgr.cxx tilemgr.hxx
 
 INCLUDES += \
index 0556b9dae66bf9979300b0bfc34415080e96e802..b18d2fab7511d72796ea2cdbcf29bd204ca71884 100644 (file)
 #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 );
@@ -91,7 +120,7 @@ fgTILECACHE::exists( const FGBucket& p )
 
 // 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() );
@@ -120,7 +149,7 @@ fgTILECACHE::fill_in( int index, FGBucket& p )
 
 // Free a tile cache entry
 void
-fgTILECACHE::entry_free( int index )
+FGTileCache::entry_free( int index )
 {
     tile_cache[index].release_fragments();
 }
@@ -128,7 +157,7 @@ fgTILECACHE::entry_free( int index )
 
 // 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;
@@ -139,7 +168,7 @@ fgTILECACHE::next_avail( void )
     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 {
@@ -183,7 +212,7 @@ fgTILECACHE::next_avail( void )
 
 
 // Destructor
-fgTILECACHE::~fgTILECACHE( void ) {
+FGTileCache::~FGTileCache( void ) {
 }
 
 
index 02984c6c68e5528cd3e4468135623474b2bb3f5f..7713584c8c7e7a074be0be952df09b996352e40e 100644 (file)
 #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 );
@@ -86,17 +78,17 @@ public:
     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 
index 5a2705ba8c6ffee5f9d3c463d86e50d17d2b2b65..94be439f9842f930e5349ca07d12cc95c272a8e9 100644 (file)
@@ -49,8 +49,8 @@
 #include <Weather/weather.hxx>
 
 #include "scenery.hxx"
-#include "tile.hxx"
 #include "tilecache.hxx"
+#include "tileentry.hxx"
 #include "tilemgr.hxx"
 
 
@@ -104,7 +104,7 @@ int fgTileMgrInit( void ) {
 
 // load a tile
 void fgTileMgrLoadTile( FGBucket& p, int *index) {
-    fgTILECACHE *c;
+    FGTileCache *c;
 
     c = &global_tile_cache;
 
@@ -140,7 +140,7 @@ static double point_line_dist_squared( const Point3D& tc, const Point3D& vp,
 // 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);
@@ -187,8 +187,8 @@ fgTileMgrCurElevNEW( const FGBucket& p ) {
     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);
@@ -238,8 +238,8 @@ fgTileMgrCurElevNEW( const FGBucket& p ) {
 // 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;
@@ -294,8 +294,8 @@ fgTileMgrCurElev( double lon, double lat, const Point3D& abs_view_pos ) {
     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);
@@ -342,7 +342,7 @@ fgTileMgrCurElev( double lon, double lat, const Point3D& abs_view_pos ) {
 // 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);
@@ -643,7 +643,7 @@ inrange( const double radius, const Point3D& center, const Point3D& vp,
 // 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;
@@ -673,8 +673,8 @@ update_tile_geometry( fgTILE *t, GLdouble *MODEL_VIEW)
 // 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;
@@ -715,14 +715,14 @@ void fgTileMgrRender( void ) {
            
            // 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);