diff --git a/Thanks b/Thanks index 90ab11a3d..13420f7af 100644 --- a/Thanks +++ b/Thanks @@ -375,6 +375,14 @@ Ed Williams http://www.best.com/~williams/index.html +Jean-Claude Wippler + Author of MetaKit - a portable, embeddible database with a portable + data file format. This software is not GPL'd but the author is kindly + allowing us to bundle MetaKit with our code. MetaKit has a liberal + X/MIT-style license. Please see the following URL for more info: + http://www.equi4.com/metakit + + WoodSoup Project http://www.woodsoup.org Provided computing resources and services so that the Flight Gear project could have real home. This includes, web services, diff --git a/docs-mini/README.JSBsim b/docs-mini/README.JSBsim index e1fc8dff2..6115d4b36 100644 --- a/docs-mini/README.JSBsim +++ b/docs-mini/README.JSBsim @@ -22,8 +22,7 @@ Currently, for JSBSim only the X-15 is available, and possibly the C-172. Here is an example command line used to start up FlightGear using JSBSim as the FDM: -fgfs --fdm=jsb --aircraft=X15 --units-feet --altitude=60000 --uBody=2000 --w -Body=120 +fgfs --fdm=jsb --aircraft=X15 --units-feet --altitude=60000 --uBody=2000 --wBody=120 [Note: uBody is the forward velocity of the aircraft, wBody is the downward velocity - from the aircraft point of view. This essentially means that the diff --git a/src/Airports/Makefile.am b/src/Airports/Makefile.am index e3a205af9..adee6d991 100644 --- a/src/Airports/Makefile.am +++ b/src/Airports/Makefile.am @@ -8,6 +8,6 @@ libAirports_a_SOURCES = \ buildsimple_SOURCES = buildsimple.cxx -buildsimple_LDADD = libAirports.a -lsgdebug -lsgmisc -lgdbm -lz +buildsimple_LDADD = libAirports.a -lsgdebug -lsgmisc -lmk4 -lz INCLUDES += -I$(top_builddir) -I$(top_builddir)/src diff --git a/src/Airports/buildsimple.cxx b/src/Airports/buildsimple.cxx index b4f2b707f..f3c9a9757 100644 --- a/src/Airports/buildsimple.cxx +++ b/src/Airports/buildsimple.cxx @@ -8,8 +8,12 @@ int main( int argc, char **argv ) { if ( argc == 3 ) { airports.load( argv[1] ); - airports.dump_gdbm( argv[2] ); + airports.dump_mk4( argv[2] ); } else { cout << "usage: " << argv[0] << " " << endl; } + + // FGAirports airport_db( argv[2] ); + // airport_db.search( "KANEZZZ", &a ); + } diff --git a/src/Airports/simple.cxx b/src/Airports/simple.cxx index 2c4314159..e9a04b9fb 100644 --- a/src/Airports/simple.cxx +++ b/src/Airports/simple.cxx @@ -28,14 +28,14 @@ # include #endif -#include // for gdbm open flags -#include // for gdbm open flags +// #include // for gdbm open flags +// #include // for gdbm open flags -#ifdef HAVE_GDBM -# include -#else -# include -#endif +// #ifdef HAVE_GDBM +// # include +// #else +// # include +// #endif #include @@ -53,13 +53,14 @@ FG_USING_NAMESPACE(std); FGAirports::FGAirports( const string& file ) { - dbf = gdbm_open( (char *)file.c_str(), 0, GDBM_READER, 0, NULL ); - if ( dbf == NULL ) { - cout << "Error opening " << file << endl; - exit(-1); - } else { - cout << "successfully opened " << file << endl; - } + // open the specified database readonly + storage = new c4_Storage( file.c_str(), false ); + + // need to do something about error handling here! + + vAirport = new c4_View; + *vAirport = + storage->GetAs("airport[ID:S,Longitude:F,Latitude:F,Elevation:F]"); } @@ -67,31 +68,24 @@ FGAirports::FGAirports( const string& file ) { bool FGAirports::search( const string& id, FGAirport* a ) const { - FGAirport *tmp; - datum content; - datum key; + c4_StringProp pID ("ID"); + c4_FloatProp pLon ("Longitude"); + c4_FloatProp pLat ("Latitude"); + c4_FloatProp pElev ("Elevation"); - key.dptr = (char *)id.c_str(); - key.dsize = id.length(); + int idx = vAirport->Find(pID[id.c_str()]); + cout << "idx = " << idx << endl; - content = gdbm_fetch( dbf, key ); - - cout << "gdbm_fetch() finished" << endl; - - if ( content.dptr != NULL ) { - tmp = (FGAirport *)content.dptr; - - // a->id = tmp->id; - a->longitude = tmp->longitude; - a->latitude = tmp->latitude; - a->elevation = tmp->elevation; - - free( content.dptr ); - - } else { + if ( idx == -1 ) { return false; } + c4_RowRef r = vAirport->GetAt(idx); + + a->longitude = (double) pLon(r); + a->latitude = (double) pLat(r); + a->elevation = (double) pElev(r); + return true; } @@ -99,27 +93,15 @@ FGAirports::search( const string& id, FGAirport* a ) const FGAirport FGAirports::search( const string& id ) const { - FGAirport a, *tmp; - datum content; - datum key; - - key.dptr = (char *)id.c_str(); - key.dsize = id.length(); - - content = gdbm_fetch( dbf, key ); - - if ( content.dptr != NULL ) { - tmp = (FGAirport *)content.dptr; - a = *tmp; - } - + FGAirport a; + search( id, &a ); return a; } // Destructor FGAirports::~FGAirports( void ) { - gdbm_close( dbf ); + // gdbm_close( dbf ); } @@ -177,44 +159,40 @@ int FGAirportsUtil::load( const string& file ) { // save the data in gdbm format -bool FGAirportsUtil::dump_gdbm( const string& file ) { +bool FGAirportsUtil::dump_mk4( const string& file ) { - GDBM_FILE dbf; + // open database for writing + c4_Storage storage( file.c_str(), true ); -#if defined( MACOS ) || defined( _MSC_VER ) - dbf = gdbm_open( (char *)file.c_str(), 0, GDBM_NEWDB | GDBM_FAST, - NULL, NULL ); -#else - dbf = gdbm_open( (char *)file.c_str(), 0, GDBM_NEWDB | GDBM_FAST, - S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH, - NULL ); -#endif + // need to do something about error handling here! - if ( dbf == NULL ) { - cout << "Error opening " << file << endl; - exit(-1); - } else { - cout << "successfully opened " << file << endl; - } + // define the properties + c4_StringProp pID ("ID"); + c4_FloatProp pLon ("Longitude"); + c4_FloatProp pLat ("Latitude"); + c4_FloatProp pElev ("Elevation"); + + // Start with an empty view of the proper structure. + c4_View vAirport = + storage.GetAs("airport[ID:S,Longitude:F,Latitude:F,Elevation:F]"); + + c4_Row row; iterator current = airports.begin(); const_iterator end = airports.end(); while ( current != end ) { - datum key; - key.dptr = (char *)current->id.c_str(); - key.dsize = current->id.length(); - - datum content; - FGAirport tmp = *current; - content.dptr = (char *)(& tmp); - content.dsize = sizeof( *current ); - - gdbm_store( dbf, key, content, GDBM_REPLACE ); + // add each airport record + pID (row) = current->id.c_str(); + pLon (row) = current->longitude; + pLat (row) = current->latitude; + pElev (row) = current->elevation; + vAirport.Add(row); ++current; } - gdbm_close( dbf ); + // commit our changes + storage.Commit(); return true; } diff --git a/src/Airports/simple.hxx b/src/Airports/simple.hxx index 6543ddce6..d0e3fd588 100644 --- a/src/Airports/simple.hxx +++ b/src/Airports/simple.hxx @@ -23,8 +23,8 @@ // $Id$ -#ifndef _AIRPORTS_HXX -#define _AIRPORTS_HXX +#ifndef _SIMPLE_HXX +#define _SIMPLE_HXX #ifndef __cplusplus @@ -36,12 +36,6 @@ # include #endif -#ifdef HAVE_GDBM -# include -#else -# include -#endif - #include #ifdef FG_HAVE_STD_INCLUDES @@ -57,6 +51,11 @@ #include STL_STRING #include +#define NDEBUG // she don't work without it. +#include +#include +#undef NDEBUG + FG_USING_STD(string); FG_USING_STD(set); @@ -99,7 +98,8 @@ class FGAirports { private: - GDBM_FILE dbf; + c4_Storage *storage; + c4_View *vAirport; public: @@ -112,7 +112,7 @@ public: // search for the specified id. // Returns true if successful, otherwise returns false. // On success, airport data is returned thru "airport" pointer. - // "airport" is not changed if "id" is not found. + // "airport" is not changed if "apt" is not found. bool search( const string& id, FGAirport* airport ) const; FGAirport search( const string& id ) const; }; @@ -142,8 +142,8 @@ public: // load the data int load( const string& file ); - // save the data in gdbm format - bool dump_gdbm( const string& file ); + // save the data in metakit format + bool dump_mk4( const string& file ); // search for the specified id. // Returns true if successful, otherwise returns false. @@ -154,6 +154,6 @@ public: }; -#endif /* _AIRPORTS_HXX */ +#endif // _SIMPLE_HXX diff --git a/src/Autopilot/auto_gui.cxx b/src/Autopilot/auto_gui.cxx index 02ceeb5f1..e662fadb6 100644 --- a/src/Autopilot/auto_gui.cxx +++ b/src/Autopilot/auto_gui.cxx @@ -595,7 +595,7 @@ void TgtAptDialog_OK (puObject *) FGPath path( current_options.get_fg_root() ); path.append( "Airports" ); - path.append( "simple.gdbm" ); + path.append( "simple.mk4" ); FGAirports airports( path.c_str() ); FGAirport a; diff --git a/src/GUI/gui.cxx b/src/GUI/gui.cxx index 8ce464eac..eb272e42c 100644 --- a/src/GUI/gui.cxx +++ b/src/GUI/gui.cxx @@ -756,7 +756,7 @@ void reInit(puObject *cb) static void toggleClouds(puObject *cb) { - FGBFI::setClouds(!FGBFI::getClouds()); + FGBFI::setClouds( !FGBFI::getClouds() ); } // This is the accessor function @@ -1034,8 +1034,9 @@ void AptDialog_OK (puObject *) { FGPath path( current_options.get_fg_root() ); path.append( "Airports" ); - path.append( "simple.gdbm" ); + path.append( "simple.mk4" ); FGAirports airports( path.c_str() ); + FGAirport a; FGTime *t = FGTime::cur_time_params; diff --git a/src/Main/Makefile.am b/src/Main/Makefile.am index 762f53236..2c4695402 100644 --- a/src/Main/Makefile.am +++ b/src/Main/Makefile.am @@ -70,7 +70,7 @@ fgfs_LDADD = \ $(SERIAL_LIBS) \ -lsgscreen -lsgmath -lsgbucket -lsgdebug -lsgmagvar -lsgmisc \ -lplibpu -lplibfnt -lplibssg -lplibsg \ - -lgdbm -lz \ + -lmk4 -lz \ $(opengl_LIBS) \ $(audio_LIBS) diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index d0953e7f3..06c5535a3 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -146,7 +146,7 @@ bool fgInitPosition( void ) { FGPath path( current_options.get_fg_root() ); path.append( "Airports" ); - path.append( "simple.gdbm" ); + path.append( "simple.mk4" ); FGAirports airports( path.c_str() ); FGAirport a; diff --git a/src/Time/fg_timer.cxx b/src/Time/fg_timer.cxx index 91fa01551..49e2713c7 100644 --- a/src/Time/fg_timer.cxx +++ b/src/Time/fg_timer.cxx @@ -103,6 +103,7 @@ int fgGetTimeInterval( void ) { static FGTimeStamp last; FGTimeStamp current; + if ( ! inited ) { inited = 1; last.stamp(); @@ -113,7 +114,7 @@ int fgGetTimeInterval( void ) { last = current; } - return(interval); + return interval; } diff --git a/src/Time/timestamp.hxx b/src/Time/timestamp.hxx index 00b7352a4..1a50c7884 100644 --- a/src/Time/timestamp.hxx +++ b/src/Time/timestamp.hxx @@ -154,7 +154,7 @@ inline void FGTimeStamp::stamp() { #endif } -// difference between time stamps in microseconds (usec) +// increment the time stamp by the number of microseconds (usec) inline FGTimeStamp operator + (const FGTimeStamp& t, const long& m) { #ifdef WIN32 return FGTimeStamp( 0, t.usec + m );