]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/fg_init.cxx
Fixed a problem with autodetecting if we need to draw our own mouse cursor
[flightgear.git] / src / Main / fg_init.cxx
index d81c9c9ca60a4b45bd9b54451f1de4ef7627210f..0c506726ffdb49e812378c8c4a30e6d03bf56aa9 100644 (file)
@@ -356,14 +356,26 @@ bool fgInitPosition( void ) {
     f->set_Longitude( fgGetDouble("/position/longitude") * DEG_TO_RAD );
     f->set_Latitude( fgGetDouble("/position/latitude") * DEG_TO_RAD );
 
+    FG_LOG( FG_GENERAL, FG_INFO,
+           "scenery.cur_elev = " << scenery.cur_elev );
+    FG_LOG( FG_GENERAL, FG_INFO,
+           "/position/altitude = " << fgGetDouble("/position/altitude") );
+
+    // if we requested on ground startups
+    if ( fgGetBool( "/sim/startup/onground" ) ) {
+       fgSetDouble("/position/altitude", scenery.cur_elev + 1 );
+    }
+
+    // if requested altitude is below ground level
     if ( scenery.cur_elev > fgGetDouble("/position/altitude") - 1) {
-        fgSetDouble("/position/altitude", scenery.cur_elev + 1 );
+       fgSetDouble("/position/altitude", scenery.cur_elev + 1 );
     }
 
     FG_LOG( FG_GENERAL, FG_INFO,
-           "starting altitude is = " << fgGetDouble("/position/altitude") );
+           "starting altitude is = " <<
+           fgGetDouble("/position/altitude") );
 
