]> git.mxchange.org Git - flightgear.git/commitdiff
First pass at tile cache, dynamic tile loading and tile unloading now works.
authorcurt <curt>
Thu, 29 Jan 1998 00:51:38 +0000 (00:51 +0000)
committercurt <curt>
Thu, 29 Jan 1998 00:51:38 +0000 (00:51 +0000)
Scenery/bucketutils.c
Scenery/depend
Scenery/obj.c
Scenery/tilecache.c
Scenery/tilecache.h
Scenery/tilemgr.c

index 2453d256f858bc95575b5284bb457d8995b41412..e3bb6e1f4697546cd8964305a788edd4ebee62a0 100644 (file)
@@ -28,7 +28,6 @@
 #include <stdio.h>
 
 #include <Include/fg_constants.h>
-#include <Main/fg_debug.h>
 #include <Scenery/bucketutils.h>
 
 
@@ -200,9 +199,8 @@ void fgBucketFind(double lon, double lat, struct fgBUCKET *p) {
 
     p->x = (lon - p->lon) * 8;
     p->y = (lat - p->lat) * 8;
-    fgPrintf( FG_TERRAIN, FG_DEBUG, 
-             "Bucket = lon,lat = %d,%d  x,y index = %d,%d\n", 
-             p->lon, p->lat, p->x, p->y);
+    /* printf( "Bucket = lon,lat = %d,%d  x,y index = %d,%d\n", 
+           p->lon, p->lat, p->x, p->y); */
 }
 
 
@@ -218,10 +216,9 @@ void fgBucketGenIdxArray(struct fgBUCKET *p1, struct fgBUCKET *tiles,
        for ( i = 0; i < width; i++ ) {
            fgBucketOffset(p1, &tiles[(j*width)+i], i - dw, j - dh);
            p2 = &tiles[(j*width)+i];
-           fgPrintf( FG_TERRAIN, FG_DEBUG, 
-                     "  bucket = %d %d %d %d  index = %ld\n", 
-                     p2->lon, p2->lat, p2->x, p2->y, 
-                     fgBucketGenIndex(&tiles[(j*width)+i]));
+           /* printf( "  bucket = %d %d %d %d  index = %ld\n", 
+                   p2->lon, p2->lat, p2->x, p2->y, 
+                   fgBucketGenIndex(&tiles[(j*width)+i])); */
        }
     }
 }
