]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/fg_init.cxx
Updated to support new weather subsystem (visibility variable determins
[flightgear.git] / src / Main / fg_init.cxx
index 149eebb780cd897189562efec1866ce66156367b..646e18b2deb2518bb4e1802b8f7458e457a82464 100644 (file)
@@ -62,6 +62,7 @@
 #include <Math/fg_geodesy.hxx>
 #include <Math/point3d.hxx>
 #include <Math/polar3d.hxx>
+#include <Misc/fgpath.hxx>
 #include <Scenery/scenery.hxx>
 #include <Scenery/tilemgr.hxx>
 #include <Time/event.hxx>
@@ -69,7 +70,8 @@
 #include <Time/light.hxx>
 #include <Time/sunpos.hxx>
 #include <Time/moonpos.hxx>
-#include <Weather/weather.hxx>
+// #include <Weather/weather.hxx>
+#include <WeatherCM/FGLocalWeatherDatabase.h>
 
 #include "fg_init.hxx"
 #include "options.hxx"
@@ -85,8 +87,40 @@ FG_USING_STD(string);
 extern const char *default_root;
 
 
+// Read in configuration (file and command line)
+bool fgInitConfig ( int argc, char **argv ) {
+    // Attempt to locate and parse a config file
+    // First check fg_root
+    FGPath config( current_options.get_fg_root() );
+    config.append( "system.fgfsrc" );
+    current_options.parse_config_file( config.str() );
+
+    // Next check home directory
+    char* envp = ::getenv( "HOME" );
+    if ( envp != NULL ) {
+       config.set( envp );
+       config.append( ".fgfsrc" );
+       current_options.parse_config_file( config.str() );
+    }
+
+    // Parse remaining command line options
+    // These will override anything specified in a config file
+    if ( current_options.parse_command_line(argc, argv) !=
+        fgOPTIONS::FG_OPTIONS_OK )
+    {
+       // Something must have gone horribly wrong with the command
+       // line parsing or maybe the user just requested help ... :-)
+       current_options.usage();
+       FG_LOG( FG_GENERAL, FG_ALERT, "\nExiting ...");
+       return false;
+    }
+
+    return true;
+}
+
+
 // Set initial position and orientation
-int fgInitPosition( void ) {
+bool fgInitPosition( void ) {
     string id;
     FGInterface *f;
 
@@ -132,12 +166,12 @@ int fgInitPosition( void ) {
            << (f->get_Latitude() * RAD_TO_DEG) << ", "
            << (f->get_Altitude() * FEET_TO_METER) << ")" );
 
-    return(1);
+    return true;
 }
 
 
 // General house keeping initializations
-int fgInitGeneral( void ) {
+bool fgInitGeneral( void ) {
     string root;
     char *mesa_win_state;
 
@@ -169,7 +203,7 @@ int fgInitGeneral( void ) {
     }
 #endif
 
-    return 1;
+    return true;
 }
 
 
@@ -177,8 +211,7 @@ int fgInitGeneral( void ) {
 // initialization routines.  If you are adding a subsystem to flight
 // gear, its initialization call should located in this routine.
 // Returns non-zero if a problem encountered.
-int fgInitSubsystems( void )
-{
+bool fgInitSubsystems( void ) {
     FGTime::cur_time_params = new FGTime();
 
     FGInterface *f; // assigned later
@@ -282,7 +315,9 @@ int fgInitSubsystems( void )
     // and should really be read in from one or more files.
 
     // Initial Velocity
-    f->set_Velocities_Local( 0.0, 0.0, 0.0 );
+    f->set_Velocities_Local( current_options.get_uBody(),
+                             current_options.get_vBody(),
+                             current_options.get_wBody());
 
     // Initial Orientation
     f->set_Euler_Angles( current_options.get_roll() * DEG_TO_RAD,
@@ -320,7 +355,7 @@ int fgInitSubsystems( void )
     FG_LOG( FG_GENERAL, FG_DEBUG, "After v->init()");
     v->UpdateViewMath(f);
     FG_LOG( FG_GENERAL, FG_DEBUG, "  abs_view_pos = " << v->get_abs_view_pos());
-    v->UpdateWorldToEye(f);
+    // v->UpdateWorldToEye(f);
 
     // Build the solar system
     //fgSolarSystemInit(*t);
@@ -371,7 +406,21 @@ int fgInitSubsystems( void )
                            fgEVENT::FG_EVENT_READY, 30000 );
 
     // Initialize the weather modeling subsystem
-    current_weather.Init();
+    // current_weather.Init();
+    // Initialize the WeatherDatabase
+    FG_LOG(FG_GENERAL, FG_INFO, "Creating LocalWeatherDatabase");
+    FGLocalWeatherDatabase::theFGLocalWeatherDatabase = 
+       new FGLocalWeatherDatabase(
+             Point3D( current_aircraft.fdm_state->get_Latitude(),
+                      current_aircraft.fdm_state->get_Longitude(),
+                      current_aircraft.fdm_state->get_Altitude() 
+                         * FEET_TO_METER) );
+
+    WeatherDatabase = FGLocalWeatherDatabase::theFGLocalWeatherDatabase;
+
+    // register the periodic update of the weather
+    global_events.Register( "weather update", fgUpdateWeatherDatabase,
+                           fgEVENT::FG_EVENT_READY, 30000);
 
     // Initialize the Cockpit subsystem
     if( fgCockpitInit( &current_aircraft )) {
@@ -422,7 +471,7 @@ int fgInitSubsystems( void )
 
     FG_LOG( FG_GENERAL, FG_INFO, endl);
 
-    return(1);
+    return true;
 }
 
 
@@ -476,7 +525,9 @@ void fgReInitSubsystems( void )
     // and should really be read in from one or more files.
 
     // Initial Velocity
-    f->set_Velocities_Local( 0.0, 0.0, 0.0 );
+    f->set_Velocities_Local( current_options.get_uBody(),
+                             current_options.get_vBody(),
+                             current_options.get_wBody());
 
     // Initial Orientation
     f->set_Euler_Angles( current_options.get_roll() * DEG_TO_RAD,
@@ -501,7 +552,7 @@ void fgReInitSubsystems( void )
     FG_LOG( FG_GENERAL, FG_DEBUG, "After v->init()");
     v->UpdateViewMath(f);
     FG_LOG( FG_GENERAL, FG_DEBUG, "  abs_view_pos = " << v->get_abs_view_pos());
-    v->UpdateWorldToEye(f);
+    // v->UpdateWorldToEye(f);
 
     fgFDMInit( current_options.get_flight_model(), cur_fdm_state, 
               1.0 / DEFAULT_MODEL_HZ );