From 4e89d05fb436eb1a419d1c305c071b04918eb48f Mon Sep 17 00:00:00 2001 From: Torsten Dreyer Date: Sun, 20 Apr 2014 20:58:12 +0200 Subject: [PATCH] YASim: implement a versioning system user attribute "version" of the airplane element of the YASim config file to define the version this config uses. Example: 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 | 16 +++++++++++----- src/FDM/YASim/Airplane.hpp | 3 ++- src/FDM/YASim/CMakeLists.txt | 1 + src/FDM/YASim/FGFDM.cpp | 16 +++++++++++----- src/FDM/YASim/FGFDM.hpp | 3 ++- src/FDM/YASim/Surface.cpp | 18 ++++++++++++++---- src/FDM/YASim/Surface.hpp | 6 +++++- src/FDM/YASim/Version.cpp | 25 ++++++++++++++++++++++++ src/FDM/YASim/Version.hpp | 37 ++++++++++++++++++++++++++++++++++++ src/FDM/YASim/Wing.cpp | 5 +++-- src/FDM/YASim/Wing.hpp | 5 ++++- 11 files changed, 115 insertions(+), 20 deletions(-) create mode 100644 src/FDM/YASim/Version.cpp create mode 100644 src/FDM/YASim/Version.hpp diff --git a/src/FDM/YASim/Airplane.cpp b/src/FDM/YASim/Airplane.cpp index 72d2b7b29..305871866 100644 --- a/src/FDM/YASim/Airplane.cpp +++ b/src/FDM/YASim/Airplane.cpp @@ -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 diff --git a/src/FDM/YASim/Airplane.hpp b/src/FDM/YASim/Airplane.hpp index 913eb49ed..7135561c2 100644 --- a/src/FDM/YASim/Airplane.hpp +++ b/src/FDM/YASim/Airplane.hpp @@ -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(); diff --git a/src/FDM/YASim/CMakeLists.txt b/src/FDM/YASim/CMakeLists.txt index 352a78b09..97a8e2581 100644 --- a/src/FDM/YASim/CMakeLists.txt +++ b/src/FDM/YASim/CMakeLists.txt @@ -26,6 +26,7 @@ set(COMMON TurbineEngine.cpp Turbulence.cpp Wing.cpp + Version.cpp ) set(SOURCES diff --git a/src/FDM/YASim/FGFDM.cpp b/src/FDM/YASim/FGFDM.cpp index ab62a33b6..1c722eac9 100644 --- a/src/FDM/YASim/FGFDM.cpp +++ b/src/FDM/YASim/FGFDM.cpp @@ -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")) diff --git a/src/FDM/YASim/FGFDM.hpp b/src/FDM/YASim/FGFDM.hpp index 4601951bd..3f5465cae 100644 --- a/src/FDM/YASim/FGFDM.hpp +++ b/src/FDM/YASim/FGFDM.hpp @@ -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); diff --git a/src/FDM/YASim/Surface.cpp b/src/FDM/YASim/Surface.cpp index 25d8da489..df5fcf247 100644 --- a/src/FDM/YASim/Surface.cpp +++ b/src/FDM/YASim/Surface.cpp @@ -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]) diff --git a/src/FDM/YASim/Surface.hpp b/src/FDM/YASim/Surface.hpp index 934eb26de..4f128f374 100644 --- a/src/FDM/YASim/Surface.hpp +++ b/src/FDM/YASim/Surface.hpp @@ -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 index 000000000..5c70211fc --- /dev/null +++ b/src/FDM/YASim/Version.cpp @@ -0,0 +1,25 @@ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "Version.hpp" +#include +#include + +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 index 000000000..3df5ef4ae --- /dev/null +++ b/src/FDM/YASim/Version.hpp @@ -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 diff --git a/src/FDM/YASim/Wing.cpp b/src/FDM/YASim/Wing.cpp index 1a6824496..a25d558f0 100644 --- a/src/FDM/YASim/Wing.cpp +++ b/src/FDM/YASim/Wing.cpp @@ -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); diff --git a/src/FDM/YASim/Wing.hpp b/src/FDM/YASim/Wing.hpp index 114960bff..addcd4b6c 100644 --- a/src/FDM/YASim/Wing.hpp +++ b/src/FDM/YASim/Wing.hpp @@ -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