]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/FGFDMExec.cpp
FG_HAVE_STD_INCLUDES -> SG_HAVE_STD_INCLUDES
[flightgear.git] / src / FDM / JSBSim / FGFDMExec.cpp
index 0eab1d6d00201ca0622a1de6d86d0912105847e5..caf4b9d146d536db458105de57b1100a07593b65 100644 (file)
@@ -1,4 +1,4 @@
-/*******************************************************************************
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
  Module:       FGFDMExec.cpp
  Author:       Jon S. Berndt
@@ -34,13 +34,13 @@ HISTORY
 --------------------------------------------------------------------------------
 11/17/98   JSB   Created
 
-********************************************************************************
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 INCLUDES
-*******************************************************************************/
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
 #ifdef FGFS
 #  include <simgear/compiler.h>
-#  ifdef FG_HAVE_STD_INCLUDES
+#  ifdef SG_HAVE_STD_INCLUDES
 #    include <iostream>
 #    include <ctime>
 #  else
@@ -63,9 +63,12 @@ INCLUDES
 #include "FGAuxiliary.h"
 #include "FGOutput.h"
 
-/*******************************************************************************
-************************************ CODE **************************************
-*******************************************************************************/
+static const char *IdSrc = "$Header$";
+static const char *IdHdr = "ID_FDMEXEC";
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+CLASS IMPLEMENTATION
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
 
 // Constructor
@@ -84,9 +87,12 @@ FGFDMExec::FGFDMExec(void)
   Auxiliary   = 0;
   Output      = 0;
 
-  allocated = false;
   terminate = false;
   frozen = false;
+  modelLoaded = false;
+  
+  Allocate();
+  
 }
 
 FGFDMExec::~FGFDMExec(void){
@@ -136,40 +142,38 @@ bool FGFDMExec::Allocate(void) {
   Schedule(Auxiliary,   1);
   Schedule(Output,     1);
   
-  allocated = true;
-  
+  modelLoaded = false;
   return result;
 
 }
 
 bool FGFDMExec::DeAllocate(void) {
-  if(allocated) {
-    if ( Atmosphere != 0 )  delete Atmosphere;
-    if ( FCS != 0 )         delete FCS;
-    if ( Aircraft != 0 )    delete Aircraft;
-    if ( Translation != 0 ) delete Translation;
-    if ( Rotation != 0 )    delete Rotation;
-    if ( Position != 0 )    delete Position;
-    if ( Auxiliary != 0 )   delete Auxiliary;
-    if ( Output != 0 )      delete Output;
-    if ( State != 0 )       delete State;
-
-    FirstModel  = 0L;
-    Error       = 0;
-
-    State       = 0;
-    Atmosphere  = 0;
-    FCS         = 0;
-    Aircraft    = 0;
-    Translation = 0;
-    Rotation    = 0;
-    Position    = 0;
-    Auxiliary   = 0;
-    Output      = 0;
-    
-    allocated = false;
+  if ( Atmosphere != 0 )  delete Atmosphere;
+  if ( FCS != 0 )         delete FCS;
+  if ( Aircraft != 0 )    delete Aircraft;
+  if ( Translation != 0 ) delete Translation;
+  if ( Rotation != 0 )    delete Rotation;
+  if ( Position != 0 )    delete Position;
+  if ( Auxiliary != 0 )   delete Auxiliary;
+  if ( Output != 0 )      delete Output;
+  if ( State != 0 )       delete State;
+
+  FirstModel  = 0L;
+  Error       = 0;
+
+  State       = 0;
+  Atmosphere  = 0;
+  FCS         = 0;
+  Aircraft    = 0;
+  Translation = 0;
+  Rotation    = 0;
+  Position    = 0;
+  Auxiliary   = 0;
+  Output      = 0;
+
+  modelLoaded = false;
   
-  }
 }
 
 
@@ -231,11 +235,22 @@ bool FGFDMExec::RunIC(FGInitialCondition *fgic)
 
 bool FGFDMExec::LoadModel(string APath, string EPath, string model)
 {
-       DeAllocate();
-  Allocate();
+       bool result=false;
+  if(modelLoaded) {
+     DeAllocate();
+     Allocate();
+  }   
   AircraftPath = APath;
        EnginePath = EPath;
-  return Aircraft->LoadAircraft(AircraftPath, EnginePath, model);
+  result = Aircraft->LoadAircraft(AircraftPath, EnginePath, model);
+
+  if (result) {
+    modelLoaded = true;
+  } else {
+    cerr << "FGFDMExec: Failed to load aircraft and/or engine model" << endl;
+  }
+
+  return result;
 }