X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FEnvironment%2Fridge_lift.cxx;h=2a26af5af960fef0a9f92bd3ab9980f343962df8;hb=89b41395d861a49ad543af166c0bd41c14dd0d2b;hp=9598f2bbb908400c9ead7f396232aeaf8b0f6f80;hpb=7b95bb5aa382d0e573e4597213a2e0f1c3d53601;p=flightgear.git diff --git a/src/Environment/ridge_lift.cxx b/src/Environment/ridge_lift.cxx index 9598f2bbb..2a26af5af 100644 --- a/src/Environment/ridge_lift.cxx +++ b/src/Environment/ridge_lift.cxx @@ -36,25 +36,12 @@ #include #include #include - +#include using std::string; #include "ridge_lift.hxx" -static string CreateIndexedPropertyName(string Property, int index) -{ - std::stringstream str; - str << index; - string tmp; - str >> tmp; - return Property + "[" + tmp + "]"; -} - -static inline double sign(double x) { - return x == 0 ? 0 : x > 0 ? 1.0 : -1.0; -} - static const double BOUNDARY1_m = 40.0; const double FGRidgeLift::dist_probe_m[] = { // in meters @@ -66,7 +53,8 @@ const double FGRidgeLift::dist_probe_m[] = { // in meters }; //constructor -FGRidgeLift::FGRidgeLift () +FGRidgeLift::FGRidgeLift () : + lift_factor(0.0) { strength = 0.0; timer = 0.0; @@ -103,42 +91,20 @@ void FGRidgeLift::init(void) void FGRidgeLift::bind() { string prop; + _tiedProperties.setRoot( fgGetNode("/environment/ridge-lift",true)); for( int i = 0; i < 5; i++ ) { - prop = CreateIndexedPropertyName("/environment/ridge-lift/probe-elev-m", i ); - fgTie( prop.c_str(), this, i, &FGRidgeLift::get_probe_elev_m); // read-only - - prop = CreateIndexedPropertyName("/environment/ridge-lift/probe-lat-deg", i ); - fgTie( prop.c_str(), this, i, &FGRidgeLift::get_probe_lat_deg); // read-only - - prop = CreateIndexedPropertyName("/environment/ridge-lift/probe-lon-deg", i ); - fgTie( prop.c_str(), this, i, &FGRidgeLift::get_probe_lon_deg); // read-only + _tiedProperties.Tie( "probe-elev-m", i, this, i, &FGRidgeLift::get_probe_elev_m ); + _tiedProperties.Tie( "probe-lat-deg", i, this, i, &FGRidgeLift::get_probe_lat_deg ); + _tiedProperties.Tie( "probe-lon-deg", i, this, i, &FGRidgeLift::get_probe_lon_deg ); } for( int i = 0; i < 4; i++ ) { - prop = CreateIndexedPropertyName("/environment/ridge-lift/slope", i ); - fgTie( prop.c_str(), this, i, &FGRidgeLift::get_slope); // read-only + _tiedProperties.Tie( "slope", i, this, i, &FGRidgeLift::get_slope ); } } void FGRidgeLift::unbind() { - string prop; - - for( int i = 0; i < 5; i++ ) { - - prop = CreateIndexedPropertyName("/environment/ridge-lift/probe-elev-m", i ); - fgUntie( prop.c_str() ); - - prop = CreateIndexedPropertyName("/environment/ridge-lift/probe-lat-deg", i ); - fgUntie( prop.c_str() ); - - prop = CreateIndexedPropertyName("/environment/ridge-lift/probe-lon-deg", i ); - fgUntie( prop.c_str() ); - } - - for( int i = 0; i < 4; i++ ) { - prop = CreateIndexedPropertyName("/environment/ridge-lift/slope", i ); - fgUntie( prop.c_str() ); - } + _tiedProperties.Untie(); } void FGRidgeLift::update(double dt) { @@ -194,7 +160,7 @@ void FGRidgeLift::update(double dt) { slope[3] = (probe_elev_m[4] - probe_elev_m[0]) / -dist_probe_m[4]; for (unsigned i = 0; i < sizeof(slope)/sizeof(slope[0]); i++) - adj_slope[i] = sin(atan(5.0 * pow ( (fabs(slope[i])),1.7) ) ) *sign(slope[i]); + adj_slope[i] = sin(atan(5.0 * pow ( (fabs(slope[i])),1.7) ) ) *SG_SIGN(slope[i]); //adjustment adj_slope[0] *= 0.2; @@ -222,8 +188,8 @@ void FGRidgeLift::update(double dt) { //boundaries double boundary2_m = 130.0; // in the lift if (lift_factor < 0.0) { // in the sink - double highest_probe_temp= max ( probe_elev_m[1], probe_elev_m[2] ); - double highest_probe_downwind_m= max ( highest_probe_temp, probe_elev_m[3] ); + double highest_probe_temp= std::max ( probe_elev_m[1], probe_elev_m[2] ); + double highest_probe_downwind_m= std::max ( highest_probe_temp, probe_elev_m[3] ); boundary2_m = highest_probe_downwind_m - probe_elev_m[0]; } @@ -234,7 +200,7 @@ void FGRidgeLift::update(double dt) { agl_factor = 1.0; } else { agl_factor = exp(-(2 + probe_elev_m[0] / 2000) * - (user_altitude_agl_m - boundary2_m) / max(probe_elev_m[0],200.0)); + (user_altitude_agl_m - boundary2_m) / std::max(probe_elev_m[0],200.0)); } double ground_wind_speed_mps = _surface_wind_speed_node->getDoubleValue() * SG_NM_TO_METER / 3600;