]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/fg_init.cxx
Code reorganization.
[flightgear.git] / src / Main / fg_init.cxx
index b985be58345888e62e0bee92e606465327439a10..8fd02cd841c05513bd06b34dd796996caa8c0255 100644 (file)
@@ -33,7 +33,7 @@
 #endif
 
 #include <GL/glut.h>
-#include <XGL/xgl.h>
+#include <simgear/xgl.h>
 
 #include <stdio.h>
 #include <stdlib.h>
 #  define _G_NO_EXTERN_TEMPLATES
 #endif
 
-#include <Include/compiler.h>
+#include <simgear/compiler.h>
 
 #include STL_STRING
 
-#include <Debug/logstream.hxx>
+#include <simgear/logstream.hxx>
+#include <simgear/constants.h>
+#include <simgear/fg_geodesy.hxx>
+#include <simgear/point3d.hxx>
+#include <simgear/polar3d.hxx>
+#include <simgear/fgpath.hxx>
+
 #include <Aircraft/aircraft.hxx>
 #include <Airports/simple.hxx>
 #include <Astro/sky.hxx>
 #include <Astro/solarsystem.hxx>
 #include <Autopilot/autopilot.hxx>
 #include <Cockpit/cockpit.hxx>
-// #include <FDM/Balloon.h>
-#include <FDM/LaRCsim.hxx>
+#include <FDM/Balloon.h>
+#include <FDM/External.hxx>
 #include <FDM/JSBsim.hxx>
-#include <Include/fg_constants.h>
+#include <FDM/LaRCsim.hxx>
+#include <FDM/MagicCarpet.hxx>
 #include <Include/general.hxx>
 #include <Joystick/joystick.hxx>
-#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>
 #include <Time/sunpos.hxx>
 #include <Time/moonpos.hxx>
 
-#ifdef FG_NEW_WEATHER
+#ifndef FG_OLD_WEATHER
 #  include <WeatherCM/FGLocalWeatherDatabase.h>
 #else
 #  include <Weather/weather.hxx>
 #endif
 
 #include "fg_init.hxx"
+#include "fg_io.hxx"
 #include "options.hxx"
 #include "views.hxx"
-#include "fg_serial.hxx"
 
 #if defined(FX) && defined(XMESA)
 #include <GL/xmesa.h>
@@ -122,7 +125,7 @@ bool fgInitConfig ( int argc, char **argv ) {
        return false;
     }
 
-    return true;
+   return true;
 }
 
 
