diff --git a/Include/LTWeather.h b/Include/LTWeather.h index 899f7b3..54df331 100644 --- a/Include/LTWeather.h +++ b/Include/LTWeather.h @@ -127,6 +127,9 @@ class LTWeather public: LTWeather(); ///< Constructor sets all arrays to all `NAN` + + /// Clear all METAR-related fields + void ClearMETAR (); /// @brief Compute interpolation settings to fill one array from a differently sized one /// @details: Both arrays are supposed to be sorted ascending. @@ -173,7 +176,7 @@ class LTWeather friend void WeatherSet (const LTWeather& w); friend void WeatherSet (const std::string& metar, const std::string& metarIcao); friend void WeatherSetConstant (const std::string& metar); -friend void WeatherDoSet (); +friend void WeatherDoSet (bool bTakeControl); friend void WeatherUpdate (); friend void WeatherReset (); friend void WeatherLogCurrent (const std::string& msg); diff --git a/Src/LTWeather.cpp b/Src/LTWeather.cpp index a526c1a..0ec612c 100644 --- a/Src/LTWeather.cpp +++ b/Src/LTWeather.cpp @@ -382,6 +382,15 @@ lOut << unit "\n"; LOG_MSG(logDEBUG, "%s\n%s", msg.c_str(), lOut.str().c_str()); } +// Clear all METAR-related fields +void LTWeather::ClearMETAR () +{ + metar.clear(); + metarFieldIcao.clear(); + posMetarField = positionTy(); +} + + // Compute interpolation settings to fill one array from a differently sized one std::array LTWeather::ComputeInterpol (const std::vector& from, const std::array& to) @@ -1380,7 +1389,6 @@ static LTWeather nextWeather; ///< next weather to set static bool bSetWeather = false; ///< is there a next weather to set? static bool bResetWeather = false; ///< Shall weather be reset, ie. handed back to XP? static LTWeather setWeather; ///< the weather we set last time -static std::string gEmptyString; ///< an empty string we can refer to if we need to return an empty reference // Initialize Weather module, dataRefs bool WeatherInit () @@ -1421,24 +1429,32 @@ void WeatherSetXPRealWeather () { if (WeatherCanSet()) wdr_change_mode.set(WDR_CM_REAL_WEATHER); + setWeather.ClearMETAR(); } /// Internal function that actually sets X-Planes weather to what's defined in nextWeather -void WeatherDoSet () +void WeatherDoSet (bool bTakeControl) { + // Remember user's setting prior to us changing weather + if (weatherOrigSource < 0) { + weatherOrigSource = wdr_weather_source.get(); + weatherOrigChangeMode = wdr_change_mode.get(); + } + if (nextWeather.update_immediately) { if (!WeatherInControl()) { - // Taking control of weather - weatherOrigSource = wdr_weather_source.get(); - weatherOrigChangeMode = wdr_change_mode.get(); + // Log weather before take-over if (dataRefs.ShallLogWeather()) { LOG_MSG(logDEBUG, "Weather originally %s (source = %d, change mode = %d)", WeatherGetSource().c_str(), weatherOrigSource, weatherOrigChangeMode); - LTWeather().Get("Weather just prior to LiveTraffic taking over:"); + LTWeather().Get("Weather just prior to LiveTraffic overriding it:"); + } + // Shall we take over control? + if (bTakeControl) { + SHOW_MSG(logINFO, "LiveTraffic takes over controlling X-Plane's weather"); + bWeatherControlling = true; } - SHOW_MSG(logINFO, "LiveTraffic takes over controlling X-Plane's weather"); - bWeatherControlling = true; } else { SHOW_MSG(logINFO, "LiveTraffic is re-setting X-Plane's weather"); } @@ -1549,7 +1565,7 @@ void WeatherSetConstant (const std::string& metar) setWeather.posMetarField = nextWeather.posMetarField; nextWeather.update_immediately = true; - WeatherDoSet(); + WeatherDoSet(false); SHOW_MSG(logINFO, "Constant weather set based on METAR"); } } @@ -1604,9 +1620,7 @@ void WeatherUpdate () "LiveTraffic takes over controlling X-Plane's weather, activating XP's real weather", bNoNearbyMETAR ? "no nearby METAR" : "flying high"); // Remember that we did _not_ use a METAR to define weather - setWeather.metar.clear(); - setWeather.metarFieldIcao.clear(); - setWeather.posMetarField = positionTy(); + setWeather.ClearMETAR(); // Set to XP real weather WeatherSetXPRealWeather(); bWeatherControlling = true; @@ -1655,16 +1669,14 @@ void WeatherUpdate () } if (!bProcessMETAR) { // Remember that we did _not_ use a METAR to define weather - setWeather.metar.clear(); - setWeather.metarFieldIcao.clear(); - setWeather.posMetarField = positionTy(); + setWeather.ClearMETAR(); } // Set weather with immediate effect if first time, or if position changed dramatically nextWeather.update_immediately |= !WeatherInControl() || !setWeather.pos.hasPosAlt() || setWeather.pos.dist(posUser) > WEATHER_MAX_DIST_M; - WeatherDoSet(); + WeatherDoSet(true); } // Reset weather settings to what they were before X-Plane took over @@ -1691,8 +1703,8 @@ void WeatherReset () weatherOrigSource = -1; weatherOrigChangeMode = -1; - setWeather.pos = setWeather.posMetarField = positionTy(); - setWeather.metar.clear(); + setWeather.pos = positionTy(); + setWeather.ClearMETAR(); bResetWeather = bSetWeather = false; } @@ -1705,10 +1717,7 @@ void WeatherLogCurrent (const std::string& msg) // Current METAR in use for weather generation const std::string& WeatherGetMETAR () { - if (WeatherInControl()) - return setWeather.metar; // if in control then return the METAR of the weather we did set - else - return gEmptyString; // otherwise (a reference to) an empty string + return setWeather.metar; // should be empty if we aren't based on METAR } // Return a human readable string on the weather source, is "LiveTraffic" if WeatherInControl() @@ -1744,8 +1753,13 @@ std::string WeatherGetSource () return std::string("LiveTraffic, unknown"); } } - else if (source == 0) // 'Preset' - return std::string(WEATHER_SOURCES[size_t(source)]) + ", " + WEATHER_PRESETS[size_t(preset)]; + else if (source == 0) { // 'Preset' + std::string s = std::string(WEATHER_SOURCES[size_t(source)]) + ", " + WEATHER_PRESETS[size_t(preset)]; + if (!setWeather.metar.empty()) { + s += ", set from given METAR"; + } + return s; + } else return std::string(WEATHER_SOURCES[size_t(source)]); } diff --git a/docs/readme.html b/docs/readme.html index 48cf5eb..0e5be45 100755 --- a/docs/readme.html +++ b/docs/readme.html @@ -177,8 +177,11 @@

v4.0.0

If you want to use OpenSky in an existing installation just activate it in the channel's settings. -
  • Increased total maximum of allowed aircraft to 300, - room needed to allow for parked aircraft at large airports.
  • +
  • + Increased number of allowed aircraft to 300, + room needed to allow for parked aircraft at large airports. + Set in Settings > Advanced. +
  • Fixed #269: No pressure altitude correcton above transition altitude (fixed at 18,000ft).