From c437c2eabd00f6201a06116613f87fc7e8a01348 Mon Sep 17 00:00:00 2001 From: Roland Winklmeier Date: Tue, 15 May 2018 09:55:56 +0200 Subject: [PATCH] Simplify the X-Plane traffic plane positions and surfaces API --- .../simulator/xplane/simulatorxplane.cpp | 83 +++++++------------ .../xplane/xswiftbustrafficproxy.cpp | 23 +++-- .../simulator/xplane/xswiftbustrafficproxy.h | 56 ++++++++++--- 3 files changed, 90 insertions(+), 72 deletions(-) diff --git a/src/plugins/simulator/xplane/simulatorxplane.cpp b/src/plugins/simulator/xplane/simulatorxplane.cpp index 1ea1ce160..bb2c8e3c3 100644 --- a/src/plugins/simulator/xplane/simulatorxplane.cpp +++ b/src/plugins/simulator/xplane/simulatorxplane.cpp @@ -707,31 +707,8 @@ namespace BlackSimPlugin // interpolation for all remote aircraft const QList xplaneAircraftList(m_xplaneAircraftObjects.values()); - QStringList posCallsigns; - QList latitudes; - QList longitudes; - QList altitudes; - QList pitches; - QList rolles; - QList headings; - - QStringList surfaceCallsign; - QList gear; - QList flap; - QList spoiler; - QList speedBrake; - QList slat; - QList wingSweep; - QList thrust; - QList elevator; - QList rudder; - QList aileron; - QList landLight; - QList beaconLight; - QList strobeLight; - QList navLight; - QList lightPattern; - QList onGround; + PlanesPositions planesPositions; + PlanesSurfaces planesSurfaces; for (const CXPlaneMPAircraft &xplaneAircraft : xplaneAircraftList) { @@ -751,13 +728,13 @@ namespace BlackSimPlugin if (!xplaneAircraft.isSameAsSent(interpolatedSituation)) { m_xplaneAircraftObjects[xplaneAircraft.getCallsign()].setSituationAsSent(interpolatedSituation); - posCallsigns.push_back(interpolatedSituation.getCallsign().asString()); - latitudes.push_back(interpolatedSituation.latitude().value(CAngleUnit::deg())); - longitudes.push_back(interpolatedSituation.longitude().value(CAngleUnit::deg())); - altitudes.push_back(interpolatedSituation.getAltitude().value(CLengthUnit::ft())); - pitches.push_back(interpolatedSituation.getPitch().value(CAngleUnit::deg())); - rolles.push_back(interpolatedSituation.getBank().value(CAngleUnit::deg())); - headings.push_back(interpolatedSituation.getHeading().value(CAngleUnit::deg())); + planesPositions.callsigns.push_back(interpolatedSituation.getCallsign().asString()); + planesPositions.latitudes.push_back(interpolatedSituation.latitude().value(CAngleUnit::deg())); + planesPositions.longitudes.push_back(interpolatedSituation.longitude().value(CAngleUnit::deg())); + planesPositions.altitudes.push_back(interpolatedSituation.getAltitude().value(CLengthUnit::ft())); + planesPositions.pitches.push_back(interpolatedSituation.getPitch().value(CAngleUnit::deg())); + planesPositions.rolls.push_back(interpolatedSituation.getBank().value(CAngleUnit::deg())); + planesPositions.headings.push_back(interpolatedSituation.getHeading().value(CAngleUnit::deg())); } } else @@ -768,35 +745,35 @@ namespace BlackSimPlugin const CAircraftParts parts(result); if (result.getPartsStatus().isSupportingParts() || parts.getPartsDetails() == CAircraftParts::GuessedParts) { - surfaceCallsign.push_back(xplaneAircraft.getCallsign().asString()); - gear.push_back(parts.isGearDown() ? 1 : 0); - flap.push_back(parts.getFlapsPercent() / 100.0); - spoiler.push_back(parts.isSpoilersOut() ? 1 : 0); - speedBrake.push_back(parts.isSpoilersOut() ? 1 : 0); - slat.push_back(parts.getFlapsPercent() / 100.0); - wingSweep.push_back(0.0); - thrust.push_back(parts.isAnyEngineOn() ? 0 : 0.75); - elevator.push_back(0.0); - rudder.push_back(0.0); - aileron.push_back(0.0); - landLight.push_back(parts.getLights().isLandingOn()); - beaconLight.push_back(parts.getLights().isBeaconOn()); - strobeLight.push_back(parts.getLights().isStrobeOn()); - navLight.push_back(parts.getLights().isNavOn()); - lightPattern.push_back(0); - onGround.push_back(parts.isOnGround()); + planesSurfaces.callsigns.push_back(xplaneAircraft.getCallsign().asString()); + planesSurfaces.gears.push_back(parts.isGearDown() ? 1 : 0); + planesSurfaces.flaps.push_back(parts.getFlapsPercent() / 100.0); + planesSurfaces.spoilers.push_back(parts.isSpoilersOut() ? 1 : 0); + planesSurfaces.speedBrakes.push_back(parts.isSpoilersOut() ? 1 : 0); + planesSurfaces.slats.push_back(parts.getFlapsPercent() / 100.0); + planesSurfaces.wingSweeps.push_back(0.0); + planesSurfaces.thrusts.push_back(parts.isAnyEngineOn() ? 0 : 0.75); + planesSurfaces.elevators.push_back(0.0); + planesSurfaces.rudders.push_back(0.0); + planesSurfaces.ailerons.push_back(0.0); + planesSurfaces.landLights.push_back(parts.getLights().isLandingOn()); + planesSurfaces.beaconLights.push_back(parts.getLights().isBeaconOn()); + planesSurfaces.strobeLights.push_back(parts.getLights().isStrobeOn()); + planesSurfaces.navLights.push_back(parts.getLights().isNavOn()); + planesSurfaces.lightPatterns.push_back(0); + planesSurfaces.onGrounds.push_back(parts.isOnGround()); } } // all callsigns - if (! posCallsigns.isEmpty()) + if (! planesPositions.isEmpty()) { - m_trafficProxy->setPlanePositions(posCallsigns, latitudes, longitudes, altitudes, pitches, rolles, headings); + m_trafficProxy->setPlanesPositions(planesPositions); } - if (! surfaceCallsign.isEmpty()) + if (! planesSurfaces.isEmpty()) { - m_trafficProxy->setPlaneSurfaces(surfaceCallsign, gear, flap, spoiler, speedBrake, slat, wingSweep, thrust, elevator, rudder, aileron, landLight, beaconLight, strobeLight, navLight, lightPattern, onGround); + m_trafficProxy->setPlanesSurfaces(planesSurfaces); } const qint64 dt = QDateTime::currentMSecsSinceEpoch() - currentTimestamp; diff --git a/src/plugins/simulator/xplane/xswiftbustrafficproxy.cpp b/src/plugins/simulator/xplane/xswiftbustrafficproxy.cpp index f9794cb18..8b7b3cce8 100644 --- a/src/plugins/simulator/xplane/xswiftbustrafficproxy.cpp +++ b/src/plugins/simulator/xplane/xswiftbustrafficproxy.cpp @@ -82,19 +82,24 @@ namespace BlackSimPlugin m_dbusInterface->callDBus(QLatin1String("removeAllPlanes")); } - void CXSwiftBusTrafficProxy::setPlanePositions(const QStringList &callsigns, const QList &latitudes, const QList &longitudes, const QList &altitudes, - const QList &pitches, const QList &rolles, const QList &headings) + void CXSwiftBusTrafficProxy::setPlanesPositions(const PlanesPositions &planesPositions) { - m_dbusInterface->callDBus(QLatin1String("setPlanePositions"), callsigns, latitudes, longitudes, altitudes, pitches, rolles, headings); + m_dbusInterface->callDBus(QLatin1String("setPlanesPositions"), + planesPositions.callsigns, planesPositions.latitudes, planesPositions.longitudes, + planesPositions.altitudes, planesPositions.pitches, planesPositions.rolls, + planesPositions.headings); } - void CXSwiftBusTrafficProxy::setPlaneSurfaces(const QStringList &callsign, const QList &gear, const QList &flap, const QList &spoiler, - const QList &speedBrake, const QList &slat, const QList &wingSweep, const QList &thrust, - const QList &elevator, const QList &rudder, const QList &aileron, const QList &landLight, - const QList &beaconLight, const QList &strobeLight, const QList &navLight, const QList &lightPattern, const QList &onGround) + void CXSwiftBusTrafficProxy::setPlanesSurfaces(const PlanesSurfaces &planesSurfaces) { - m_dbusInterface->callDBus(QLatin1String("setPlaneSurfaces"), callsign, gear, flap, spoiler, speedBrake, slat, wingSweep, thrust, elevator, rudder, aileron, - landLight, beaconLight, strobeLight, navLight, lightPattern, onGround); + m_dbusInterface->callDBus(QLatin1String("setPlanesSurfaces"), + planesSurfaces.callsigns, planesSurfaces.gears, planesSurfaces.flaps, + planesSurfaces.spoilers, planesSurfaces.speedBrakes, planesSurfaces.slats, + planesSurfaces.wingSweeps, planesSurfaces.thrusts, planesSurfaces.elevators, + planesSurfaces.rudders, planesSurfaces.ailerons, + planesSurfaces.landLights, planesSurfaces.beaconLights, planesSurfaces.strobeLights, + planesSurfaces.navLights, planesSurfaces.lightPatterns, + planesSurfaces.onGrounds); } void CXSwiftBusTrafficProxy::setPlaneTransponder(const QString &callsign, int code, bool modeC, bool ident) diff --git a/src/plugins/simulator/xplane/xswiftbustrafficproxy.h b/src/plugins/simulator/xplane/xswiftbustrafficproxy.h index 51182df2a..c4490a781 100644 --- a/src/plugins/simulator/xplane/xswiftbustrafficproxy.h +++ b/src/plugins/simulator/xplane/xswiftbustrafficproxy.h @@ -31,6 +31,49 @@ namespace BlackSimPlugin { namespace XPlane { + //! List of doubles + using QDoubleList = QList; + + //! Planes positions + struct PlanesPositions + { + //! Is empty? + bool isEmpty() const { return callsigns.isEmpty(); } + + QStringList callsigns; //!< List of callsigns + QList latitudes; //!< List of latitudes + QList longitudes; //!< List of longitudes + QList altitudes; //!< List of altitudes + QList pitches; //!< List of pitches + QList rolls; //!< List of rolls + QList headings; //!< List of headings + }; + + //! Planes surfaces + struct PlanesSurfaces + { + //! Is empty? + bool isEmpty() const { return callsigns.isEmpty(); } + + QStringList callsigns; //!< List of callsigns + QList gears; //!< List of gears + QList flaps; //!< List of flaps + QList spoilers; //!< List of spoilers + QList speedBrakes; //!< List of speedBrakes + QList slats; //!< List of slats + QList wingSweeps; //!< List of wingSweeps + QList thrusts; //!< List of thrusts + QList elevators; //!< List of elevators + QList rudders; //!< List of rudders + QList ailerons; //!< List of ailerons + QList landLights; //!< List of landLights + QList beaconLights; //!< List of beaconLights + QList strobeLights; //!< List of strobeLights + QList navLights; //!< List of navLights + QList lightPatterns; //!< List of lightPatterns + QList onGrounds; //!< List of onGrounds + }; + /*! * Proxy object connected to a real XSwiftBus::CTraffic object via DBus */ @@ -39,9 +82,6 @@ namespace BlackSimPlugin Q_OBJECT public: - //! List of doubles - using QDoubleList = QList; - //! Elevation callback using ElevationCallback = std::function; @@ -113,15 +153,11 @@ namespace BlackSimPlugin //! \copydoc XSwiftBus::CTraffic::removeAllPlanes void removeAllPlanes(); - //! \copydoc XSwiftBus::CTraffic::setPlanePositions - void setPlanePositions(const QStringList &callsigns, const QList &latitudes, const QList &longitudes, const QList &altitudes, - const QList &pitches, const QList &rolles, const QList &headings); + //! \copydoc XSwiftBus::CTraffic::setPlanesPositions + void setPlanesPositions(const PlanesPositions &planesPositions); //! \copydoc XSwiftBus::CTraffic::setPlaneSurfaces - void setPlaneSurfaces(const QStringList &callsign, const QList &gear, const QList &flap, const QList &spoiler, - const QList &speedBrake, const QList &slat, const QList &wingSweep, const QList &thrust, - const QList &elevator, const QList &rudder, const QList &aileron, const QList &landLight, - const QList &beaconLight, const QList &strobeLight, const QList &navLight, const QList &lightPattern, const QList &onGround); + void setPlanesSurfaces(const PlanesSurfaces &planesSurfaces); //! \copydoc XSwiftBus::CTraffic::setPlaneTransponder void setPlaneTransponder(const QString &callsign, int code, bool modeC, bool ident);