]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/fg_init.cxx
set /sim/fg-current to current working directory; getcwd() is defined in
[flightgear.git] / src / Main / fg_init.cxx
index d50e4f7ab28cc751515f3fb2cc3d48cf7c216b89..626f05291cba152a68244a4728efec445c2db771 100644 (file)
 #if defined( unix ) || defined( __CYGWIN__ )
 #  include <unistd.h>           // for gethostname()
 #endif
+#if defined( _MSC_VER) || defined(__MINGW32__)
+#  include <direct.h>           // for getcwd()
+#  define getcwd _getcwd
+#endif
 
 // work around a stdc++ lib bug in some versions of linux, but doesn't
 // seem to hurt to have this here for all versions of Linux.
@@ -67,7 +71,6 @@
 #include <Airports/runways.hxx>
 #include <Airports/simple.hxx>
 #include <AIModel/AIManager.hxx>
-#include <ATC/ATCdisplay.hxx>
 #include <ATC/ATCmgr.hxx>
 #include <ATC/AIMgr.hxx>
 #include <Autopilot/route_mgr.hxx>
@@ -1310,6 +1313,8 @@ bool fgInitGeneral() {
     }
 #endif
 
+    char buf[256], *cwd = getcwd(buf, 256);
+    fgSetString("/sim/fg-current", cwd ? cwd : "");
     return true;
 }
 
