1
0
Fork 0

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:
<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.
This commit is contained in:
Torsten Dreyer 2014-04-20 20:58:12 +02:00
parent b3c7cb7c15
commit 4e89d05fb4
11 changed files with 115 additions and 20 deletions

View file

@ -368,7 +368,7 @@ int Airplane::addWeight(float* pos, float size)
WeightRec* wr = new WeightRec(); WeightRec* wr = new WeightRec();
wr->handle = _model.getBody()->addMass(0, pos); wr->handle = _model.getBody()->addMass(0, pos);
wr->surf = new Surface(); wr->surf = new Surface(this);
wr->surf->setPosition(pos); wr->surf->setPosition(pos);
wr->surf->setTotalDrag(size*size); wr->surf->setTotalDrag(size*size);
_model.addSurface(wr->surf); _model.addSurface(wr->surf);
@ -544,13 +544,19 @@ float Airplane::compileFuselage(Fuselage* f)
wgt += mass; wgt += mass;
// Make a Surface too // Make a Surface too
Surface* s = new Surface(); Surface* s = new Surface(this);
s->setPosition(pos); s->setPosition(pos);
float sideDrag = len/wid; float sideDrag = len/wid;
if( isVersionOrNewer( YASIM_VERSION_32 ) ) {
s->setXDrag(f->_cx); s->setXDrag(f->_cx);
}
s->setYDrag(sideDrag*f->_cy); s->setYDrag(sideDrag*f->_cy);
s->setZDrag(sideDrag*f->_cz); s->setZDrag(sideDrag*f->_cz);
if( isVersionOrNewer( YASIM_VERSION_32 ) ) {
s->setTotalDrag(scale*segWgt); s->setTotalDrag(scale*segWgt);
} else {
s->setTotalDrag(scale*segWgt*f->_cx);
}
s->setInducedDrag(f->_idrag); s->setInducedDrag(f->_idrag);
// FIXME: fails for fuselages aligned along the Y axis // FIXME: fails for fuselages aligned along the Y axis
@ -575,7 +581,7 @@ void Airplane::compileGear(GearRec* gr)
Gear* g = gr->gear; Gear* g = gr->gear;
// Make a Surface object for the aerodynamic behavior // Make a Surface object for the aerodynamic behavior
Surface* s = new Surface(); Surface* s = new Surface(this);
gr->surf = s; gr->surf = s;
// Put the surface at the half-way point on the gear strut, give // Put the surface at the half-way point on the gear strut, give

View file

