mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +08:00
refs #849, simulator context
* detect when network is connected (to receive data for statistics) * function to get statistics * also added function to re-initialize last model set (unrelated, but in same class)
This commit is contained in:
committed by
Mathew Sutcliffe
parent
928dd9f34a
commit
44d7e3cca9
@@ -35,9 +35,11 @@
|
||||
#include "blackmisc/pq/length.h"
|
||||
#include "blackmisc/pq/time.h"
|
||||
#include "blackmisc/simulation/aircraftmodellist.h"
|
||||
#include "blackmisc/simulation/matchingstatistics.h"
|
||||
#include "blackmisc/simulation/simulatorplugininfo.h"
|
||||
#include "blackmisc/simulation/simulatorplugininfolist.h"
|
||||
#include "blackmisc/simulation/simulatorinternals.h"
|
||||
#include "blackmisc/simulation/matchingstatistics.h"
|
||||
#include "blackmisc/simulation/interpolationrenderingsetup.h"
|
||||
#include "blackmisc/weather/weathergrid.h"
|
||||
|
||||
@@ -203,6 +205,9 @@ namespace BlackCore
|
||||
//! Parse a given command line
|
||||
virtual bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) = 0;
|
||||
|
||||
//! Current matching statistics
|
||||
virtual BlackMisc::Simulation::CMatchingStatistics getCurrentMatchingStatistics(bool missingOnly) const = 0;
|
||||
|
||||
protected:
|
||||
//! Constructor
|
||||
IContextSimulator(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : CContext(mode, runtime) {}
|
||||
|
||||
@@ -216,13 +216,20 @@ namespace BlackCore
|
||||
}
|
||||
|
||||
//! \copydoc IContextSimulator::parseCommandLine
|
||||
virtual bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator)
|
||||
virtual bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) override
|
||||
{
|
||||
Q_UNUSED(commandLine);
|
||||
Q_UNUSED(originator);
|
||||
logEmptyContextWarning(Q_FUNC_INFO);
|
||||
return false;
|
||||
}
|
||||
|
||||
//! \copydoc IContextSimulator::getCurrentMatchingStatistics
|
||||
virtual BlackMisc::Simulation::CMatchingStatistics getCurrentMatchingStatistics(bool missingOnly) const override
|
||||
{
|
||||
Q_UNUSED(missingOnly);
|
||||
return BlackMisc::Simulation::CMatchingStatistics();
|
||||
}
|
||||
};
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -62,6 +62,9 @@ namespace BlackCore
|
||||
|
||||
connect(&m_modelSetLoader, &CAircraftModelSetLoader::simulatorChanged, this, &CContextSimulator::ps_modelSetChanged);
|
||||
connect(&m_modelSetLoader, &CAircraftModelSetLoader::cacheChanged, this, &CContextSimulator::ps_modelSetChanged);
|
||||
|
||||
// deferred init of last model set, if no other data are set in meantime
|
||||
QTimer::singleShot(1250, this, &CContextSimulator::initByLastUsedModelSet);
|
||||
}
|
||||
|
||||
CContextSimulator *CContextSimulator::registerWithDBus(CDBusServer *server)
|
||||
@@ -150,12 +153,7 @@ namespace BlackCore
|
||||
CAircraftModelList CContextSimulator::getModelSet() const
|
||||
{
|
||||
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; }
|
||||
|
||||
// If no ISimulator object is available, return a dummy.
|
||||
if (m_simulatorPlugin.first.isUnspecified()) { return CAircraftModelList(); }
|
||||
|
||||
Q_ASSERT(m_simulatorPlugin.second);
|
||||
return m_modelMatcher.getModelSet();
|
||||
return m_aircraftMatcher.getModelSet();
|
||||
}
|
||||
|
||||
CSimulatorInfo CContextSimulator::simulatorsWithInitializedModelSet() const
|
||||
@@ -292,8 +290,8 @@ namespace BlackCore
|
||||
setRemoteAircraftProvider(renderedAircraftProvider);
|
||||
const CSimulatorInfo simInfo(simulatorPluginInfo.getIdentifier());
|
||||
m_modelSetLoader.changeSimulator(simInfo);
|
||||
m_modelMatcher.setModelSet(m_modelSetLoader.getAircraftModels());
|
||||
m_modelMatcher.setDefaultModel(simulator->getDefaultModel());
|
||||
m_aircraftMatcher.setModelSet(m_modelSetLoader.getAircraftModels(), simInfo);
|
||||
m_aircraftMatcher.setDefaultModel(simulator->getDefaultModel());
|
||||
|
||||
bool c = connect(simulator, &ISimulator::simulatorStatusChanged, this, &CContextSimulator::ps_onSimulatorStatusChanged);
|
||||
Q_ASSERT(c);
|
||||
@@ -373,7 +371,7 @@ namespace BlackCore
|
||||
listener->moveToThread(&m_listenersThread);
|
||||
}
|
||||
|
||||
bool s = QMetaObject::invokeMethod(listener, "start", Qt::QueuedConnection);
|
||||
const bool s = QMetaObject::invokeMethod(listener, "start", Qt::QueuedConnection);
|
||||
Q_ASSERT_X(s, Q_FUNC_INFO, "cannot invoke method");
|
||||
Q_UNUSED(s);
|
||||
|
||||
@@ -426,7 +424,7 @@ namespace BlackCore
|
||||
|
||||
CStatusMessageList matchingMessages;
|
||||
CStatusMessageList *pMatchingMessages = m_enableMatchingMessages ? &matchingMessages : nullptr;
|
||||
const CAircraftModel aircraftModel = m_modelMatcher.getClosestMatch(remoteAircraft, pMatchingMessages);
|
||||
const CAircraftModel aircraftModel = m_aircraftMatcher.getClosestMatch(remoteAircraft, pMatchingMessages);
|
||||
Q_ASSERT_X(remoteAircraft.getCallsign() == aircraftModel.getCallsign(), Q_FUNC_INFO, "Mismatching callsigns");
|
||||
updateAircraftModel(callsign, aircraftModel, identifier());
|
||||
const CSimulatedAircraft aircraftAfterModelApplied = getAircraftInRangeForCallsign(remoteAircraft.getCallsign());
|
||||
@@ -508,6 +506,22 @@ namespace BlackCore
|
||||
m_simulatorPlugin.second->changeRemoteAircraftEnabled(aircraft);
|
||||
}
|
||||
|
||||
void CContextSimulator::ps_networkConnectionStatusChanged(int from, int to)
|
||||
{
|
||||
Q_UNUSED(from);
|
||||
BLACK_VERIFY_X(getIContextNetwork(), Q_FUNC_INFO, "Missing network context");
|
||||
const INetwork::ConnectionStatus statusTo = static_cast<INetwork::ConnectionStatus>(to);
|
||||
if (statusTo == INetwork::Connected && this->getIContextNetwork())
|
||||
{
|
||||
this->m_networkSessionId = this->getIContextNetwork()->getConnectedServer().getServerSessionId();
|
||||
}
|
||||
else if (!m_networkSessionId.isEmpty())
|
||||
{
|
||||
this->m_networkSessionId.clear();
|
||||
this->m_aircraftMatcher.clearMatchingStatistics();
|
||||
}
|
||||
}
|
||||
|
||||
void CContextSimulator::ps_addingRemoteAircraftFailed(const CSimulatedAircraft &remoteAircraft, const CStatusMessage &message)
|
||||
{
|
||||
if (!isSimulatorSimulating()) { return; }
|
||||
@@ -517,13 +531,18 @@ namespace BlackCore
|
||||
void CContextSimulator::ps_updateSimulatorCockpitFromContext(const CSimulatedAircraft &ownAircraft, const CIdentifier &originator)
|
||||
{
|
||||
if (!isSimulatorSimulating()) { return; }
|
||||
// avoid loops
|
||||
if (originator.getName().isEmpty() || originator == IContextSimulator::InterfaceName()) { return; }
|
||||
|
||||
// update
|
||||
m_simulatorPlugin.second->updateOwnSimulatorCockpit(ownAircraft, originator);
|
||||
}
|
||||
|
||||
void CContextSimulator::ps_networkRequestedNewAircraft(const CCallsign &callsign, const QString &aircraftIcao, const QString &airlineIcao, const QString &livery)
|
||||
{
|
||||
if (m_networkSessionId.isEmpty()) { return; }
|
||||
m_aircraftMatcher.evaluateStatisticsEntry(m_networkSessionId, callsign, aircraftIcao, airlineIcao, livery);
|
||||
}
|
||||
|
||||
void CContextSimulator::ps_relayStatusMessageToSimulator(const BlackMisc::CStatusMessage &message)
|
||||
{
|
||||
if (!isSimulatorSimulating()) { return; }
|
||||
@@ -582,6 +601,15 @@ namespace BlackCore
|
||||
emit CContext::changedLogOrDebugSettings();
|
||||
}
|
||||
|
||||
CMatchingStatistics CContextSimulator::getCurrentMatchingStatistics(bool missingOnly) const
|
||||
{
|
||||
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << missingOnly; }
|
||||
const CMatchingStatistics statistics = this->m_aircraftMatcher.getCurrentStatistics();
|
||||
return missingOnly ?
|
||||
statistics.findMissingOnly() :
|
||||
statistics;
|
||||
}
|
||||
|
||||
bool CContextSimulator::parseCommandLine(const QString &commandLine, const CIdentifier &originator)
|
||||
{
|
||||
Q_UNUSED(originator);
|
||||
@@ -654,5 +682,22 @@ namespace BlackCore
|
||||
this->m_matchingMessages.insert(callsign, messages);
|
||||
}
|
||||
}
|
||||
|
||||
void CContextSimulator::initByLastUsedModelSet()
|
||||
{
|
||||
// no models in matcher, but in cache, we can set them as default
|
||||
const CSimulatorInfo sim(m_modelSetLoader.getSimulator());
|
||||
if (!m_aircraftMatcher.hasModels() && m_modelSetLoader.getAircraftModelsCount() > 0)
|
||||
{
|
||||
const CAircraftModelList models(m_modelSetLoader.getAircraftModels());
|
||||
CLogMessage(this).info("Init aircraft matcher with %1 models from set for '%2'") << models.size() << sim.toQString();
|
||||
m_aircraftMatcher.setModelSet(models, sim);
|
||||
}
|
||||
else
|
||||
{
|
||||
CLogMessage(this).info("Start loading of model set for '%1'") << sim.toQString();
|
||||
m_modelSetLoader.admitCache(); // when ready chache change signal
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
#ifndef BLACKCORE_CONTEXT_CONTEXTSIMULATOR_IMPL_H
|
||||
#define BLACKCORE_CONTEXT_CONTEXTSIMULATOR_IMPL_H
|
||||
|
||||
|
||||
#include "blackcore/aircraftmatcher.h"
|
||||
#include "blackcore/blackcoreexport.h"
|
||||
#include "blackcore/context/contextsimulator.h"
|
||||
@@ -101,6 +100,7 @@ namespace BlackCore
|
||||
virtual BlackMisc::CStatusMessageList getMatchingMessages(const BlackMisc::Aviation::CCallsign &callsign) const override;
|
||||
virtual bool isMatchingMessagesEnabled() const override;
|
||||
virtual void enableMatchingMessages(bool enabled) override;
|
||||
BlackMisc::Simulation::CMatchingStatistics getCurrentMatchingStatistics(bool missingOnly) const;
|
||||
//! @}
|
||||
|
||||
//! \ingroup commandline
|
||||
@@ -122,10 +122,7 @@ namespace BlackCore
|
||||
CContextSimulator *registerWithDBus(BlackMisc::CDBusServer *server);
|
||||
|
||||
private slots:
|
||||
|
||||
//
|
||||
// ------------ slots connected with network context and not to be used other by network contect ---------
|
||||
//
|
||||
// ------------ slots connected with network or other contexts ---------
|
||||
//! \ingroup crosscontextslot
|
||||
//! @{
|
||||
|
||||
@@ -141,10 +138,16 @@ namespace BlackCore
|
||||
//! Enable / disable aircraft
|
||||
void ps_changedRemoteAircraftEnabled(const BlackMisc::Simulation::CSimulatedAircraft &aircraft);
|
||||
|
||||
//! Network connection status
|
||||
void ps_networkConnectionStatusChanged(int from, int to);
|
||||
|
||||
//! Update simulator cockpit from context, because someone else has changed cockpit (e.g. GUI, 3rd party)
|
||||
void ps_updateSimulatorCockpitFromContext(const BlackMisc::Simulation::CSimulatedAircraft &ownAircraft, const BlackMisc::CIdentifier &originator);
|
||||
|
||||
//! Raw data when a new aircraft was requested, used for statistics
|
||||
void ps_networkRequestedNewAircraft(const BlackMisc::Aviation::CCallsign &callsign, const QString &aircraftIcao, const QString &airlineIcao, const QString &livery);
|
||||
//! @}
|
||||
//
|
||||
// ------------ slots connected with network context and not to be used other by network contect ---------
|
||||
//
|
||||
// ------------ slots connected with network or other contexts ---------
|
||||
|
||||
//! Handle new connection status of simulator
|
||||
void ps_onSimulatorStatusChanged(int status);
|
||||
@@ -164,10 +167,6 @@ namespace BlackCore
|
||||
//! Failed adding remote aircraft
|
||||
void ps_addingRemoteAircraftFailed(const BlackMisc::Simulation::CSimulatedAircraft &remoteAircraft, const BlackMisc::CStatusMessage &message);
|
||||
|
||||
//! Update simulator cockpit from context, because someone else has changed cockpit (e.g. GUI, 3rd party)
|
||||
//! \ingroup crosscontextslot
|
||||
void ps_updateSimulatorCockpitFromContext(const BlackMisc::Simulation::CSimulatedAircraft &ownAircraft, const BlackMisc::CIdentifier &originator);
|
||||
|
||||
//! Relay status message to simulator under consideration of settings
|
||||
void ps_relayStatusMessageToSimulator(const BlackMisc::CStatusMessage &message);
|
||||
|
||||
@@ -193,17 +192,21 @@ namespace BlackCore
|
||||
//! Add to message list for matching
|
||||
void addMatchingMessages(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::CStatusMessageList &messages);
|
||||
|
||||
//! Load the last know model set
|
||||
void initByLastUsedModelSet();
|
||||
|
||||
QPair<BlackMisc::Simulation::CSimulatorPluginInfo, ISimulator *> m_simulatorPlugin; //!< Currently loaded simulator plugin
|
||||
CPluginManagerSimulator *m_plugins = nullptr;
|
||||
BlackMisc::CRegularThread m_listenersThread; //!< waiting for plugin
|
||||
BlackCore::CWeatherManager m_weatherManager { this };
|
||||
BlackMisc::CSetting<BlackCore::Application::TEnabledSimulators> m_enabledSimulators { this, &CContextSimulator::restoreSimulatorPlugins };
|
||||
BlackCore::CAircraftMatcher m_modelMatcher; //!< Model matcher
|
||||
BlackCore::CAircraftMatcher m_aircraftMatcher; //!< Model matcher
|
||||
BlackMisc::Simulation::CAircraftModelSetLoader m_modelSetLoader { this }; //!< load model set from caches
|
||||
QMap<BlackMisc::Aviation::CCallsign, BlackMisc::CStatusMessageList> m_matchingMessages;
|
||||
BlackMisc::CSettingReadOnly<BlackMisc::Simulation::TSimulatorMessages> m_messageSettings { this }; //!< settings for messages
|
||||
bool m_initallyAddAircrafts = false;
|
||||
bool m_enableMatchingMessages = true;
|
||||
QString m_networkSessionId; //! Network session, if not connected empty
|
||||
};
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -198,5 +198,10 @@ namespace BlackCore
|
||||
{
|
||||
return m_dBusInterface->callDBusRet<bool>(QLatin1Literal("parseCommandLine"), commandLine, originator);
|
||||
}
|
||||
|
||||
CMatchingStatistics CContextSimulatorProxy::getCurrentMatchingStatistics(bool missingOnly) const
|
||||
{
|
||||
return m_dBusInterface->callDBusRet<CMatchingStatistics>(QLatin1Literal("getCurrentMatchingStatistics"), missingOnly);
|
||||
}
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -79,6 +79,7 @@ namespace BlackCore
|
||||
virtual bool isMatchingMessagesEnabled() const override;
|
||||
virtual void enableMatchingMessages(bool enabled) override;
|
||||
virtual bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) override;
|
||||
virtual BlackMisc::Simulation::CMatchingStatistics getCurrentMatchingStatistics(bool missingOnly) const override;
|
||||
//! @}
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user