mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-26 02:35:38 +08:00
Ref T232, some (dispatch) timer code was duplicated
* fixed a bug, where a non existing timer was killed * unified code in base class
This commit is contained in:
@@ -85,7 +85,10 @@ namespace BlackCore
|
|||||||
CLogMessage(this).info("Initialized simulator driver: '%1'") << m_simulatorPluginInfo.toQString();
|
CLogMessage(this).info("Initialized simulator driver: '%1'") << m_simulatorPluginInfo.toQString();
|
||||||
}
|
}
|
||||||
|
|
||||||
CSimulatorCommon::~CSimulatorCommon() { }
|
CSimulatorCommon::~CSimulatorCommon()
|
||||||
|
{
|
||||||
|
this->safeKillTimer();
|
||||||
|
}
|
||||||
|
|
||||||
const CLogCategoryList &CSimulatorCommon::getLogCategories()
|
const CLogCategoryList &CSimulatorCommon::getLogCategories()
|
||||||
{
|
{
|
||||||
@@ -500,6 +503,13 @@ namespace BlackCore
|
|||||||
this->blinkHighlightedAircraft();
|
this->blinkHighlightedAircraft();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSimulatorCommon::safeKillTimer()
|
||||||
|
{
|
||||||
|
if (m_timerId < 0) { return; }
|
||||||
|
this->killTimer(m_timerId);
|
||||||
|
m_timerId = -1;
|
||||||
|
}
|
||||||
|
|
||||||
void CSimulatorCommon::onRecalculatedRenderedAircraft(const CAirspaceAircraftSnapshot &snapshot)
|
void CSimulatorCommon::onRecalculatedRenderedAircraft(const CAirspaceAircraftSnapshot &snapshot)
|
||||||
{
|
{
|
||||||
if (!snapshot.isValidSnapshot()) { return;}
|
if (!snapshot.isValidSnapshot()) { return;}
|
||||||
|
|||||||
@@ -206,8 +206,12 @@ namespace BlackCore
|
|||||||
//! Slow timer used to highlight aircraft, can be used for other things too
|
//! Slow timer used to highlight aircraft, can be used for other things too
|
||||||
virtual void oneSecondTimerTimeout();
|
virtual void oneSecondTimerTimeout();
|
||||||
|
|
||||||
|
//! Kill timer if id is valid
|
||||||
|
void safeKillTimer();
|
||||||
|
|
||||||
bool m_pausedSimFreezesInterpolation = false; //!< paused simulator will also pause interpolation (so AI aircraft will hold)
|
bool m_pausedSimFreezesInterpolation = false; //!< paused simulator will also pause interpolation (so AI aircraft will hold)
|
||||||
bool m_autoCalcAirportDistance = true; //!< automatically calculate airport distance and bearing
|
bool m_autoCalcAirportDistance = true; //!< automatically calculate airport distance and bearing
|
||||||
|
int m_timerId = -1; //!< dispatch timer id
|
||||||
int m_statsUpdateAircraftCountMs = 0; //!< statistics update count
|
int m_statsUpdateAircraftCountMs = 0; //!< statistics update count
|
||||||
qint64 m_statsUpdateAircraftTimeTotalMs = 0; //!< statistics update time
|
qint64 m_statsUpdateAircraftTimeTotalMs = 0; //!< statistics update time
|
||||||
qint64 m_statsUpdateAircraftTimeAvgMs = 0; //!< statistics update time
|
qint64 m_statsUpdateAircraftTimeAvgMs = 0; //!< statistics update time
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ namespace BlackSimPlugin
|
|||||||
m_fsuipc->connect(); // connect FSUIPC too
|
m_fsuipc->connect(); // connect FSUIPC too
|
||||||
}
|
}
|
||||||
initSimulatorInternals();
|
initSimulatorInternals();
|
||||||
m_dispatchTimerId = startTimer(50);
|
m_timerId = startTimer(50);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,8 +154,7 @@ namespace BlackSimPlugin
|
|||||||
|
|
||||||
// Don't forward messages when disconnected
|
// Don't forward messages when disconnected
|
||||||
disconnect(m_connectionHostMessages);
|
disconnect(m_connectionHostMessages);
|
||||||
killTimer(m_dispatchTimerId);
|
safeKillTimer();
|
||||||
m_dispatchTimerId = -1;
|
|
||||||
disconnectAllClients();
|
disconnectAllClients();
|
||||||
|
|
||||||
// disconnect FSUIPC and status
|
// disconnect FSUIPC and status
|
||||||
|
|||||||
@@ -102,7 +102,6 @@ namespace BlackSimPlugin
|
|||||||
|
|
||||||
QHash<BlackMisc::Aviation::CCallsign, QPointer<CFs9Client>> m_hashFs9Clients;
|
QHash<BlackMisc::Aviation::CCallsign, QPointer<CFs9Client>> m_hashFs9Clients;
|
||||||
QMetaObject::Connection m_connectionHostMessages;
|
QMetaObject::Connection m_connectionHostMessages;
|
||||||
int m_dispatchTimerId = -1;
|
|
||||||
bool m_simConnected = false; //!< Is simulator connected?
|
bool m_simConnected = false; //!< Is simulator connected?
|
||||||
QSharedPointer<CFs9Host> m_fs9Host;
|
QSharedPointer<CFs9Host> m_fs9Host;
|
||||||
QSharedPointer<CLobbyClient> m_lobbyClient;
|
QSharedPointer<CLobbyClient> m_lobbyClient;
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ namespace BlackSimPlugin
|
|||||||
// set structures and move on
|
// set structures and move on
|
||||||
this->initEvents();
|
this->initEvents();
|
||||||
this->initDataDefinitionsWhenConnected();
|
this->initDataDefinitionsWhenConnected();
|
||||||
m_simConnectTimerId = startTimer(DispatchIntervalMs);
|
m_timerId = startTimer(DispatchIntervalMs);
|
||||||
// do not start m_addPendingAircraftTimer here, it will be started when object was added
|
// do not start m_addPendingAircraftTimer here, it will be started when object was added
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -99,8 +99,7 @@ namespace BlackSimPlugin
|
|||||||
bool CSimulatorFsxCommon::disconnectFrom()
|
bool CSimulatorFsxCommon::disconnectFrom()
|
||||||
{
|
{
|
||||||
if (!m_simConnected) { return true; }
|
if (!m_simConnected) { return true; }
|
||||||
if (m_simConnectTimerId >= 0) { killTimer(m_simConnectTimerId); }
|
this->safeKillTimer();
|
||||||
m_simConnectTimerId = -1;
|
|
||||||
m_simSimulating = false; // treat as stopped, just setting the flag here avoids overhead of on onSimStopped
|
m_simSimulating = false; // treat as stopped, just setting the flag here avoids overhead of on onSimStopped
|
||||||
if (m_hSimConnect)
|
if (m_hSimConnect)
|
||||||
{
|
{
|
||||||
@@ -338,7 +337,7 @@ namespace BlackSimPlugin
|
|||||||
{
|
{
|
||||||
// reset complete state, we are going down
|
// reset complete state, we are going down
|
||||||
m_simulatingChangedTs = QDateTime::currentMSecsSinceEpoch();
|
m_simulatingChangedTs = QDateTime::currentMSecsSinceEpoch();
|
||||||
if (m_simConnectTimerId >= 0) { killTimer(m_simConnectTimerId); }
|
this->safeKillTimer();
|
||||||
|
|
||||||
// if called from dispatch function, avoid that SimConnectProc disconnects itself while in SimConnectProc
|
// if called from dispatch function, avoid that SimConnectProc disconnects itself while in SimConnectProc
|
||||||
QTimer::singleShot(0, this, &CSimulatorFsxCommon::disconnectFrom);
|
QTimer::singleShot(0, this, &CSimulatorFsxCommon::disconnectFrom);
|
||||||
@@ -1503,8 +1502,7 @@ namespace BlackSimPlugin
|
|||||||
|
|
||||||
void CSimulatorFsxCommon::reset()
|
void CSimulatorFsxCommon::reset()
|
||||||
{
|
{
|
||||||
if (m_simConnectTimerId >= 0) { killTimer(m_simConnectTimerId); }
|
this->safeKillTimer();
|
||||||
m_simConnectTimerId = -1;
|
|
||||||
m_simulatingChangedTs = -1;
|
m_simulatingChangedTs = -1;
|
||||||
m_simConnected = false;
|
m_simConnected = false;
|
||||||
m_simSimulating = false;
|
m_simSimulating = false;
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ namespace BlackSimPlugin
|
|||||||
//! @}
|
//! @}
|
||||||
|
|
||||||
//! Timer event (our SimConnect event loop), runs dispatch
|
//! Timer event (our SimConnect event loop), runs dispatch
|
||||||
//! \sa m_simconnectTimerId
|
//! \sa m_timerId
|
||||||
//! \sa CSimulatorFsxCommon::dispatch
|
//! \sa CSimulatorFsxCommon::dispatch
|
||||||
virtual void timerEvent(QTimerEvent *event) override;
|
virtual void timerEvent(QTimerEvent *event) override;
|
||||||
|
|
||||||
@@ -354,7 +354,6 @@ namespace BlackSimPlugin
|
|||||||
bool m_traceSendId = false; //!< trace the send ids, meant for dedugging
|
bool m_traceSendId = false; //!< trace the send ids, meant for dedugging
|
||||||
qint64 m_simulatingChangedTs = -1; //!< timestamp, when simulating changed (used to avoid jitter)
|
qint64 m_simulatingChangedTs = -1; //!< timestamp, when simulating changed (used to avoid jitter)
|
||||||
int m_syncDeferredCounter = 0; //!< Set when synchronized, used to wait some time
|
int m_syncDeferredCounter = 0; //!< Set when synchronized, used to wait some time
|
||||||
int m_simConnectTimerId = -1; //!< Timer identifier
|
|
||||||
int m_skipCockpitUpdateCycles = 0; //!< skip some update cycles to allow changes in simulator cockpit to be set
|
int m_skipCockpitUpdateCycles = 0; //!< skip some update cycles to allow changes in simulator cockpit to be set
|
||||||
int m_interpolationRequest = 0; //!< current interpolation request
|
int m_interpolationRequest = 0; //!< current interpolation request
|
||||||
int m_dispatchErrors = 0; //!< number of dispatched failed, \sa dispatch
|
int m_dispatchErrors = 0; //!< number of dispatched failed, \sa dispatch
|
||||||
|
|||||||
Reference in New Issue
Block a user