@ -6,6 +6,7 @@
#include "Wing.hpp" #include "Wing.hpp"
#include "Rotor.hpp" #include "Rotor.hpp"
#include "Vector.hpp" #include "Vector.hpp"
#include "Version.hpp"
namespace yasim { namespace yasim {
@ -15,7 +16,7 @@ class Launchbar;
class Thruster; class Thruster;
class Hitch; class Hitch;
class Airplane { class Airplane : public Version {
public: public:
Airplane(); Airplane();
~Airplane(); ~Airplane();

View file

@ -26,6 +26,7 @@ set(COMMON
TurbineEngine.cpp TurbineEngine.cpp
Turbulence.cpp Turbulence.cpp
Wing.cpp Wing.cpp
Version.cpp
) )
set(SOURCES set(SOURCES

View file

@ -219,6 +219,12 @@ void FGFDM::startElement(const char* name, const XMLAttributes &atts)
if(eq(name, "airplane")) { if(eq(name, "airplane")) {
_airplane.setWeight(attrf(a, "mass") * LBS2KG); _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")) { } else if(eq(name, "approach")) {
float spd = attrf(a, "speed") * KTS2MPS; float spd = attrf(a, "speed") * KTS2MPS;
float alt = attrf(a, "alt", 0) * FT2M; float alt = attrf(a, "alt", 0) * FT2M;
@ -259,11 +265,11 @@ void FGFDM::startElement(const char* name, const XMLAttributes &atts)
#undef p2 #undef p2
r->setInUse(); r->setInUse();
} else if(eq(name, "wing")) { } else if(eq(name, "wing")) {
_airplane.setWing(parseWing(a, name)); _airplane.setWing(parseWing(a, name, &_airplane));
} else if(eq(name, "hstab")) { } else if(eq(name, "hstab")) {
_airplane.setTail(parseWing(a, name)); _airplane.setTail(parseWing(a, name, &_airplane));
} else if(eq(name, "vstab") || eq(name, "mstab")) { } 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")) { } else if(eq(name, "piston-engine")) {
parsePistonEngine(a); parsePistonEngine(a);
} else if(eq(name, "turbine-engine")) { } 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; float defDihed = 0;
if(eq(type, "vstab")) if(eq(type, "vstab"))

View file

@ -10,6 +10,7 @@
namespace yasim { namespace yasim {
class Wing; class Wing;
class Version;
// This class forms the "glue" to the FlightGear codebase. It handles // This class forms the "glue" to the FlightGear codebase. It handles
// parsing of XML airplane files, interfacing to the properties // parsing of XML airplane files, interfacing to the properties
@ -39,7 +40,7 @@ private:
void setOutputProperties(float dt); void setOutputProperties(float dt);
Rotor* parseRotor(XMLAttributes* a, const char* name); 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 parseAxis(const char* name);
int parseOutput(const char* name); int parseOutput(const char* name);
void parseWeight(XMLAttributes* a); void parseWeight(XMLAttributes* a);

View file

@ -2,7 +2,8 @@
#include "Surface.hpp" #include "Surface.hpp"
namespace yasim { namespace yasim {
Surface::Surface() Surface::Surface( Version * version ) :
_version(version)
{ {
// Start in a "sane" mode, so unset stuff doesn't freak us out // Start in a "sane" mode, so unset stuff doesn't freak us out
_c0 = 1; _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 // coordinates. Since out[] is now the force vector and is
// roughly parallel with Z, the small-angle approximation // roughly parallel with Z, the small-angle approximation
// must change its X component. // must change its X component.
if( _version->isVersionOrNewer( Version::YASIM_VERSION_32 )) {
out[0] += incidence * out[2]; out[0] += incidence * out[2];
} else {
out[2] -= incidence * out[0];
}
// Convert back to external coordinates // Convert back to external coordinates
Math::tmul33(_orient, out, out); Math::tmul33(_orient, out, out);
@ -282,8 +287,13 @@ float Surface::stallFunc(float* v)
if(stallAlpha == 0) if(stallAlpha == 0)
return 1; return 1;
if(i == 0) if(i == 0) {
if( _version->isVersionOrNewer( Version::YASIM_VERSION_32 )) {
stallAlpha += _slatPos * _slatAlpha; stallAlpha += _slatPos * _slatAlpha;
} else {
stallAlpha += _slatAlpha;
}
}
// Beyond the stall // Beyond the stall
if(alpha > stallAlpha+_widths[i]) if(alpha > stallAlpha+_widths[i])

View file

@ -1,6 +1,8 @@
#ifndef _SURFACE_HPP #ifndef _SURFACE_HPP
#define _SURFACE_HPP #define _SURFACE_HPP
#include "Version.hpp"
namespace yasim { namespace yasim {
// FIXME: need a "chord" member for calculating moments. Generic // FIXME: need a "chord" member for calculating moments. Generic
@ -9,7 +11,7 @@ namespace yasim {
class Surface class Surface
{ {
public: public:
Surface(); Surface( Version * version );
// Position of this surface in local coords // Position of this surface in local coords
void setPosition(float* p); void setPosition(float* p);
@ -102,6 +104,8 @@ private:
float _incidence; float _incidence;
float _twist; float _twist;
float _inducedDrag; float _inducedDrag;
Version * _version;
}; };
}; // namespace yasim }; // namespace yasim

25
src/FDM/YASim/Version.cpp Normal file
View file

@ -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

37
src/FDM/YASim/Version.hpp Normal file
View file

@ -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

View file

@ -4,7 +4,8 @@
namespace yasim { namespace yasim {
Wing::Wing() Wing::Wing( Version * version ) :
_version(version)
{ {
_mirror = false; _mirror = false;
_base[0] = _base[1] = _base[2] = 0; _base[0] = _base[1] = _base[2] = 0;
@ -426,7 +427,7 @@ float Wing::getLiftRatio()
Surface* Wing::newSurface(float* pos, float* orient, float chord, Surface* Wing::newSurface(float* pos, float* orient, float chord,
bool flap0, bool flap1, bool slat, bool spoiler) bool flap0, bool flap1, bool slat, bool spoiler)
{ {
Surface* s = new Surface(); Surface* s = new Surface(_version);
s->setPosition(pos); s->setPosition(pos);
s->setOrientation(orient); s->setOrientation(orient);

View file

@ -2,6 +2,7 @@
#define _WING_HPP #define _WING_HPP
#include "Vector.hpp" #include "Vector.hpp"
#include "Version.hpp"
namespace yasim { namespace yasim {
@ -10,7 +11,7 @@ class Surface;
// FIXME: need to handle "inverted" controls for mirrored wings. // FIXME: need to handle "inverted" controls for mirrored wings.
class Wing { class Wing {
public: public:
Wing(); Wing( Version * version );
~Wing(); ~Wing();
// Do we mirror ourselves about the XZ plane? // Do we mirror ourselves about the XZ plane?
@ -122,6 +123,8 @@ private:
float _slatEnd; float _slatEnd;
float _slatAoA; float _slatAoA;
float _slatDrag; float _slatDrag;
Version * _version;
}; };
}; // namespace yasim }; // namespace yasim