1
0
Fork 0

Wrapped zlib calls up so we can conditionally comment out zlib support.

This commit is contained in:
curt 1998-04-28 21:42:50 +00:00
parent 4e992277a9
commit 09bd08b931
4 changed files with 76 additions and 50 deletions

View file

@ -29,7 +29,7 @@
#include <Debug/fg_debug.h>
#include <Include/general.h>
#include <zlib/zlib.h>
#include <Include/fg_zlib.h>
#include "airports.hxx"
@ -42,10 +42,10 @@ fgAIRPORTS::fgAIRPORTS( void ) {
// load the data
int fgAIRPORTS::load( char *file ) {
fgGENERAL *g;
char path[256], gzpath[256], line[256];
char path[256], fgpath[256], line[256];
char id[5];
double lon, lat, elev;
gzFile f;
fgFile f;
g = &general;
@ -54,30 +54,36 @@ int fgAIRPORTS::load( char *file ) {
strcat(path, g->root_dir);
strcat(path, "/Scenery/");
strcat(path, "Airports");
strcpy(gzpath, path);
strcat(gzpath, ".gz");
strcpy(fgpath, path);
strcat(fgpath, ".gz");
// first try "path.gz"
if ( (f = gzopen(gzpath, "rb")) == NULL ) {
if ( (f = fgopen(fgpath, "rb")) == NULL ) {
// next try "path"
if ( (f = gzopen(path, "rb")) == NULL ) {
if ( (f = fgopen(path, "rb")) == NULL ) {
fgPrintf(FG_GENERAL, FG_EXIT, "Cannot open file: %s\n", path);
}
}
size = 0;
while ( gzgets(f, line, 250) != NULL ) {
while ( fggets(f, line, 250) != NULL ) {
// printf("%s", line);
sscanf( line, "%s %lf %lf %lfl\n", id, &lon, &lat, &elev );
strcpy(airports[size].id, id);
airports[size].longitude = lon;
airports[size].latitude = lat;
airports[size].elevation = elev;
if ( size < MAX_AIRPORTS ) {
sscanf( line, "%s %lf %lf %lfl\n", id, &lon, &lat, &elev );
strcpy(airports[size].id, id);
airports[size].longitude = lon;
airports[size].latitude = lat;
airports[size].elevation = elev;
} else {
fgPrintf( FG_GENERAL, FG_EXIT,
"Overran size of airport list in fgAIRPORTS::load()\n");
}
size++;
}
gzclose(f);
fgclose(f);
}
@ -103,6 +109,9 @@ fgAIRPORTS::~fgAIRPORTS( void ) {
// $Log$
// Revision 1.2 1998/04/28 21:42:50 curt
// Wrapped zlib calls up so we can conditionally comment out zlib support.
//
// Revision 1.1 1998/04/25 15:11:11 curt
// Added an command line option to set starting position based on airport ID.
//

View file

@ -40,11 +40,11 @@
#include <Debug/fg_debug.h>
#include <Include/fg_constants.h>
#include <Include/fg_zlib.h>
#include <Math/mat3.h>
#include <Math/fg_random.h>
#include <Scenery/obj.h>
#include <Scenery/scenery.h>
#include <zlib/zlib.h>
#define MAXNODES 100000
@ -98,28 +98,32 @@ float calc_lat(double x, double y, double z) {
/* Load a .obj file and generate the GL call list */
GLint fgObjLoad(char *path, struct fgCartesianPoint *ref, double *radius) {
char gzpath[256], line[256], winding_str[256];
char fgpath[256], line[256], winding_str[256];
double approx_normal[3], normal[3], scale;
// double x, y, z, xmax, xmin, ymax, ymin, zmax, zmin;
GLfloat sgenparams[] = { 1.0, 0.0, 0.0, 0.0 };
GLint tile;
gzFile f;
fgFile f;
int first, ncount, vncount, n1, n2, n3, n4;
static int use_per_vertex_norms = 1;
int winding;
int last1, last2, odd;
// First try "path.obz" (compressed format)
strcpy(gzpath, path);
strcat(gzpath, ".obz");
if ( (f = gzopen(gzpath, "rb")) == NULL ) {
strcpy(fgpath, path);
strcat(fgpath, ".obz");
if ( (f = fgopen(fgpath, "rb")) == NULL ) {
// Next try "path.obj" (uncompressed format)
strcat(path, ".obj");
if ( (f = gzopen(path, "rb")) == NULL ) {
strcpy(fgpath, path);
strcat(fgpath, ".obj");
if ( (f = fgopen(fgpath, "rb")) == NULL ) {
// Next try "path.obj.gz" (compressed format)
strcat(path, ".gz");
if ( (f = gzopen(path, "rb")) == NULL ) {
fgPrintf(FG_TERRAIN, FG_ALERT, "Cannot open file: %s\n", path);
strcat(fgpath, ".gz");
if ( (f = fgopen(fgpath, "rb")) == NULL ) {
strcpy(fgpath, path);
strcat(fgpath, ".obj");
fgPrintf( FG_TERRAIN, FG_ALERT,
"Cannot open file: %s\n", fgpath );
return(-1);
}
}
@ -143,7 +147,7 @@ GLint fgObjLoad(char *path, struct fgCartesianPoint *ref, double *radius) {
ncount = 1;
vncount = 1;
while ( gzgets(f, line, 250) != NULL ) {
while ( fggets(f, line, 250) != NULL ) {
if ( line[0] == '#' ) {
/* comment -- ignore */
} else if ( line[0] == '\n' ) {
@ -463,7 +467,7 @@ GLint fgObjLoad(char *path, struct fgCartesianPoint *ref, double *radius) {
xglEndList();
gzclose(f);
fgclose(f);
/* reference point is the "center" (now included in input file) */
/*
@ -477,11 +481,14 @@ GLint fgObjLoad(char *path, struct fgCartesianPoint *ref, double *radius) {
/* $Log$
/* Revision 1.34 1998/04/28 01:21:42 curt
/* Tweaked texture parameter calculations to keep the number smaller. This
/* avoids the "swimming" problem.
/* Type-ified fgTIME and fgVIEW.
/* Revision 1.35 1998/04/28 21:43:26 curt
/* Wrapped zlib calls up so we can conditionally comment out zlib support.
/*
* Revision 1.34 1998/04/28 01:21:42 curt
* Tweaked texture parameter calculations to keep the number smaller. This
* avoids the "swimming" problem.
* Type-ified fgTIME and fgVIEW.
*
* Revision 1.33 1998/04/27 15:58:15 curt
* Screwing around with texture coordinate generation ... still needs work.
*

View file

@ -57,7 +57,7 @@ struct fgSCENERY scenery;
/* Initialize the Scenery Management system */
int fgSceneryInit( void ) {
fgGENERAL *g;
char path[1024];
char path[1024], fgpath[1024];
GLubyte *texbuf;
int width, height;
@ -74,9 +74,16 @@ int fgSceneryInit( void ) {
strcat(path, "/Textures/");
strcat(path, "desert.rgb");
// Try uncompressed
if ( (texbuf = read_rgb_texture(path, &width, &height)) == NULL ) {
fgPrintf( FG_GENERAL, FG_EXIT, "Error in loading textures!\n" );
return(0);
// Try compressed
strcpy(fgpath, path);
strcat(fgpath, ".gz");
if ( (texbuf = read_rgb_texture(fgpath, &width, &height)) == NULL ) {
fgPrintf( FG_GENERAL, FG_EXIT, "Error in loading texture %s\n",
path );
return(0);
}
}
xglTexImage2D(GL_TEXTURE_2D, 0, 3, height, width, 0,
@ -116,11 +123,14 @@ void fgSceneryRender( void ) {
/* $Log$
/* Revision 1.41 1998/04/24 00:51:08 curt
/* Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H"
/* Tweaked the scenery file extentions to be "file.obj" (uncompressed)
/* or "file.obz" (compressed.)
/* Revision 1.42 1998/04/28 21:43:27 curt
/* Wrapped zlib calls up so we can conditionally comment out zlib support.
/*
* Revision 1.41 1998/04/24 00:51:08 curt
* Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H"
* Tweaked the scenery file extentions to be "file.obj" (uncompressed)
* or "file.obz" (compressed.)
*
* Revision 1.40 1998/04/18 04:14:06 curt
* Moved fg_debug.c to it's own library.
*

View file

@ -7,7 +7,7 @@
#include <stdlib.h>
#include <string.h>
#include <zlib/zlib.h>
#include <Include/fg_zlib.h>
#include "texload.h"
@ -20,7 +20,7 @@ typedef struct _ImageRec {
unsigned int wasteBytes;
char name[80];
unsigned long colorMap;
gzFile file;
fgFile file;
unsigned char *tmp;
unsigned long rleEnd;
unsigned int *rowStart;
@ -88,12 +88,12 @@ static ImageRec *ImageOpen(char *fileName)
fprintf(stderr, "Out of memory!\n");
exit(1);
}
if ((image->file = gzopen(fileName, "rb")) == NULL) {
if ((image->file = fgopen(fileName, "rb")) == NULL) {
return NULL;
}
// fread(image, 1, 12, image->file);
gzread(image->file, image, 12);
fgread(image->file, image, 12);
if (swapFlag) {
ConvertShort(&image->imagic, 6);
@ -114,11 +114,11 @@ static ImageRec *ImageOpen(char *fileName)
exit(1);
}
image->rleEnd = 512 + (2 * x);
gzseek(image->file, 512, SEEK_SET);
fgseek(image->file, 512, SEEK_SET);
// fread(image->rowStart, 1, x, image->file);
gzread(image->file, image->rowStart, x);
fgread(image->file, image->rowStart, x);
// fread(image->rowSize, 1, x, image->file);
gzread(image->file, image->rowSize, x);
fgread(image->file, image->rowSize, x);
if (swapFlag) {
ConvertUint(image->rowStart, x/(int) sizeof(unsigned));
ConvertUint((unsigned *)image->rowSize, x/(int) sizeof(int));
@ -129,7 +129,7 @@ static ImageRec *ImageOpen(char *fileName)
static void
ImageClose(ImageRec *image) {
gzclose(image->file);
fgclose(image->file);
free(image->tmp);
free(image);
}
@ -140,10 +140,10 @@ ImageGetRow(ImageRec *image, unsigned char *buf, int y, int z) {
int count;
if ((image->type & 0xFF00) == 0x0100) {
gzseek(image->file, (long) image->rowStart[y+z*image->ysize], SEEK_SET);
fgseek(image->file, (long) image->rowStart[y+z*image->ysize], SEEK_SET);
// fread(image->tmp, 1, (unsigned int)image->rowSize[y+z*image->ysize],
// image->file);
gzread(image->file, image->tmp,
fgread(image->file, image->tmp,
(unsigned int)image->rowSize[y+z*image->ysize]);
iPtr = image->tmp;
@ -166,10 +166,10 @@ ImageGetRow(ImageRec *image, unsigned char *buf, int y, int z) {
}
}
} else {
gzseek(image->file, 512+(y*image->xsize)+(z*image->xsize*image->ysize),
fgseek(image->file, 512+(y*image->xsize)+(z*image->xsize*image->ysize),
SEEK_SET);
// fread(buf, 1, image->xsize, image->file);
gzread(image->file, buf, image->xsize);
fgread(image->file, buf, image->xsize);
}
}