-    f->set_Altitude( fgGetDouble("/position/altitude") * METER_TO_FEET );
+    f->set_Altitude( fgGetDouble("/position/altitude") );
     FG_LOG( FG_GENERAL, FG_INFO,
            "Initial position is: ("
            << (f->get_Longitude() * RAD_TO_DEG) << ", "
@@ -488,25 +500,30 @@ bool fgInitSubsystems( void ) {
            "Current terrain elevation after tile mgr init " <<
            scenery.cur_elev );
 
+    double dt = 1.0 / fgGetInt("/sim/model-hz");
+    // cout << "dt = " << dt << endl;
+
     const string &model = fgGetString("/sim/flight-model");
     if (model == "larcsim") {
-       cur_fdm_state = new FGLaRCsim;
+       cur_fdm_state = new FGLaRCsim( dt );
     } else if (model == "jsb") {
-       cur_fdm_state = new FGJSBsim;
+       cur_fdm_state = new FGJSBsim( dt );
     } else if (model == "ada") {
-       cur_fdm_state = new FGADA;
+       cur_fdm_state = new FGADA( dt );
     } else if (model == "balloon") {
-       cur_fdm_state = new FGBalloonSim;
+       cur_fdm_state = new FGBalloonSim( dt );
     } else if (model == "magic") {
-       cur_fdm_state = new FGMagicCarpet;
+       cur_fdm_state = new FGMagicCarpet( dt );
     } else if (model == "external") {
-       cur_fdm_state = new FGExternal;
+       cur_fdm_state = new FGExternal( dt );
     } else {
        FG_LOG(FG_GENERAL, FG_ALERT,
               "Unrecognized flight model '" << model
               << ", can't init aircraft");
        exit(-1);
     }
+    cur_fdm_state->stamp();
+    cur_fdm_state->set_remainder( 0 );
 
     // allocates structures so must happen before any of the flight
     // model or control parameters are set
@@ -563,10 +580,10 @@ bool fgInitSubsystems( void ) {
     fgVelocityInit();
 
     // Initial Orientation
-    cur_fdm_state->
-       set_Euler_Angles( fgGetDouble("/orientation/roll") * DEG_TO_RAD,
-                         fgGetDouble("/orientation/pitch") * DEG_TO_RAD,
-                         fgGetDouble("/orientation/heading") * DEG_TO_RAD );
+//     cur_fdm_state->
+//     set_Euler_Angles( fgGetDouble("/orientation/roll") * DEG_TO_RAD,
+//                       fgGetDouble("/orientation/pitch") * DEG_TO_RAD,
+//                       fgGetDouble("/orientation/heading") * DEG_TO_RAD );
 
     // Initialize the event manager
     global_events.Init();
@@ -692,12 +709,14 @@ bool fgInitSubsystems( void ) {
     // Initialize the flight model subsystem data structures base on
     // above values
 
-    if ( cur_fdm_state->init( 1.0 / fgGetInt("/sim/model-hz") ) ) {
-       // fdm init successful
-    } else {
-       FG_LOG( FG_GENERAL, FG_ALERT, "FDM init() failed!  Cannot continue." );
-       exit(-1);
-    }
+    cur_fdm_state->init();
+    cur_fdm_state->bind();
+//     if ( cur_fdm_state->init( 1.0 / fgGetInt("/sim/model-hz") ) ) {
+//     // fdm init successful
+//     } else {
+//     FG_LOG( FG_GENERAL, FG_ALERT, "FDM init() failed!  Cannot continue." );
+//     exit(-1);
+//     }
 
     // *ABCD* I'm just sticking this here for now, it should probably
     // move eventually
@@ -759,16 +778,29 @@ bool fgInitSubsystems( void ) {
 
     FG_LOG( FG_GENERAL, FG_INFO, endl);
 
+                               // Save the initial state for future
+                               // reference.
+    globals->saveInitialState();
+
     return true;
 }
 
 
 void fgReInitSubsystems( void )
 {
+    FG_LOG( FG_GENERAL, FG_INFO,
+           "/position/altitude = " << fgGetDouble("/position/altitude") );
+
     bool freeze = globals->get_freeze();
     if( !freeze )
         globals->set_freeze( true );
     
+    // Initialize the Scenery Management subsystem
+    if ( ! fgSceneryInit() ) {
+       FG_LOG( FG_GENERAL, FG_ALERT, "Error in Scenery initialization!" );
+       exit(-1);
+    }
+
     if( global_tile_mgr.init() ) {
        // Load the local scenery data
        global_tile_mgr.update( fgGetDouble("/position/longitude"),
@@ -780,9 +812,9 @@ void fgReInitSubsystems( void )
 
     // cout << "current scenery elev = " << scenery.cur_elev << endl;
 
-    fgInitPosition();
     fgFDMSetGroundElevation( fgGetString("/sim/flight-model"), 
                             scenery.cur_elev );
+    fgInitPosition();
 
     // Reset our altitude if we are below ground
     FG_LOG( FG_GENERAL, FG_DEBUG, "Current altitude = "
@@ -810,10 +842,10 @@ void fgReInitSubsystems( void )
     fgVelocityInit();
 
     // Initial Orientation
-    cur_fdm_state->
-       set_Euler_Angles( fgGetDouble("/orientation/roll") * DEG_TO_RAD,
-                         fgGetDouble("/orientation/pitch") * DEG_TO_RAD,
-                         fgGetDouble("/orientation/heading") * DEG_TO_RAD );
+//     cur_fdm_state->
+//     set_Euler_Angles( fgGetDouble("/orientation/roll") * DEG_TO_RAD,
+//                       fgGetDouble("/orientation/pitch") * DEG_TO_RAD,
+//                       fgGetDouble("/orientation/heading") * DEG_TO_RAD );
 
     // Initialize view parameters
     FGViewerRPH *pilot_view =
@@ -838,7 +870,9 @@ void fgReInitSubsystems( void )
     FG_LOG( FG_GENERAL, FG_DEBUG, "  abs_view_pos = "
            << globals->get_current_view()->get_abs_view_pos());
 
-    cur_fdm_state->init( 1.0 / fgGetInt("/sim/model-hz") );
+    cur_fdm_state->init();
+//     cur_fdm_state->bind();
+//     cur_fdm_state->init( 1.0 / fgGetInt("/sim/model-hz") );
 
     scenery.cur_elev = cur_fdm_state->get_Runway_altitude() * FEET_TO_METER;