]> git.mxchange.org Git - flightgear.git/commitdiff
YASim: implement a versioning system
authorTorsten Dreyer <torsten@t3r.de>
Sun, 20 Apr 2014 18:58:12 +0000 (20:58 +0200)
committerTorsten Dreyer <torsten@t3r.de>
Sun, 20 Apr 2014 18:58:12 +0000 (20:58 +0200)
user attribute "version" of the airplane element of the YASim config file
to define the version this config uses.
Example:
<airplane mass="1344" version="YASIM_VERSION_CURRENT">

Initially, the following can be used:
YASIM_VERSION_ORIGINAL - The original version of YASim as implemented up to
                         FlightGear 3.0.0
YASIM_VERSION_32 - The version of YASim implemented in FlightGear 3.2.x
                   (and the development version 3.1.x)
YASIM_VERSION_CURRENT - The current and latest version of YASim.

src/FDM/YASim/Airplane.cpp
src/FDM/YASim/Airplane.hpp
src/FDM/YASim/CMakeLists.txt
src/FDM/YASim/FGFDM.cpp
src/FDM/YASim/FGFDM.hpp
src/FDM/YASim/Surface.cpp
src/FDM/YASim/Surface.hpp
src/FDM/YASim/Version.cpp [new file with mode: 0644]
src/FDM/YASim/Version.hpp [new file with mode: 0644]
src/FDM/YASim/Wing.cpp
src/FDM/YASim/Wing.hpp

index 72d2b7b299dbc73080df06ec5aaf1db01f85ac4c..3058718661ed67dd986a67e5fb739b41267f5eac 100644 (file)
@@ -368,7 +368,7 @@ int Airplane::addWeight(float* pos, float size)
     WeightRec* wr = new WeightRec();
     wr->handle = _model.getBody()->addMass(0, pos);
 
-    wr->surf = new Surface();
+    wr->surf = new Surface(this);
     wr->surf->setPosition(pos);
     wr->surf->setTotalDrag(size*size);
     _model.addSurface(wr->surf);
@@ -544,13 +544,19 @@ float Airplane::compileFuselage(Fuselage* f)
         wgt += mass;
 
         // Make a Surface too
-        Surface* s = new Surface();
+        Surface* s = new Surface(this);
         s->setPosition(pos);
        float sideDrag = len/wid;
-        s->setXDrag(f->_cx);
+       if( isVersionOrNewer( YASIM_VERSION_32 ) ) {
+               s->setXDrag(f->_cx);
+       }
         s->setYDrag(sideDrag*f->_cy);
         s->setZDrag(sideDrag*f->_cz);
-        s->setTotalDrag(scale*segWgt);
+       if( isVersionOrNewer( YASIM_VERSION_32 ) ) {
+               s->setTotalDrag(scale*segWgt);
+       } else {
+               s->setTotalDrag(scale*segWgt*f->_cx);
+       }
         s->setInducedDrag(f->_idrag);
 
         // FIXME: fails for fuselages aligned along the Y axis
@@ -575,7 +581,7 @@ void Airplane::compileGear(GearRec* gr)
     Gear* g = gr->gear;
 
     // Make a Surface object for the aerodynamic behavior
-    Surface* s = new Surface();
+    Surface* s = new Surface(this);
     gr->surf = s;
 
     // Put the surface at the half-way point on the gear strut, give
index 913eb49edcc3126c379e4887164302eda52e5b4f..7135561c28768ca2d6fc1c06be63b907f29481ed 100644 (file)
@@ -6,6 +6,7 @@
 #include "Wing.hpp"
 #include "Rotor.hpp"
 #include "Vector.hpp"
