]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/JSBSim.cpp
Updated to latest JSBSim, including preliminary support for
[flightgear.git] / src / FDM / JSBSim / JSBSim.cpp
index 499e95167f9918953f3cddc96127fd22ea8fcbd2..e79d96fc78c212208482d3a64cc857af6f641831 100644 (file)
@@ -50,22 +50,16 @@ INCLUDES
 #include "FGAuxiliary.h"
 #include "FGOutput.h"
 #include "FGConfigFile.h"
+#include "FGScript.h"
 
 #ifdef FGFS
 #include <simgear/compiler.h>
 #include STL_IOSTREAM
-#  ifdef SG_HAVE_STD_INCLUDES
-#    include <ctime>
-#  else
-#    include <time.h>
-#  endif
 #else
 #  if defined(sgi) && !defined(__GNUC__)
 #    include <iostream.h>
-#    include <time.h>
 #  else
 #    include <iostream>
-#    include <ctime>
 #  endif
 #endif
 
@@ -104,58 +98,54 @@ IMPLEMENTATION
 int main(int argc, char** argv)
 {
   FGFDMExec* FDMExec;
-  float cmd = 0.0;
   bool result = false;
-  bool scripted = false;
-
-  if (argc == 2) {
-    FGConfigFile testFile(argv[1]);
+  bool Scripted = false;
+  FGScript* Script;
 
-    if (!testFile.IsOpen()) {
-      cout << "Script file not opened" << endl;
-      exit(-1); 
-    }
-
-    testFile.GetNextConfigLine();
-    if (testFile.GetValue("runscript").length() <= 0) {
-      cout << "File: " << argv[1] << " is not a script file" << endl;
-      exit(-1); 
-    }
-    scripted = true;
-  } else if (argc != 3) {
-    cout << endl
+  if (argc != 3 && argc != 2) {
+    cerr << endl
          << "  You must enter the name of a registered aircraft and reset point:"
          << endl << endl << "  FDM <aircraft name> <reset file>" << endl;
-    cout << endl << "  Alternatively, you may specify only the name of a script file:"
+    cerr << endl << "  Alternatively, you may specify only the name of a script file:"
          << endl << endl << "  FDM <script file>" << endl << endl;
     exit(0);
   }
 
   FDMExec = new FGFDMExec();
 
-  if (scripted) {
-    result = FDMExec->LoadScript(argv[1]);
+  if (argc == 2) { // SCRIPTED CASE
+
+    Script = new FGScript(FDMExec);
+    result = Script->LoadScript(argv[1]);
+
     if (!result) {
       cerr << "Script file " << argv[1] << " was not successfully loaded" << endl;
       exit(-1);
     }
-  } else {
-    // result = FDMExec->LoadModel("aircraft", "engine", string(argv[1]));
-    FGInitialCondition IC(FDMExec);
-    result = IC.Load("aircraft","engine",string(argv[1]));
 
-    if (!result) {
-       cerr << "Aircraft file " << argv[1] << " was not found" << endl;
-           exit(-1);
-    }
-    if ( ! FDMExec->GetState()->Reset("aircraft", string(argv[1]), string(argv[2]))) {
-       cerr << "JSBSim could not be started" << endl;
-           exit(-1);
+    Scripted = true;
+
+  } else {        // form jsbsim <acname> <resetfile>
+
+    if ( ! FDMExec->LoadModel("aircraft", "engine", string(argv[1]))) {
+       cerr << "  JSBSim could not be started" << endl << endl;
+      exit(-1);
     }                   
+
+    FGInitialCondition IC(FDMExec);
+    if ( ! IC.Load("aircraft",string(argv[1]),string(argv[2]))) {
+       cerr << "Initialization unsuccessful" << endl;
+      exit(-1);
+    }
   }
 
-  struct FGJSBBase::Message* msg;
-  while (FDMExec->Run()) {
+//
+// RUN loop. MESSAGES are read inside the Run() loop and output as necessary.
+//
+
+  FGJSBBase::Message* msg;
+  result = FDMExec->Run();
+  while (result) {
     while (FDMExec->ReadMessage()) {
       msg = FDMExec->ProcessMessage();
       switch (msg->type) {
@@ -176,6 +166,12 @@ int main(int argc, char** argv)
              break;
       }
     }
+
+    if (Scripted) {
+      if (!Script->RunScript()) break;
+    }
+
+    result = FDMExec->Run();
   }
 
   delete FDMExec;