diff --git a/src/blackgui/components/loginadvcomponent.cpp b/src/blackgui/components/loginadvcomponent.cpp index 8b1f86a0a..ad423c24a 100644 --- a/src/blackgui/components/loginadvcomponent.cpp +++ b/src/blackgui/components/loginadvcomponent.cpp @@ -108,6 +108,7 @@ namespace BlackGui { connect(sGui->getIContextSimulator(), &IContextSimulator::vitalityLost, this, &CLoginAdvComponent::autoLogoffDetection, Qt::QueuedConnection); connect(sGui->getIContextSimulator(), &IContextSimulator::simulatorStatusChanged, this, &CLoginAdvComponent::onSimulatorStatusChanged, Qt::QueuedConnection); + connect(sGui->getIContextSimulator(), &IContextSimulator::insufficientFrameRateDetected, this, &CLoginAdvComponent::autoLogoffFrameRate, Qt::QueuedConnection); } // inital setup, if data already available @@ -341,6 +342,22 @@ namespace BlackGui emit this->requestLoginPage(); } + void CLoginAdvComponent::autoLogoffFrameRate(bool fatal) + { + //! \fixme code duplication with function above + if (!ui->cb_AutoLogoff->isChecked()) { return; } + if (!this->hasValidContexts()) { return; } + if (!sGui->getIContextNetwork()->isConnected()) { return; } + + const auto msg = fatal + ? CStatusMessage(this, CStatusMessage::SeverityError, u"Sim frame rate too low to maintain constant simulation rate. Disconnecting to avoid disrupting the network.") + : CStatusMessage(this, CStatusMessage::SeverityWarning, u"Sim frame rate too low to maintain constant simulation rate. Reduce graphics quality to avoid disconnection."); + const int delaySecs = 30; + this->showOverlayHTMLMessage(msg, qRound(1000 * delaySecs * 0.8)); + + emit this->requestLoginPage(); + } + bool CLoginAdvComponent::updateOwnAircraftCallsignAndPilotFromGuiValues() { if (!this->hasValidContexts()) { return false; } diff --git a/src/blackgui/components/loginadvcomponent.h b/src/blackgui/components/loginadvcomponent.h index 695ed1376..4091cdeaa 100644 --- a/src/blackgui/components/loginadvcomponent.h +++ b/src/blackgui/components/loginadvcomponent.h @@ -127,6 +127,9 @@ namespace BlackGui //! Auto-logoff detection void autoLogoffDetection(); + //! Logoff due to insufficient simulator frame rate + void autoLogoffFrameRate(bool fatal); + //! Pause/Continue timeout void toggleTimeout(); diff --git a/src/blackgui/components/logincomponent.cpp b/src/blackgui/components/logincomponent.cpp index 531a17f27..335077f35 100644 --- a/src/blackgui/components/logincomponent.cpp +++ b/src/blackgui/components/logincomponent.cpp @@ -146,6 +146,7 @@ namespace BlackGui connect(sGui->getIContextSimulator(), &IContextSimulator::ownAircraftModelChanged, this, &CLoginComponent::onSimulatorModelChanged, Qt::QueuedConnection); connect(sGui->getIContextSimulator(), &IContextSimulator::vitalityLost, this, &CLoginComponent::autoLogoffDetection, Qt::QueuedConnection); connect(sGui->getIContextSimulator(), &IContextSimulator::simulatorStatusChanged, this, &CLoginComponent::onSimulatorStatusChanged, Qt::QueuedConnection); + connect(sGui->getIContextSimulator(), &IContextSimulator::insufficientFrameRateDetected, this, &CLoginComponent::autoLogoffFrameRate, Qt::QueuedConnection); } if (sGui && sGui->getIContextNetwork()) @@ -722,6 +723,23 @@ namespace BlackGui emit this->requestLoginPage(); } + void CLoginComponent::autoLogoffFrameRate(bool fatal) + { + //! \fixme code duplication with function above + if (!ui->cb_AutoLogoff->isChecked()) { return; } + if (!this->hasValidContexts()) { return; } + if (!sGui->getIContextNetwork()->isConnected()) { return; } + + const auto msg = fatal + ? CStatusMessage(this, CStatusMessage::SeverityError, u"Sim frame rate too low to maintain constant simulation rate. Disconnecting to avoid disrupting the network.") + : CStatusMessage(this, CStatusMessage::SeverityWarning, u"Sim frame rate too low to maintain constant simulation rate. Reduce graphics quality to avoid disconnection."); + const int delaySecs = 30; + this->showOverlayHTMLMessage(msg, qRound(1000 * delaySecs * 0.8)); + if (fatal) { this->setLogoffCountdown(delaySecs); } + + emit this->requestLoginPage(); + } + void CLoginComponent::lookupOwnAircraftModel() { if (!this->hasValidContexts()) { return; } diff --git a/src/blackgui/components/logincomponent.h b/src/blackgui/components/logincomponent.h index b6e7f4c7c..eacc85a72 100644 --- a/src/blackgui/components/logincomponent.h +++ b/src/blackgui/components/logincomponent.h @@ -182,6 +182,9 @@ namespace BlackGui //! Auto-logoff detection void autoLogoffDetection(); + //! Logoff due to insufficient simulator frame rate + void autoLogoffFrameRate(bool fatal); + //! Lookup own model void lookupOwnAircraftModel();