Ref T370, further remove models improvements

* timer checks not only for add, but also for remove
* renamed to facilitate changes
This commit is contained in:
Klaus Basan
2018-09-23 20:10:17 +02:00
parent 6962a7bddb
commit 22160c146e
3 changed files with 25 additions and 14 deletions

View File

@@ -286,6 +286,7 @@ namespace BlackSimPlugin
CCallsignSet CSimConnectObjects::getAllCallsigns(bool withoutProbes) const CCallsignSet CSimConnectObjects::getAllCallsigns(bool withoutProbes) const
{ {
if (this->isEmpty()) { return CCallsignSet(); }
if (!withoutProbes) { return CCallsignSet(this->keys()); } if (!withoutProbes) { return CCallsignSet(this->keys()); }
CCallsignSet callsigns; CCallsignSet callsigns;
for (const CSimConnectObject &simObject : this->values()) for (const CSimConnectObject &simObject : this->values())

View File

@@ -65,12 +65,12 @@ namespace BlackSimPlugin
Q_ASSERT_X(remoteAircraftProvider, Q_FUNC_INFO, "Missing provider"); Q_ASSERT_X(remoteAircraftProvider, Q_FUNC_INFO, "Missing provider");
Q_ASSERT_X(sApp, Q_FUNC_INFO, "Missing global object"); Q_ASSERT_X(sApp, Q_FUNC_INFO, "Missing global object");
m_addPendingSimObjTimer.setInterval(AddPendingAircraftIntervalMs); m_simObjectTimer.setInterval(AddPendingAircraftIntervalMs);
m_useFsuipc = false; m_useFsuipc = false;
// default model will be set in derived class // default model will be set in derived class
CSimulatorFsxCommon::registerHelp(); CSimulatorFsxCommon::registerHelp();
connect(&m_addPendingSimObjTimer, &QTimer::timeout, this, &CSimulatorFsxCommon::addPendingAircraftByTimer); connect(&m_simObjectTimer, &QTimer::timeout, this, &CSimulatorFsxCommon::timerBasedObjectAddOrRemove);
} }
CSimulatorFsxCommon::~CSimulatorFsxCommon() CSimulatorFsxCommon::~CSimulatorFsxCommon()
@@ -990,9 +990,10 @@ namespace BlackSimPlugin
} }
} }
void CSimulatorFsxCommon::addPendingAircraftByTimer() void CSimulatorFsxCommon::timerBasedObjectAddOrRemove()
{ {
this->addPendingAircraft(AddByTimer); this->addPendingAircraft(AddByTimer);
this->physicallyRemoveAircraftNotInProvider();
} }
void CSimulatorFsxCommon::addPendingAircraftAfterAdded() void CSimulatorFsxCommon::addPendingAircraftAfterAdded()
@@ -1281,7 +1282,7 @@ namespace BlackSimPlugin
Q_ASSERT_X(newRemoteAircraft.hasModelString(), Q_FUNC_INFO, "missing model string"); Q_ASSERT_X(newRemoteAircraft.hasModelString(), Q_FUNC_INFO, "missing model string");
// reset timer // reset timer
m_addPendingSimObjTimer.start(AddPendingAircraftIntervalMs); // restart m_simObjectTimer.start(AddPendingAircraftIntervalMs); // restart
const CSimConnectObjects outdatedAdded = m_simConnectObjects.removeOutdatedPendingAdded(CSimConnectObject::AllTypes); const CSimConnectObjects outdatedAdded = m_simConnectObjects.removeOutdatedPendingAdded(CSimConnectObject::AllTypes);
if (!outdatedAdded.isEmpty()) if (!outdatedAdded.isEmpty())
@@ -1526,12 +1527,7 @@ namespace BlackSimPlugin
} }
// cleanup function, actually this should not be needed // cleanup function, actually this should not be needed
const QPointer<CSimulatorFsxCommon> myself(this); this->physicallyRemoveAircraftNotInProviderAsync();
QTimer::singleShot(100, this, [ = ]
{
if (!myself) { return; }
CSimulatorFsxCommon::physicallyRemoveAircraftNotInProvider();
});
// bye // bye
return true; return true;
@@ -2130,6 +2126,7 @@ namespace BlackSimPlugin
CCallsignSet CSimulatorFsxCommon::getCallsignsMissingInProvider() const CCallsignSet CSimulatorFsxCommon::getCallsignsMissingInProvider() const
{ {
if (m_simConnectObjects.isEmpty()) { return CCallsignSet(); }
const CCallsignSet simObjectCallsigns(m_simConnectObjects.getAllCallsigns(true)); const CCallsignSet simObjectCallsigns(m_simConnectObjects.getAllCallsigns(true));
const CCallsignSet providerCallsigns(this->getAircraftInRangeCallsigns()); const CCallsignSet providerCallsigns(this->getAircraftInRangeCallsigns());
return simObjectCallsigns.difference(providerCallsigns); return simObjectCallsigns.difference(providerCallsigns);
@@ -2312,6 +2309,16 @@ namespace BlackSimPlugin
return callsignsToBeRemoved; return callsignsToBeRemoved;
} }
void CSimulatorFsxCommon::physicallyRemoveAircraftNotInProviderAsync()
{
const QPointer<CSimulatorFsxCommon> myself(this);
QTimer::singleShot(100, this, [ = ]
{
if (!myself || !sApp || sApp->isShuttingDown()) { return; }
CSimulatorFsxCommon::physicallyRemoveAircraftNotInProvider();
});
}
CSimulatorFsxCommonListener::CSimulatorFsxCommonListener(const CSimulatorPluginInfo &info) : CSimulatorFsxCommonListener::CSimulatorFsxCommonListener(const CSimulatorPluginInfo &info) :
ISimulatorListener(info) ISimulatorListener(info)
{ {

View File

@@ -294,9 +294,12 @@ namespace BlackSimPlugin
int physicallyInitAITerrainProbes(const BlackMisc::Geo::ICoordinateGeodetic &coordinate, int number); int physicallyInitAITerrainProbes(const BlackMisc::Geo::ICoordinateGeodetic &coordinate, int number);
//! Remove aircraft no longer in provider //! Remove aircraft no longer in provider
//! \remark kind of cleanup function, in an ideal this should never need to cleanup something //! \remark kind of cleanup function, in an ideal scenario this should never need to cleanup something
BlackMisc::Aviation::CCallsignSet physicallyRemoveAircraftNotInProvider(); BlackMisc::Aviation::CCallsignSet physicallyRemoveAircraftNotInProvider();
//! ASynchronous version of physicallyRemoveAircraftNotInProvider
void physicallyRemoveAircraftNotInProviderAsync();
//! Verify that an object has been added in simulator //! Verify that an object has been added in simulator
//! \remark checks if the object was really added after an "add request" and not directly removed again //! \remark checks if the object was really added after an "add request" and not directly removed again
//! \remark requests further data on remote aircraft (lights, ..) when correctly added //! \remark requests further data on remote aircraft (lights, ..) when correctly added
@@ -315,7 +318,7 @@ namespace BlackSimPlugin
void verifyAddedTerrainProbe(const BlackMisc::Simulation::CSimulatedAircraft &remoteAircraftIn); void verifyAddedTerrainProbe(const BlackMisc::Simulation::CSimulatedAircraft &remoteAircraftIn);
//! Add next aircraft based on timer //! Add next aircraft based on timer
void addPendingAircraftByTimer(); void timerBasedObjectAddOrRemove();
//! Add next aircraft after another has been confirmed //! Add next aircraft after another has been confirmed
void addPendingAircraftAfterAdded(); void addPendingAircraftAfterAdded();
@@ -549,7 +552,7 @@ namespace BlackSimPlugin
CSimConnectObjects m_addPendingAircraft; //!< aircraft/probes awaiting to be added; CSimConnectObjects m_addPendingAircraft; //!< aircraft/probes awaiting to be added;
SIMCONNECT_DATA_REQUEST_ID m_requestIdSimObjAircraft = static_cast<SIMCONNECT_DATA_REQUEST_ID>(RequestSimObjAircraftStart); //!< request id, use obtainRequestIdForSimObjAircraft to get id SIMCONNECT_DATA_REQUEST_ID m_requestIdSimObjAircraft = static_cast<SIMCONNECT_DATA_REQUEST_ID>(RequestSimObjAircraftStart); //!< request id, use obtainRequestIdForSimObjAircraft to get id
SIMCONNECT_DATA_REQUEST_ID m_requestIdSimObjTerrainProbe = static_cast<SIMCONNECT_DATA_REQUEST_ID>(RequestSimObjTerrainProbeStart); //!< request id, use obtainRequestIdForSimObjTerrainProbe to get id SIMCONNECT_DATA_REQUEST_ID m_requestIdSimObjTerrainProbe = static_cast<SIMCONNECT_DATA_REQUEST_ID>(RequestSimObjTerrainProbeStart); //!< request id, use obtainRequestIdForSimObjTerrainProbe to get id
QTimer m_addPendingSimObjTimer; //!< updating of SimObjects awaiting to be added QTimer m_simObjectTimer; //!< updating of SimObjects awaiting to be added
//! Request id to string //! Request id to string
static QString requestIdToString(DWORD requestId); static QString requestIdToString(DWORD requestId);