#include <stdio.h>
#include <Include/fg_constants.h>
-#include <Main/fg_debug.h>
#include <Scenery/bucketutils.h>
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); */
}
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])); */
}
}
}
/* $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.
+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
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;
return(0);
}
- area = xglGenLists(1);
- xglNewList(area, GL_COMPILE);
+ tile = xglGenLists(1);
+ xglNewList(tile, GL_COMPILE);
first = 1;
ncount = 1;
/* 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,
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.
#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 */
}
-/* 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 );
}
}
+/* 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 ) {
}
-/* 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 = ¤t_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.
#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 */
/* 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 );
/* $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.
*
#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 ) {
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);
}
/* $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.