@@ -1328,90 +1333,83 @@ void fgInitFDM() {
     double dt = 1.0 / fgGetInt("/sim/model-hz");
     string model = fgGetString("/sim/flight-model");
 
-    try {
-        if ( model == "larcsim" ) {
-            cur_fdm_state = new FGLaRCsim( dt );
-        } else if ( model == "jsb" ) {
-            cur_fdm_state = new FGJSBsim( dt );
+    if ( model == "larcsim" ) {
+        cur_fdm_state = new FGLaRCsim( dt );
+    } else if ( model == "jsb" ) {
+        cur_fdm_state = new FGJSBsim( dt );
 #if ENABLE_SP_FDM
-        } else if ( model == "ada" ) {
-            cur_fdm_state = new FGADA( dt );
-        } else if ( model == "acms" ) {
-            cur_fdm_state = new FGACMS( dt );
+    } else if ( model == "ada" ) {
+        cur_fdm_state = new FGADA( dt );
+    } else if ( model == "acms" ) {
+        cur_fdm_state = new FGACMS( dt );
 #endif
-        } else if ( model == "balloon" ) {
-            cur_fdm_state = new FGBalloonSim( dt );
-        } else if ( model == "magic" ) {
-            cur_fdm_state = new FGMagicCarpet( dt );
-        } else if ( model == "ufo" ) {
-            cur_fdm_state = new FGUFO( dt );
-        } else if ( model == "external" ) {
-            // external is a synonym for "--fdm=null" and is
-            // maintained here for backwards compatibility
-            cur_fdm_state = new FGNullFDM( dt );
-        } else if ( model.find("network") == 0 ) {
-            string host = "localhost";
-            int port1 = 5501;
-            int port2 = 5502;
-            int port3 = 5503;
-            string net_options = model.substr(8);
-            string::size_type begin, end;
-            begin = 0;
-            // host
-            end = net_options.find( ",", begin );
-            if ( end != string::npos ) {
-                host = net_options.substr(begin, end - begin);
-                begin = end + 1;
-            }
-            // port1
-            end = net_options.find( ",", begin );
-            if ( end != string::npos ) {
-                port1 = atoi( net_options.substr(begin, end - begin).c_str() );
-                begin = end + 1;
-            }
-            // port2
-            end = net_options.find( ",", begin );
-            if ( end != string::npos ) {
-                port2 = atoi( net_options.substr(begin, end - begin).c_str() );
-                begin = end + 1;
-            }
-            // port3
-            end = net_options.find( ",", begin );
-            if ( end != string::npos ) {
-                port3 = atoi( net_options.substr(begin, end - begin).c_str() );
-                begin = end + 1;
-            }
-            cur_fdm_state = new FGExternalNet( dt, host, port1, port2, port3 );
-        } else if ( model.find("pipe") == 0 ) {
-            // /* old */ string pipe_path = model.substr(5);
-            // /* old */ cur_fdm_state = new FGExternalPipe( dt, pipe_path );
-            string pipe_path = "";
-            string pipe_protocol = "";
-            string pipe_options = model.substr(5);
-            string::size_type begin, end;
-            begin = 0;
-            // pipe file path
-            end = pipe_options.find( ",", begin );
-            if ( end != string::npos ) {
-                pipe_path = pipe_options.substr(begin, end - begin);
-                begin = end + 1;
-            }
-            // protocol (last option)
-            pipe_protocol = pipe_options.substr(begin);
-            cur_fdm_state = new FGExternalPipe( dt, pipe_path, pipe_protocol );
-        } else if ( model == "null" ) {
-            cur_fdm_state = new FGNullFDM( dt );
-        } else if ( model == "yasim" ) {
-            cur_fdm_state = new YASim( dt );
-        } else {
-            SG_LOG(SG_GENERAL, SG_ALERT,
-                   "Unrecognized flight model '" << model
-                   << "', cannot init flight dynamics model.");
-            exit(-1);
+    } else if ( model == "balloon" ) {
+        cur_fdm_state = new FGBalloonSim( dt );
+    } else if ( model == "magic" ) {
+        cur_fdm_state = new FGMagicCarpet( dt );
+    } else if ( model == "ufo" ) {
+        cur_fdm_state = new FGUFO( dt );
+    } else if ( model == "external" ) {
+        // external is a synonym for "--fdm=null" and is
+        // maintained here for backwards compatibility
+        cur_fdm_state = new FGNullFDM( dt );
+    } else if ( model.find("network") == 0 ) {
+        string host = "localhost";
+        int port1 = 5501;
+        int port2 = 5502;
+        int port3 = 5503;
+        string net_options = model.substr(8);
+        string::size_type begin, end;
+        begin = 0;
+        // host
+        end = net_options.find( ",", begin );
+        if ( end != string::npos ) {
+            host = net_options.substr(begin, end - begin);
+            begin = end + 1;
         }
-    } catch ( ... ) {
-        SG_LOG(SG_GENERAL, SG_ALERT, "FlightGear aborting\n\n");
-        exit(-1);
+        // port1
+        end = net_options.find( ",", begin );
+        if ( end != string::npos ) {
+            port1 = atoi( net_options.substr(begin, end - begin).c_str() );
+            begin = end + 1;
+        }
+        // port2
+        end = net_options.find( ",", begin );
+        if ( end != string::npos ) {
+            port2 = atoi( net_options.substr(begin, end - begin).c_str() );
+            begin = end + 1;
+        }
+        // port3
+        end = net_options.find( ",", begin );
+        if ( end != string::npos ) {
+            port3 = atoi( net_options.substr(begin, end - begin).c_str() );
+            begin = end + 1;
+        }
+        cur_fdm_state = new FGExternalNet( dt, host, port1, port2, port3 );
+    } else if ( model.find("pipe") == 0 ) {
+        // /* old */ string pipe_path = model.substr(5);
+        // /* old */ cur_fdm_state = new FGExternalPipe( dt, pipe_path );
+        string pipe_path = "";
+        string pipe_protocol = "";
+        string pipe_options = model.substr(5);
+        string::size_type begin, end;
+        begin = 0;
+        // pipe file path
+        end = pipe_options.find( ",", begin );
+        if ( end != string::npos ) {
+            pipe_path = pipe_options.substr(begin, end - begin);
+            begin = end + 1;
+        }
+        // protocol (last option)
+        pipe_protocol = pipe_options.substr(begin);
+        cur_fdm_state = new FGExternalPipe( dt, pipe_path, pipe_protocol );
+    } else if ( model == "null" ) {
+        cur_fdm_state = new FGNullFDM( dt );
+    } else if ( model == "yasim" ) {
+        cur_fdm_state = new YASim( dt );
+    } else {
+        throw sg_throwable(string("Unrecognized flight model '") + model
+               + "', cannot init flight dynamics model.");
     }
 }
 
@@ -1718,14 +1716,6 @@ bool fgInitSubsystems() {
     globals->add_subsystem("voice", new FGVoiceMgr);
 #endif
 
-    ////////////////////////////////////////////////////////////////////
-    // Initialise ATC display system
-    ////////////////////////////////////////////////////////////////////
-
-    SG_LOG(SG_GENERAL, SG_INFO, "  ATC Display");
-    globals->set_ATC_display(new FGATCDisplay);
-    globals->get_ATC_display()->init(); 
-
     ////////////////////////////////////////////////////////////////////
     // Initialise the ATC Manager 
     ////////////////////////////////////////////////////////////////////