From 9692b3fe1ed6917f423badc47bb2b8065e25c82d Mon Sep 17 00:00:00 2001 From: curt Date: Sat, 25 Apr 1998 15:11:10 +0000 Subject: [PATCH] Added an command line option to set starting position based on airport ID. --- Main/Makefile.am | 1 + Main/Makefile.in | 8 +- Main/airports.cxx | 109 +++++++++ Main/airports.hxx | 74 ++++++ Main/fg_init.cxx | 604 ++++++++++++++++++++++++---------------------- Main/fg_init.hxx | 94 ++++---- Main/options.cxx | 10 +- Main/options.hxx | 6 + 8 files changed, 571 insertions(+), 335 deletions(-) create mode 100644 Main/airports.cxx create mode 100644 Main/airports.hxx diff --git a/Main/Makefile.am b/Main/Makefile.am index 30292e068..08cc5d65b 100644 --- a/Main/Makefile.am +++ b/Main/Makefile.am @@ -7,6 +7,7 @@ bin_SCRIPTS = runfg runfg.bat fg_SOURCES = \ GLUTkey.cxx GLUTkey.hxx \ GLUTmain.cxx \ + airports.cxx airports.hxx \ fg_config.h \ fg_init.cxx fg_init.hxx \ options.cxx options.hxx \ diff --git a/Main/Makefile.in b/Main/Makefile.in index 3d13ea6f3..64171d5f9 100644 --- a/Main/Makefile.in +++ b/Main/Makefile.in @@ -80,6 +80,7 @@ bin_SCRIPTS = runfg runfg.bat fg_SOURCES = \ GLUTkey.cxx GLUTkey.hxx \ GLUTmain.cxx \ + airports.cxx airports.hxx \ fg_config.h \ fg_init.cxx fg_init.hxx \ options.cxx options.hxx \ @@ -116,7 +117,8 @@ X_CFLAGS = @X_CFLAGS@ X_LIBS = @X_LIBS@ X_EXTRA_LIBS = @X_EXTRA_LIBS@ X_PRE_LIBS = @X_PRE_LIBS@ -fg_OBJECTS = GLUTkey.o GLUTmain.o fg_init.o options.o views.o +fg_OBJECTS = GLUTkey.o GLUTmain.o airports.o fg_init.o options.o \ +views.o fg_DEPENDENCIES = $(top_builddir)/Simulator/Aircraft/libAircraft.la \ $(top_builddir)/Simulator/Astro/libAstro.la \ $(top_builddir)/Simulator/Autopilot/libAutopilot.la \ @@ -146,8 +148,8 @@ DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) TAR = tar GZIP = --best -DEP_FILES = .deps/GLUTkey.P .deps/GLUTmain.P .deps/fg_init.P \ -.deps/options.P .deps/views.P +DEP_FILES = .deps/GLUTkey.P .deps/GLUTmain.P .deps/airports.P \ +.deps/fg_init.P .deps/options.P .deps/views.P CXXMKDEP = $(CXX) -M $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS) SOURCES = $(fg_SOURCES) OBJECTS = $(fg_OBJECTS) diff --git a/Main/airports.cxx b/Main/airports.cxx new file mode 100644 index 000000000..2422a8351 --- /dev/null +++ b/Main/airports.cxx @@ -0,0 +1,109 @@ +// +// airports.cxx -- a really simplistic class to manage airport ID, +// lat, lon of the center of one of it's runways, and +// elevation in feet. +// +// Written by Curtis Olson, started April 1998. +// +// Copyright (C) 1998 Curtis L. Olson - curt@me.umn.edu +// +// 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 + +#include +#include +#include + +#include "airports.hxx" + + +// Constructor +fgAIRPORTS::fgAIRPORTS( void ) { +} + + +// load the data +int fgAIRPORTS::load( char *file ) { + fgGENERAL *g; + char path[256], gzpath[256], line[256]; + char id[5]; + double lon, lat, elev; + gzFile f; + + g = &general; + + // build the path name to the ambient lookup table + path[0] = '\0'; + strcat(path, g->root_dir); + strcat(path, "/Scenery/"); + strcat(path, "Airports"); + strcpy(gzpath, path); + strcat(gzpath, ".gz"); + + // first try "path.gz" + if ( (f = gzopen(gzpath, "rb")) == NULL ) { + // next try "path" + if ( (f = gzopen(path, "rb")) == NULL ) { + fgPrintf(FG_GENERAL, FG_EXIT, "Cannot open file: %s\n", path); + } + } + + size = 0; + while ( gzgets(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; + + size++; + } + + gzclose(f); +} + + +// search for the specified id +fgAIRPORT fgAIRPORTS::search( char *id ) { + fgAIRPORT a; + int i; + + for ( i = 0; i < size; i++ ) { + if ( strcmp(airports[i].id, id) == 0 ) { + return(airports[i]); + } + } + + strcpy(a.id, "none"); + return(a); +} + + +// Destructor +fgAIRPORTS::~fgAIRPORTS( void ) { +} + + +// $Log$ +// Revision 1.1 1998/04/25 15:11:11 curt +// Added an command line option to set starting position based on airport ID. +// +// diff --git a/Main/airports.hxx b/Main/airports.hxx new file mode 100644 index 000000000..af4ea1eb0 --- /dev/null +++ b/Main/airports.hxx @@ -0,0 +1,74 @@ +// +// airports.hxx -- a really simplistic class to manage airport ID, +// lat, lon of the center of one of it's runways, and +// elevation in feet. +// +// Written by Curtis Olson, started April 1998. +// +// Copyright (C) 1998 Curtis L. Olson - curt@me.umn.edu +// +// 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) + + +#ifndef _AIRPORTS_HXX +#define _AIRPORTS_HXX + + +#ifndef __cplusplus +# error This library requires C++ +#endif + + +#define MAX_AIRPORTS 10000 + + +typedef struct { + char id[5]; + double longitude, latitude, elevation; +} fgAIRPORT; + + +class fgAIRPORTS { + fgAIRPORT airports[MAX_AIRPORTS]; + int size; + +public: + + // Constructor + fgAIRPORTS( void ); + + // load the data + int load( char *file ); + + // search for the specified id + fgAIRPORT search( char *id ); + + // Destructor + ~fgAIRPORTS( void ); + +}; + + +#endif /* _AIRPORTS_HXX */ + + +// $Log$ +// Revision 1.1 1998/04/25 15:11:11 curt +// Added an command line option to set starting position based on airport ID. +// +// diff --git a/Main/fg_init.cxx b/Main/fg_init.cxx index ef22e2fce..39c12580e 100644 --- a/Main/fg_init.cxx +++ b/Main/fg_init.cxx @@ -1,29 +1,27 @@ -/* -*- Mode: C++ -*- - * - * fg_init.c -- Flight Gear top level initialization routines - * - * Written by Curtis Olson, started August 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) - **************************************************************************/ +// +// fg_init.cxx -- Flight Gear top level initialization routines +// +// Written by Curtis Olson, started August 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 HAVE_CONFIG_H @@ -55,74 +53,23 @@ #include