diff --git a/src/plugins/simulator/xplane/simulatorxplane.cpp b/src/plugins/simulator/xplane/simulatorxplane.cpp index 856f9a98b..431d144de 100644 --- a/src/plugins/simulator/xplane/simulatorxplane.cpp +++ b/src/plugins/simulator/xplane/simulatorxplane.cpp @@ -527,7 +527,7 @@ namespace BlackSimPlugin if (! isRemoteAircraftSupportingParts(situation.getCallsign())) { - // if aircraft not supporting parts then guess (currently only onGround is guessed) + // if aircraft not supporting parts then guess the basics (onGround, gear, lights) //! \todo not working for vtol BlackMisc::Aviation::CAircraftParts parts; parts.setMSecsSinceEpoch(situation.getMSecsSinceEpoch()); @@ -541,8 +541,17 @@ namespace BlackSimPlugin if (nearestAirport != m_airportsInRange.cend() && situation.getAltitude() - nearestAirport->getElevation() < CLength(50, CLengthUnit::ft())) { parts.setOnGround(true); + parts.setGearDown(true); } } + if (situation.getAltitude() < CAltitude(10'000, CLengthUnit::ft())) + { + parts.setLights({ true, true, true, true, true, true, true, true }); + } + else + { + parts.setLights({ true, false, false, true, true, true, true, true }); + } ps_remoteProviderAddAircraftParts(situation.getCallsign(), parts); } } @@ -550,9 +559,11 @@ namespace BlackSimPlugin void CSimulatorXPlane::ps_remoteProviderAddAircraftParts(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Aviation::CAircraftParts &parts) { Q_ASSERT(isConnected()); - //! \fixme Parts currently not used by libxplanemp - m_traffic->addPlaneSurfaces(callsign.asString(), true, 0, 0, 0, 0, 0, 0, 0, 0, 0, true, true, true, true, 0, parts.isOnGround(), - parts.getAdjustedMSecsSinceEpoch() - QDateTime::currentMSecsSinceEpoch()); + m_traffic->addPlaneSurfaces(callsign.asString(), parts.isGearDown() ? 1 : 0, + parts.getFlapsPercent() / 100.0, parts.isSpoilersOut() ? 1 : 0, parts.isSpoilersOut() ? 1 : 0, parts.getFlapsPercent() / 100.0, + 0, parts.isAnyEngineOn() ? 0 : 0.75, 0, 0, 0, + parts.getLights().isLandingOn(), parts.getLights().isBeaconOn(), parts.getLights().isStrobeOn(), parts.getLights().isNavOn(), + 0, parts.isOnGround(), parts.getAdjustedMSecsSinceEpoch() - QDateTime::currentMSecsSinceEpoch()); m_traffic->setPlaneTransponder(callsign.asString(), 2000, true, false); } diff --git a/src/xbus/traffic.cpp b/src/xbus/traffic.cpp index 7c165bdb0..6a7553965 100644 --- a/src/xbus/traffic.cpp +++ b/src/xbus/traffic.cpp @@ -278,8 +278,7 @@ namespace XBus void CTraffic::addPlaneSurfaces(const QString &callsign, double gear, double flap, double spoiler, double speedBrake, double slat, double wingSweep, double thrust, double elevator, double rudder, double aileron, bool landLight, bool beaconLight, bool strobeLight, bool navLight, int lightPattern, bool onGround, qint64 relativeTime) { - const auto plane = m_planesByCallsign.value(callsign, nullptr); - if (plane) + const auto surfaces = std::make_pair(relativeTime + QDateTime::currentMSecsSinceEpoch(), [ = ](Plane *plane) { plane->hasSurfaces = true; plane->surfaces.gearPosition = gear; @@ -297,6 +296,13 @@ namespace XBus plane->surfaces.lights.strbLights = strobeLight; plane->surfaces.lights.navLights = navLight; plane->surfaces.lights.flashPattern = lightPattern; + }); + + const auto plane = m_planesByCallsign.value(callsign, nullptr); + if (plane) + { + if (plane->hasSurfaces) { plane->pendingSurfaces.push_back(surfaces); } + else { surfaces.second(plane); } BlackMisc::Aviation::CAircraftParts parts; parts.setOnGround(onGround); @@ -372,6 +378,12 @@ namespace XBus case xpmpDataType_Surfaces: if (plane->hasSurfaces) { + const auto currentTime = QDateTime::currentMSecsSinceEpoch(); + while (! plane->pendingSurfaces.isEmpty() && plane->pendingSurfaces.front().first <= currentTime) + { + plane->pendingSurfaces.front().second(plane); + plane->pendingSurfaces.pop_front(); + } const auto io_surfaces = static_cast(io_data); if (memcmpPayload(io_surfaces, &plane->surfaces)) diff --git a/src/xbus/traffic.h b/src/xbus/traffic.h index a10dec5ed..e84f4163b 100644 --- a/src/xbus/traffic.h +++ b/src/xbus/traffic.h @@ -22,6 +22,8 @@ #include #include #include "XPMPMultiplayer.h" +#include +#include //! \cond PRIVATE #define XBUS_TRAFFIC_INTERFACENAME "org.swift_project.xbus.traffic" @@ -138,6 +140,7 @@ namespace XBus CTerrainProbe terrainProbe; BlackMisc::Simulation::CInterpolationHints hints(); XPMPPlaneSurfaces_t surfaces; + QVector>> pendingSurfaces; XPMPPlaneRadar_t xpdr; Plane(void *id_, QString callsign_, QString aircraftIcao_, QString airlineIcao_, QString livery_); };