Issue #37 Emit signal when FPS drops below threshold

This commit is contained in:
Mat Sutcliffe
2021-08-09 00:10:30 +01:00
parent 14e03bd4b5
commit f311906d04
5 changed files with 27 additions and 1 deletions

View File

@@ -120,6 +120,9 @@ namespace BlackCore
//! A formerly vital driver is no longer vital/responding //! A formerly vital driver is no longer vital/responding
void vitalityLost(); void vitalityLost();
//! Frame rate has fallen too far below the threshold to maintain consistent sim rate
void insufficientFrameRateDetected(bool fatal);
//! Render restrictions have been changed //! Render restrictions have been changed
void renderRestrictionsChanged(bool restricted, bool enabled, int maxAircraft, const BlackMisc::PhysicalQuantities::CLength &maxRenderedDistance); void renderRestrictionsChanged(bool restricted, bool enabled, int maxAircraft, const BlackMisc::PhysicalQuantities::CLength &maxRenderedDistance);

View File

@@ -534,6 +534,10 @@ namespace BlackCore
c = connect(simulator, &ISimulator::autoPublishDataWritten, this, &IContextSimulator::autoPublishDataWritten); c = connect(simulator, &ISimulator::autoPublishDataWritten, this, &IContextSimulator::autoPublishDataWritten);
Q_ASSERT(c); Q_ASSERT(c);
// disconnect for X-Plane FPS below 20
c = connect(simulator, &ISimulator::insufficientFrameRateDetected, this, &IContextSimulator::insufficientFrameRateDetected);
Q_ASSERT(c);
// log from context to simulator // log from context to simulator
c = connect(CLogHandler::instance(), &CLogHandler::localMessageLogged, this, &CContextSimulator::relayStatusMessageToSimulator); c = connect(CLogHandler::instance(), &CLogHandler::localMessageLogged, this, &CContextSimulator::relayStatusMessageToSimulator);
Q_ASSERT(c); Q_ASSERT(c);

View File

@@ -104,6 +104,9 @@ namespace BlackCore
s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(), s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(),
"validatedModelSet", this, SIGNAL(validatedModelSet(BlackMisc::Simulation::CSimulatorInfo, BlackMisc::Simulation::CAircraftModelList, BlackMisc::Simulation::CAircraftModelList, bool, BlackMisc::CStatusMessageList))); "validatedModelSet", this, SIGNAL(validatedModelSet(BlackMisc::Simulation::CSimulatorInfo, BlackMisc::Simulation::CAircraftModelList, BlackMisc::Simulation::CAircraftModelList, bool, BlackMisc::CStatusMessageList)));
Q_ASSERT(s); Q_ASSERT(s);
s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(),
"insufficientFrameRateDetected", this, SIGNAL(insufficientFrameRateDetected(bool)));
Q_ASSERT(s);
Q_UNUSED(s) Q_UNUSED(s)
this->relayBaseClassSignals(serviceName, connection, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName()); this->relayBaseClassSignals(serviceName, connection, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName());
} }

View File

@@ -411,6 +411,9 @@ namespace BlackCore
//! Auto publish data written for simulator //! Auto publish data written for simulator
void autoPublishDataWritten(const BlackMisc::Simulation::CSimulatorInfo &simulator); void autoPublishDataWritten(const BlackMisc::Simulation::CSimulatorInfo &simulator);
//! Frame rate has fallen too far below the threshold to maintain consistent sim rate
void insufficientFrameRateDetected(bool fatal);
protected: protected:
//! Constructor with all the providers //! Constructor with all the providers
ISimulator(const BlackMisc::Simulation::CSimulatorPluginInfo &pluginInfo, ISimulator(const BlackMisc::Simulation::CSimulatorPluginInfo &pluginInfo,

View File

@@ -444,10 +444,23 @@ namespace BlackSimPlugin
} }
// FPS // FPS
// reading FPS resets average, so we only monitor over some time
if ((m_slowTimerCalls % 5u) == 0u) if ((m_slowTimerCalls % 5u) == 0u)
{ {
// reading FPS resets average, so we only monitor over some time constexpr double warningMiles = 1;
constexpr double disconnectMiles = 2;
const double previousMiles = m_trackMilesShort;
m_serviceProxy->getFrameStats(&m_averageFps, &m_simTimeRatio, &m_trackMilesShort, &m_minutesLate); m_serviceProxy->getFrameStats(&m_averageFps, &m_simTimeRatio, &m_trackMilesShort, &m_minutesLate);
if (previousMiles < disconnectMiles && m_trackMilesShort >= disconnectMiles)
{
emit insufficientFrameRateDetected(true);
}
else if (previousMiles < warningMiles && m_trackMilesShort >= warningMiles)
{
emit insufficientFrameRateDetected(false);
}
} }
} }
} }