Ref T681, preparations to use CG from DB

* renamed to "getSimulatorCG" ...
* pass simulator settings to sim.env.provider to decide what CG to use
* store DB CG and init it when aircraft is added
* style
This commit is contained in:
Klaus Basan
2019-06-10 19:54:35 +02:00
committed by Mat Sutcliffe
parent 33c3ee68f1
commit 6d490e9a49
14 changed files with 196 additions and 64 deletions

View File

@@ -885,12 +885,21 @@ namespace BlackCore
newAircraft.setRendered(false); // reset rendering
newAircraft.calculcateAndUpdateRelativeDistanceAndBearing(this->getOwnAircraftPosition()); // distance from myself
Q_ASSERT_X(sApp->hasWebDataServices(), Q_FUNC_INFO, "No web services");
if (this->getConnectedServer().getEcosystem() == CEcosystem::vatsim())
{
sApp->getWebDataServices()->updateWithVatsimDataFileData(newAircraft);
}
return CRemoteAircraftProvider::addNewAircraftInRange(newAircraft);
const bool added = CRemoteAircraftProvider::addNewAircraftInRange(newAircraft);
if (added && aircraft.hasModelString())
{
// most likely I could take the CG at this time from aircraft
// to make sure it is really the DB value i query again
const CAircraftModel model = sApp->getWebDataServices()->getModelForModelString(aircraft.getModelString());
const CLength cg = model.hasValidDbKey() ? model.getCG() : CLength::null();
this->rememberCGFromDB(cg, aircraft.getModelString());
this->rememberCGFromDB(cg, aircraft.getCallsign());
}
return added;
}
void CAirspaceMonitor::asyncAddNewAircraftInRange(const CSimulatedAircraftList &aircraft, bool readyForModelMatching)
@@ -1184,7 +1193,7 @@ namespace BlackCore
}
// CG from provider
const CLength cg = this->getCG(callsign); // always x-check against simulator to override guessed values and reflect changed CGs
const CLength cg = this->getSimulatorCG(callsign); // always x-check against simulator to override guessed values and reflect changed CGs
if (!cg.isNull()) { correctedSituation.setCG(cg); }
// store corrected situation

View File

@@ -970,6 +970,26 @@ namespace BlackCore
m_airspace->updateMarkAllAsNotRendered();
}
CLength CContextNetwork::getCGFromDB(const CCallsign &callsign) const
{
return m_airspace->getCGFromDB(callsign);
}
CLength CContextNetwork::getCGFromDB(const QString &modelString) const
{
return m_airspace->getCGFromDB(modelString);
}
void CContextNetwork::rememberCGFromDB(const CLength &cgFromDB, const CCallsign &callsign)
{
m_airspace->rememberCGFromDB(cgFromDB, callsign);
}
void CContextNetwork::rememberCGFromDB(const CLength &cgFromDB, const QString &modelString)
{
m_airspace->rememberCGFromDB(cgFromDB, modelString);
}
int CContextNetwork::reInitializeAllAircraft()
{
if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; }

View File

