]> git.mxchange.org Git - flightgear.git/blobdiff - JSBsim/FGEngine.cpp
Added initial support for native SGI compilers.
[flightgear.git] / JSBsim / FGEngine.cpp
index 8ceca33be6208fcd27f47c35bcc7f2c1e33302c7..c14149d28fac354fa01a983d2fee92acaad3bce4 100644 (file)
@@ -28,48 +28,64 @@ FUNCTIONAL DESCRIPTION
 --------------------------------------------------------------------------------
 See header file.
 
-ARGUMENTS
---------------------------------------------------------------------------------
-
-
 HISTORY
 --------------------------------------------------------------------------------
-
 01/21/99   JSB   Created
 
 ********************************************************************************
 INCLUDES
 *******************************************************************************/
 
+#include <fstream.h>
+
 #include "FGEngine.h"
 #include "FGState.h"
+#include "FGFDMExec.h"
+#include "FGAtmosphere.h"
 #include "FGFCS.h"
-#include <fstream.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include "FGAircraft.h"
+#include "FGTranslation.h"
+#include "FGRotation.h"
+#include "FGPosition.h"
+#include "FGAuxiliary.h"
+#include "FGOutput.h"
 
 /*******************************************************************************
 ************************************ CODE **************************************
 *******************************************************************************/
 
 
-FGEngine::FGEngine(char *engineName)
+FGEngine::FGEngine(FGFDMExec* fdex, string enginePath, string engineName, 
+                  int num)
 {
-  char fullpath[250];
-  char tag[220];
+  string fullpath;
+  string tag;
+
+  FDMExec = fdex;
+
+  State       = FDMExec->GetState();
+  Atmosphere  = FDMExec->GetAtmosphere();
+  FCS         = FDMExec->GetFCS();
+  Aircraft    = FDMExec->GetAircraft();
+  Translation = FDMExec->GetTranslation();
+  Rotation    = FDMExec->GetRotation();
+  Position    = FDMExec->GetPosition();
+  Auxiliary   = FDMExec->GetAuxiliary();
+  Output      = FDMExec->GetOutput();
 
-  strcpy(Name, engineName);
-  sprintf(fullpath,"/h/curt/projects/FlightGear/Simulator/FDM/JSBsim/engine/%s.dat", engineName);
-  ifstream enginefile(fullpath);
+  Name = engineName;
+  fullpath = enginePath + "/" + engineName + ".dat";
+  ifstream enginefile(fullpath.c_str());
 
   if (enginefile) {
     enginefile >> tag;
-    if (strstr(tag,"ROCKET")) Type = 0;
-    else if (strstr(tag,"PISTON")) Type = 1;
-    else if (strstr(tag,"TURBOPROP")) Type = 2;
-    else if (strstr(tag,"TURBOJET")) Type = 3;
-    else Type = 0;
+
+    if      (tag == "ROCKET")    Type = etRocket;
+    else if (tag == "PISTON")    Type = etPiston;
+    else if (tag == "TURBOPROP") Type = etTurboProp;
+    else if (tag == "TURBOJET")  Type = etTurboJet;
+    else                         Type = etUnknown;
+
     enginefile >> X;
     enginefile >> Y;
     enginefile >> Z;
@@ -78,13 +94,14 @@ FGEngine::FGEngine(char *engineName)
     enginefile >> MaxThrottle;
     enginefile >> MinThrottle;
     enginefile >> SLFuelFlowMax;
-    if (Type == 0)
+    if (Type == 1)
       enginefile >> SLOxiFlowMax;
     enginefile.close();
   } else {
     cerr << "Unable to open engine definition file " << engineName << endl;
   }
 
+  EngineNumber = num;
   Thrust = 0.0;
   Starved = Flameout = false;
 }
@@ -99,7 +116,7 @@ float FGEngine::CalcRocketThrust(void)
 {
   float lastThrust;
 
-  Throttle = FCS->GetThrottle();
+  Throttle = FCS->GetThrottle(EngineNumber);
   lastThrust = Thrust;                 // last actual thrust
 
   if (Throttle < MinThrottle || Starved) {
@@ -107,12 +124,12 @@ float FGEngine::CalcRocketThrust(void)
     Flameout = true;
   } else {
     PctPower = Throttle / MaxThrottle;
-    Thrust = PctPower*((1.0 - State->Getrho() / 0.002378)*(VacThrustMax - SLThrustMax) +
+    Thrust = PctPower*((1.0 - Atmosphere->Getrho() / 0.002378)*(VacThrustMax - SLThrustMax) +
                               SLThrustMax); // desired thrust
     Flameout = false;
   }
 
-  Thrust +=    0.8*(Thrust - lastThrust); // actual thrust
+  Thrust += 0.8*(Thrust - lastThrust); // actual thrust
 
   return Thrust;
 }
@@ -127,15 +144,15 @@ float FGEngine::CalcPistonThrust(void)
 float FGEngine::CalcThrust(void)
 {
   switch(Type) {
-  case 0: // Rocket
+  case etRocket:
     return CalcRocketThrust();
-    break;
-  case 1: // Piston
+    // break;
+  case etPiston:
     return CalcPistonThrust();
-    break;
+    // break;
   default:
     return 9999.0;
-    break;
+    // break;
   }
 }