mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 20:15:35 +08:00
* added unload function to disconnect signals / slots and simulator * changed remote provider to return signal/slot connections to manually disconnect functor connects * flag so pause can freeze or continue AI aircraft * slightly changed unload behaviour in simulator context Remark: Tested for FSX only Solves #424 for FSX
This commit is contained in:
@@ -56,6 +56,7 @@ namespace BlackSimPlugin
|
||||
CSimulatorFsx::~CSimulatorFsx()
|
||||
{
|
||||
disconnectFrom();
|
||||
// fsuipc is disconnected in CSimulatorFsCommon
|
||||
}
|
||||
|
||||
bool CSimulatorFsx::isConnected() const
|
||||
@@ -168,7 +169,7 @@ namespace BlackSimPlugin
|
||||
emit modelMatchingCompleted(aircraftAfterModelApplied);
|
||||
|
||||
// create AI
|
||||
if (isSimulating())
|
||||
if (isConnected())
|
||||
{
|
||||
//! \todo FSX driver if exists, recreate (new model?, new ICAO code)
|
||||
QByteArray m = aircraftModel.getModelString().toLocal8Bit();
|
||||
@@ -304,7 +305,9 @@ namespace BlackSimPlugin
|
||||
void CSimulatorFsx::onSimRunning()
|
||||
{
|
||||
if (m_simRunning) { return; }
|
||||
m_simRunning = true;
|
||||
qDebug() << "onSimRunning";
|
||||
m_simRunning = true; // only place where this should be set to true
|
||||
m_simConnected = true;
|
||||
HRESULT hr = SimConnect_RequestDataOnSimObject(m_hSimConnect, CSimConnectDefinitions::RequestOwnAircraft,
|
||||
CSimConnectDefinitions::DataOwnAircraft,
|
||||
SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_PERIOD_VISUAL_FRAME);
|
||||
@@ -340,11 +343,7 @@ namespace BlackSimPlugin
|
||||
|
||||
void CSimulatorFsx::onSimStopped()
|
||||
{
|
||||
if (m_simRunning)
|
||||
{
|
||||
m_simRunning = false;
|
||||
mapperInstance()->gracefulShutdown(); // stop background reading if ongoing
|
||||
}
|
||||
m_simRunning = false;
|
||||
emitSimulatorCombinedStatus();
|
||||
}
|
||||
|
||||
@@ -355,8 +354,14 @@ namespace BlackSimPlugin
|
||||
|
||||
void CSimulatorFsx::onSimExit()
|
||||
{
|
||||
// reset complete state, we are going down
|
||||
m_simConnected = false;
|
||||
this->onSimStopped();
|
||||
m_simRunning = false;
|
||||
m_simPaused = false;
|
||||
|
||||
// stop background reading if ongoing
|
||||
mapperInstance()->gracefulShutdown();
|
||||
emitSimulatorCombinedStatus();
|
||||
}
|
||||
|
||||
void CSimulatorFsx::updateOwnAircraftFromSimulator(DataDefinitionOwnAircraft simulatorOwnAircraft)
|
||||
@@ -503,12 +508,13 @@ namespace BlackSimPlugin
|
||||
initDataDefinitionsWhenConnected();
|
||||
m_simconnectTimerId = startTimer(10);
|
||||
m_simConnected = true;
|
||||
|
||||
emitSimulatorCombinedStatus();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_simconnectTimerId >= 0) { killTimer(m_simconnectTimerId); }
|
||||
m_simConnected = false;
|
||||
m_simRunning = false;
|
||||
emitSimulatorCombinedStatus();
|
||||
}
|
||||
}
|
||||
@@ -549,6 +555,7 @@ namespace BlackSimPlugin
|
||||
hr += SimConnect_SubscribeToSystemEvent(m_hSimConnect, SystemEventObjectRemoved, "ObjectRemoved");
|
||||
hr += SimConnect_SubscribeToSystemEvent(m_hSimConnect, SystemEventFrame, "Frame");
|
||||
hr += SimConnect_SubscribeToSystemEvent(m_hSimConnect, SystemEventPause, "Pause");
|
||||
hr += SimConnect_SubscribeToSystemEvent(m_hSimConnect, SystemEventFlightLoaded, "FlightLoaded");
|
||||
if (hr != S_OK)
|
||||
{
|
||||
CLogMessage(this).error("FSX plugin error: %1") << "SimConnect_SubscribeToSystemEvent failed";
|
||||
@@ -624,7 +631,7 @@ namespace BlackSimPlugin
|
||||
Q_ASSERT_X(BlackCore::isCurrentThreadCreatingThread(this), Q_FUNC_INFO, "thread");
|
||||
|
||||
// nothing to do, reset request id and exit
|
||||
if (this->isPaused()) { return; } // no interpolation while paused
|
||||
if (this->isPaused() && this->m_pausedSimFreezesInterpolation) { return; } // no interpolation while paused
|
||||
int remoteAircraftNo = this->getAircraftInRangeCount();
|
||||
if (remoteAircraftNo < 1) { m_interpolationRequest = 0; return; }
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ namespace BlackSimPlugin
|
||||
SystemEventSlewToggle,
|
||||
SystemEventFrame,
|
||||
SystemEventPause,
|
||||
SystemEventFlightLoaded,
|
||||
EventPauseToggle,
|
||||
EventFreezeLat,
|
||||
EventFreezeAlt,
|
||||
@@ -127,15 +128,6 @@ namespace BlackSimPlugin
|
||||
//! \copydoc ISimulator::physicallyRenderedAircraft
|
||||
virtual BlackMisc::Aviation::CCallsignSet physicallyRenderedAircraft() const override;
|
||||
|
||||
//! Called when sim has started
|
||||
void onSimRunning();
|
||||
|
||||
//! Called when sim has stopped
|
||||
void onSimStopped();
|
||||
|
||||
//! Slot called every visual frame
|
||||
void onSimFrame();
|
||||
|
||||
//! Called when data about our own aircraft are received
|
||||
void updateOwnAircraftFromSimulator(DataDefinitionOwnAircraft simulatorOwnAircraft);
|
||||
|
||||
@@ -145,9 +137,6 @@ namespace BlackSimPlugin
|
||||
//! Set ID of a SimConnect object
|
||||
void setSimConnectObjectID(DWORD requestID, DWORD objectID);
|
||||
|
||||
//! \private
|
||||
void onSimExit();
|
||||
|
||||
protected:
|
||||
//! Timer event (our SimConnect event loop), runs \sa ps_dispatch
|
||||
//! \sa m_simconnectTimerId
|
||||
@@ -161,6 +150,18 @@ namespace BlackSimPlugin
|
||||
void ps_connectToFinished();
|
||||
|
||||
private:
|
||||
//! Called when sim has started
|
||||
void onSimRunning();
|
||||
|
||||
//! Slot called every visual frame
|
||||
void onSimFrame();
|
||||
|
||||
//! Called when simulator has stopped, e.g. by selecting the "select aircraft screen"
|
||||
void onSimStopped();
|
||||
|
||||
//! Simulator is going down
|
||||
void onSimExit();
|
||||
|
||||
//! Remove a remote aircraft
|
||||
bool physicallyRemoveRemoteAircraft(const CSimConnectObject &simObject);
|
||||
|
||||
|
||||
@@ -60,18 +60,18 @@ namespace BlackSimPlugin
|
||||
}
|
||||
case SIMCONNECT_RECV_ID_QUIT:
|
||||
{
|
||||
simulatorFsx->onSimExit(); // TODO: What is the difference to sim stopped?
|
||||
simulatorFsx->onSimExit();
|
||||
break;
|
||||
}
|
||||
case SIMCONNECT_RECV_ID_EVENT:
|
||||
{
|
||||
SIMCONNECT_RECV_EVENT *event = static_cast<SIMCONNECT_RECV_EVENT *>(pData);
|
||||
|
||||
switch (event->uEventID)
|
||||
{
|
||||
case SystemEventSimStatus:
|
||||
{
|
||||
if (event->dwData)
|
||||
bool running = event->dwData ? true : false;
|
||||
if (running)
|
||||
{
|
||||
simulatorFsx->onSimRunning();
|
||||
}
|
||||
@@ -83,22 +83,27 @@ namespace BlackSimPlugin
|
||||
}
|
||||
case SystemEventPause:
|
||||
{
|
||||
simulatorFsx->m_simPaused = event->dwData ? true : false;
|
||||
bool p = event->dwData ? true : false;
|
||||
simulatorFsx->m_simPaused = p;
|
||||
simulatorFsx->emitSimulatorCombinedStatus();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SIMCONNECT_RECV_ID_EVENT_OBJECT_ADDREMOVE:
|
||||
{
|
||||
SIMCONNECT_RECV_EVENT_OBJECT_ADDREMOVE *event = static_cast<SIMCONNECT_RECV_EVENT_OBJECT_ADDREMOVE *>(pData);
|
||||
if (event->uEventID == SystemEventObjectAdded)
|
||||
switch (event->uEventID)
|
||||
{
|
||||
//
|
||||
}
|
||||
else if (event->uEventID == SystemEventObjectRemoved)
|
||||
{
|
||||
//
|
||||
case SystemEventObjectAdded:
|
||||
break;
|
||||
case SystemEventObjectRemoved:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -171,7 +176,7 @@ namespace BlackSimPlugin
|
||||
for (unsigned i = 0; i < pAirportList->dwArraySize; ++i)
|
||||
{
|
||||
SIMCONNECT_DATA_FACILITY_AIRPORT *pFacilityAirport = pAirportList->rgData + i;
|
||||
if (!pFacilityAirport) break;
|
||||
if (!pFacilityAirport) { break; }
|
||||
const QString icao(pFacilityAirport->Icao);
|
||||
if (icao.isEmpty()) { continue; } // airfield without ICAO code
|
||||
if (!CAirportIcaoCode::isValidIcaoDesignator(icao)) { continue; } // tiny airfields in SIM
|
||||
@@ -200,6 +205,18 @@ namespace BlackSimPlugin
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SIMCONNECT_RECV_ID_EVENT_FILENAME:
|
||||
{
|
||||
SIMCONNECT_RECV_EVENT_FILENAME *event = static_cast<SIMCONNECT_RECV_EVENT_FILENAME *>(pData);
|
||||
switch (event->uEventID)
|
||||
{
|
||||
case SystemEventFlightLoaded:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user