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 <Debug/fg_debug.h>
#include <Include/general.h> #include <Include/general.h>
#include <zlib/zlib.h> #include <Include/fg_zlib.h>
#include "airports.hxx" #include "airports.hxx"
@ -42,10 +42,10 @@ fgAIRPORTS::fgAIRPORTS( void ) {
// load the data // load the data
int fgAIRPORTS::load( char *file ) { int fgAIRPORTS::load( char *file ) {
fgGENERAL *g; fgGENERAL *g;
char path[256], gzpath[256], line[256]; char path[256], fgpath[256], line[256];
char id[5]; char id[5];
double lon, lat, elev; double lon, lat, elev;
gzFile f; fgFile f;
g = &general; g = &general;
@ -54,30 +54,36 @@ int fgAIRPORTS::load( char *file ) {
strcat(path, g->root_dir); strcat(path, g->root_dir);
strcat(path, "/Scenery/"); strcat(path, "/Scenery/");
strcat(path, "Airports"); strcat(path, "Airports");
strcpy(gzpath, path); strcpy(fgpath, path);
strcat(gzpath, ".gz"); strcat(fgpath, ".gz");
// first try "path.gz" // first try "path.gz"
if ( (f = gzopen(gzpath, "rb")) == NULL ) { if ( (f = fgopen(fgpath, "rb")) == NULL ) {
// next try "path" // 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); fgPrintf(FG_GENERAL, FG_EXIT, "Cannot open file: %s\n", path);
} }
} }
size = 0; size = 0;
while ( gzgets(f, line, 250) != NULL ) { while ( fggets(f, line, 250) != NULL ) {
// printf("%s", line); // printf("%s", line);
if ( size < MAX_AIRPORTS ) {
sscanf( line, "%s %lf %lf %lfl\n", id, &lon, &lat, &elev ); sscanf( line, "%s %lf %lf %lfl\n", id, &lon, &lat, &elev );
strcpy(airports[size].id, id); strcpy(airports[size].id, id);
airports[size].longitude = lon; airports[size].longitude = lon;
airports[size].latitude = lat; airports[size].latitude = lat;
airports[size].elevation = elev; airports[size].elevation = elev;
} else {
fgPrintf( FG_GENERAL, FG_EXIT,
"Overran size of airport list in fgAIRPORTS::load()\n");
}
size++; size++;
} }
gzclose(f); fgclose(f);
} }
@ -103,6 +109,9 @@ fgAIRPORTS::~fgAIRPORTS( void ) {
// $Log$ // $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 // Revision 1.1 1998/04/25 15:11:11 curt
// Added an command line option to set starting position based on airport ID. // 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 <Debug/fg_debug.h>
#include <Include/fg_constants.h> #include <Include/fg_constants.h>
#include <Include/fg_zlib.h>
#include <Math/mat3.h> #include <Math/mat3.h>
#include <Math/fg_random.h> #include <Math/fg_random.h>
#include <Scenery/obj.h> #include <Scenery/obj.h>
#include <Scenery/scenery.h> #include <Scenery/scenery.h>
#include <zlib/zlib.h>
#define MAXNODES 100000 #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 */ /* Load a .obj file and generate the GL call list */
GLint fgObjLoad(char *path, struct fgCartesianPoint *ref, double *radius) { 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 approx_normal[3], normal[3], scale;
// double x, y, z, xmax, xmin, ymax, ymin, zmax, zmin; // double x, y, z, xmax, xmin, ymax, ymin, zmax, zmin;
GLfloat sgenparams[] = { 1.0, 0.0, 0.0, 0.0 }; GLfloat sgenparams[] = { 1.0, 0.0, 0.0, 0.0 };
GLint tile; GLint tile;
gzFile f; fgFile f;
int first, ncount, vncount, n1, n2, n3, n4; int first, ncount, vncount, n1, n2, n3, n4;
static int use_per_vertex_norms = 1; static int use_per_vertex_norms = 1;
int winding; int winding;
int last1, last2, odd; int last1, last2, odd;
// First try "path.obz" (compressed format) // First try "path.obz" (compressed format)
strcpy(gzpath, path); strcpy(fgpath, path);
strcat(gzpath, ".obz"); strcat(fgpath, ".obz");
if ( (f = gzopen(gzpath, "rb")) == NULL ) { if ( (f = fgopen(fgpath, "rb")) == NULL ) {
// Next try "path.obj" (uncompressed format) // Next try "path.obj" (uncompressed format)
strcat(path, ".obj"); strcpy(fgpath, path);
if ( (f = gzopen(path, "rb")) == NULL ) { strcat(fgpath, ".obj");
if ( (f = fgopen(fgpath, "rb")) == NULL ) {
// Next try "path.obj.gz" (compressed format) // Next try "path.obj.gz" (compressed format)
strcat(path, ".gz"); strcat(fgpath, ".gz");
if ( (f = gzopen(path, "rb")) == NULL ) { if ( (f = fgopen(fgpath, "rb")) == NULL ) {
fgPrintf(FG_TERRAIN, FG_ALERT, "Cannot open file: %s\n", path); strcpy(fgpath, path);
strcat(fgpath, ".obj");
fgPrintf( FG_TERRAIN, FG_ALERT,
"Cannot open file: %s\n", fgpath );
return(-1); return(-1);
} }
} }
@ -143,7 +147,7 @@ GLint fgObjLoad(char *path, struct fgCartesianPoint *ref, double *radius) {
ncount = 1; ncount = 1;
vncount = 1; vncount = 1;
while ( gzgets(f, line, 250) != NULL ) { while ( fggets(f, line, 250) != NULL ) {
if ( line[0] == '#' ) { if ( line[0] == '#' ) {
/* comment -- ignore */ /* comment -- ignore */
} else if ( line[0] == '\n' ) { } else if ( line[0] == '\n' ) {
@ -463,7 +467,7 @@ GLint fgObjLoad(char *path, struct fgCartesianPoint *ref, double *radius) {
xglEndList(); xglEndList();
gzclose(f); fgclose(f);
/* reference point is the "center" (now included in input file) */ /* reference point is the "center" (now included in input file) */
/* /*
@ -477,11 +481,14 @@ GLint fgObjLoad(char *path, struct fgCartesianPoint *ref, double *radius) {
/* $Log$ /* $Log$
/* Revision 1.34 1998/04/28 01:21:42 curt /* Revision 1.35 1998/04/28 21:43:26 curt
/* Tweaked texture parameter calculations to keep the number smaller. This /* Wrapped zlib calls up so we can conditionally comment out zlib support.
/* avoids the "swimming" problem.
/* Type-ified fgTIME and fgVIEW.
/* /*
* 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 * Revision 1.33 1998/04/27 15:58:15 curt
* Screwing around with texture coordinate generation ... still needs work. * Screwing around with texture coordinate generation ... still needs work.
* *

View file

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

View file

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