@@ -109,6 +109,10 @@ namespace BlackCore
virtual int updateMultipleAircraftEnabled(const BlackMisc::Aviation::CCallsignSet &callsigns, bool enabled) override;
virtual int updateAircraftGroundElevation(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Geo::CElevationPlane &elevation, BlackMisc::Aviation::CAircraftSituation::GndElevationInfo info) override;
virtual void updateMarkAllAsNotRendered() override;
virtual BlackMisc::PhysicalQuantities::CLength getCGFromDB(const BlackMisc::Aviation::CCallsign &callsign) const override;
virtual BlackMisc::PhysicalQuantities::CLength getCGFromDB(const QString &modelString) const override;
virtual void rememberCGFromDB(const BlackMisc::PhysicalQuantities::CLength &cgFromDB, const BlackMisc::Aviation::CCallsign &callsign) override;
virtual void rememberCGFromDB(const BlackMisc::PhysicalQuantities::CLength &cgFromDB, const QString &modelString) override;
virtual BlackMisc::Simulation::CAirspaceAircraftSnapshot getLatestAirspaceAircraftSnapshot() const override;
virtual BlackMisc::Geo::CElevationPlane averageElevationOfNonMovingAircraft(const BlackMisc::Aviation::CAircraftSituation &reference, const BlackMisc::PhysicalQuantities::CLength &range, int minValues = 1) const override;
virtual QList<QMetaObject::Connection> connectRemoteAircraftProviderSignals(

View File

@@ -638,7 +638,7 @@ namespace BlackCore
CStatusMessageList *pMatchingMessages = m_logMatchingMessages > 0 ? &matchingMessages : nullptr;
CAircraftModel aircraftModel = m_aircraftMatcher.getClosestMatch(remoteAircraft, whatToLog, pMatchingMessages, true);
Q_ASSERT_X(remoteAircraft.getCallsign() == aircraftModel.getCallsign(), Q_FUNC_INFO, "Mismatching callsigns");
const CLength cg = m_simulatorPlugin.second->getCGPerModelString(aircraftModel.getModelString());
const CLength cg = m_simulatorPlugin.second->getSimulatorCGPerModelString(aircraftModel.getModelString());
if (!cg.isNull()) { aircraftModel.setCG(cg); }
this->updateAircraftModel(callsign, aircraftModel, this->identifier());

View File

@@ -649,11 +649,11 @@ namespace BlackCore
}
ISimulator::ISimulator(const CSimulatorPluginInfo &pluginInfo,
IOwnAircraftProvider *ownAircraftProvider,
IRemoteAircraftProvider *remoteAircraftProvider,
IWeatherGridProvider *weatherGridProvider,
IClientProvider *clientProvider,
QObject *parent) :
IOwnAircraftProvider *ownAircraftProvider,
IRemoteAircraftProvider *remoteAircraftProvider,
IWeatherGridProvider *weatherGridProvider,
IClientProvider *clientProvider,
QObject *parent) :
QObject(parent),
COwnAircraftAware(ownAircraftProvider),
CRemoteAircraftAware(remoteAircraftProvider),
@@ -688,9 +688,11 @@ namespace BlackCore
connect(sApp->getWebDataServices(), &CWebDataServices::swiftDbAirportsRead, this, &ISimulator::onSwiftDbAirportsRead, Qt::QueuedConnection);
connect(sApp->getWebDataServices(), &CWebDataServices::swiftDbModelMatchingEntitiesRead, this, &ISimulator::onSwiftDbModelMatchingEntitiesRead, Qt::QueuedConnection);
}
connect(sApp, &CApplication::aboutToShutdown, this, &ISimulator::unload, Qt::QueuedConnection);
// provider
this->setNewPluginInfo(pluginInfo, m_multiSettings.getSettings(pluginInfo.getSimulatorInfo()));
// info data
m_simulatorInternals.setSimulatorName(this->getSimulatorName());
m_simulatorInternals.setSwiftPluginName(this->getSimulatorPluginInfo().toQString());
@@ -833,7 +835,7 @@ namespace BlackCore
m_simulatorInternals.setSimulatorInstallationDirectory(s.getSimulatorDirectoryOrDefault());
}
void ISimulator::rememberElevationAndCG(const CCallsign &callsign, const QString &modelString, const Geo::CElevationPlane &elevation, const CLength &cg)
void ISimulator::rememberElevationAndCG(const CCallsign &callsign, const QString &modelString, const CElevationPlane &elevation, const CLength &cg)
{
if (callsign.isEmpty()) { return; }
if (!elevation.isNull())
@@ -844,7 +846,7 @@ namespace BlackCore
}
const CLength cgO = this->overriddenCGorDefault(cg, modelString);
if (!cgO.isNull() && !this->hasSameCG(cgO, callsign))
if (!cgO.isNull() && !this->hasSameSimulatorCG(cgO, callsign))
{
this->insertCG(cgO, modelString, callsign); // per model string and CG

View File

@@ -195,7 +195,7 @@ namespace BlackCore
void reloadWeatherSettings();
//! Settings for current simulator
BlackMisc::Simulation::Settings::CSpecializedSimulatorSettings getSimulatorSettings() const { return m_settings.getSpecializedSettings(this->getSimulatorInfo()); }
BlackMisc::Simulation::Settings::CSpecializedSimulatorSettings getSimulatorSettings() const { return m_multiSettings.getSpecializedSettings(this->getSimulatorInfo()); }
//! Driver will be unloaded
virtual void unload();
@@ -574,7 +574,7 @@ namespace BlackCore
bool m_limitUpdateAircraft = false; //!< limit the update frequency by using BlackMisc::CTokenBucket
// general settings
BlackMisc::Simulation::Settings::CMultiSimulatorSettings m_settings { this }; //!< simulator settings for all simulators
BlackMisc::Simulation::Settings::CMultiSimulatorSettings m_multiSettings { this }; //!< simulator settings for all simulators
// weather
bool m_isWeatherActivated = false; //!< Is simulator weather activated?