@@ -269,9 +266,12 @@ int main() {
 
 
 /* $Log$
-/* Revision 1.4  1998/01/27 03:26:41  curt
-/* Playing with new fgPrintf command.
+/* Revision 1.5  1998/01/29 00:51:38  curt
+/* First pass at tile cache, dynamic tile loading and tile unloading now works.
 /*
+ * Revision 1.4  1998/01/27 03:26:41  curt
+ * Playing with new fgPrintf command.
+ *
  * Revision 1.3  1998/01/27 00:48:01  curt
  * Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
  * system and commandline/config file processing code.
index 8063cae33c5da314abd690efd97ac34a2e2a204a..0944d3a2a262d4c929b26a3c4b62639862deeaaa 100644 (file)
@@ -1,7 +1,9 @@
+bucketutils.o: bucketutils.c
 common.o: common.c
 geometry.o: geometry.c
 mesh.o: mesh.c
 obj.o: obj.c
 scenery.o: scenery.c
+texload.o: texload.c texload.h
+tilecache.o: tilecache.c
 tilemgr.o: tilemgr.c
-tileutils.o: tileutils.c
index 61e7195cbb80fb4136565fc5c338a2d6c5c629ca..316c7af2eed4a5f920870524419d81e664c82be9 100644 (file)
@@ -67,7 +67,8 @@ void calc_normal(float p1[3], float p2[3], float p3[3], double normal[3])
 GLint fgObjLoad(char *path, struct fgCartesianPoint *ref) {
     char line[256], winding_str[256];
     double approx_normal[3], normal[3], scale;
-    GLint area;
+    float x, y, z, xmax, xmin, ymax, ymin, zmax, zmin;
+    GLint tile;
     FILE *f;
     int first, ncount, vncount, n1, n2, n3, n4;
     static int use_vertex_norms = 1;
@@ -80,8 +81,8 @@ GLint fgObjLoad(char *path, struct fgCartesianPoint *ref) {
        return(0);
     }
 
-    area = xglGenLists(1);
-    xglNewList(area, GL_COMPILE);
+    tile = xglGenLists(1);
+    xglNewList(tile, GL_COMPILE);
 
     first = 1;
     ncount = 1;
@@ -96,15 +97,37 @@ GLint fgObjLoad(char *path, struct fgCartesianPoint *ref) {
            /* node (vertex) */
            if ( ncount < MAXNODES ) {
                /* fgPrintf( FG_TERRAIN, FG_DEBUG, "vertex = %s", line); */
-               sscanf(line, "v %f %f %f\n", 
-                      &nodes[ncount][0], &nodes[ncount][1], &nodes[ncount][2]);
+               sscanf(line, "v %f %f %f\n", &x, &y, &z);
+               nodes[ncount][0] = x;
+               nodes[ncount][1] = y;
+               nodes[ncount][2] = z;
+
+               /* first time through set min's and max'es */
                if ( ncount == 1 ) {
-                   /* first node becomes the reference point */
-                   ref->x = nodes[ncount][0];
-                   ref->y = nodes[ncount][1];
-                   ref->z = nodes[ncount][2];
-                   /* scenery.center = ref; */
+                   xmin = x;
+                   xmax = x;
+                   ymin = y;
+                   ymax = y;
+                   zmin = z;
+                   zmax = z;
                }
+    
+               /* keep track of min/max vertex values */
+               if ( x < xmin ) xmin = x;
+               if ( x > xmax ) xmax = x;
+               if ( y < ymin ) ymin = y;
+               if ( y > ymax ) ymax = y;
+               if ( z < zmin ) zmin = z;
+               if ( z > zmax ) zmax = z;               
+
+               /* reference point is the "center" */
+               /* this is overkill to calculate it everytime we get a
+                 * new node, but it's hard to know with the .obj
+                 * format when we are done with vertices */
+               ref->x = (xmin + xmax) / 2;
+               ref->y = (ymin + ymax) / 2;
+               ref->z = (zmin + zmax) / 2;
+
                ncount++;
            } else {
                fgPrintf( FG_TERRAIN, FG_EXIT, 
@@ -327,14 +350,17 @@ GLint fgObjLoad(char *path, struct fgCartesianPoint *ref) {
 
     fclose(f);
 
-    return(area);
+    return(tile);
 }
 
 
 /* $Log$
-/* Revision 1.19  1998/01/27 03:26:42  curt
-/* Playing with new fgPrintf command.
+/* Revision 1.20  1998/01/29 00:51:39  curt
+/* First pass at tile cache, dynamic tile loading and tile unloading now works.
 /*
+ * Revision 1.19  1998/01/27 03:26:42  curt
+ * Playing with new fgPrintf command.
+ *
  * Revision 1.18  1998/01/19 19:27:16  curt
  * Merged in make system changes from Bob Kuehne <rpk@sgi.com>
  * This should simplify things tremendously.
index 0adb150f97fe947be2d1ea394caf11878c6cc736..49b203903c9f639f134932343a95ee88d907b204 100644 (file)
 #include <XGL/xgl.h>
 
 #include <Include/general.h>
+#include <Main/fg_debug.h>
+#include <Main/views.h>
 #include <Scenery/bucketutils.h>
 #include <Scenery/obj.h>
 #include <Scenery/tilecache.h>
-#include <Main/fg_debug.h>
 
 
 /* tile cache */
@@ -54,17 +55,24 @@ void fgTileCacheInit( void ) {
 }
 
 
-/* Return index of next available slot in tile cache */
-int fgTileCacheNextAvail( void ) {
-     int i;
-     
-     for ( i = 0; i < FG_TILE_CACHE_SIZE; i++ ) {
-        if ( tile_cache[i].used == 0 ) {
-            return(i);
-        }
-     }
-
-     return(-1);
+/* Search for the specified "bucket" in the cache */
+int fgTileCacheExists( struct fgBUCKET *p ) {
+    int i;
+
+    for ( i = 0; i < FG_TILE_CACHE_SIZE; i++ ) {
+       if ( tile_cache[i].tile_bucket.lon == p->lon ) {
+           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 ) {
+                       printf("TILE EXISTS in cache ... index = %d\n", i);
+                       return( i );
+                   }
+               }
+           }
+       }
+    }
+    
+    return( -1 );
 }
 
 
@@ -94,6 +102,22 @@ void fgTileCacheEntryFillIn( int index, struct fgBUCKET *p ) {
 }
 
 
+/* Free a tile cache entry */
+void fgTileCacheEntryFree( int index ) {
+    /* Mark this cache entry as un-used */
+    tile_cache[index].used = 0;
+
+    /* Update the bucket */
+    printf( "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 );
+
+    /* Load the appropriate area and get the display list pointer */
+    xglDeleteLists( tile_cache[index].display_list, 1 );
+}
+
+
 /* Return info for a tile cache entry */
 void fgTileCacheEntryInfo( int index, GLint *display_list, 
                           struct fgCartesianPoint *local_ref ) {
@@ -106,16 +130,68 @@ void fgTileCacheEntryInfo( int index, GLint *display_list,
 }
 
 
-/* Free the specified cache entry
-void fgTileCacheEntryFree( in index ) {
+/* Return index of next available slot in tile cache */
+int fgTileCacheNextAvail( void ) {
+    struct fgVIEW *v;
+    int i;
+    float dx, dy, dz, max, med, min, tmp;
+    float dist, max_dist;
+    int max_index;
+    
+    v = &current_view;
+
+    max_dist = 0.0;
+    max_index = 0;
+
+    for ( i = 0; i < FG_TILE_CACHE_SIZE; i++ ) {
+       if ( tile_cache[i].used == 0 ) {
+           return(i);
+       } else {
+           /* calculate approximate distance from view point */
+           printf( "DIST Abs view pos = %.4f, %.4f, %.4f\n", 
+                   v->abs_view_pos.x, v->abs_view_pos.y, v->abs_view_pos.z);
+           printf( "    ref point = %.4f, %.4f, %.4f\n", 
+                   tile_cache[i].local_ref.x, tile_cache[i].local_ref.y,
+                   tile_cache[i].local_ref.z);
+
+           dx = fabs(tile_cache[i].local_ref.x - v->abs_view_pos.x);
+           dy = fabs(tile_cache[i].local_ref.y - v->abs_view_pos.y);
+           dz = fabs(tile_cache[i].local_ref.z - v->abs_view_pos.z);
+
+           max = dx; med = dy; min = dz;
+           if ( max < med ) {
+               tmp = max; max = med; med = tmp;
+           }
+           if ( max < min ) {
+               tmp = max; max = min; min = tmp;
+           }
+           dist = max + (med + min) / 4;
+
+           printf("    distance = %.2f\n", dist);
+
+           if ( dist > max_dist ) {
+               max_dist = dist;
+               max_index = i;
+           }
+       }
+    }
+
+    /* If we made it this far, then there were no open cache entries.
+     * We will instead free the furthest cache entry and return it's
+     * index. */
+    
+    fgTileCacheEntryFree( max_index );
+    return( max_index );
 }
-*/
 
 
 /* $Log$
-/* Revision 1.4  1998/01/27 03:26:43  curt
-/* Playing with new fgPrintf command.
+/* Revision 1.5  1998/01/29 00:51:39  curt
+/* First pass at tile cache, dynamic tile loading and tile unloading now works.
 /*
+ * Revision 1.4  1998/01/27 03:26:43  curt
+ * Playing with new fgPrintf command.
+ *
  * Revision 1.3  1998/01/27 00:48:03  curt
  * Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
  * system and commandline/config file processing code.
index 2e46bda9c773d259a6682c1825eb990781d5dc16..ed143392b962287b2da8efd51f0f08625ae282bb 100644 (file)
 #include <Scenery/bucketutils.h>
 #include <Include/fg_types.h>
 
-
-#define FG_TILE_CACHE_SIZE 100   /* Must be > FG_LOCAL_X_Y */
+/* For best results ...
+ *
+ * FG_TILE_CACHE_SIZE >= FG_LOCAL_X_Y + max(FG_LOCAL_X, FG_LOCAL_Y) */
+#define FG_TILE_CACHE_SIZE 12   
 
 
 /* Tile cache record */
@@ -58,6 +60,9 @@ extern struct fgTILE tile_cache[FG_TILE_CACHE_SIZE];
 /* Initialize the tile cache subsystem */
 void fgTileCacheInit( void );
 
+/* Search for the specified "bucket" in the cache */
+int fgTileCacheExists( struct fgBUCKET *p );
+
 /* Return index of next available slot in tile cache */
 int fgTileCacheNextAvail( void );
 
@@ -73,10 +78,13 @@ void fgTileCacheEntryInfo( int index, GLint *display_list,
 
 
 /* $Log$
-/* Revision 1.2  1998/01/27 00:48:04  curt
-/* Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
-/* system and commandline/config file processing code.
+/* Revision 1.3  1998/01/29 00:51:40  curt
+/* First pass at tile cache, dynamic tile loading and tile unloading now works.
 /*
+ * Revision 1.2  1998/01/27 00:48:04  curt
+ * Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
+ * system and commandline/config file processing code.
+ *
  * Revision 1.1  1998/01/24 00:03:29  curt
  * Initial revision.
  *
index 4ab70954386d2b3789f0dc518c1e99cf6c2f6d16..324f2f89c8ab2d4a4fdcdc151a62cd44e7bdca4a 100644 (file)
 #define FG_LOCAL_Y           3   /* should be odd */
 #define FG_LOCAL_X_Y         9   /* At least FG_LOCAL_X times FG_LOCAL_Y */
 
-#define FG_TILE_CACHE_SIZE 100   /* Must be > FG_LOCAL_X_Y */
-
 
 /* closest (potentially viewable) tiles, centered on current tile.
  * This is an array of pointers to cache indexes. */
 int tiles[FG_LOCAL_X_Y];
 
-/* tile cache */
-struct fgTILE tile_cache[FG_TILE_CACHE_SIZE];
-
 
 /* Initialize the Tile Manager subsystem */
 void fgTileMgrInit( void ) {
@@ -70,10 +65,15 @@ void fgTileMgrLoadTile( struct fgBUCKET *p, int *index) {
     fgPrintf( FG_TERRAIN, FG_DEBUG, "Updating for bucket %d %d %d %d\n", 
           p->lon, p->lat, p->x, p->y);
     
-    *index = fgTileCacheNextAvail();
+    /* if not in cache, load tile into the next available slot */
+    if ( (*index = fgTileCacheExists(p)) < 0 ) {
+       *index = fgTileCacheNextAvail();
+       fgTileCacheEntryFillIn(*index, p);
+    }
+
+    printf( "SELECTED cache index of %d\n", *index);
     fgPrintf( FG_TERRAIN, FG_DEBUG, "Selected cache index of %d\n", *index);
     
-    fgTileCacheEntryFillIn(*index, p);
 }
 
 
@@ -213,9 +213,12 @@ void fgTileMgrRender( void ) {
 
 
 /* $Log$
-/* Revision 1.9  1998/01/27 03:26:44  curt
-/* Playing with new fgPrintf command.
+/* Revision 1.10  1998/01/29 00:51:40  curt
+/* First pass at tile cache, dynamic tile loading and tile unloading now works.
 /*
+ * Revision 1.9  1998/01/27 03:26:44  curt
+ * Playing with new fgPrintf command.
+ *
  * Revision 1.8  1998/01/27 00:48:04  curt
  * Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
  * system and commandline/config file processing code.