From cb422d72cfd69bdb4e18cd6d80fb54b48841432c Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sat, 17 Nov 2018 23:03:30 +0100 Subject: [PATCH] Misc. style issues interpolation/model adding --- src/blackcore/aircraftmatcher.cpp | 2 +- src/blackcore/simulator.cpp | 6 ++--- src/blackmisc/simulation/aircraftmodel.cpp | 15 +++--------- .../simulation/fscommon/aircraftcfgparser.cpp | 2 +- src/blackmisc/simulation/interpolator.cpp | 2 +- .../simulation/interpolatorspline.cpp | 3 ++- .../fsxcommon/simulatorfsxcommon.cpp | 24 +++++++++---------- .../simulator/fsxcommon/simulatorfsxcommon.h | 2 +- .../fsxcommon/simulatorfsxsimconnectproc.cpp | 13 ++++++---- 9 files changed, 32 insertions(+), 37 deletions(-) diff --git a/src/blackcore/aircraftmatcher.cpp b/src/blackcore/aircraftmatcher.cpp index 8ac8e6bd5..95c710e15 100644 --- a/src/blackcore/aircraftmatcher.cpp +++ b/src/blackcore/aircraftmatcher.cpp @@ -229,7 +229,7 @@ namespace BlackCore break; } BLACK_FALLTHROUGH; - case CAircraftMatcherSetup::PickFirst: + case CAircraftMatcherSetup::PickFirst: // fallthru intentionally default: usedStrategy = CAircraftMatcherSetup::PickFirst; // re-assigned if fall-through matchedModel = candidates.front(); diff --git a/src/blackcore/simulator.cpp b/src/blackcore/simulator.cpp index c1aecd681..5d3048207 100644 --- a/src/blackcore/simulator.cpp +++ b/src/blackcore/simulator.cpp @@ -233,7 +233,7 @@ namespace BlackCore void ISimulator::reset() { - this->clearAllRemoteAircraftData(); + this->clearAllRemoteAircraftData(); // reset } bool ISimulator::isUpdateAllRemoteAircraft(qint64 currentTimestamp) const @@ -489,7 +489,7 @@ namespace BlackCore { this->physicallyRemoveAllRemoteAircraft(); const CStatusMessageList msgs = this->debugVerifyStateAfterAllAircraftRemoved(); - this->clearAllRemoteAircraftData(); + this->clearAllRemoteAircraftData(); // "dot command" if (!msgs.isEmpty()) { emit this->driverMessages(msgs); } const CSimulatedAircraftList aircraft = this->getAircraftInRange(); for (const CSimulatedAircraft &a : aircraft) @@ -734,7 +734,7 @@ namespace BlackCore const int r = this->physicallyRemoveMultipleRemoteAircraft(callsigns); // leave no trash - this->clearAllRemoteAircraftData(); + this->clearAllRemoteAircraftData(); // remove all aircraft return r; } diff --git a/src/blackmisc/simulation/aircraftmodel.cpp b/src/blackmisc/simulation/aircraftmodel.cpp index 4638be062..e182786b0 100644 --- a/src/blackmisc/simulation/aircraftmodel.cpp +++ b/src/blackmisc/simulation/aircraftmodel.cpp @@ -927,28 +927,19 @@ namespace BlackMisc if (!aircraftIcao.isLoadedFromDb()) { - if (idAircraftIcao >= 0) - { - aircraftIcao.setDbKey(idAircraftIcao); - } + if (idAircraftIcao >= 0) { aircraftIcao.setDbKey(idAircraftIcao); } } if (!livery.isLoadedFromDb()) { const int idLivery = json.value(prefix % QStringLiteral("idlivery")).toInt(-1); - if (idLivery >= 0) - { - livery.setDbKey(idLivery); - } + if (idLivery >= 0) { livery.setDbKey(idLivery); } } if (!distributor.isLoadedFromDb()) { const QString idDistributor = json.value(prefix % QStringLiteral("iddistributor")).toString(); - if (!idDistributor.isEmpty()) - { - distributor.setDbKey(idDistributor); - } + if (!idDistributor.isEmpty()) { distributor.setDbKey(idDistributor); } } if (!cachedAircraftIcao && aircraftIcao.isLoadedFromDb()) { aircraftIcaos[aircraftIcao.getDbKey()] = aircraftIcao; } diff --git a/src/blackmisc/simulation/fscommon/aircraftcfgparser.cpp b/src/blackmisc/simulation/fscommon/aircraftcfgparser.cpp index 8ce329c9b..f8c9a3847 100644 --- a/src/blackmisc/simulation/fscommon/aircraftcfgparser.cpp +++ b/src/blackmisc/simulation/fscommon/aircraftcfgparser.cpp @@ -217,7 +217,7 @@ namespace BlackMisc CAircraftCfgEntriesList CAircraftCfgParser::performParsingOfSingleFile(const QString &fileName, bool &ok, CStatusMessageList &msgs) { - // due to the filter we expect only "aircraft.cfg" here + // due to the filter we expect only "aircraft.cfg" files here // remark: in a 1st version I have used QSettings to parse to file as ini file // unfortunately some files are malformed which could end up in wrong data diff --git a/src/blackmisc/simulation/interpolator.cpp b/src/blackmisc/simulation/interpolator.cpp index 61ff04fd8..8174c51b0 100644 --- a/src/blackmisc/simulation/interpolator.cpp +++ b/src/blackmisc/simulation/interpolator.cpp @@ -118,7 +118,7 @@ namespace BlackMisc // oldest last, null ignored if (!latest.isNull()) { situations.push_back(latest); } - if (!newer.isNull()) { situations.push_back(newer); } + if (!newer.isNull()) { situations.push_back(newer); } if (!oldest.isNull()) { situations.push_back(oldest); } const bool sorted = situations.isSortedAdjustedLatestFirstWithoutNullPositions(); diff --git a/src/blackmisc/simulation/interpolatorspline.cpp b/src/blackmisc/simulation/interpolatorspline.cpp index 6bc91c85a..dc7829edc 100644 --- a/src/blackmisc/simulation/interpolatorspline.cpp +++ b/src/blackmisc/simulation/interpolatorspline.cpp @@ -142,13 +142,14 @@ namespace BlackMisc if (m_currentSituations.isEmpty()) { return false; } // and use the real values if available + // m_s[0] .. oldest -> m_[2] .. latest const CAircraftSituation latest = m_currentSituations.front(); if (latest.isNewerThanAdjusted(m_s[1])) { m_s[2] = latest; } const qint64 currentAdjusted = m_s[1].getAdjustedMSecsSinceEpoch(); const CAircraftSituation older = m_currentSituations.findObjectBeforeAdjustedOrDefault(currentAdjusted); if (!older.isNull()) { m_s[0] = older; } const qint64 latestAdjusted = m_s[2].getAdjustedMSecsSinceEpoch(); - const qint64 olderAdjusted = m_s[0].getAdjustedMSecsSinceEpoch(); + const qint64 olderAdjusted = m_s[0].getAdjustedMSecsSinceEpoch(); // not having a new situation itself is quite normal, // only if it persits it is critical. diff --git a/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp b/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp index 1c49063ec..082cfe1ab 100644 --- a/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp +++ b/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp @@ -674,7 +674,7 @@ namespace BlackSimPlugin } // slower updates - if (m_ownAircraftUpdate % 10 == 0) + if (m_ownAircraftUpdateCycles % 10 == 0) { if (m_isWeatherActivated) { @@ -694,7 +694,7 @@ namespace BlackSimPlugin // init terrain probes here has the advantage we can also switch it on/off at runtime if (m_useFsxTerrainProbe && !m_initFsxTerrainProbes) { - this->physicallyInitAITerrainProbes(position, 2); + this->physicallyInitAITerrainProbes(position, 2); // init probe } // SB4 offsets @@ -702,7 +702,7 @@ namespace BlackSimPlugin m_simulatorInternals.setValue(QStringLiteral("fsx/sb4packets"), m_useSbOffsets ? QString::number(m_sbDataReceived) : QStringLiteral("disabled")); } - m_ownAircraftUpdate++; // with 50updates/sec long enough even for 32bit + m_ownAircraftUpdateCycles++; // with 50updates/sec long enough even for 32bit } void CSimulatorFsxCommon::triggerUpdateRemoteAircraftFromSimulator(const CSimConnectObject &simObject, const DataDefinitionPosData &remoteAircraftData) @@ -827,9 +827,9 @@ namespace BlackSimPlugin const QPointer myself(this); QTimer::singleShot(1000, this, [ = ] { - // also triggers new add if required - if (!myself) { return; } - if (this->isShuttingDownOrDisconnected()) { return; } + // verify aircraft and also triggers new add if required + // do not do this in the event loop, so we do this deferred + if (!myself || this->isShuttingDownOrDisconnected()) { return; } this->verifyAddedRemoteAircraft(verifyAircraft); }); return true; @@ -922,7 +922,7 @@ namespace BlackSimPlugin emit this->physicallyAddingRemoteModelFailed(CSimulatedAircraft(), false, msg); } - // trigger new adding from pending if any + // trigger adding pending aircraft if there are any if (!m_addPendingAircraft.isEmpty()) { this->addPendingAircraftAfterAdded(); @@ -1020,7 +1020,7 @@ namespace BlackSimPlugin // no simObject reference outside that block, because it will be deleted { CSimConnectObject &simObject = m_simConnectObjects[remoteAircraftIn.getCallsign()]; - simObject.setConfirmedAdded(true); + simObject.setConfirmedAdded(true); // terrain probe simObject.resetTimestampToNow(); cs = simObject.getCallsign(); CLogMessage(this).info("Probe: '%1' '%2' confirmed, %3") << simObject.getCallsignAsString() << simObject.getAircraftModelString() << simObject.toQString(); @@ -1052,7 +1052,7 @@ namespace BlackSimPlugin void CSimulatorFsxCommon::addPendingAircraftAfterAdded() { - this->addPendingAircraft(AddAfterAdded); + this->addPendingAircraft(AddAfterAdded); // addPendingAircraft is already "non blocking" } void CSimulatorFsxCommon::addPendingAircraft(AircraftAddMode mode) @@ -2003,8 +2003,8 @@ namespace BlackSimPlugin { // MSFS has inverted pitch and bank angles SIMCONNECT_DATA_PBH pbh; - pbh.Pitch = -situation.getPitch().value(CAngleUnit::deg()); - pbh.Bank = -situation.getBank().value(CAngleUnit::deg()); + pbh.Pitch = -situation.getPitch().value(CAngleUnit::deg()); + pbh.Bank = -situation.getBank().value(CAngleUnit::deg()); pbh.Heading = situation.getHeading().value(CAngleUnit::deg()); return pbh; } @@ -2213,7 +2213,7 @@ namespace BlackSimPlugin m_sbDataReceived = 0; m_syncTimeDeferredCounter = 0; m_skipCockpitUpdateCycles = 0; - m_ownAircraftUpdate = 0; + m_ownAircraftUpdateCycles = 0; m_requestIdSimObjAircraft = static_cast(RequestSimObjAircraftStart); m_dispatchErrors = 0; m_receiveExceptionCount = 0; diff --git a/src/plugins/simulator/fsxcommon/simulatorfsxcommon.h b/src/plugins/simulator/fsxcommon/simulatorfsxcommon.h index 2e9f883dd..8ff8e9ddd 100644 --- a/src/plugins/simulator/fsxcommon/simulatorfsxcommon.h +++ b/src/plugins/simulator/fsxcommon/simulatorfsxcommon.h @@ -564,7 +564,7 @@ namespace BlackSimPlugin int m_sbDataReceived = 0; //!< SB4 area data received int m_syncTimeDeferredCounter = 0; //!< Set when synchronized, used to wait some time int m_skipCockpitUpdateCycles = 0; //!< skip some update cycles to allow changes in simulator cockpit to be set - int m_ownAircraftUpdate = 0; //!< own aircraft update + int m_ownAircraftUpdateCycles = 0; //!< own aircraft update // tracing dispatch performance int m_dispatchErrors = 0; //!< number of dispatched failed, \sa dispatch diff --git a/src/plugins/simulator/fsxcommon/simulatorfsxsimconnectproc.cpp b/src/plugins/simulator/fsxcommon/simulatorfsxsimconnectproc.cpp index 8a779b752..48671dc2c 100644 --- a/src/plugins/simulator/fsxcommon/simulatorfsxsimconnectproc.cpp +++ b/src/plugins/simulator/fsxcommon/simulatorfsxsimconnectproc.cpp @@ -48,10 +48,10 @@ namespace BlackSimPlugin case SIMCONNECT_RECV_ID_OPEN: { SIMCONNECT_RECV_OPEN *event = static_cast(pData); - const QString simConnectVersion = QString("%1.%2.%3.%4").arg(event->dwSimConnectVersionMajor).arg(event->dwSimConnectVersionMinor).arg(event->dwSimConnectBuildMajor).arg(event->dwSimConnectBuildMinor); - const QString version = QString("%1.%2.%3.%4").arg(event->dwApplicationVersionMajor).arg(event->dwApplicationVersionMinor).arg(event->dwApplicationBuildMajor).arg(event->dwApplicationBuildMinor); - const QString name = CSimulatorFsxCommon::fsxCharToQString(event->szApplicationName); - const QString details = QString("Name: '%1' Version: %2 SimConnect: %3").arg(name, version, simConnectVersion); + const QString simConnectVersion = QStringLiteral("%1.%2.%3.%4").arg(event->dwSimConnectVersionMajor).arg(event->dwSimConnectVersionMinor).arg(event->dwSimConnectBuildMajor).arg(event->dwSimConnectBuildMinor); + const QString version = QStringLiteral("%1.%2.%3.%4").arg(event->dwApplicationVersionMajor).arg(event->dwApplicationVersionMinor).arg(event->dwApplicationBuildMajor).arg(event->dwApplicationBuildMinor); + const QString name = CSimulatorFsxCommon::fsxCharToQString(event->szApplicationName); + const QString details = QStringLiteral("Name: '%1' Version: %2 SimConnect: %3").arg(name, version, simConnectVersion); simulatorFsxP3D->setSimulatorDetails(name, details, version); simulatorFsxP3D->m_simConnectVersion = simConnectVersion; CLogMessage(simulatorFsxP3D).info("Connected to %1: '%2'") << simulatorFsxP3D->getSimulatorPluginInfo().getIdentifier() << details; @@ -179,7 +179,10 @@ namespace BlackSimPlugin case SystemEventObjectRemoved: simulatorFsxP3D->simulatorReportedObjectRemoved(objectId); break; - case SystemEventObjectAdded: // added in SIMCONNECT_RECV_ID_ASSIGNED_OBJECT_ID + case SystemEventObjectAdded: + // added in SIMCONNECT_RECV_ID_ASSIGNED_OBJECT_ID + // this event here is normally received before SIMCONNECT_RECV_ID_ASSIGNED_OBJECT_ID + break; default: break; }