From e1538573fe6994314ffddf31604459c83348e14e Mon Sep 17 00:00:00 2001 From: Roland Winklmeier Date: Thu, 8 Mar 2018 17:34:00 +0100 Subject: [PATCH] Remove old xswiftbus interpolator code ref T259 --- .../simulator/xplane/simulatorxplane.cpp | 160 ++++++------------ .../simulator/xplane/simulatorxplane.h | 1 - src/xswiftbus/traffic.cpp | 131 ++------------ src/xswiftbus/traffic.h | 18 +- 4 files changed, 62 insertions(+), 248 deletions(-) diff --git a/src/plugins/simulator/xplane/simulatorxplane.cpp b/src/plugins/simulator/xplane/simulatorxplane.cpp index 676dbc063..47581567f 100644 --- a/src/plugins/simulator/xplane/simulatorxplane.cpp +++ b/src/plugins/simulator/xplane/simulatorxplane.cpp @@ -371,24 +371,16 @@ namespace BlackSimPlugin { if (!isConnected()) { return false; } - if (c_driverInterpolation) + if (mode == CInterpolatorMulti::ModeUnknown) { return false; } + if (callsign.isEmpty()) { - if (mode == CInterpolatorMulti::ModeUnknown) { return false; } - if (callsign.isEmpty()) - { - const int c = m_xplaneAircraftObjects.setInterpolatorModes(mode); - return c > 0; - } - else - { - if (!m_xplaneAircraftObjects.contains(callsign)) { return false; } - return m_xplaneAircraftObjects[callsign].setInterpolatorMode(mode); - } + const int c = m_xplaneAircraftObjects.setInterpolatorModes(mode); + return c > 0; } else { - m_trafficProxy->setInterpolatorMode(callsign.asString(), mode == CInterpolatorMulti::ModeSpline); - return true; + if (!m_xplaneAircraftObjects.contains(callsign)) { return false; } + return m_xplaneAircraftObjects[callsign].setInterpolatorMode(mode); } } @@ -403,15 +395,7 @@ namespace BlackSimPlugin bool CSimulatorXPlane::isPhysicallyRenderedAircraft(const CCallsign &callsign) const { - if (c_driverInterpolation) - { - return m_xplaneAircraftObjects.contains(callsign); - } - else - { - //! \todo XP implement isRenderedAircraft correctly. This is a workaround, but not telling me if a callsign is really(!) visible in simulator - return getAircraftInRangeForCallsign(callsign).isRendered(); - } + return m_xplaneAircraftObjects.contains(callsign); } bool CSimulatorXPlane::updateOwnSimulatorCockpit(const Simulation::CSimulatedAircraft &aircraft, const CIdentifier &originator) @@ -501,48 +485,27 @@ namespace BlackSimPlugin bool CSimulatorXPlane::physicallyAddRemoteAircraft(const CSimulatedAircraft &newRemoteAircraft) { Q_ASSERT(isConnected()); - if (c_driverInterpolation) - { - // entry checks - Q_ASSERT_X(CThreadUtils::isCurrentThreadObjectThread(this), Q_FUNC_INFO, "thread"); - Q_ASSERT_X(!newRemoteAircraft.getCallsign().isEmpty(), Q_FUNC_INFO, "empty callsign"); - Q_ASSERT_X(newRemoteAircraft.hasModelString(), Q_FUNC_INFO, "missing model string"); + // entry checks + Q_ASSERT_X(CThreadUtils::isCurrentThreadObjectThread(this), Q_FUNC_INFO, "thread"); + Q_ASSERT_X(!newRemoteAircraft.getCallsign().isEmpty(), Q_FUNC_INFO, "empty callsign"); + Q_ASSERT_X(newRemoteAircraft.hasModelString(), Q_FUNC_INFO, "missing model string"); - m_xplaneAircraftObjects.insert(newRemoteAircraft.getCallsign(), CXPlaneMPAircraft(newRemoteAircraft, &m_interpolationLogger)); - CAircraftModel aircraftModel = newRemoteAircraft.getModel(); - QString livery = aircraftModel.getLivery().getCombinedCode(); //! \todo livery resolution for XP - m_trafficProxy->addPlane(newRemoteAircraft.getCallsign().asString(), aircraftModel.getModelString(), - newRemoteAircraft.getAircraftIcaoCode().getDesignator(), - newRemoteAircraft.getAirlineIcaoCode().getDesignator(), - livery); + m_xplaneAircraftObjects.insert(newRemoteAircraft.getCallsign(), CXPlaneMPAircraft(newRemoteAircraft, &m_interpolationLogger)); + CAircraftModel aircraftModel = newRemoteAircraft.getModel(); + QString livery = aircraftModel.getLivery().getCombinedCode(); //! \todo livery resolution for XP + m_trafficProxy->addPlane(newRemoteAircraft.getCallsign().asString(), aircraftModel.getModelString(), + newRemoteAircraft.getAircraftIcaoCode().getDesignator(), + newRemoteAircraft.getAirlineIcaoCode().getDesignator(), + livery); - CLogMessage(this).info("XP: Added aircraft %1") << newRemoteAircraft.getCallsign().toQString(); + CLogMessage(this).info("XP: Added aircraft %1") << newRemoteAircraft.getCallsign().toQString(); - bool rendered = true; - updateAircraftRendered(newRemoteAircraft.getCallsign(), rendered); + bool rendered = true; + updateAircraftRendered(newRemoteAircraft.getCallsign(), rendered); - CSimulatedAircraft remoteAircraftCopy(newRemoteAircraft); - remoteAircraftCopy.setRendered(rendered); - emit this->aircraftRenderingChanged(remoteAircraftCopy); - } - else - { - CAircraftModel aircraftModel = newRemoteAircraft.getModel(); - QString livery = aircraftModel.getLivery().getCombinedCode(); //! \todo livery resolution for XP - m_trafficProxy->addPlane(newRemoteAircraft.getCallsign().asString(), aircraftModel.getModelString(), - newRemoteAircraft.getAircraftIcaoCode().getDesignator(), - newRemoteAircraft.getAirlineIcaoCode().getDesignator(), - livery); - - CLogMessage(this).info("XP: Added aircraft %1") << newRemoteAircraft.getCallsign().toQString(); - - bool rendered = true; - updateAircraftRendered(newRemoteAircraft.getCallsign(), rendered); - - CSimulatedAircraft remoteAircraftCopy(newRemoteAircraft); - remoteAircraftCopy.setRendered(rendered); - emit this->aircraftRenderingChanged(remoteAircraftCopy); - } + CSimulatedAircraft remoteAircraftCopy(newRemoteAircraft); + remoteAircraftCopy.setRendered(rendered); + emit this->aircraftRenderingChanged(remoteAircraftCopy); return true; } @@ -550,39 +513,29 @@ namespace BlackSimPlugin { Q_ASSERT(isConnected()); - if (c_driverInterpolation) + // only remove from sim + Q_ASSERT_X(CThreadUtils::isCurrentThreadObjectThread(this), Q_FUNC_INFO, "wrong thread"); + if (callsign.isEmpty()) { return false; } // can happen if an object is not an aircraft + + // really remove from simulator + if (!m_xplaneAircraftObjects.contains(callsign)) { return false; } // already fully removed or not yet added + + // mark in provider + const bool updated = this->updateAircraftRendered(callsign, false); + if (updated) { - // only remove from sim - Q_ASSERT_X(CThreadUtils::isCurrentThreadObjectThread(this), Q_FUNC_INFO, "wrong thread"); - if (callsign.isEmpty()) { return false; } // can happen if an object is not an aircraft - - // really remove from simulator - if (!m_xplaneAircraftObjects.contains(callsign)) { return false; } // already fully removed or not yet added - - // mark in provider - const bool updated = this->updateAircraftRendered(callsign, false); - if (updated) - { - Q_ASSERT_X(m_xplaneAircraftObjects.contains(callsign), Q_FUNC_INFO, "Aircraft removed"); - const CXPlaneMPAircraft &xplaneAircraft = m_xplaneAircraftObjects[callsign]; - CSimulatedAircraft aircraft(xplaneAircraft.getAircraft()); - aircraft.setRendered(false); - emit this->aircraftRenderingChanged(aircraft); - } - - m_trafficProxy->removePlane(callsign.asString()); - m_xplaneAircraftObjects.remove(callsign); - - // bye - return true; - } - else - { - m_trafficProxy->removePlane(callsign.asString()); - this->updateAircraftRendered(callsign, false); - CLogMessage(this).info("XP: Removed aircraft %1") << callsign.toQString(); - return true; + Q_ASSERT_X(m_xplaneAircraftObjects.contains(callsign), Q_FUNC_INFO, "Aircraft removed"); + const CXPlaneMPAircraft &xplaneAircraft = m_xplaneAircraftObjects[callsign]; + CSimulatedAircraft aircraft(xplaneAircraft.getAircraft()); + aircraft.setRendered(false); + emit this->aircraftRenderingChanged(aircraft); } + + m_trafficProxy->removePlane(callsign.asString()); + m_xplaneAircraftObjects.remove(callsign); + + // bye + return true; } int CSimulatorXPlane::physicallyRemoveAllRemoteAircraft() @@ -591,25 +544,14 @@ namespace BlackSimPlugin //! \todo XP driver obtain number of removed aircraft resetHighlighting(); - if (c_driverInterpolation) + // remove one by one + int r = 0; + const CCallsignSet callsigns = m_xplaneAircraftObjects.getAllCallsigns(); + for (const CCallsign &cs : callsigns) { - // remove one by one - int r = 0; - const CCallsignSet callsigns = m_xplaneAircraftObjects.getAllCallsigns(); - for (const CCallsign &cs : callsigns) - { - if (this->physicallyRemoveRemoteAircraft(cs)) { r++; } - } - return r; - } - else - { - const int r = getAircraftInRangeCount(); - m_trafficProxy->removeAllPlanes(); - this->updateMarkAllAsNotRendered(); - CLogMessage(this).info("XP: Removed all aircraft"); - return r; + if (this->physicallyRemoveRemoteAircraft(cs)) { r++; } } + return r; } CCallsignSet CSimulatorXPlane::physicallyRenderedAircraft() const diff --git a/src/plugins/simulator/xplane/simulatorxplane.h b/src/plugins/simulator/xplane/simulatorxplane.h index e13ebed00..5e065ab7c 100644 --- a/src/plugins/simulator/xplane/simulatorxplane.h +++ b/src/plugins/simulator/xplane/simulatorxplane.h @@ -155,7 +155,6 @@ namespace BlackSimPlugin void requestRemoteAircraftDataFromXPlane(); void updateRemoteAircraftFromSimulator(const QString &callsign, double latitudeDeg, double longitudeDeg, double elevationMeters, double modelVerticalOffsetMeters); - static constexpr bool c_driverInterpolation = true; static constexpr int GuessRemoteAircraftPartsCycle = 20; //!< guess every n-th cycle // XSwiftBus interpolation diff --git a/src/xswiftbus/traffic.cpp b/src/xswiftbus/traffic.cpp index 8676588d3..e1605531d 100644 --- a/src/xswiftbus/traffic.cpp +++ b/src/xswiftbus/traffic.cpp @@ -14,8 +14,6 @@ #endif #include "traffic.h" #include "utils.h" -#include "blackmisc/simulation/interpolator.h" -#include "blackmisc/aviation/aircraftsituation.h" #include "blackmisc/aviation/callsign.h" #include "blackmisc/verify.h" #include "XPMPMultiplayer.h" @@ -33,8 +31,7 @@ namespace XSwiftBus { CTraffic::Plane::Plane(void *id_, QString callsign_, QString aircraftIcao_, QString airlineIcao_, QString livery_, QString modelName_) - : id(id_), callsign(callsign_), aircraftIcao(aircraftIcao_), airlineIcao(airlineIcao_), livery(livery_), modelName(modelName_), - interpolator(callsign) + : id(id_), callsign(callsign_), aircraftIcao(aircraftIcao_), airlineIcao(airlineIcao_), livery(livery_), modelName(modelName_) { std::memset(static_cast(&surfaces), 0, sizeof(surfaces)); surfaces.lights.bcnLights = surfaces.lights.landLights = surfaces.lights.navLights = surfaces.lights.strbLights = 1; @@ -228,27 +225,6 @@ namespace XSwiftBus m_planesById.clear(); } - void CTraffic::addPlanePosition(const QString &callsign, double latitude, double longitude, double altitude, double pitch, double roll, double heading, qint64 relativeTime, qint64 timeOffset) - { - Plane *plane = m_planesByCallsign.value(callsign, nullptr); - if (!plane) { return; } - - using namespace BlackMisc::PhysicalQuantities; - using namespace BlackMisc::Aviation; - using namespace BlackMisc::Geo; - CAircraftSituation situation( - callsign, - CCoordinateGeodetic(latitude, longitude, altitude), - CHeading(heading, CHeading::True, CAngleUnit::deg()), - CAngle(pitch, CAngleUnit::deg()), - CAngle(roll, CAngleUnit::deg()), - CSpeed(0, CSpeedUnit::kts()) - ); - situation.setMSecsSinceEpoch(relativeTime + QDateTime::currentMSecsSinceEpoch()); - situation.setTimeOffsetMs(timeOffset); - // plane->interpolator.addAircraftSituation(situation); - } - void CTraffic::setPlanePosition(const QString &callsign, double latitude, double longitude, double altitude, double pitch, double roll, double heading) { Plane *plane = m_planesByCallsign.value(callsign, nullptr); @@ -261,41 +237,6 @@ namespace XSwiftBus plane->position.heading = static_cast(heading); } - 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, qint64 timeOffset) - { - Plane *plane = m_planesByCallsign.value(callsign, nullptr); - if (!plane) { return; } - const auto surfaces = std::make_pair(relativeTime + timeOffset + QDateTime::currentMSecsSinceEpoch(), [ = ](Plane * plane) - { - plane->hasSurfaces = true; - plane->targetGearPosition = gear; - plane->surfaces.flapRatio = flap; - plane->surfaces.spoilerRatio = spoiler; - plane->surfaces.speedBrakeRatio = speedBrake; - plane->surfaces.slatRatio = slat; - plane->surfaces.wingSweep = wingSweep; - plane->surfaces.thrust = thrust; - plane->surfaces.yokePitch = elevator; - plane->surfaces.yokeHeading = rudder; - plane->surfaces.yokeRoll = aileron; - plane->surfaces.lights.landLights = landLight; - plane->surfaces.lights.bcnLights = beaconLight; - plane->surfaces.lights.strbLights = strobeLight; - plane->surfaces.lights.navLights = navLight; - plane->surfaces.lights.flashPattern = lightPattern; - }); - - if (plane->hasSurfaces) { plane->pendingSurfaces.push_back(surfaces); } - else { surfaces.second(plane); } - -// BlackMisc::Aviation::CAircraftParts parts; -// parts.setOnGround(onGround); -// parts.setMSecsSinceEpoch(relativeTime + QDateTime::currentMSecsSinceEpoch()); -// parts.setTimeOffsetMs(timeOffset); -// plane->interpolator.addAircraftParts(parts); - } - void CTraffic::setPlaneSurfaces(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) { @@ -332,23 +273,6 @@ namespace XSwiftBus else { plane->xpdr.mode = xpmpTransponderMode_Standby; } } - void CTraffic::setInterpolatorMode(const QString &callsign, bool spline) - { - Plane *plane = m_planesByCallsign.value(callsign, nullptr); - if (plane) - { - plane->interpolator.setMode(spline ? BlackMisc::Simulation::CInterpolatorMulti::ModeSpline - : BlackMisc::Simulation::CInterpolatorMulti::ModeLinear); - } - else if (callsign.isEmpty()) - { - for (const auto &callsign : BlackMisc::makeKeysRange(BlackMisc::as_const(m_planesByCallsign))) - { - setInterpolatorMode(callsign, spline); - } - } - } - void CTraffic::requestRemoteAircraftData() { if (m_planesByCallsign.empty()) { return; } @@ -387,40 +311,15 @@ namespace XSwiftBus { case xpmpDataType_Position: { - if (c_driverInterpolation) - { - const auto io_position = static_cast(io_data); - io_position->lat = plane->position.lat; - io_position->lon = plane->position.lon; - io_position->elevation = plane->position.elevation; - io_position->pitch = plane->position.pitch; - io_position->roll = plane->position.roll; - io_position->heading = plane->position.heading; - std::strncpy(io_position->label, plane->label, sizeof(plane->label)); // fixme don't need to copy on every frame - return xpmpData_NewData; - } - else - { - BlackMisc::Simulation::CInterpolationAndRenderingSetupPerCallsign setup; - BlackMisc::Simulation::CInterpolationStatus status; - BlackMisc::Aviation::CAircraftSituation situation = plane->interpolator.getInterpolatedSituation(-1, setup, status); - if (! status.hasValidSituation()) { return xpmpData_Unavailable; } - - //! \fixme KB 2018-01 commented out with T229. Change detection needs to go somewhere else - // if (! status.hasChangedPosition()) { return xpmpData_Unchanged; } - - using namespace BlackMisc::PhysicalQuantities; - using namespace BlackMisc::Aviation; - const auto io_position = static_cast(io_data); - io_position->lat = situation.latitude().value(CAngleUnit::deg()); - io_position->lon = situation.longitude().value(CAngleUnit::deg()); - io_position->elevation = situation.getAltitude().value(CLengthUnit::ft()); - io_position->pitch = static_cast(situation.getPitch().value(CAngleUnit::deg())); - io_position->roll = static_cast(situation.getBank().value(CAngleUnit::deg())); - io_position->heading = static_cast(situation.getHeading().value(CAngleUnit::deg())); - std::strncpy(io_position->label, plane->label, sizeof(plane->label)); // fixme don't need to copy on every frame - return xpmpData_NewData; - } + const auto io_position = static_cast(io_data); + io_position->lat = plane->position.lat; + io_position->lon = plane->position.lon; + io_position->elevation = plane->position.elevation; + io_position->pitch = plane->position.pitch; + io_position->roll = plane->position.roll; + io_position->heading = plane->position.heading; + std::strncpy(io_position->label, plane->label, sizeof(plane->label)); // fixme don't need to copy on every frame + return xpmpData_NewData; } case xpmpDataType_Surfaces: @@ -428,16 +327,6 @@ namespace XSwiftBus { const auto currentTime = QDateTime::currentMSecsSinceEpoch(); - if (! c_driverInterpolation) - { - while (! plane->pendingSurfaces.isEmpty() && plane->pendingSurfaces.constFirst().first <= currentTime) - { - //! \todo if gear is currently retracted, look ahead and pull gear position from pendingSurfaces up to 5 seconds in the future - plane->pendingSurfaces.constFirst().second(plane); - plane->pendingSurfaces.pop_front(); - } - } - if (plane->surfaces.gearPosition != plane->targetGearPosition) { // interpolate gear position diff --git a/src/xswiftbus/traffic.h b/src/xswiftbus/traffic.h index c8c313bef..fd094f554 100644 --- a/src/xswiftbus/traffic.h +++ b/src/xswiftbus/traffic.h @@ -14,9 +14,7 @@ #include "datarefs.h" #include "terrainprobe.h" -#include "blackmisc/aviation/aircraftsituationlist.h" -#include "blackmisc/aviation/aircraftpartslist.h" -#include "blackmisc/simulation/interpolatormulti.h" +#include #include #include #include @@ -106,16 +104,9 @@ namespace XSwiftBus //! Remove all traffic aircraft void removeAllPlanes(); - //! Add the position of a traffic aircraft - void addPlanePosition(const QString &callsign, double latitude, double longitude, double altitude, double pitch, double roll, double heading, qint64 relativeTime, qint64 timeOffset); - //! Set the position of a traffic aircraft void setPlanePosition(const QString &callsign, double latitude, double longitude, double altitude, double pitch, double roll, double heading); - //! Add the flight control surfaces and lights of a traffic aircraft - void 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, qint64 timeOffset); - //! Set the flight control surfaces and lights of a traffic aircraft void setPlaneSurfaces(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); @@ -123,9 +114,6 @@ namespace XSwiftBus //! Set the transponder of a traffic aircraft void setPlaneTransponder(const QString &callsign, int code, bool modeC, bool ident); - //! Set interpolation mode for a traffic aircraft - void setInterpolatorMode(const QString &callsign, bool spline); - //! Request traffic plane data. A signal remoteAircraftData will be emitted for each known plane void requestRemoteAircraftData(); @@ -133,8 +121,6 @@ namespace XSwiftBus bool m_initialized = false; bool m_enabled = false; - static constexpr bool c_driverInterpolation = true; - void emitSimFrame(); static int preferences(const char *section, const char *name, int def); @@ -151,10 +137,8 @@ namespace XSwiftBus bool hasSurfaces = false; bool hasXpdr = false; char label[32] {}; - BlackMisc::Simulation::CInterpolatorMulti interpolator; CTerrainProbe terrainProbe; XPMPPlaneSurfaces_t surfaces; - QVector>> pendingSurfaces; float targetGearPosition = 0; qint64 prevSurfacesLerpTime = 0; XPMPPlaneRadar_t xpdr;