@@ -180,7 +183,10 @@ bool fgInitPosition( void ) {
 // General house keeping initializations
 bool fgInitGeneral( void ) {
     string root;
+
+#if defined(FX) && defined(XMESA)
     char *mesa_win_state;
+#endif
 
     FG_LOG( FG_GENERAL, FG_INFO, "General Initialization" );
     FG_LOG( FG_GENERAL, FG_INFO, "======= ==============" );
@@ -223,7 +229,6 @@ bool fgInitSubsystems( void ) {
 
     fgLIGHT *l = &cur_light_params;
     FGTime *t = FGTime::cur_time_params;
-    FGView *v = &current_view;
 
     FG_LOG( FG_GENERAL, FG_INFO, "Initialize Subsystems");
     FG_LOG( FG_GENERAL, FG_INFO, "========== ==========");
@@ -232,9 +237,15 @@ bool fgInitSubsystems( void ) {
        cur_fdm_state = new FGLaRCsim;
     } else if ( current_options.get_flight_model() == FGInterface::FG_JSBSIM ) {
        cur_fdm_state = new FGJSBsim;
-    // } else if ( current_options.get_flight_model() == 
-    //             FGInterface::FG_BALLOONSIM ) {
-    //     cur_fdm_state = new FGBalloonSim;
+    } else if ( current_options.get_flight_model() == 
+               FGInterface::FG_BALLOONSIM ) {
+       cur_fdm_state = new FGBalloonSim;
+    } else if ( current_options.get_flight_model() == 
+               FGInterface::FG_MAGICCARPET ) {
+       cur_fdm_state = new FGMagicCarpet;
+    } else if ( current_options.get_flight_model() == 
+               FGInterface::FG_EXTERNAL ) {
+       cur_fdm_state = new FGExternal;
     } else {
        FG_LOG( FG_GENERAL, FG_ALERT,
                "No flight model, can't init aircraft" );
@@ -310,7 +321,7 @@ bool fgInitSubsystems( void ) {
            << (cur_fdm_state->get_Altitude() * FEET_TO_METER) << ")" );
 
     // We need to calculate a few more values here that would normally
-    // be calculated by the FDM so that the v->UpdateViewMath()
+    // be calculated by the FDM so that the current_view.UpdateViewMath()
     // routine doesn't get hosed.
 
     double sea_level_radius_meters;
@@ -368,12 +379,14 @@ bool fgInitSubsystems( void ) {
     t->update(*cur_fdm_state);
 
     // Initialize view parameters
-    FG_LOG( FG_GENERAL, FG_DEBUG, "Before v->init()");
-    v->Init();
-    FG_LOG( FG_GENERAL, FG_DEBUG, "After v->init()");
-    v->UpdateViewMath(*cur_fdm_state);
-    FG_LOG( FG_GENERAL, FG_DEBUG, "  abs_view_pos = " << v->get_abs_view_pos());
-    // v->UpdateWorldToEye(f);
+    FG_LOG( FG_GENERAL, FG_DEBUG, "Before current_view.init()");
+    current_view.Init();
+    pilot_view.Init();
+    FG_LOG( FG_GENERAL, FG_DEBUG, "After current_view.init()");
+    current_view.UpdateViewMath(*cur_fdm_state);
+    pilot_view.UpdateViewMath(*cur_fdm_state);
+    FG_LOG( FG_GENERAL, FG_DEBUG, "  abs_view_pos = " << current_view.get_abs_view_pos());
+    // current_view.UpdateWorldToEye(f);
 
     // Build the solar system
     //fgSolarSystemInit(*t);
@@ -422,23 +435,31 @@ bool fgInitSubsystems( void ) {
                            fgMethodCallback<fgLIGHT>( &cur_light_params,
                                                       &fgLIGHT::Update),
                            fgEVENT::FG_EVENT_READY, 30000 );
+    // update the current timezone each 30 minutes
+    global_events.Register( "fgTIME::updateLocal()",
+                           fgMethodCallback<FGTime>(FGTime::cur_time_params, 
+                                                    &FGTime::updateLocal),
+                           fgEVENT::FG_EVENT_READY, 1800000);
 
     // Initialize the weather modeling subsystem
-#ifdef FG_NEW_WEATHER
+#ifndef FG_OLD_WEATHER
     // Initialize the WeatherDatabase
     FG_LOG(FG_GENERAL, FG_INFO, "Creating LocalWeatherDatabase");
+    sgVec3 position;
+    sgSetVec3( position, current_aircraft.fdm_state->get_Latitude(),
+              current_aircraft.fdm_state->get_Longitude(),
+              current_aircraft.fdm_state->get_Altitude() * FEET_TO_METER );
     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) );
+       new FGLocalWeatherDatabase( position );
+    // cout << theFGLocalWeatherDatabase << endl;
+    // cout << "visibility = " 
+    //      << theFGLocalWeatherDatabase->getWeatherVisibility() << endl;
 
     WeatherDatabase = FGLocalWeatherDatabase::theFGLocalWeatherDatabase;
-
+     
     // register the periodic update of the weather
     global_events.Register( "weather update", fgUpdateWeatherDatabase,
-                           fgEVENT::FG_EVENT_READY, 30000);
+                            fgEVENT::FG_EVENT_READY, 30000);
 #else
     current_weather.Init();
 #endif
@@ -486,9 +507,9 @@ bool fgInitSubsystems( void ) {
     // Autopilot init added here, by Jeff Goeke-Smith
     fgAPInit(&current_aircraft);
 
-    // Initialize serial ports
+    // Initialize I/O channels
 #if ! defined( MACOS )
-    fgSerialInit();
+    fgIOInit();
 #endif
 
     FG_LOG( FG_GENERAL, FG_INFO, endl);
@@ -499,7 +520,6 @@ bool fgInitSubsystems( void ) {
 
 void fgReInitSubsystems( void )
 {
-    FGView *v = &current_view;
     FGTime *t = FGTime::cur_time_params;
     
     int toggle_pause = t->getPause();
@@ -568,15 +588,15 @@ void fgReInitSubsystems( void )
     cur_fdm_state->set_CG_Position( 0.0, 0.0, 0.0 );
 
     // Initialize view parameters
-    // FG_LOG( FG_GENERAL, FG_DEBUG, "Before v->init()");
-    // v->Init();
-    v->set_view_offset( 0.0 );
-    v->set_goal_view_offset( 0.0 );
-
-    FG_LOG( FG_GENERAL, FG_DEBUG, "After v->init()");
-    v->UpdateViewMath(*cur_fdm_state);
-    FG_LOG( FG_GENERAL, FG_DEBUG, "  abs_view_pos = " << v->get_abs_view_pos());
-    // v->UpdateWorldToEye(f);
+    current_view.set_view_offset( 0.0 );
+    current_view.set_goal_view_offset( 0.0 );
+    pilot_view.set_view_offset( 0.0 );
+    pilot_view.set_goal_view_offset( 0.0 );
+
+    FG_LOG( FG_GENERAL, FG_DEBUG, "After current_view.init()");
+    current_view.UpdateViewMath(*cur_fdm_state);
+    pilot_view.UpdateViewMath(*cur_fdm_state);
+    FG_LOG( FG_GENERAL, FG_DEBUG, "  abs_view_pos = " << current_view.get_abs_view_pos());
 
     // fgFDMInit( current_options.get_flight_model(), cur_fdm_state, 
     //            1.0 / current_options.get_model_hz() );