]> git.mxchange.org Git - flightgear.git/commitdiff
"area" renamed to "tile"
authorcurt <curt>
Wed, 7 Jan 1998 23:50:01 +0000 (23:50 +0000)
committercurt <curt>
Wed, 7 Jan 1998 23:50:01 +0000 (23:50 +0000)
Scenery/areamgr.c [deleted file]
Scenery/areautils.c [deleted file]
Scenery/areautils.h [deleted file]
Scenery/tilemgr.c [new file with mode: 0644]
Scenery/tilemgr.h [new file with mode: 0644]
Scenery/tileutils.c [new file with mode: 0644]
Scenery/tileutils.h [new file with mode: 0644]

diff --git a/Scenery/areamgr.c b/Scenery/areamgr.c
deleted file mode 100644 (file)
index 3491c26..0000000
+++ /dev/null
@@ -1,291 +0,0 @@
-/**************************************************************************
- * areamgr.c -- routines to handle dynamic management of scenery areas
- *
- * Written by Curtis Olson, started October 1997.
- *
- * Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * $Id$
- * (Log is kept at end of this file)
- **************************************************************************/
-
-
-#ifdef WIN32
-#  include <windows.h>
-#endif
-
-#include <GL/glut.h>
-#include "../XGL/xgl.h"
-
-#include <math.h>
-
-#include "../Include/constants.h"
-/* temporary */
-#include "../Math/fg_random.h"
-
-
-struct ai {
-    int lon;  /* longitude (-180 to 179) */
-    int lat;  /* latitude (-90 to 89) */
-    int x;    /* x (0 to 7) */
-    int y;    /* y (0 to 7) */
-};
-
-
-/* we're entering into hacking territory here ... what fun. ;-) */
-long int area_array[7][7];
-
-
-/* Generate the unique scenery area index containing the specified
-   lon/lat parameters.
-
-   The index is constructed as follows:
-
-   9 bits - to represent 360 degrees of longitude (-180 to 179)
-   8 bits - to represent 180 degrees of latitude (-90 to 89)
-
-   Each 1 degree by 1 degree area is further broken down into an 8x8
-   grid.  So we also need:
-
-   3 bits - to represent x (0 to 7)
-   3 bits - to represent y (0 to 7) */
-static long gen_index(struct ai *p) {
-    long index = 0;
-
-    index = ((p->lon + 180) << 14) + ((p->lat + 90) << 6) + (p->y << 3) + p->x;
-    /* printf("  generated index = %ld\n", index); */
-
-    return(index);
-}
-
-
-/* Parse a unique scenery area index and find the lon, lat, x, and y */
-static void parse_index(long int index, struct ai *p) {
-    p->lon = index >> 14;
-    index -= p->lon << 14;
-    p->lon -= 180;
-
-    p->lat = index >> 6;
-    index -= p->lat << 6;
-    p->lat -= 90;
-
-    p->y = index >> 3;
-    index -= p->y << 3;
-
-    p->x = index;
-}
-
-
-/* Build a path name from an area index */
-static void gen_path(long int index, char *path) {
-    struct ai p;
-    int top_lon, top_lat, main_lon, main_lat;
-    char hem, pole;
-
-    parse_index(index, &p);
-
-    path[0] = '\0';
-
-    top_lon = p.lon / 10;
-    main_lon = p.lon;
-    if ( (p.lon < 0) && (top_lon * 10 != p.lon) ) {
-       top_lon -= 1;
-       main_lon -= 1;
-    }
-    top_lon *= 10;
-    if ( top_lon >= 0 ) {
-       hem = 'e';
-    } else {
-       hem = 'w';
-       top_lon *= -1;
-    }
-    if ( main_lon < 0 ) {
-       main_lon *= -1;
-    }
-
-    top_lat = p.lat / 10;
-    main_lat = p.lat;
-    if ( (p.lat < 0) && (top_lat * 10 != p.lat) ) {
-       top_lat -= 1;
-       main_lat -= 1;
-    }
-    top_lat *= 10;
-    if ( top_lat >= 0 ) {
-       pole = 'n';
-    } else {
-       pole = 's';
-       top_lat *= -1;
-    }
-    if ( main_lat < 0 ) {
-       main_lat *= -1;
-    }
-
-    sprintf(path, "%c%03d%c%03d/%c%03d%c%03d/%ld.ter", 
-           hem, top_lon, pole, top_lat,
-           hem, main_lon, pole, main_lat,
-           index);
-}
-
-
-/* offset an ai struct by the specified amounts in the X & Y direction */
-static void offset_ai(struct ai *in, struct ai *out, int x, int y) {
-    int diff, temp;
-    int dist_lat;
-
-    out->lon = in->lon;
-    out->lat = in->lat;
-    out->x = in->x;
-    out->y = in->y;
-
-    /* do X direction */
-    diff = out->x + x;
-    /* printf("      reducing x (%d)\n", diff); */
-    if ( diff >= 0 ) {
-       temp = diff / 8;
-    } else if ( diff < -7 ) {
-       temp = (diff + 1) / 8 - 1;
-    } else {
-       temp = diff / 8 - 1;
-    }
-    out->x = ((diff % 8) + 8) % 8;
-    out->lon = ( (out->lon + 180 + 360 + temp) % 360 ) - 180;
-
-    /* do Y direction */
-    diff = out->y + y;
-    /* printf("      reducing x (%d)\n", diff); */
-    if ( diff >= 0 ) {
-       temp = diff / 8;
-    } else if ( diff < -7 ) {
-       temp = (diff + 1) / 8 - 1;
-    } else {
-       temp = diff / 8 - 1;
-    }
-    out->y = ((diff % 8) + 8) % 8;
-    out->lat = out->lat + temp;
-
-    if ( out->lat >= 90 ) {
-       dist_lat = out->lat - 90;
-       /* printf("      +lat = %d  +y = %d\n", dist_lat, out->y); */
-       
-       out->lat = 90 - (dist_lat + 1);
-       out->lon = ( (out->lon + 180 + 180) % 360 ) - 180;
-       out->y = 7 - out->y;
-    }
-
-    if ( out->lat < -90 ) {
-       dist_lat = -90 - out->lat;
-       /* printf("      +lat = %d  +y = %d\n", dist_lat, out->y); */
-       
-       out->lat = -90 + (dist_lat - 1);
-       out->lon = ( (out->lon + 180 + 180) % 360 ) - 180;
-       out->y = 7 - out->y;
-    }
-}
-
-
-/* Given a lat/lon, fill in the local area index array */
-static void gen_idx_array(double lon, double lat) {
-    struct ai p1, p2, p3;
-    double diff;
-    char path[256];
-    long int index = 0;
-    int i, j;
-
-    printf("lon = %.2f  lat = %.2f\n", lon, lat);
-
-    diff = lon - (double)(int)lon;
-    printf("diff = %.2f\n", diff);
-    if ( (lon >= 0) || (fabs(diff) < FG_EPSILON) ) {
-       p1.lon = (int)lon;
-    } else {
-       p1.lon = (int)lon - 1;
-    }
-    printf("  p1.lon = %d\n", p1.lon);
-
-    diff = lat - (double)(int)lat;
-    printf("diff = %.2f\n", diff);
-    if ( (lat >= 0) || (fabs(diff) < FG_EPSILON) ) {
-       p1.lat = (int)lat;
-    } else {
-       p1.lat = (int)lat - 1;
-    }
-    printf("  p1.lat = %d\n", p1.lat);
-
-    p1.x = (lon - p1.lon) * 8;
-    p1.y = (lat - p1.lat) * 8;
-    printf("  lon,lat = %d,%d  x,y index = %d,%d\n", 
-          p1.lon, p1.lat, p1.x, p1.y);
-
-    for ( i = -3; i <= 3; i++ ) {
-       for ( j = -3; j <= 3; j++ ) {
-           offset_ai(&p1, &p2, i, j);
-           printf("  %d %d %d %d\n", p2.lon, p2.lat, p2.x, p2.y);
-           area_array[i][j] = gen_index(&p2);
-           printf("  generated index = %ld\n", area_array[i][j]);
-
-           /* parse_index(area_array[i][j], &p3); */
-           /* printf("  %d %d %d %d\n", p3.lon, p3.lat, p3.x, p3.y); */
-           gen_path(area_array[i][j], path);
-           printf("  path = %s\n\n", path);
-       }
-    }
-}
-
-
-main() {
-    struct ai p1;
-    int i, j, index;
-    double lon, lat;
-
-    fg_srandom();
-
-    p1.lon = 180;
-    p1.lat = 90;
-    p1.x = 7;
-    p1.y = 7;
-
-    /* printf("Max index = %ld\n", gen_index(&p1)); */
-
-    lon = -50.0;
-    lat = -50.0;
-    gen_idx_array(lon, lat);
-
-    lon = 50.0;
-    lat = 50.0;
-    gen_idx_array(lon, lat);
-
-    for ( i = 0; i < 100; i++ ) {
-       lon = ( 360.0 * fg_random() ) - 180.0;
-       lat = ( 180.0 * fg_random() ) - 90.0;
-
-       gen_idx_array(lon, lat);
-    }
-}
-
-
-/* $Log$
-/* Revision 1.2  1998/01/07 03:29:29  curt
-/* Given an arbitrary lat/lon, we can now:
-/*   generate a unique index for the chunk containing the lat/lon
-/*   generate a path name to the chunk file
-/*   build a list of the indexes of all the nearby areas.
-/*
- * Revision 1.1  1998/01/07 02:05:48  curt
- * Initial revision.
- * */
-
-
diff --git a/Scenery/areautils.c b/Scenery/areautils.c
deleted file mode 100644 (file)
index 533ad58..0000000
+++ /dev/null
@@ -1,281 +0,0 @@
-/**************************************************************************
- * areautils.c -- support routines to handle dynamic management of scenery areas
- *
- * Written by Curtis Olson, started January 1998.
- *
- * Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * $Id$
- * (Log is kept at end of this file)
- **************************************************************************/
-
-
-#ifdef WIN32
-#  include <windows.h>
-#endif
-
-#include <GL/glut.h>
-#include "../XGL/xgl.h"
-
-#include <math.h>
-
-#include "areautils.h"
-#include "../Include/constants.h"
-
-
-/* Generate the unique scenery area index containing the specified
-   lon/lat parameters.
-
-   The index is constructed as follows:
-
-   9 bits - to represent 360 degrees of longitude (-180 to 179)
-   8 bits - to represent 180 degrees of latitude (-90 to 89)
-
-   Each 1 degree by 1 degree area is further broken down into an 8x8
-   grid.  So we also need:
-
-   3 bits - to represent x (0 to 7)
-   3 bits - to represent y (0 to 7) */
-static long gen_index(struct bucket *p) {
-    long index = 0;
-
-    index = ((p->lon + 180) << 14) + ((p->lat + 90) << 6) + (p->y << 3) + p->x;
-    /* printf("  generated index = %ld\n", index); */
-
-    return(index);
-}
-
-
-/* Parse a unique scenery area index and find the lon, lat, x, and y */
-static void parse_index(long int index, struct bucket *p) {
-    p->lon = index >> 14;
-    index -= p->lon << 14;
-    p->lon -= 180;
-
-    p->lat = index >> 6;
-    index -= p->lat << 6;
-    p->lat -= 90;
-
-    p->y = index >> 3;
-    index -= p->y << 3;
-
-    p->x = index;
-}
-
-
-/* Build a path name from an area index */
-static void gen_path(long int index, char *path) {
-    struct bucket p;
-    int top_lon, top_lat, main_lon, main_lat;
-    char hem, pole;
-
-    parse_index(index, &p);
-
-    path[0] = '\0';
-
-    top_lon = p.lon / 10;
-    main_lon = p.lon;
-    if ( (p.lon < 0) && (top_lon * 10 != p.lon) ) {
-       top_lon -= 1;
-       main_lon -= 1;
-    }
-    top_lon *= 10;
-    if ( top_lon >= 0 ) {
-       hem = 'e';
-    } else {
-       hem = 'w';
-       top_lon *= -1;
-    }
-    if ( main_lon < 0 ) {
-       main_lon *= -1;
-    }
-
-    top_lat = p.lat / 10;
-    main_lat = p.lat;
-    if ( (p.lat < 0) && (top_lat * 10 != p.lat) ) {
-       top_lat -= 1;
-       main_lat -= 1;
-    }
-    top_lat *= 10;
-    if ( top_lat >= 0 ) {
-       pole = 'n';
-    } else {
-       pole = 's';
-       top_lat *= -1;
-    }
-    if ( main_lat < 0 ) {
-       main_lat *= -1;
-    }
-
-    sprintf(path, "%c%03d%c%03d/%c%03d%c%03d/%ld.ter", 
-           hem, top_lon, pole, top_lat,
-           hem, main_lon, pole, main_lat,
-           index);
-}
-
-
-/* offset an bucket struct by the specified amounts in the X & Y direction */
-static void offset_bucket(struct bucket *in, struct bucket *out, int x, int y) {
-    int diff, temp;
-    int dist_lat;
-
-    out->lon = in->lon;
-    out->lat = in->lat;
-    out->x = in->x;
-    out->y = in->y;
-
-    /* do X direction */
-    diff = out->x + x;
-    /* printf("      reducing x (%d)\n", diff); */
-    if ( diff >= 0 ) {
-       temp = diff / 8;
-    } else if ( diff < -7 ) {
-       temp = (diff + 1) / 8 - 1;
-    } else {
-       temp = diff / 8 - 1;
-    }
-    out->x = ((diff % 8) + 8) % 8;
-    out->lon = ( (out->lon + 180 + 360 + temp) % 360 ) - 180;
-
-    /* do Y direction */
-    diff = out->y + y;
-    /* printf("      reducing x (%d)\n", diff); */
-    if ( diff >= 0 ) {
-       temp = diff / 8;
-    } else if ( diff < -7 ) {
-       temp = (diff + 1) / 8 - 1;
-    } else {
-       temp = diff / 8 - 1;
-    }
-    out->y = ((diff % 8) + 8) % 8;
-    out->lat = out->lat + temp;
-
-    if ( out->lat >= 90 ) {
-       dist_lat = out->lat - 90;
-       /* printf("      +lat = %d  +y = %d\n", dist_lat, out->y); */
-       
-       out->lat = 90 - (dist_lat + 1);
-       out->lon = ( (out->lon + 180 + 180) % 360 ) - 180;
-       out->y = 7 - out->y;
-    }
-
-    if ( out->lat < -90 ) {
-       dist_lat = -90 - out->lat;
-       /* printf("      +lat = %d  +y = %d\n", dist_lat, out->y); */
-       
-       out->lat = -90 + (dist_lat - 1);
-       out->lon = ( (out->lon + 180 + 180) % 360 ) - 180;
-       out->y = 7 - out->y;
-    }
-}
-
-
-/* Given a lat/lon, find the "bucket" or area that it falls within */
-static void find_bucket(double lon, double lat, struct bucket *p) {
-    double diff;
-
-    diff = lon - (double)(int)lon;
-    /* printf("diff = %.2f\n", diff); */
-    if ( (lon >= 0) || (fabs(diff) < FG_EPSILON) ) {
-       p->lon = (int)lon;
-    } else {
-       p->lon = (int)lon - 1;
-    }
-    /* printf("  p->lon = %d\n", p->lon); */
-
-    diff = lat - (double)(int)lat;
-    /* printf("diff = %.2f\n", diff); */
-    if ( (lat >= 0) || (fabs(diff) < FG_EPSILON) ) {
-       p->lat = (int)lat;
-    } else {
-       p->lat = (int)lat - 1;
-    }
-    /* printf("  p->lat = %d\n", p->lat); */
-
-    p->x = (lon - p->lon) * 8;
-    p->y = (lat - p->lat) * 8;
-    printf("Bucket = lon,lat = %d,%d  x,y index = %d,%d\n", 
-          p->lon, p->lat, p->x, p->y);
-}
-
-
-/* Given a lat/lon, fill in the local area index array */
-static void gen_idx_array(struct bucket *p1, long int *area, 
-                         int width, int height) {
-    struct bucket p2;
-    int dw, dh, i, j;
-
-    dh = height / 2;
-    dw = width / 2;
-    for ( j = 0; j < height; j++ ) {
-       for ( i = 0; i < width; i++ ) {
-           offset_bucket(p1, &p2, i - dw, j - dh);
-           area[(j*width)+i] = gen_index(&p2);
-           printf("  bucket = %d %d %d %d  index = %ld\n", 
-                  p2.lon, p2.lat, p2.x, p2.y, area[(j*width)+i]);
-       }
-    }
-}
-
-
-int main() {
-    struct bucket p1;
-    long int area[49];
-    char path[256];
-    double lon, lat;
-    int i, j;
-
-    p1.lon = 180;
-    p1.lat = 90;
-    p1.x = 7;
-    p1.y = 7;
-
-    /* printf("Max index = %ld\n", gen_index(&p1)); */
-
-    lon = -50.0;
-    lat = -50.0;
-    find_bucket(lon, lat, &p1);
-    gen_idx_array(&p1, area, 7, 7);
-    for ( j = 0; j < 7; j++ ) {
-       for ( i = 0; i < 7; i++ ) {
-           gen_path(area[(j*7)+i], path);
-           printf("  path = %s\n", path);
-       }
-    }
-
-    lon = 50.0;
-    lat = 50.0;
-    find_bucket(lon, lat, &p1);
-    gen_idx_array(&p1, area, 7, 7);
-    for ( j = 0; j < 7; j++ ) {
-       for ( i = 0; i < 7; i++ ) {
-           gen_path(area[(j*7)+i], path);
-           printf("  path = %s\n", path);
-       }
-    }
-
-    return(1);
-}
-
-
-/* $Log$
-/* Revision 1.1  1998/01/07 23:23:40  curt
-/* Initial revision.
-/*
- * */
-
-
diff --git a/Scenery/areautils.h b/Scenery/areautils.h
deleted file mode 100644 (file)
index 7a14df2..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-/**************************************************************************
- * areautils.h -- support routines to handle dynamic management of scenery areas
- *
- * Written by Curtis Olson, started January 1998.
- *
- * Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * $Id$
- * (Log is kept at end of this file)
- **************************************************************************/
-
-
-struct bucket {
-    int lon;  /* longitude (-180 to 179) */
-    int lat;  /* latitude (-90 to 89) */
-    int x;    /* x (0 to 7) */
-    int y;    /* y (0 to 7) */
-};
-
-
-/* Generate the unique scenery area index containing the specified
-   lon/lat parameters.
-
-   The index is constructed as follows:
-
-   9 bits - to represent 360 degrees of longitude (-180 to 179)
-   8 bits - to represent 180 degrees of latitude (-90 to 89)
-
-   Each 1 degree by 1 degree area is further broken down into an 8x8
-   grid.  So we also need:
-
-   3 bits - to represent x (0 to 7)
-   3 bits - to represent y (0 to 7) */
-static long gen_index(struct bucket *p);
-
-
-/* Parse a unique scenery area index and find the lon, lat, x, and y */
-static void parse_index(long int index, struct bucket *p);
-
-
-/* Build a path name from an area index */
-static void gen_path(long int index, char *path);
-
-
-/* offset an bucket struct by the specified amounts in the X & Y direction */
-static void offset_bucket(struct bucket *in, struct bucket *out, int x, int y);
-
-
-/* Given a lat/lon, find the "bucket" or area that it falls within */
-static void find_bucket(double lon, double lat, struct bucket *p);
-
-
-/* Given a lat/lon, fill in the local area index array */
-static void gen_idx_array(struct bucket *p1, long int *area, 
-                         int width, int height);
-
-
-/* $Log$
-/* Revision 1.1  1998/01/07 23:23:40  curt
-/* Initial revision.
-/*
- * */
-
-
diff --git a/Scenery/tilemgr.c b/Scenery/tilemgr.c
new file mode 100644 (file)
index 0000000..d2ce0b3
--- /dev/null
@@ -0,0 +1,77 @@
+/**************************************************************************
+ * tilemgr.c -- routines to handle dynamic management of scenery tiles
+ *
+ * Written by Curtis Olson, started January 1998.
+ *
+ * Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id$
+ * (Log is kept at end of this file)
+ **************************************************************************/
+
+
+#ifdef WIN32
+#  include <windows.h>
+#endif
+
+#include <GL/glut.h>
+#include "../XGL/xgl.h"
+
+#include "tileutils.h"
+
+#include "../Aircraft/aircraft.h"
+
+
+/* here's where we keep the array of closest (potentially viewable) tiles */
+static long int tile[49];
+
+
+/* Initialize the Tile Manager subsystem */
+void fgTileMgrInit() {
+    printf("Initializing Tile Manager subsystem.\n");
+    /* fgTileCacheInit(); */
+}
+
+
+/* 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. */
+void fgTileMgrUpdate() {
+    struct fgFLIGHT *f;
+    struct bucket p;
+
+    f = &current_aircraft.flight;
+
+    find_bucket(FG_Longitude, FG_Latitude, &p);
+    gen_idx_array(&p, tile, 7, 7);
+}
+
+
+/* $Log$
+/* Revision 1.1  1998/01/07 23:50:51  curt
+/* "area" renamed to "tile"
+/*
+ * Revision 1.2  1998/01/07 03:29:29  curt
+ * Given an arbitrary lat/lon, we can now:
+ *   generate a unique index for the chunk containing the lat/lon
+ *   generate a path name to the chunk file
+ *   build a list of the indexes of all the nearby areas.
+ *
+ * Revision 1.1  1998/01/07 02:05:48  curt
+ * Initial revision.
+ * */
+
+
diff --git a/Scenery/tilemgr.h b/Scenery/tilemgr.h
new file mode 100644 (file)
index 0000000..23d208b
--- /dev/null
@@ -0,0 +1,42 @@
+/**************************************************************************
+ * tilemgr.h -- routines to handle dynamic management of scenery tiles
+ *
+ * Written by Curtis Olson, started January 1998.
+ *
+ * Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id$
+ * (Log is kept at end of this file)
+ **************************************************************************/
+
+
+/* Initialize the Tile Manager subsystem */
+void fgTileMgrInit();
+
+
+/* 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. */
+void fgTileMgrUpdate();
+
+
+/* $Log$
+/* Revision 1.1  1998/01/07 23:50:51  curt
+/* "area" renamed to "tile"
+/*
+ * */
+
+
diff --git a/Scenery/tileutils.c b/Scenery/tileutils.c
new file mode 100644 (file)
index 0000000..c4ac1ee
--- /dev/null
@@ -0,0 +1,279 @@
+/**************************************************************************
+ * tileutils.c -- support routines to handle dynamic management of scenery tiles
+ *
+ * Written by Curtis Olson, started January 1998.
+ *
+ * Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id$
+ * (Log is kept at end of this file)
+ **************************************************************************/
+
+
+#include <math.h>
+#include <stdio.h>
+
+#include "tileutils.h"
+#include "../Include/constants.h"
+
+
+/* Generate the unique scenery tile index containing the specified
+   lon/lat parameters.
+
+   The index is constructed as follows:
+
+   9 bits - to represent 360 degrees of longitude (-180 to 179)
+   8 bits - to represent 180 degrees of latitude (-90 to 89)
+
+   Each 1 degree by 1 degree tile is further broken down into an 8x8
+   grid.  So we also need:
+
+   3 bits - to represent x (0 to 7)
+   3 bits - to represent y (0 to 7) */
+static long gen_index(struct bucket *p) {
+    long index = 0;
+
+    index = ((p->lon + 180) << 14) + ((p->lat + 90) << 6) + (p->y << 3) + p->x;
+    /* printf("  generated index = %ld\n", index); */
+
+    return(index);
+}
+
+
+/* Parse a unique scenery tile index and find the lon, lat, x, and y */
+static void parse_index(long int index, struct bucket *p) {
+    p->lon = index >> 14;
+    index -= p->lon << 14;
+    p->lon -= 180;
+
+    p->lat = index >> 6;
+    index -= p->lat << 6;
+    p->lat -= 90;
+
+    p->y = index >> 3;
+    index -= p->y << 3;
+
+    p->x = index;
+}
+
+
+/* Build a path name from an tile index */
+void gen_path(long int index, char *path) {
+    struct bucket p;
+    int top_lon, top_lat, main_lon, main_lat;
+    char hem, pole;
+
+    parse_index(index, &p);
+
+    path[0] = '\0';
+
+    top_lon = p.lon / 10;
+    main_lon = p.lon;
+    if ( (p.lon < 0) && (top_lon * 10 != p.lon) ) {
+       top_lon -= 1;
+       main_lon -= 1;
+    }
+    top_lon *= 10;
+    if ( top_lon >= 0 ) {
+       hem = 'e';
+    } else {
+       hem = 'w';
+       top_lon *= -1;
+    }
+    if ( main_lon < 0 ) {
+       main_lon *= -1;
+    }
+
+    top_lat = p.lat / 10;
+    main_lat = p.lat;
+    if ( (p.lat < 0) && (top_lat * 10 != p.lat) ) {
+       top_lat -= 1;
+       main_lat -= 1;
+    }
+    top_lat *= 10;
+    if ( top_lat >= 0 ) {
+       pole = 'n';
+    } else {
+       pole = 's';
+       top_lat *= -1;
+    }
+    if ( main_lat < 0 ) {
+       main_lat *= -1;
+    }
+
+    sprintf(path, "%c%03d%c%03d/%c%03d%c%03d/%ld.ter", 
+           hem, top_lon, pole, top_lat,
+           hem, main_lon, pole, main_lat,
+           index);
+}
+
+
+/* offset an bucket struct by the specified amounts in the X & Y direction */
+static void offset_bucket(struct bucket *in, struct bucket *out, int x, int y) {
+    int diff, temp;
+    int dist_lat;
+
+    out->lon = in->lon;
+    out->lat = in->lat;
+    out->x = in->x;
+    out->y = in->y;
+
+    /* do X direction */
+    diff = out->x + x;
+    /* printf("      reducing x (%d)\n", diff); */
+    if ( diff >= 0 ) {
+       temp = diff / 8;
+    } else if ( diff < -7 ) {
+       temp = (diff + 1) / 8 - 1;
+    } else {
+       temp = diff / 8 - 1;
+    }
+    out->x = ((diff % 8) + 8) % 8;
+    out->lon = ( (out->lon + 180 + 360 + temp) % 360 ) - 180;
+
+    /* do Y direction */
+    diff = out->y + y;
+    /* printf("      reducing x (%d)\n", diff); */
+    if ( diff >= 0 ) {
+       temp = diff / 8;
+    } else if ( diff < -7 ) {
+       temp = (diff + 1) / 8 - 1;
+    } else {
+       temp = diff / 8 - 1;
+    }
+    out->y = ((diff % 8) + 8) % 8;
+    out->lat = out->lat + temp;
+
+    if ( out->lat >= 90 ) {
+       dist_lat = out->lat - 90;
+       /* printf("      +lat = %d  +y = %d\n", dist_lat, out->y); */
+       
+       out->lat = 90 - (dist_lat + 1);
+       out->lon = ( (out->lon + 180 + 180) % 360 ) - 180;
+       out->y = 7 - out->y;
+    }
+
+    if ( out->lat < -90 ) {
+       dist_lat = -90 - out->lat;
+       /* printf("      +lat = %d  +y = %d\n", dist_lat, out->y); */
+       
+       out->lat = -90 + (dist_lat - 1);
+       out->lon = ( (out->lon + 180 + 180) % 360 ) - 180;
+       out->y = 7 - out->y;
+    }
+}
+
+
+/* Given a lat/lon, find the "bucket" or tile that it falls within */
+void find_bucket(double lon, double lat, struct bucket *p) {
+    double diff;
+
+    diff = lon - (double)(int)lon;
+    /* printf("diff = %.2f\n", diff); */
+    if ( (lon >= 0) || (fabs(diff) < FG_EPSILON) ) {
+       p->lon = (int)lon;
+    } else {
+       p->lon = (int)lon - 1;
+    }
+    /* printf("  p->lon = %d\n", p->lon); */
+
+    diff = lat - (double)(int)lat;
+    /* printf("diff = %.2f\n", diff); */
+    if ( (lat >= 0) || (fabs(diff) < FG_EPSILON) ) {
+       p->lat = (int)lat;
+    } else {
+       p->lat = (int)lat - 1;
+    }
+    /* printf("  p->lat = %d\n", p->lat); */
+
+    p->x = (lon - p->lon) * 8;
+    p->y = (lat - p->lat) * 8;
+    printf("Bucket = lon,lat = %d,%d  x,y index = %d,%d\n", 
+          p->lon, p->lat, p->x, p->y);
+}
+
+
+/* Given a lat/lon, fill in the local tile index array */
+void gen_idx_array(struct bucket *p1, long int *tile, 
+                         int width, int height) {
+    struct bucket p2;
+    int dw, dh, i, j;
+
+    dh = height / 2;
+    dw = width / 2;
+    for ( j = 0; j < height; j++ ) {
+       for ( i = 0; i < width; i++ ) {
+           offset_bucket(p1, &p2, i - dw, j - dh);
+           tile[(j*width)+i] = gen_index(&p2);
+           printf("  bucket = %d %d %d %d  index = %ld\n", 
+                  p2.lon, p2.lat, p2.x, p2.y, tile[(j*width)+i]);
+       }
+    }
+}
+
+
+/* sample main for testing
+int main() {
+    struct bucket p1;
+    long int tile[49];
+    char path[256];
+    double lon, lat;
+    int i, j;
+
+    p1.lon = 180;
+    p1.lat = 90;
+    p1.x = 7;
+    p1.y = 7;
+
+    printf("Max index = %ld\n", gen_index(&p1));
+
+    lon = -50.0;
+    lat = -50.0;
+    find_bucket(lon, lat, &p1);
+    gen_idx_array(&p1, tile, 7, 7);
+    for ( j = 0; j < 7; j++ ) {
+       for ( i = 0; i < 7; i++ ) {
+           gen_path(tile[(j*7)+i], path);
+           printf("  path = %s\n", path);
+       }
+    }
+
+    lon = 50.0;
+    lat = 50.0;
+    find_bucket(lon, lat, &p1);
+    gen_idx_array(&p1, tile, 7, 7);
+    for ( j = 0; j < 7; j++ ) {
+       for ( i = 0; i < 7; i++ ) {
+           gen_path(tile[(j*7)+i], path);
+           printf("  path = %s\n", path);
+       }
+    }
+
+    return(1);
+} */
+
+
+/* $Log$
+/* Revision 1.1  1998/01/07 23:50:52  curt
+/* "area" renamed to "tile"
+/*
+ * Revision 1.1  1998/01/07 23:23:40  curt
+ * Initial revision.
+ *
+ * */
+
+
diff --git a/Scenery/tileutils.h b/Scenery/tileutils.h
new file mode 100644 (file)
index 0000000..14374c5
--- /dev/null
@@ -0,0 +1,81 @@
+/**************************************************************************
+ * tileutils.h -- support routines to handle dynamic management of scenery tiles
+ *
+ * Written by Curtis Olson, started January 1998.
+ *
+ * Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id$
+ * (Log is kept at end of this file)
+ **************************************************************************/
+
+
+struct bucket {
+    int lon;  /* longitude (-180 to 179) */
+    int lat;  /* latitude (-90 to 89) */
+    int x;    /* x (0 to 7) */
+    int y;    /* y (0 to 7) */
+};
+
+
+/* Generate the unique scenery tile index containing the specified
+   lon/lat parameters.
+
+   The index is constructed as follows:
+
+   9 bits - to represent 360 degrees of longitude (-180 to 179)
+   8 bits - to represent 180 degrees of latitude (-90 to 89)
+
+   Each 1 degree by 1 degree tile is further broken down into an 8x8
+   grid.  So we also need:
+
+   3 bits - to represent x (0 to 7)
+   3 bits - to represent y (0 to 7) */
+/* static long gen_index(struct bucket *p); */
+
+
+/* Parse a unique scenery tile index and find the lon, lat, x, and y */
+/* static void parse_index(long int index, struct bucket *p); */
+
+
+/* Build a path name from an tile index */
+void gen_path(long int index, char *path);
+
+
+/* offset an bucket struct by the specified amounts in the X & Y direction */
+/* static void offset_bucket(struct bucket *in, struct bucket *out, int x, int y); */
+
+
+/* Given a lat/lon, find the "bucket" or tile that it falls within */
+void find_bucket(double lon, double lat, struct bucket *p);
+
+
+/* Given a lat/lon, fill in the local tile index array */
+void gen_idx_array(struct bucket *p1, long int *tile, 
+                         int width, int height);
+
+
+/* $Log$
+/* Revision 1.1  1998/01/07 23:50:52  curt
+/* "area" renamed to "tile"
+/*
+ * Revision 1.1  1998/01/07 23:23:40  curt
+ * Initial revision.
+ *
+ * */
+
+