#include "environment_mgr.hxx"
#include "environment_ctrl.hxx"
-SG_USING_STD(sort);
+using std::sort;
class metar_filter : public FGAirportSearchFilter {
virtual bool pass(FGAirport *a) { return a->getMetar(); }
MaxCloudAltitudeChangeFtSec( 20.0 ),
MaxCloudThicknessChangeFtSec( 50.0 ),
MaxCloudInterpolationHeightFt( 5000.0 ),
+ MaxCloudInterpolationDeltaFt( 4000.0 ),
_error_count( 0 ),
_stale_count( 0 ),
{
#if defined(ENABLE_THREADS)
thread = new MetarThread(this);
- thread->start( 1 );
+ thread->setProcessorAffinity(1);
+ thread->start();
#endif // ENABLE_THREADS
}
double pressure;
double temp;
double dewpoint;
+
+ // If we aren't in the METAR scenario, don't attempt to interpolate.
+ if (strcmp(fgGetString("/environment/weather-scenario", "METAR"), "METAR")) return;
if (metar_loaded) {
// Generate interpolated values between the METAR and the current
// factor by the maximum wind change.
double x = fabs(current[0] - metar[0]);
double y = fabs(current[1] - metar[1]);
- double dx = x / (x + y);
- double dy = 1 - dx;
- double maxdx = dx * MaxWindChangeKtsSec;
- double maxdy = dy * MaxWindChangeKtsSec;
+ // only interpolate if we have a difference
+ if (x + y > 0) {
+ double dx = x / (x + y);
+ double dy = 1 - dx;
- // Interpolate each component separately.
- current[0] = interpolate_val(current[0], metar[0], maxdx);
- current[1] = interpolate_val(current[1], metar[1], maxdy);
+ double maxdx = dx * MaxWindChangeKtsSec;
+ double maxdy = dy * MaxWindChangeKtsSec;
+
+ // Interpolate each component separately.
+ current[0] = interpolate_val(current[0], metar[0], maxdx);
+ current[1] = interpolate_val(current[1], metar[1], maxdy);
+ }
// Now convert back to polar coordinates.
if ((current[0] == 0.0) && (current[1] == 0.0)) {
double current_alt = fgGetDouble(s);
double required_alt = (*layer)->getDoubleValue("elevation-ft");
- if (current_alt < -9000 || required_alt < -9000
- || fabs(aircraft_alt - required_alt) > MaxCloudInterpolationHeightFt) {
- // We don't interpolate any values that are too high above us,
- // or too far below us to be visible. Nor do we interpolate
- // values to or from -9999, which is used as a placeholder
- // when there isn't actually a cloud layer present.
+ if (current_alt < -9000 || required_alt < -9000 ||
+ fabs(aircraft_alt - required_alt) > MaxCloudInterpolationHeightFt ||
+ fabs(current_alt - required_alt) > MaxCloudInterpolationDeltaFt) {
+ // We don't interpolate any layers that are
+ // - too far above us to be visible
+ // - too far below us to be visible
+ // - with too large a difference to make interpolation sensible
+ // - to or from -9999 (used as a placeholder)
+ // - any values that are too high above us,
snprintf(s, 128, cl, i);
strncat(s, "/elevation-ft", 128);
if (current_alt != required_alt)
dewpoint = fgGetDouble("/environment/metar/dewpoint-degc");
// Set the cloud layers by copying over the METAR versions.
- SGPropertyNode * clouds = fgGetNode("/environment/metar/clouds");
+ SGPropertyNode * clouds = fgGetNode("/environment/metar/clouds", true);
vector<SGPropertyNode_ptr> layers = clouds->getChildren("layer");
vector<SGPropertyNode_ptr>::const_iterator layer;
strncat(s, "/span-m", 128);
fgSetDouble(s, 40000.0);
}
+
+ // Force an update of the 3D clouds
+ fgSetDouble("/environment/rebuild-layers", 1.0);
}
fgSetupWind(dir_from, dir_to, speed, gust);
const FGAirport* a = globals->get_airports()
->search( longitude->getDoubleValue(),
latitude->getDoubleValue(),
+ 360.0,
metar_only );
if ( a ) {
FGMetarResult result = fetch_data( a->getId() );
{
_error_count = 0;
_error_dt = 0.0;
-
-#if 0
- update_env_config();
-#endif
+ metar_loaded = false;
env->reinit();
}
const FGAirport* a = globals->get_airports()
->search( longitude->getDoubleValue(),
latitude->getDoubleValue(),
+ 360.0,
metar_only );
if ( a ) {
if ( !last_apt || last_apt->getId() != a->getId()