]> git.mxchange.org Git - flightgear.git/blobdiff - Scenery/tileutils.c
Merged in make system changes from Bob Kuehne <rpk@sgi.com>
[flightgear.git] / Scenery / tileutils.c
index 358f48c299d66b6be2d98455d99666ff556866ff..ec424ff4ea07c7f8b0713f624c6ee52251658f88 100644 (file)
@@ -27,8 +27,8 @@
 #include <math.h>
 #include <stdio.h>
 
-#include "tileutils.h"
-#include "../Include/constants.h"
+#include <Scenery/tileutils.h>
+#include <Include/constants.h>
 
 
 /* Generate the unique scenery tile index containing the specified
@@ -44,7 +44,7 @@
 
    3 bits - to represent x (0 to 7)
    3 bits - to represent y (0 to 7) */
-static long gen_index(struct bucket *p) {
+long int gen_index(struct bucket *p) {
     long index = 0;
 
     index = ((p->lon + 180) << 14) + ((p->lat + 90) << 6) + (p->y << 3) + p->x;
@@ -55,7 +55,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) {
+void parse_index(long int index, struct bucket *p) {
     p->lon = index >> 14;
     index -= p->lon << 14;
     p->lon -= 180;
@@ -72,20 +72,19 @@ 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) {
-    struct bucket p;
+void gen_base_path(struct bucket *p, char *path) {
+    long int index;
     int top_lon, top_lat, main_lon, main_lat;
     char hem, pole;
 
-    parse_index(index, &p);
+    index = gen_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 = 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 ) {
@@ -98,11 +97,10 @@ void gen_path(long int index, char *path) {
        main_lon *= -1;
     }
 
-    top_lat = p.lat / 10;
-    main_lat = p.lat;
-    if ( (p.lat < 0) && (top_lat * 10 != p.lat) ) {
+    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 ) {
@@ -115,15 +113,14 @@ void gen_path(long int index, char *path) {
        main_lat *= -1;
     }
 
-    sprintf(path, "%c%03d%c%03d/%c%03d%c%03d/%ld.ter", 
+    sprintf(path, "%c%03d%c%03d/%c%03d%c%03d", 
            hem, top_lon, pole, top_lat,
-           hem, main_lon, pole, main_lat,
-           index);
+           hem, main_lon, pole, main_lat);
 }
 
 
 /* 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) {
+void offset_bucket(struct bucket *in, struct bucket *out, int x, int y) {
     int diff, temp;
     int dist_lat;
 
@@ -208,19 +205,20 @@ 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 *tiles, 
+void gen_idx_array(struct bucket *p1, struct bucket *tiles, 
                          int width, int height) {
-    struct bucket p2;
+    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);
-           tiles[(j*width)+i] = gen_index(&p2);
+           offset_bucket(p1, &tiles[(j*width)+i], i - dw, j - dh);
+           p2 = &tiles[(j*width)+i];
            printf("  bucket = %d %d %d %d  index = %ld\n", 
-                  p2.lon, p2.lat, p2.x, p2.y, tiles[(j*width)+i]);
+                  p2->lon, p2->lat, p2->x, p2->y, 
+                  gen_index(&tiles[(j*width)+i]));
        }
     }
 }
@@ -268,9 +266,23 @@ int main() {
 
 
 /* $Log$
-/* Revision 1.2  1998/01/08 02:22:28  curt
-/* Continue working on basic features.
+/* Revision 1.6  1998/01/19 19:27:18  curt
+/* Merged in make system changes from Bob Kuehne <rpk@sgi.com>
+/* This should simplify things tremendously.
 /*
+ * Revision 1.5  1998/01/14 02:19:04  curt
+ * Makde offset_bucket visible to outside.
+ *
+ * Revision 1.4  1998/01/13 00:23:12  curt
+ * Initial changes to support loading and management of scenery tiles.  Note,
+ * there's still a fair amount of work left to be done.
+ *
+ * Revision 1.3  1998/01/10 00:01:47  curt
+ * Misc api changes and tweaks.
+ *
+ * Revision 1.2  1998/01/08 02:22:28  curt
+ * Continue working on basic features.
+ *
  * Revision 1.1  1998/01/07 23:50:52  curt
  * "area" renamed to "tile"
  *