diff --git a/src/blackcore/simulatorcommon.cpp b/src/blackcore/simulatorcommon.cpp index d2394afb1..e6e0de4cc 100644 --- a/src/blackcore/simulatorcommon.cpp +++ b/src/blackcore/simulatorcommon.cpp @@ -609,6 +609,23 @@ namespace BlackCore return m + addDetails.arg(details); } + bool CSimulatorCommon::clampedLog(const CCallsign &callsign, const CStatusMessage &message) + { + if (message.isEmpty()) { return false; } + constexpr qint64 Timeout = 2000; + const qint64 clampTs = m_clampedLogMsg.value(callsign, -1); + const qint64 ts = QDateTime::currentMSecsSinceEpoch(); + if (clampTs > 0 && ((clampTs + Timeout) > ts)) { return false; } + CLogMessage::preformatted(message); + m_clampedLogMsg[callsign] = ts; + return true; + } + + void CSimulatorCommon::removedClampedLog(const CCallsign &callsign) + { + m_clampedLogMsg.remove(callsign); + } + void CSimulatorCommon::onRecalculatedRenderedAircraft(const CAirspaceAircraftSnapshot &snapshot) { if (!snapshot.isValidSnapshot()) { return;} @@ -690,6 +707,7 @@ namespace BlackCore // rendering related stuff m_addAgainAircraftWhenRemoved.clear(); m_callsignsToBeRendered.clear(); + m_clampedLogMsg.clear(); this->resetHighlighting(); this->resetAircraftStatistics(); @@ -728,6 +746,7 @@ namespace BlackCore void CSimulatorCommon::callPhysicallyRemoveRemoteAircraft(const CCallsign &remoteCallsign) { m_statsPhysicallyRemovedAircraft++; + m_clampedLogMsg.clear(); this->physicallyRemoveRemoteAircraft(remoteCallsign); } diff --git a/src/blackcore/simulatorcommon.h b/src/blackcore/simulatorcommon.h index 639f17650..1af6e4b96 100644 --- a/src/blackcore/simulatorcommon.h +++ b/src/blackcore/simulatorcommon.h @@ -202,14 +202,28 @@ namespace BlackCore //! 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 - int m_statsUpdateAircraftCountMs = 0; //!< statistics update count - qint64 m_statsUpdateAircraftTimeTotalMs = 0; //!< statistics update time - qint64 m_statsUpdateAircraftTimeAvgMs = 0; //!< statistics update time - BlackMisc::Simulation::CSimulatorInternals m_simulatorInternals; //!< setup object - BlackMisc::Simulation::CInterpolationLogger m_interpolationLogger; //!< log interpolation + //! Can a new log message be generated without generating a "message" overflow + //! \remark works per callsign + //! \remark use this function when there is a risk that a lot of log. messages will be generated in a short time + bool clampedLog(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::CStatusMessage &message); + + //! Mark as justed logged + //! \remark touch, but also return if it can be logged + //! \remark use this function when there is a risk that a lot of log. messages will be generated in a short time + void removedClampedLog(const BlackMisc::Aviation::CCallsign &callsign); + + //! Lookup against DB data + static BlackMisc::Simulation::CAircraftModel reverseLookupModel(const BlackMisc::Simulation::CAircraftModel &model); + + 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 + int m_statsUpdateAircraftCountMs = 0; //!< statistics update count + qint64 m_statsUpdateAircraftTimeTotalMs = 0; //!< statistics update time + qint64 m_statsUpdateAircraftTimeAvgMs = 0; //!< statistics update time + BlackMisc::Simulation::CSimulatorInternals m_simulatorInternals; //!< setup object + BlackMisc::Simulation::CInterpolationLogger m_interpolationLogger; //!< log interpolation + QMap m_clampedLogMsg; //!< when logged last so there, can be used so there is no log message overflow // some optional functionality which can be used by the simulators as needed BlackMisc::Simulation::CSimulatedAircraftList m_addAgainAircraftWhenRemoved; //!< add this model again when removed, normally used to change model @@ -219,9 +233,6 @@ namespace BlackCore BlackMisc::Geo::CCoordinateGeodetic m_lastWeatherPosition; //!< Own aircraft position at which weather was fetched and injected last BlackMisc::CSetting m_weatherScenarioSettings { this, &CSimulatorCommon::reloadWeatherSettings }; //!< Selected weather scenario - //! Lookup against DB data - static BlackMisc::Simulation::CAircraftModel reverseLookupModel(const BlackMisc::Simulation::CAircraftModel &model); - private: // remote aircraft provider ("rap") bound void rapOnRecalculatedRenderedAircraft(const BlackMisc::Simulation::CAirspaceAircraftSnapshot &snapshot); diff --git a/src/blackmisc/simulation/interpolator.cpp b/src/blackmisc/simulation/interpolator.cpp index ec4a16e0d..46a58bdcb 100644 --- a/src/blackmisc/simulation/interpolator.cpp +++ b/src/blackmisc/simulation/interpolator.cpp @@ -372,16 +372,20 @@ namespace BlackMisc this->getAndFetchModelCG(); // update CG } - m_currentInterpolationStatus.setSituationsCount(m_currentSituations.size()); + bool success = false; + const int situationsSize = m_currentSituations.sizeInt(); + m_currentInterpolationStatus.setSituationsCount(situationsSize); if (m_currentSituations.isEmpty()) { + const bool inRange = this->isAircraftInRange(m_callsign); m_lastInterpolation = CAircraftSituation::null(); // no interpolation possible for that step - m_currentInterpolationStatus.setExtraInfo(this->isAircraftInRange(m_callsign) ? + m_currentInterpolationStatus.setExtraInfo(inRange ? QString("No situations, but remote aircraft '%1'").arg(m_callsign.asString()) : QString("Unknown remote aircraft: '%1'").arg(m_callsign.asString())); } else { + success = true; m_interpolatedSituationsCounter++; // with the latest updates of T243 the order and the offsets are supposed to be correct @@ -393,7 +397,7 @@ namespace BlackMisc } } - return true; + return success; } template diff --git a/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp b/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp index b64101832..0480e424a 100644 --- a/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp +++ b/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp @@ -949,6 +949,15 @@ namespace BlackSimPlugin situation = situations.findClosestTimeDistanceAdjusted(QDateTime::currentMSecsSinceEpoch()); Q_ASSERT_X(!situation.isPositionOrAltitudeNull(), Q_FUNC_INFO, "Invalid situation for new aircraft"); } + + const bool validSituation = situation.isPositionOrAltitudeNull(); + canAdd = validSituation; + if (CBuildConfig::isLocalDeveloperDebugBuild()) + { + BLACK_VERIFY_X(validSituation, Q_FUNC_INFO, "Expect valid situation"); + const CStatusMessage sm = CStatusMessage(this).warning("Invalid situation for '%1'") << callsign; + this->clampedLog(callsign, sm); + } } // check if we can add, do not add if simulator is stopped or other objects pending @@ -1267,6 +1276,7 @@ namespace BlackSimPlugin if (hr == S_OK) { if (m_traceSendId) { this->traceSendId(simObject.getObjectId(), Q_FUNC_INFO); } + this->removedClampedLog(callsign); } else { @@ -1277,7 +1287,9 @@ namespace BlackSimPlugin else { static const QString so("SimObject id: %1"); - CLogMessage(this).warning(this->getInvalidSituationLogMessage(callsign, result.getInterpolationStatus(), so.arg(simObject.getObjectId()))); + const QString msg = this->getInvalidSituationLogMessage(callsign, result.getInterpolationStatus(), so.arg(simObject.getObjectId())); + const CStatusMessage sm(this, CStatusMessage::SeverityWarning, msg); + this->clampedLog(callsign, sm); } // Interpolated parts