First pass at tile cache, dynamic tile loading and tile unloading now works.
This commit is contained in:
parent
4db0288d75
commit
4ec2093a99
6 changed files with 169 additions and 54 deletions
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -32,10 +32,11 @@
|
|||
#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);
|
||||
}
|
||||
}
|
||||
/* Search for the specified "bucket" in the cache */
|
||||
int fgTileCacheExists( struct fgBUCKET *p ) {
|
||||
int i;
|
||||
|
||||
return(-1);
|
||||
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 = ¤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.
|
||||
|
|
|
@ -38,8 +38,10 @@
|
|||
#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.
|
||||
*
|
||||
|
|
|
@ -46,16 +46,11 @@
|
|||
#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.
|
||||
|
|
Loading…
Add table
Reference in a new issue