]> git.mxchange.org Git - flightgear.git/blobdiff - Scenery/tilecache.cxx
Converted to new logstream debugging facility. This allows release
[flightgear.git] / Scenery / tilecache.cxx
index 43c979fff450780ff73eab5de09d9b53e7b5c78d..993e28551d200b9ad9fa5507b53b9dd8e428fb73 100644 (file)
@@ -33,8 +33,9 @@
 #include <GL/glut.h>
 #include <XGL/xgl.h>
 
+#include <Airports/genapt.hxx>
 #include <Bucket/bucketutils.h>
-#include <Debug/fg_debug.h>
+#include <Debug/logstream.hxx>
 #include <Main/options.hxx>
 #include <Main/views.hxx>
 #include <Objects/obj.hxx>
@@ -53,10 +54,12 @@ fgTILECACHE::fgTILECACHE( void ) {
 
 
 // Initialize the tile cache subsystem
-void fgTILECACHE::Init( void ) {
+void
+fgTILECACHE::init( void )
+{
     int i;
 
-    fgPrintf(FG_TERRAIN, FG_INFO, "Initializing the tile cache.\n");
+    FG_LOG( FG_TERRAIN, FG_INFO, "Initializing the tile cache." );
 
     for ( i = 0; i < FG_TILE_CACHE_SIZE; i++ ) {
        tile_cache[i].used = 0;
@@ -65,7 +68,9 @@ void fgTILECACHE::Init( void ) {
 
 
 // Search for the specified "bucket" in the cache
-int fgTILECACHE::Exists( fgBUCKET *p ) {
+int
+fgTILECACHE::exists( fgBUCKET *p )
+{
     int i;
 
     for ( i = 0; i < FG_TILE_CACHE_SIZE; i++ ) {
@@ -73,8 +78,8 @@ int fgTILECACHE::Exists( fgBUCKET *p ) {
            if ( tile_cache[i].tile_bucket.lat == p->lat ) {
                if ( tile_cache[i].tile_bucket.x == p->x ) {
                    if ( tile_cache[i].tile_bucket.y == p->y ) {
-                       fgPrintf( FG_TERRAIN, FG_DEBUG, 
-                                 "TILE EXISTS in cache ... index = %d\n", i );
+                       FG_LOG( FG_TERRAIN, FG_DEBUG, 
+                               "TILE EXISTS in cache ... index = " << i );
                        return( i );
                    }
                }
@@ -87,10 +92,12 @@ int fgTILECACHE::Exists( fgBUCKET *p ) {
 
 
 // Fill in a tile cache entry with real data for the specified bucket
-void fgTILECACHE::EntryFillIn( int index, fgBUCKET *p ) {
-    string root;
+void
+fgTILECACHE::fill_in( int index, fgBUCKET *p )
+{
+    string root, tile_path, apt_path;
+    char index_str[256];
     char base_path[256];
-    char file_name[256];
 
     // Mark this cache entry as used
     tile_cache[index].used = 1;
@@ -104,31 +111,40 @@ void fgTILECACHE::EntryFillIn( int index, fgBUCKET *p ) {
     // Load the appropriate data file and built tile fragment list
     fgBucketGenBasePath(p, base_path);
     root = current_options.get_fg_root();
-    sprintf(file_name, "%s/Scenery/%s/%ld", root.c_str(), 
-           base_path, fgBucketGenIndex(p));
-    fgObjLoad(file_name, &tile_cache[index]);
-    /*
-    tile_cache[index].display_list = 
-       fgObjLoad(file_name, &tile_cache[index].local_ref,
-                 &tile_cache[index].bounding_radius);    
-                 */
+    sprintf( index_str, "%ld", fgBucketGenIndex(p) );
+
+    tile_path = root + "/Scenery/" + base_path + "/" + index_str;
+    fgObjLoad( tile_path.c_str(), &tile_cache[index] );
+
+    // cout << " ncount before = " << tile_cache[index].ncount << "\n";
+    // cout << " fragments before = " << tile_cache[index].fragment_list.size()
+    //      << "\n";
+
+    apt_path = tile_path + ".apt";
+    fgAptGenerate( apt_path, &tile_cache[index] );
+
+    // cout << " ncount after = " << tile_cache[index].ncount << "\n";
+    // cout << " fragments after = " << tile_cache[index].fragment_list.size()
+    //      << "\n";
 }
 
 
 // Free a tile cache entry
-void fgTILECACHE::EntryFree( int index ) {
+void
+fgTILECACHE::entry_free( int index )
+{
     fgFRAGMENT *fragment;
 
     // Mark this cache entry as un-used
     tile_cache[index].used = 0;
 
     // Update the bucket
-    fgPrintf( FG_TERRAIN, FG_DEBUG, 
-             "FREEING TILE = (%d %d %d %d)\n",
-             tile_cache[index].tile_bucket.lon, 
-             tile_cache[index].tile_bucket.lat, 
-             tile_cache[index].tile_bucket.x,
-             tile_cache[index].tile_bucket.y );
+    FG_LOG( FG_TERRAIN, FG_DEBUG, 
+           "FREEING TILE = ("
+           << tile_cache[index].tile_bucket.lon << " "
+           << tile_cache[index].tile_bucket.lat << " "
+           << tile_cache[index].tile_bucket.x << " "
+           << tile_cache[index].tile_bucket.y << ")" );
 
     // Step through the fragment list, deleting the display list, then
     // the fragment, until the list is empty.
@@ -144,16 +160,21 @@ void fgTILECACHE::EntryFree( int index ) {
 
 
 // Return the specified tile cache entry 
-fgTILE *fgTILECACHE::GetTile( int index ) {
+fgTILE *
+fgTILECACHE::get_tile( int index )
+{
     return ( &tile_cache[index] );
 }
 
 
 // Return index of next available slot in tile cache
-int fgTILECACHE::NextAvail( void ) {
+int
+fgTILECACHE::next_avail( void )
+{
     fgVIEW *v;
+    Point3D delta;
     int i;
-    float dx, dy, dz, max, med, min, tmp;
+    float max, med, min, tmp;
     float dist, max_dist;
     int max_index;
     
@@ -167,19 +188,22 @@ int fgTILECACHE::NextAvail( void ) {
            return(i);
        } else {
            // calculate approximate distance from view point
-           fgPrintf( FG_TERRAIN, FG_DEBUG,
-                     "DIST Abs view pos = %.4f, %.4f, %.4f\n", 
-                     v->abs_view_pos.x, v->abs_view_pos.y, v->abs_view_pos.z );
-           fgPrintf( FG_TERRAIN, FG_DEBUG,
-                     "    ref point = %.4f, %.4f, %.4f\n", 
-                     tile_cache[i].center.x, tile_cache[i].center.y,
-                     tile_cache[i].center.z);
-
-           dx = fabs(tile_cache[i].center.x - v->abs_view_pos.x);
-           dy = fabs(tile_cache[i].center.y - v->abs_view_pos.y);
-           dz = fabs(tile_cache[i].center.z - v->abs_view_pos.z);
-
-           max = dx; med = dy; min = dz;
+           FG_LOG( FG_TERRAIN, FG_DEBUG,
+                   "DIST Abs view pos = "
+                   << v->abs_view_pos.x() << ", "
+                   << v->abs_view_pos.y() << ", "
+                   << v->abs_view_pos.z() );
+           FG_LOG( FG_TERRAIN, FG_DEBUG,
+                   "    ref point = "
+                   << tile_cache[i].center.x() << ", "
+                   << tile_cache[i].center.y() << ", "
+                   << tile_cache[i].center.z() );
+
+           delta.setx( fabs(tile_cache[i].center.x() - v->abs_view_pos.x() ) );
+           delta.sety( fabs(tile_cache[i].center.y() - v->abs_view_pos.y() ) );
+           delta.setz( fabs(tile_cache[i].center.z() - v->abs_view_pos.z() ) );
+
+           max = delta.x(); med = delta.y(); min = delta.z();
            if ( max < med ) {
                tmp = max; max = med; med = tmp;
            }
@@ -188,7 +212,7 @@ int fgTILECACHE::NextAvail( void ) {
            }
            dist = max + (med + min) / 4;
 
-           fgPrintf( FG_TERRAIN, FG_DEBUG, "    distance = %.2f\n", dist);
+           FG_LOG( FG_TERRAIN, FG_DEBUG, "    distance = " << dist );
 
            if ( dist > max_dist ) {
                max_dist = dist;
@@ -201,7 +225,7 @@ int fgTILECACHE::NextAvail( void ) {
     // We will instead free the furthest cache entry and return it's
     // index.
     
-    EntryFree( max_index );
+    entry_free( max_index );
     return( max_index );
 }
 
@@ -212,6 +236,20 @@ fgTILECACHE::~fgTILECACHE( void ) {
 
 
 // $Log$
+// Revision 1.19  1998/11/06 21:18:21  curt
+// Converted to new logstream debugging facility.  This allows release
+// builds with no messages at all (and no performance impact) by using
+// the -DFG_NDEBUG flag.
+//
+// Revision 1.18  1998/10/16 18:12:28  curt
+// Fixed a bug in the conversion to Point3D.
+//
+// Revision 1.17  1998/10/16 00:55:48  curt
+// Converted to Point3D class.
+//
+// Revision 1.16  1998/09/14 12:45:23  curt
+// minor tweaks.
+//
 // Revision 1.15  1998/08/27 17:02:10  curt
 // Contributions from Bernie Bright <bbright@c031.aone.net.au>
 // - use strings for fg_root and airport_id and added methods to return