mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-20 12:35:43 +08:00
refs #789, improvements to try to solve FSX issue in driver
* more asserts to find issues * limit number of exceptions displayed * reset() function (there was an issue with not cleaned up values) * using CSimConnectObjects and adjustments for the previous changes
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
#include "blackcore/application.h"
|
||||
#include "blackcore/pluginmanagersimulator.h"
|
||||
#include "blackcore/simulator.h"
|
||||
#include "blackmisc/verify.h"
|
||||
#include "blackmisc/aviation/callsign.h"
|
||||
#include "blackmisc/compare.h"
|
||||
#include "blackmisc/dbusserver.h"
|
||||
@@ -494,9 +495,10 @@ namespace BlackCore
|
||||
void CContextSimulator::ps_addedRemoteAircraft(const CSimulatedAircraft &remoteAircraft)
|
||||
{
|
||||
if (!isSimulatorSimulating()) { return; }
|
||||
Q_ASSERT(!remoteAircraft.getCallsign().isEmpty());
|
||||
|
||||
const CCallsign callsign = remoteAircraft.getCallsign();
|
||||
BLACK_VERIFY_X(!callsign.isEmpty(), Q_FUNC_INFO, "Remote aircrft with empty callsign");
|
||||
if (callsign.isEmpty()) { return; }
|
||||
|
||||
CStatusMessageList matchingMessages;
|
||||
CStatusMessageList *pMatchingMessages = m_enableMatchingMessages ? &matchingMessages : nullptr;
|
||||
const CAircraftModel aircraftModel = m_modelMatcher.getClosestMatch(remoteAircraft, pMatchingMessages);
|
||||
|
||||
@@ -80,12 +80,14 @@ namespace BlackCore
|
||||
|
||||
bool CSimulatorCommon::logicallyAddRemoteAircraft(const CSimulatedAircraft &remoteAircraft)
|
||||
{
|
||||
Q_ASSERT_X(remoteAircraft.hasModelString(), Q_FUNC_INFO, "Missing model string");
|
||||
Q_ASSERT_X(remoteAircraft.hasCallsign(), Q_FUNC_INFO, "Missing callsign");
|
||||
if (!remoteAircraft.isEnabled()) { return false; }
|
||||
|
||||
// if not restriced, directly change
|
||||
if (!isRenderingRestricted()) { this->physicallyAddRemoteAircraft(remoteAircraft); return true; }
|
||||
|
||||
// will be added with next snapshot
|
||||
// will be added with next snapshot ps_recalculateRenderedAircraft
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -94,7 +96,7 @@ namespace BlackCore
|
||||
// if not restriced, directly change
|
||||
if (!isRenderingRestricted()) { this->physicallyRemoveRemoteAircraft(callsign); return true; }
|
||||
|
||||
// will be added with next snapshot
|
||||
// will be added with next snapshot ps_recalculateRenderedAircraft
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -322,11 +324,11 @@ namespace BlackCore
|
||||
|
||||
void CSimulatorCommon::highlightAircraft(const BlackMisc::Simulation::CSimulatedAircraft &aircraftToHighlight, bool enableHighlight, const BlackMisc::PhysicalQuantities::CTime &displayTime)
|
||||
{
|
||||
CCallsign cs(aircraftToHighlight.getCallsign());
|
||||
const CCallsign cs(aircraftToHighlight.getCallsign());
|
||||
this->m_highlightedAircraft.removeByCallsign(cs);
|
||||
if (enableHighlight)
|
||||
{
|
||||
qint64 deltaT = displayTime.valueRounded(CTimeUnit::ms(), 0);
|
||||
const qint64 deltaT = displayTime.valueRounded(CTimeUnit::ms(), 0);
|
||||
this->m_highlightEndTimeMsEpoch = QDateTime::currentMSecsSinceEpoch() + deltaT;
|
||||
this->m_highlightedAircraft.push_back(aircraftToHighlight);
|
||||
}
|
||||
@@ -432,4 +434,36 @@ namespace BlackCore
|
||||
{
|
||||
Q_UNUSED(callsign);
|
||||
}
|
||||
|
||||
void CSimulatorCommon::ps_queueForAdding(const CSimulatedAircraft &aircraft)
|
||||
{
|
||||
m_pendingAircraftToAdd.replaceOrAddByCallsign(aircraft);
|
||||
QTimer::singleShot(500, this, [ = ]
|
||||
{
|
||||
this->physicallyAddNextQueuedAircraft();
|
||||
});
|
||||
}
|
||||
|
||||
void CSimulatorCommon::physicallyAddNextQueuedAircraft()
|
||||
{
|
||||
if (m_pendingAircraftToAdd.isEmpty()) { return; } // delete in meantime
|
||||
CSimulatedAircraft nextAircraft(m_pendingAircraftToAdd.front()); // normally it should always find a value
|
||||
m_pendingAircraftToAdd.pop_front();
|
||||
this->physicallyAddRemoteAircraft(nextAircraft);
|
||||
}
|
||||
|
||||
void CSimulatorCommon::reset()
|
||||
{
|
||||
m_statsUpdateAircraftCountMs = 0;
|
||||
m_statsUpdateAircraftTimeAvgMs = 0;
|
||||
m_statsUpdateAircraftTimeTotalMs = 0;
|
||||
this->clearAllAircraft();
|
||||
}
|
||||
|
||||
void CSimulatorCommon::clearAllAircraft()
|
||||
{
|
||||
m_aircraftToAddAgainWhenRemoved.clear();
|
||||
m_pendingAircraftToAdd.clear();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -88,6 +88,8 @@ namespace BlackCore
|
||||
//! @}
|
||||
|
||||
protected slots:
|
||||
|
||||
//! \name Connected with remote aircraft provider signals {
|
||||
//! Slow timer used to highlight aircraft, can be used for other things too
|
||||
virtual void ps_oneSecondTimer();
|
||||
|
||||
@@ -102,6 +104,11 @@ namespace BlackCore
|
||||
|
||||
//! Provider removed aircraft
|
||||
virtual void ps_remoteProviderRemovedAircraft(const BlackMisc::Aviation::CCallsign &callsign);
|
||||
//! @}
|
||||
|
||||
//! Add when pending aircraft is added
|
||||
//! \remark no need to use this if multiple models can be added to simulator at once
|
||||
void ps_queueForAdding(const BlackMisc::Simulation::CSimulatedAircraft &aircraft);
|
||||
|
||||
protected:
|
||||
//! Constructor
|
||||
@@ -117,6 +124,12 @@ namespace BlackCore
|
||||
//! \copydoc ISimulator::logicallyRemoveRemoteAircraft
|
||||
virtual bool logicallyRemoveRemoteAircraft(const BlackMisc::Aviation::CCallsign &callsign) override;
|
||||
|
||||
//! Reset state
|
||||
virtual void reset();
|
||||
|
||||
//! Clear all aircraft related data
|
||||
virtual void clearAllAircraft();
|
||||
|
||||
//! Blink the highlighted aircraft
|
||||
void blinkHighlightedAircraft();
|
||||
|
||||
@@ -132,15 +145,22 @@ namespace BlackCore
|
||||
//! Set own model
|
||||
void reverseLookupAndUpdateOwnAircraftModel(const QString &modelString);
|
||||
|
||||
protected:
|
||||
//! Add the next qeueud aircraft
|
||||
void physicallyAddNextQueuedAircraft();
|
||||
|
||||
BlackMisc::IInterpolator *m_interpolator = nullptr; //!< interpolator instance
|
||||
bool m_pausedSimFreezesInterpolation = false; //!< paused simulator will also pause interpolation (so AI aircraft will hold)
|
||||
BlackMisc::Simulation::CSimulatorSetup m_simulatorSetup; //!< setup object
|
||||
BlackMisc::CInterpolationAndRenderingSetup m_interpolationRenderingSetup; //!< debug messages, rendering etc.
|
||||
BlackMisc::Simulation::CAircraftModel m_defaultModel; //!< default model
|
||||
qint64 m_statsUpdateAircraftTimeTotalMs = 0; //!< statistics update time
|
||||
qint64 m_statsUpdateAircraftTimeAvgMs = 0; //!< statistics update time
|
||||
int m_statsUpdateAircraftCountMs = 0; //!< statistics update time
|
||||
|
||||
// some optional functionality which can be used by the sims as needed
|
||||
BlackMisc::Simulation::CSimulatedAircraftList m_aircraftToAddAgainWhenRemoved; //!< add this model again when removed, normally used to change model
|
||||
BlackMisc::Simulation::CSimulatedAircraftList m_pendingAircraftToAdd; //!< used with qeued adding, here only one model is added add a time and only after it is confirmed by the sim. the next model is added
|
||||
|
||||
//! Lookup against DB data
|
||||
static BlackMisc::Simulation::CAircraftModel reverseLookupModel(const BlackMisc::Simulation::CAircraftModel &model);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user