From e50bb6d5c7993a670e0731ae99c05a55ad416897 Mon Sep 17 00:00:00 2001 From: Mat Sutcliffe Date: Sat, 25 Jan 2020 13:30:38 +0000 Subject: [PATCH] [xplane] Add monitoring of the number of minutes behind due to low FPS --- src/blackcore/simulator.cpp | 2 ++ src/blackcore/simulator.h | 4 ++++ src/blackgui/components/simulatorcomponent.cpp | 3 +++ src/plugins/simulator/xplane/simulatorxplane.cpp | 2 +- .../simulator/xplane/xswiftbusserviceproxy.cpp | 14 ++++++++------ .../simulator/xplane/xswiftbusserviceproxy.h | 4 ++-- .../org.swift_project.xswiftbus.service.xml | 1 + src/xswiftbus/plugin.cpp | 4 ++-- src/xswiftbus/service.cpp | 14 +++++++++----- src/xswiftbus/service.h | 7 ++++--- 10 files changed, 36 insertions(+), 19 deletions(-) diff --git a/src/blackcore/simulator.cpp b/src/blackcore/simulator.cpp index 55ec0e528..f46a16910 100644 --- a/src/blackcore/simulator.cpp +++ b/src/blackcore/simulator.cpp @@ -262,6 +262,7 @@ namespace BlackCore m_averageFps = -1.0; m_simTimeRatio = 1.0; m_trackMilesShort = 0.0; + m_minutesLate = 0.0; } bool ISimulator::isUpdateAllRemoteAircraft(qint64 currentTimestamp) const @@ -1039,6 +1040,7 @@ namespace BlackCore m_averageFps = -1.0; m_simTimeRatio = 1.0; m_trackMilesShort = 0.0; + m_minutesLate = 0.0; return true; } diff --git a/src/blackcore/simulator.h b/src/blackcore/simulator.h index 2dc35ac90..8eaee10df 100644 --- a/src/blackcore/simulator.h +++ b/src/blackcore/simulator.h @@ -224,6 +224,9 @@ namespace BlackCore //! Number of track miles over-reported, due to low FPS double getTrackMilesShort() const { return m_trackMilesShort; } + //! Number of minutes behind scedule, due to low FPS + double getMinutesLate() const { return m_minutesLate; } + //! Send situation/parts for testing virtual bool testSendSituationAndParts(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Aviation::CAircraftSituation &situation, const BlackMisc::Aviation::CAircraftParts &parts) = 0; @@ -587,6 +590,7 @@ namespace BlackCore double m_averageFps = -1.0; //!< FPS double m_simTimeRatio = 1.0; //!< ratio of simulation time to real time, due to low FPS (X-Plane) double m_trackMilesShort = 0.0; //!< difference between real and reported groundspeed, multiplied by time + double m_minutesLate = 0.0; //!< difference between real and reported groundspeed, integrated over time qint64 m_updateAllRemoteAircraftUntil = 0; //!< force an update of all remote aircraft, used when own aircraft is moved, paused to make sure all remote aircraft are updated qint64 m_statsUpdateAircraftTimeTotalMs = 0; //!< statistics total update time qint64 m_statsCurrentUpdateTimeMs = 0; //!< statistics current update time diff --git a/src/blackgui/components/simulatorcomponent.cpp b/src/blackgui/components/simulatorcomponent.cpp index 1f16bd61e..b62d7924c 100644 --- a/src/blackgui/components/simulatorcomponent.cpp +++ b/src/blackgui/components/simulatorcomponent.cpp @@ -157,6 +157,9 @@ namespace BlackGui const double miles = sGui->getISimulator()->getTrackMilesShort(); this->addOrUpdateLiveDataByName(QStringLiteral("Miles Short"), QString::number(miles, 'f', 1), CIconList::allIcons().findByIndex(CIcons::ApplicationSimulator)); + + const double minutes = sGui->getISimulator()->getMinutesLate(); + this->addOrUpdateLiveDataByName(QStringLiteral("Minutes Late"), QString::number(minutes, 'f', 1), CIconList::allIcons().findByIndex(CIcons::ApplicationSimulator)); } } diff --git a/src/plugins/simulator/xplane/simulatorxplane.cpp b/src/plugins/simulator/xplane/simulatorxplane.cpp index de1c43dd0..73a0350ba 100644 --- a/src/plugins/simulator/xplane/simulatorxplane.cpp +++ b/src/plugins/simulator/xplane/simulatorxplane.cpp @@ -369,7 +369,7 @@ namespace BlackSimPlugin if ((m_slowTimerCalls % 5u) == 0u) { // reading FPS resets average, so we only monitor over some time - m_serviceProxy->getFrameStats(&m_averageFps, &m_simTimeRatio, &m_trackMilesShort); + m_serviceProxy->getFrameStats(&m_averageFps, &m_simTimeRatio, &m_trackMilesShort, &m_minutesLate); } } } diff --git a/src/plugins/simulator/xplane/xswiftbusserviceproxy.cpp b/src/plugins/simulator/xplane/xswiftbusserviceproxy.cpp index 5aec10f49..387481c71 100644 --- a/src/plugins/simulator/xplane/xswiftbusserviceproxy.cpp +++ b/src/plugins/simulator/xplane/xswiftbusserviceproxy.cpp @@ -319,32 +319,34 @@ namespace BlackSimPlugin m_dbusInterface->callDBusAsync(QLatin1String("isUsingRealTime"), setterCallback(o_isRealTime)); } - void CXSwiftBusServiceProxy::getFrameStats(double *o_averageFps, double *o_simTimeRatio, double *o_trackMilesLost) const + void CXSwiftBusServiceProxy::getFrameStats(double *o_averageFps, double *o_simTimeRatio, double *o_trackMilesShort, double *o_minutesLate) const { std::function callback = [ = ](QDBusPendingCallWatcher * watcher) { - QDBusPendingReply reply = *watcher; + QDBusPendingReply reply = *watcher; if (!reply.isError()) { *o_averageFps = reply.argumentAt<0>(); *o_simTimeRatio = reply.argumentAt<1>(); - *o_trackMilesLost = reply.argumentAt<2>(); + *o_trackMilesShort = reply.argumentAt<2>(); + *o_minutesLate = reply.argumentAt<3>(); } watcher->deleteLater(); }; m_dbusInterface->callDBusAsync(QLatin1String("getFrameStats"), callback)->waitForFinished(); } - void CXSwiftBusServiceProxy::getFrameStatsAsync(double *o_averageFps, double *o_simTimeRatio, double *o_trackMilesLost) + void CXSwiftBusServiceProxy::getFrameStatsAsync(double *o_averageFps, double *o_simTimeRatio, double *o_trackMilesShort, double *o_minutesLate) { std::function callback = [ = ](QDBusPendingCallWatcher * watcher) { - QDBusPendingReply reply = *watcher; + QDBusPendingReply reply = *watcher; if (!reply.isError()) { *o_averageFps = reply.argumentAt<0>(); *o_simTimeRatio = reply.argumentAt<1>(); - *o_trackMilesLost = reply.argumentAt<2>(); + *o_trackMilesShort = reply.argumentAt<2>(); + *o_minutesLate = reply.argumentAt<3>(); } watcher->deleteLater(); }; diff --git a/src/plugins/simulator/xplane/xswiftbusserviceproxy.h b/src/plugins/simulator/xplane/xswiftbusserviceproxy.h index da2d7abca..822d6a1a1 100644 --- a/src/plugins/simulator/xplane/xswiftbusserviceproxy.h +++ b/src/plugins/simulator/xplane/xswiftbusserviceproxy.h @@ -210,8 +210,8 @@ namespace BlackSimPlugin //! \copydoc XSwiftBus::CService::getFrameStats //! @{ - void getFrameStats(double *o_averageFps, double *o_simTimeRatio, double *o_trackMilesLost) const; - void getFrameStatsAsync(double *o_averageFps, double *o_simTimeRatio, double *o_trackMilesLost); + void getFrameStats(double *o_averageFps, double *o_simTimeRatio, double *o_trackMilesShort, double *o_minutesLate) const; + void getFrameStatsAsync(double *o_averageFps, double *o_simTimeRatio, double *o_trackMilesShort, double *o_minutesLate); //! @} //! \copydoc XSwiftBus::CService::getLatitudeDeg diff --git a/src/xswiftbus/org.swift_project.xswiftbus.service.xml b/src/xswiftbus/org.swift_project.xswiftbus.service.xml index cf66e6030..9b3324143 100644 --- a/src/xswiftbus/org.swift_project.xswiftbus.service.xml +++ b/src/xswiftbus/org.swift_project.xswiftbus.service.xml @@ -67,6 +67,7 @@ R"XML( + diff --git a/src/xswiftbus/plugin.cpp b/src/xswiftbus/plugin.cpp index 04092dbc4..216914528 100644 --- a/src/xswiftbus/plugin.cpp +++ b/src/xswiftbus/plugin.cpp @@ -161,7 +161,7 @@ namespace XSwiftBus if (m_service) { m_service->onAircraftModelChanged(); - m_service->resetMilesLost(); + m_service->resetFrameTotals(); } } @@ -170,7 +170,7 @@ namespace XSwiftBus if (m_service) { m_service->updateAirportsInRange(); - m_service->resetMilesLost(); + m_service->resetFrameTotals(); } } diff --git a/src/xswiftbus/service.cpp b/src/xswiftbus/service.cpp index 4d915faf2..6a8647192 100644 --- a/src/xswiftbus/service.cpp +++ b/src/xswiftbus/service.cpp @@ -35,23 +35,25 @@ namespace XSwiftBus float m_total = 0; float m_totalOverBudget = 0; float m_totalMetersShort = 0; + float m_totalSecondsLate = 0; size_t m_lastSampleIndex = 0; static constexpr size_t c_maxSampleCount = 500; static constexpr float c_framePeriodBudget = 0.05f; FramePeriodSampler() : CDrawable(xplm_Phase_LastCockpit, false) {} - std::tuple getFrameStats() + std::tuple getFrameStats() { if (m_total == 0) { return {}; } const float fps = m_samples.size() / m_total; const float ratio = 1 - m_totalOverBudget / m_total; const float miles = m_totalMetersShort / 1852.0f; + const float minutes = m_totalSecondsLate / 60.0f; m_total = 0; m_totalOverBudget = 0; m_samples.clear(); m_lastSampleIndex = 0; - return std::make_tuple(fps, ratio, miles); + return std::make_tuple(fps, ratio, miles, minutes); } protected: @@ -80,6 +82,7 @@ namespace XSwiftBus const float metersShort = m_groundSpeed.get() * std::max(0.0f, current - c_framePeriodBudget); m_totalMetersShort += metersShort; + if (m_groundSpeed.get() > 1.0f) { m_totalSecondsLate += std::max(0.0f, current - c_framePeriodBudget); } } }; @@ -118,14 +121,14 @@ namespace XSwiftBus return XSWIFTBUS_COMMIT; } - std::tuple CService::getFrameStats() + std::tuple CService::getFrameStats() { if (!m_framePeriodSampler) { return {}; } const auto result = m_framePeriodSampler->getFrameStats(); - return std::make_tuple(static_cast(std::get<0>(result)), static_cast(std::get<1>(result)), static_cast(std::get<2>(result))); + return std::make_tuple(static_cast(std::get<0>(result)), static_cast(std::get<1>(result)), static_cast(std::get<2>(result)), static_cast(std::get<3>(result))); } - void CService::resetMilesLost() + void CService::resetFrameTotals() { if (m_framePeriodSampler) { @@ -590,6 +593,7 @@ namespace XSwiftBus reply.appendArgument(std::get<0>(stats)); reply.appendArgument(std::get<1>(stats)); reply.appendArgument(std::get<2>(stats)); + reply.appendArgument(std::get<3>(stats)); sendDBusMessage(reply); }); } diff --git a/src/xswiftbus/service.h b/src/xswiftbus/service.h index 74b518cdf..3eab7b76f 100644 --- a/src/xswiftbus/service.h +++ b/src/xswiftbus/service.h @@ -114,11 +114,12 @@ namespace XSwiftBus //! or since this function was last called, whichever is later. //! Second part is the average simulation time ratio during the same period. //! Third part is the total track miles over-reported during the same period. + //! Fourth part is the total minutes behind scedule during the same period. //! \return Zero if no samples were collected since this function was last called. - std::tuple getFrameStats(); + std::tuple getFrameStats(); - //! Reset the monitoring of total track miles lost due to low frame rate. - void resetMilesLost(); + //! Reset the monitoring of total miles and minutes lost due to low frame rate. + void resetFrameTotals(); //! Get aircraft latitude in degrees double getLatitudeDeg() const { return m_latitude.get(); }