Ref T270, improved setup/logger handling

* utility functions to enable logging
* logger access and access to log messages
This commit is contained in:
Klaus Basan
2018-05-18 00:06:42 +02:00
parent e3465f432c
commit a3a62919fc
6 changed files with 59 additions and 16 deletions

View File

@@ -487,11 +487,9 @@ namespace BlackCore
if (parser.hasPart(2)) if (parser.hasPart(2))
{ {
const CCallsign cs(parser.part(2)); const CCallsign cs(parser.part(2));
CInterpolationAndRenderingSetupPerCallsign setup = this->getInterpolationSetupPerCallsignOrDefault(cs); const bool changed = this->setInterpolationMode(part1, cs);
const bool changed = setup.setInterpolatorMode(part1);
if (changed) if (changed)
{ {
this->setInterpolationSetupPerCallsign(setup, cs);
emit this->interpolationAndRenderingSetupChanged(); emit this->interpolationAndRenderingSetupChanged();
} }
CLogMessage(this).info(changed ? "Changed interpolation mode for '%1'" : "Unchanged interpolation mode for '%1'") << cs.asString(); CLogMessage(this).info(changed ? "Changed interpolation mode for '%1'" : "Unchanged interpolation mode for '%1'") << cs.asString();
@@ -761,6 +759,23 @@ namespace BlackCore
this->physicallyRemoveRemoteAircraft(remoteCallsign); this->physicallyRemoveRemoteAircraft(remoteCallsign);
} }
QString CSimulatorCommon::latestLoggedDataFormatted(const CCallsign &cs) const
{
const SituationLog s = m_interpolationLogger.getLastSituationLog(cs);
const PartsLog p = m_interpolationLogger.getLastPartsLog(cs);
static const QString sep("\n------\n");
QString dm;
if (s.tsCurrent > 0)
{
dm = QStringLiteral("Setup: ") % s.usedSetup.toQString(true) %
QStringLiteral("\n\n") %
QStringLiteral("Situation: ") % s.toQString(false, true, true, true, true, sep);
}
if (p.tsCurrent > 0) { dm += (dm.isEmpty() ? QStringLiteral("") : QStringLiteral("\n\n")) % QStringLiteral("Parts: ") % p.toQString(sep); }
return dm;
}
void CSimulatorCommon::displayLoggedSituationInSimulator(const CCallsign &cs, bool stopLogging, int times) void CSimulatorCommon::displayLoggedSituationInSimulator(const CCallsign &cs, bool stopLogging, int times)
{ {
if (cs.isEmpty()) { return; } if (cs.isEmpty()) { return; }
@@ -781,18 +796,7 @@ namespace BlackCore
return; return;
} }
const SituationLog s = m_interpolationLogger.getLastSituationLog(cs); const QString dm = this->latestLoggedDataFormatted(cs);
const PartsLog p = m_interpolationLogger.getLastPartsLog(cs);
QString dm;
static const QString sep("\n------\n");
if (s.tsCurrent > 0)
{
dm = QStringLiteral("Setup: ") % s.usedSetup.toQString(true) %
QStringLiteral("\n\n") %
QStringLiteral("Situation: ") % s.toQString(false, true, true, true, true, sep);
}
if (p.tsCurrent > 0) { dm += (dm.isEmpty() ? QStringLiteral("") : QStringLiteral("\n\n")) % QStringLiteral("Parts: ") % p.toQString(sep); }
if (!dm.isEmpty()) if (!dm.isEmpty())
{ {
this->displayStatusMessage(CStatusMessage(this).info(dm)); this->displayStatusMessage(CStatusMessage(this).info(dm));

View File

@@ -114,6 +114,12 @@ namespace BlackCore
//! Counter removed aircraft //! Counter removed aircraft
int getStatisticsPhysicallyRemovedAircraft() const { return m_statsPhysicallyRemovedAircraft; } int getStatisticsPhysicallyRemovedAircraft() const { return m_statsPhysicallyRemovedAircraft; }
//! Access to logger
const BlackMisc::Simulation::CInterpolationLogger &interpolationLogger() const { return m_interpolationLogger; }
//! The latest logged data formatted
QString latestLoggedDataFormatted(const BlackMisc::Aviation::CCallsign &cs) const;
protected: protected:
//! Constructor //! Constructor
CSimulatorCommon(const BlackMisc::Simulation::CSimulatorPluginInfo &info, CSimulatorCommon(const BlackMisc::Simulation::CSimulatorPluginInfo &info,

View File

@@ -64,6 +64,13 @@ namespace BlackMisc
} }
} }
bool CInterpolationAndRenderingSetupBase::setLogInterpolation(bool log)
{
if (m_logInterpolation == log) { return false; }
m_logInterpolation = log;
return true;
}
bool CInterpolationAndRenderingSetupBase::setEnabledAircraftParts(bool enabled) bool CInterpolationAndRenderingSetupBase::setEnabledAircraftParts(bool enabled)
{ {
if (m_enabledAircraftParts == enabled) { return false; } if (m_enabledAircraftParts == enabled) { return false; }

View File

@@ -58,7 +58,7 @@ namespace BlackMisc
bool logInterpolation() const { return m_logInterpolation; } bool logInterpolation() const { return m_logInterpolation; }
//! Log.interpolation //! Log.interpolation
void setLogInterpolation(bool log) { m_logInterpolation = log; } bool setLogInterpolation(bool log);
//! Full interpolation (skip optimizations like checking if aircraft moves etc.) //! Full interpolation (skip optimizations like checking if aircraft moves etc.)
bool isForcingVtolInterpolation() const { return m_forceVtolInterpolation; } bool isForcingVtolInterpolation() const { return m_forceVtolInterpolation; }

View File

@@ -57,6 +57,24 @@ namespace BlackMisc
return callsigns; return callsigns;
} }
bool IInterpolationSetupProvider::setInterpolationMode(const QString &modeAsString, const CCallsign &callsign)
{
CInterpolationAndRenderingSetupPerCallsign setup = this->getInterpolationSetupPerCallsignOrDefault(callsign);
if (!setup.setInterpolatorMode(modeAsString)) { return false; }
// changed value
return this->setInterpolationSetupPerCallsign(setup, callsign, true);
}
bool IInterpolationSetupProvider::setLogInterpolation(bool log, const CCallsign &callsign)
{
CInterpolationAndRenderingSetupPerCallsign setup = this->getInterpolationSetupPerCallsignOrDefault(callsign);
if (!setup.setLogInterpolation(log)) { return false; }
// changed value
return this->setInterpolationSetupPerCallsign(setup, callsign, true);
}
bool IInterpolationSetupProvider::setInterpolationSetupGlobal(const CInterpolationAndRenderingSetupGlobal &setup) bool IInterpolationSetupProvider::setInterpolationSetupGlobal(const CInterpolationAndRenderingSetupGlobal &setup)
{ {
{ {

View File

@@ -50,6 +50,14 @@ namespace BlackMisc
//! \threadsafe //! \threadsafe
Aviation::CCallsignSet getLogCallsigns() const; Aviation::CCallsignSet getLogCallsigns() const;
//! Set mode as string
//! \threadsafe
bool setInterpolationMode(const QString &modeAsString, const Aviation::CCallsign &callsign);
//! Enable/disable logging
//! \threadsafe
bool setLogInterpolation(bool log, const Aviation::CCallsign &callsign);
protected: protected:
//! Set the global setup //! Set the global setup
//! \threadsafe //! \threadsafe