From 1f3e5c6abfbcdb181dffd9a24df1fb2aa2ec5c14 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Fri, 27 Apr 2018 02:32:41 +0200 Subject: [PATCH] Formatting, minor tweaks --- src/blackcore/simulatorcommon.cpp | 17 +++++++++++++++-- src/blackcore/simulatorcommon.h | 3 +++ src/blackmisc/aviation/heading.h | 1 + src/blackmisc/pq/physicalquantity.cpp | 2 +- src/blackmisc/pq/speed.h | 5 ++--- .../simulation/airspaceaircraftsnapshot.h | 2 +- .../simulation/simulationenvironmentprovider.h | 1 + .../simulator/fsxcommon/simconnectobject.h | 5 ++++- .../simulator/fsxcommon/simulatorfsxcommon.cpp | 4 +++- .../simulator/fsxcommon/simulatorfsxcommon.h | 2 +- .../simulator/xplane/simulatorxplane.cpp | 5 ++--- 11 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/blackcore/simulatorcommon.cpp b/src/blackcore/simulatorcommon.cpp index d7c65523c..8db0d3902 100644 --- a/src/blackcore/simulatorcommon.cpp +++ b/src/blackcore/simulatorcommon.cpp @@ -41,7 +41,6 @@ using namespace BlackMisc::Simulation; using namespace BlackMisc::PhysicalQuantities; using namespace BlackMisc::Simulation; using namespace BlackMisc::Weather; -using namespace BlackCore; using namespace BlackCore::Db; namespace BlackCore @@ -317,8 +316,10 @@ namespace BlackCore this->stopHighlighting(); this->logicallyRemoveRemoteAircraft(callsign); if (!this->isAircraftInRange(callsign)) { return false; } + const QPointer myself(this); QTimer::singleShot(2500, this, [ = ] { + if (myself.isNull()) { return; } if (this->isShuttingDown()) { return; } if (!this->isAircraftInRange(callsign)) { return; } const CSimulatedAircraft aircraft = this->getAircraftInRangeForCallsign(callsign); @@ -583,6 +584,16 @@ namespace BlackCore m_timerId = -1; } + QString CSimulatorCommon::getInvalidSituationLogMessage(const CCallsign &callsign, const CInterpolationStatus &status, const QString &details) const + { + static const QString msg("Cs: '%1' Interpolation: '%2'"); + const QString m = msg.arg(callsign.asString(), status.toQString()); + if (details.isEmpty()) { return m; } + + static const QString addDetails(" details: '%1'"); + return m + addDetails.arg(details); + } + void CSimulatorCommon::onRecalculatedRenderedAircraft(const CAirspaceAircraftSnapshot &snapshot) { if (!snapshot.isValidSnapshot()) { return;} @@ -729,7 +740,7 @@ namespace BlackCore const PartsLog p = m_interpolationLogger.getLastPartsLog(cs); QString dm; - static const QString sep("\n"); + static const QString sep("\n------\n"); if (s.tsCurrent > 0) { dm = QStringLiteral("Setup: ") % s.usedSetup.toQString(true) % @@ -744,8 +755,10 @@ namespace BlackCore } const int t = 4500 + (qrand() % 1000); // makes sure not always using the same time difference + const QPointer myself(this); QTimer::singleShot(t, this, [ = ] { + if (myself.isNull()) { return; } this->displayLoggedSituationInSimulator(cs, stopLogging, times - 1); }); } diff --git a/src/blackcore/simulatorcommon.h b/src/blackcore/simulatorcommon.h index 6bdef72b7..ba14d31b9 100644 --- a/src/blackcore/simulatorcommon.h +++ b/src/blackcore/simulatorcommon.h @@ -198,6 +198,9 @@ namespace BlackCore //! Kill timer if id is valid void safeKillTimer(); + //! Info about invalid situation + QString getInvalidSituationLogMessage(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Simulation::CInterpolationStatus &status, const QString &details = {}) const; + bool m_pausedSimFreezesInterpolation = false; //!< paused simulator will also pause interpolation (so AI aircraft will hold) bool m_autoCalcAirportDistance = true; //!< automatically calculate airport distance and bearing int m_timerId = -1; //!< dispatch timer id diff --git a/src/blackmisc/aviation/heading.h b/src/blackmisc/aviation/heading.h index aa7df0570..17616ac92 100644 --- a/src/blackmisc/aviation/heading.h +++ b/src/blackmisc/aviation/heading.h @@ -99,5 +99,6 @@ namespace BlackMisc } // ns Q_DECLARE_METATYPE(BlackMisc::Aviation::CHeading) +Q_DECLARE_METATYPE(BlackMisc::Aviation::CHeading::ReferenceNorth) #endif // guard diff --git a/src/blackmisc/pq/physicalquantity.cpp b/src/blackmisc/pq/physicalquantity.cpp index e1b71eea6..0a201347d 100644 --- a/src/blackmisc/pq/physicalquantity.cpp +++ b/src/blackmisc/pq/physicalquantity.cpp @@ -357,7 +357,7 @@ namespace BlackMisc template QString CPhysicalQuantity::convertToQString(bool i18n) const { - if (this->isNull()) { return i18n ? QCoreApplication::translate("CPhysicalQuantity", "undefined") : "undefined"; } + if (this->isNull()) { return QStringLiteral("null"); } return this->valueRoundedWithUnit(this->getUnit(), -1, i18n); } diff --git a/src/blackmisc/pq/speed.h b/src/blackmisc/pq/speed.h index 0573692f0..0a3c4b183 100644 --- a/src/blackmisc/pq/speed.h +++ b/src/blackmisc/pq/speed.h @@ -19,7 +19,6 @@ namespace BlackMisc { namespace PhysicalQuantities { - /*! * Speed class, e.g. "m/s", "NM/h", "km/h", "ft/s" */ @@ -36,8 +35,8 @@ namespace BlackMisc CSpeed(const QString &unitString) : CPhysicalQuantity(unitString) {} }; - } -} + } // ns +} // ns Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CSpeed) diff --git a/src/blackmisc/simulation/airspaceaircraftsnapshot.h b/src/blackmisc/simulation/airspaceaircraftsnapshot.h index 189ca49da..60abe52dd 100644 --- a/src/blackmisc/simulation/airspaceaircraftsnapshot.h +++ b/src/blackmisc/simulation/airspaceaircraftsnapshot.h @@ -31,7 +31,7 @@ namespace BlackMisc { namespace Simulation { - //! Current situation in the sky analyzed. + //! Current situation in the skies analyzed. class BLACKMISC_EXPORT CAirspaceAircraftSnapshot : public CValueObject { public: diff --git a/src/blackmisc/simulation/simulationenvironmentprovider.h b/src/blackmisc/simulation/simulationenvironmentprovider.h index 60bb96a7d..39fb31320 100644 --- a/src/blackmisc/simulation/simulationenvironmentprovider.h +++ b/src/blackmisc/simulation/simulationenvironmentprovider.h @@ -15,6 +15,7 @@ #include "simulatorplugininfo.h" #include "aircraftmodel.h" #include "blackmisc/provider.h" +#include "blackmisc/pq/length.h" #include "blackmisc/geo/coordinategeodeticlist.h" #include "blackmisc/geo/elevationplane.h" diff --git a/src/plugins/simulator/fsxcommon/simconnectobject.h b/src/plugins/simulator/fsxcommon/simconnectobject.h index 7762cd031..3d57f0abd 100644 --- a/src/plugins/simulator/fsxcommon/simconnectobject.h +++ b/src/plugins/simulator/fsxcommon/simconnectobject.h @@ -121,9 +121,12 @@ namespace BlackSimPlugin //! Set Simconnect object id void setObjectId(DWORD id); - //! Set Simconnect object id + //! Get Simconnect object id DWORD getObjectId() const { return m_objectId; } + //! Get Simconnect object id + QString getObjectIdAsString() const { return QString::number(this->getObjectId()); } + //! Valid request id? bool hasValidRequestId() const { return m_validRequestId; } diff --git a/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp b/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp index a210ce55e..55503885c 100644 --- a/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp +++ b/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp @@ -723,8 +723,10 @@ namespace BlackSimPlugin if (!toBeAddedAircraft.isEmpty()) { const CSimulatedAircraft nextPendingAircraft(m_addPendingAircraft.front()); + const QPointer myself(this); QTimer::singleShot(100, this, [ = ] { + if (myself.isNull()) { return; } this->physicallyAddRemoteAircraftImpl(nextPendingAircraft, mode); }); } @@ -742,7 +744,7 @@ namespace BlackSimPlugin const CSimConnectObject simObject = m_simConnectObjects.getSimObjectForObjectId(objectID); if (!simObject.hasValidRequestAndObjectId()) { return false; } // object id from somewhere else const CCallsign callsign(simObject.getCallsign()); - Q_ASSERT_X(!callsign.isEmpty(), Q_FUNC_INFO, "missing callsign"); + Q_ASSERT_X(!callsign.isEmpty(), Q_FUNC_INFO, "Missing callsign for removed object"); if (simObject.isPendingRemoved()) { diff --git a/src/plugins/simulator/fsxcommon/simulatorfsxcommon.h b/src/plugins/simulator/fsxcommon/simulatorfsxcommon.h index 30b652338..7dd6b66c1 100644 --- a/src/plugins/simulator/fsxcommon/simulatorfsxcommon.h +++ b/src/plugins/simulator/fsxcommon/simulatorfsxcommon.h @@ -97,7 +97,7 @@ namespace BlackSimPlugin }; //! FSX Simulator Implementation - class CSimulatorFsxCommon : public BlackSimPlugin::FsCommon::CSimulatorFsCommon + class CSimulatorFsxCommon : public FsCommon::CSimulatorFsCommon { Q_OBJECT Q_INTERFACES(BlackCore::ISimulator) diff --git a/src/plugins/simulator/xplane/simulatorxplane.cpp b/src/plugins/simulator/xplane/simulatorxplane.cpp index 4e726d385..fda67f55f 100644 --- a/src/plugins/simulator/xplane/simulatorxplane.cpp +++ b/src/plugins/simulator/xplane/simulatorxplane.cpp @@ -721,12 +721,11 @@ namespace BlackSimPlugin } else { - CLogMessage(this).warning("Invalid situation for callsign: '%1' info: '%2'") - << callsign - << interpolatorStatus.toQString(); + CLogMessage(this).warning(this->getInvalidSituationLogMessage(callsign, interpolatorStatus)); } this->updateRemoteAircraftParts(xplaneAircraft, parts, partsStatus); + } // all callsigns const qint64 dt = QDateTime::currentMSecsSinceEpoch() - currentTimestamp;