+#include "Version.hpp"
 
 namespace yasim {
 
@@ -15,7 +16,7 @@ class Launchbar;
 class Thruster;
 class Hitch;
 
-class Airplane {
+class Airplane : public Version {
 public:
     Airplane();
     ~Airplane();
index 352a78b09bfff709dc235dd4e2294952c1761e6d..97a8e2581c0fc0ed711fe84e7a7dc0ad41753647 100644 (file)
@@ -26,6 +26,7 @@ set(COMMON
        TurbineEngine.cpp
        Turbulence.cpp
        Wing.cpp
+       Version.cpp
        )
 
 set(SOURCES
index ab62a33b65e27d7bc8982189b1920a4c46ff8282..1c722eac9397f0acb11836a3a15806f7271cbacd 100644 (file)
@@ -219,6 +219,12 @@ void FGFDM::startElement(const char* name, const XMLAttributes &atts)
 
     if(eq(name, "airplane")) {
        _airplane.setWeight(attrf(a, "mass") * LBS2KG);
+        if(a->hasAttribute("version")) {
+          _airplane.setVersion( a->getValue("version") );
+        }
+        if( !_airplane.isVersionOrNewer( Version::YASIM_VERSION_CURRENT ) ) {
+          SG_LOG(SG_FLIGHT,SG_ALERT, "This aircraft does not use the latest yasim configuration version.");
+        }
     } else if(eq(name, "approach")) {
        float spd = attrf(a, "speed") * KTS2MPS;
        float alt = attrf(a, "alt", 0) * FT2M;
@@ -259,11 +265,11 @@ void FGFDM::startElement(const char* name, const XMLAttributes &atts)
         #undef p2
         r->setInUse();
     } else if(eq(name, "wing")) {
-       _airplane.setWing(parseWing(a, name));
+       _airplane.setWing(parseWing(a, name, &_airplane));
     } else if(eq(name, "hstab")) {
-       _airplane.setTail(parseWing(a, name));
+       _airplane.setTail(parseWing(a, name, &_airplane));
     } else if(eq(name, "vstab") || eq(name, "mstab")) {
-       _airplane.addVStab(parseWing(a, name));
+       _airplane.addVStab(parseWing(a, name, &_airplane));
     } else if(eq(name, "piston-engine")) {
         parsePistonEngine(a);
     } else if(eq(name, "turbine-engine")) {
@@ -691,9 +697,9 @@ void FGFDM::setOutputProperties(float dt)
     }
 }
 
-Wing* FGFDM::parseWing(XMLAttributes* a, const char* type)
+Wing* FGFDM::parseWing(XMLAttributes* a, const char* type, Version * version)
 {
-    Wing* w = new Wing();
+    Wing* w = new Wing(version);
 
     float defDihed = 0;
     if(eq(type, "vstab"))
index 4601951bd8b7dd3cfb45823ebb8d01186c090ce2..3f5465cae7e85859913008f3b9e3e5fe9fb95bdb 100644 (file)
@@ -10,6 +10,7 @@
 namespace yasim {
 
 class Wing;
+class Version;
 
 // This class forms the "glue" to the FlightGear codebase.  It handles
 // parsing of XML airplane files, interfacing to the properties
@@ -39,7 +40,7 @@ private:
     void setOutputProperties(float dt);
 
     Rotor* parseRotor(XMLAttributes* a, const char* name);
-    Wing* parseWing(XMLAttributes* a, const char* name);
+    Wing* parseWing(XMLAttributes* a, const char* name, Version * version);
     int parseAxis(const char* name);
     int parseOutput(const char* name);
     void parseWeight(XMLAttributes* a);
index 25d8da48918e7aac1fadc9f1c549d305a0f2e0ff..df5fcf24719b24b87bdbadd33810c62240f523cc 100644 (file)
@@ -2,7 +2,8 @@
 #include "Surface.hpp"
 namespace yasim {
 
-Surface::Surface()
+Surface::Surface( Version * version ) :
+    _version(version)
 {
     // Start in a "sane" mode, so unset stuff doesn't freak us out
     _c0 = 1;
@@ -228,7 +229,11 @@ void Surface::calcForce(float* v, float rho, float* out, float* torque)
     // coordinates. Since out[] is now the force vector and is
     // roughly parallel with Z, the small-angle approximation
     // must change its X component.
-    out[0] += incidence * out[2];
+    if( _version->isVersionOrNewer( Version::YASIM_VERSION_32 )) {
+       out[0] += incidence * out[2];
+    } else {
+       out[2] -= incidence * out[0];
+    }
 
     // Convert back to external coordinates
     Math::tmul33(_orient, out, out);
@@ -282,8 +287,13 @@ float Surface::stallFunc(float* v)
     if(stallAlpha == 0)
         return 1;
 
-    if(i == 0)
-       stallAlpha += _slatPos * _slatAlpha;
+    if(i == 0) {
+       if( _version->isVersionOrNewer( Version::YASIM_VERSION_32 )) {
+           stallAlpha += _slatPos * _slatAlpha;
+       } else {
+           stallAlpha += _slatAlpha;
+       }
+    }
 
     // Beyond the stall
     if(alpha > stallAlpha+_widths[i])
index 934eb26de10ee12e0a44c2dbe5b7b4f59680d82d..4f128f3742b2ddb744a9927a53b0e295c5cb4771 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef _SURFACE_HPP
 #define _SURFACE_HPP
 
+#include "Version.hpp"
+
 namespace yasim {
 
 // FIXME: need a "chord" member for calculating moments.  Generic
@@ -9,7 +11,7 @@ namespace yasim {
 class Surface
 {
 public:
-    Surface();
+    Surface( Version * version );
 
     // Position of this surface in local coords
     void setPosition(float* p);
@@ -102,6 +104,8 @@ private:
     float _incidence;
     float _twist;
     float _inducedDrag;
+
+    Version * _version;
 };
 
 }; // namespace yasim
diff --git a/src/FDM/YASim/Version.cpp b/src/FDM/YASim/Version.cpp
new file mode 100644 (file)
index 0000000..5c70211
--- /dev/null
@@ -0,0 +1,25 @@
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#include "Version.hpp"
+#include <simgear/debug/logstream.hxx>
+#include <string>
+
+namespace yasim {
+void Version::setVersion( const char * version )
+{
+  const std::string v(version);
+  
+  if( v ==  "YASIM_VERSION_ORIGINAL" ) {
+    _version = YASIM_VERSION_ORIGINAL;
+  } else if( v == "YASIM_VERSION_32" ) {
+    _version = YASIM_VERSION_32;
+  } else if( v == "YASIM_VERSION_CURRENT" ) {
+    _version = YASIM_VERSION_CURRENT;
+  } else {
+    SG_LOG(SG_FLIGHT,SG_ALERT,"unknown yasim version '" << version << "' ignored, using YASIM_VERSION_ORIGINAL");
+  }
+}
+
+} // namespace yasim
diff --git a/src/FDM/YASim/Version.hpp b/src/FDM/YASim/Version.hpp
new file mode 100644 (file)
index 0000000..3df5ef4
--- /dev/null
@@ -0,0 +1,37 @@
+#ifndef _VERSION_HPP
+#define _VERSION_HPP
+
+namespace yasim {
+
+class Version {
+public:
+  Version() : _version(YASIM_VERSION_ORIGINAL) {}
+  virtual ~Version() {}
+
+  typedef enum {
+    YASIM_VERSION_ORIGINAL = 0,
+    YASIM_VERSION_32,
+    YASIM_VERSION_CURRENT = YASIM_VERSION_32
+  } YASIM_VERSION;
+
+  void setVersion( const char * version );
+  bool isVersion( YASIM_VERSION version );
+  bool isVersionOrNewer( YASIM_VERSION version );
+
+private:
+  YASIM_VERSION _version;
+};
+
+inline bool Version::isVersion( YASIM_VERSION version )
+{
+  return _version == version;
+}
+
+inline bool Version::isVersionOrNewer( YASIM_VERSION version )
+{
+  return _version >= version;
+}
+
+
+}; // namespace yasim
+#endif // _WING_HPP
index 1a68244962bd91a54815c94c8229bc779f18588e..a25d558f0099ac31544fa9f5de4774f048b0018b 100644 (file)
@@ -4,7 +4,8 @@
 
 namespace yasim {
 
-Wing::Wing()
+Wing::Wing( Version * version ) :
+  _version(version)
 {
     _mirror = false;
     _base[0] = _base[1] = _base[2] = 0;
@@ -426,7 +427,7 @@ float Wing::getLiftRatio()
 Surface* Wing::newSurface(float* pos, float* orient, float chord,
                           bool flap0, bool flap1, bool slat, bool spoiler)
 {
-    Surface* s = new Surface();
+    Surface* s = new Surface(_version);
 
     s->setPosition(pos);
     s->setOrientation(orient);
index 114960bff8d4b8bfbe4fafddfff89f0690811e68..addcd4b6c756f282917b4899229b54194a29781d 100644 (file)
@@ -2,6 +2,7 @@
 #define _WING_HPP
 
 #include "Vector.hpp"
+#include "Version.hpp"
 
 namespace yasim {
 
@@ -10,7 +11,7 @@ class Surface;
 // FIXME: need to handle "inverted" controls for mirrored wings.
 class Wing {
 public:
-    Wing();
+    Wing( Version * version );
     ~Wing();
 
     // Do we mirror ourselves about the XZ plane?
@@ -122,6 +123,8 @@ private:
     float _slatEnd;
     float _slatAoA;
     float _slatDrag;
+
+    Version * _version;
 };
 
 }; // namespace yasim