refs #395, prepared for logical / physical add/remote member functions

* renamed functions
* added access to snapshot
* moved simulator base class in own files (.h/.cpp)
This commit is contained in:
Klaus Basan
2015-05-03 01:28:55 +02:00
committed by Mathew Sutcliffe
parent 91f0b99cc5
commit e9f7810efc
23 changed files with 641 additions and 470 deletions

View File

@@ -93,13 +93,13 @@ namespace BlackSimPlugin
return true;
}
bool CSimulatorFs9::addRemoteAircraft(const CSimulatedAircraft &newRemoteAircraft)
bool CSimulatorFs9::physicallyAddRemoteAircraft(const CSimulatedAircraft &newRemoteAircraft)
{
CCallsign callsign = newRemoteAircraft.getCallsign();
if (m_hashFs9Clients.contains(callsign))
{
// already exists, remove first
this->removeRemoteAircraft(callsign);
this->physicallyRemoveRemoteAircraft(callsign);
}
CFs9Client *client = new CFs9Client(m_interpolator, this, callsign.toQString(), CTime(25, CTimeUnit::ms()));
@@ -113,7 +113,7 @@ namespace BlackSimPlugin
return true;
}
bool CSimulatorFs9::removeRemoteAircraft(const CCallsign &callsign)
bool CSimulatorFs9::physicallyRemoveRemoteAircraft(const CCallsign &callsign)
{
if (!m_hashFs9Clients.contains(callsign)) { return false; }
@@ -125,15 +125,20 @@ namespace BlackSimPlugin
return true;
}
void CSimulatorFs9::removeAllRemoteAircraft()
void CSimulatorFs9::physicallyRemoveAllRemoteAircraft()
{
QList<CCallsign> callsigns(this->m_hashFs9Clients.keys());
for (const CCallsign &cs : callsigns)
{
removeRemoteAircraft(cs);
physicallyRemoveRemoteAircraft(cs);
}
}
CCallsignSet CSimulatorFs9::physicallyRenderedAircraft() const
{
return this->m_hashFs9Clients.keys();
}
bool CSimulatorFs9::updateOwnSimulatorCockpit(const CAircraft &ownAircraft, const QString &originator)
{
if (originator == this->simulatorOriginator()) { return false; }
@@ -200,7 +205,7 @@ namespace BlackSimPlugin
this->displayStatusMessage(message.asStatusMessage(true, true));
}
bool CSimulatorFs9::isRenderedAircraft(const CCallsign &callsign) const
bool CSimulatorFs9::isPhysicallyRenderedAircraft(const CCallsign &callsign) const
{
return m_hashFs9Clients.contains(callsign);
}
@@ -273,7 +278,7 @@ namespace BlackSimPlugin
// Stop all FS9 client tasks
for (auto fs9Client : m_hashFs9Clients.keys())
{
removeRemoteAircraft(fs9Client);
physicallyRemoveRemoteAircraft(fs9Client);
}
}

View File

@@ -66,14 +66,20 @@ namespace BlackSimPlugin
//! \copydoc ISimulator::disconnectFrom()
virtual bool disconnectFrom() override;
//! \copydoc ISimulator::addRemoteAircraft()
virtual bool addRemoteAircraft(const BlackMisc::Simulation::CSimulatedAircraft &newRemoteAircraft) override;
//! \copydoc ISimulator::physicallyAddRemoteAircraft()
virtual bool physicallyAddRemoteAircraft(const BlackMisc::Simulation::CSimulatedAircraft &newRemoteAircraft) override;
//! \copydoc ISimulator::removeRemoteAircraft()
virtual bool removeRemoteAircraft(const BlackMisc::Aviation::CCallsign &callsign) override;
//! \copydoc ISimulator::physicallyRemoveRemoteAircraft()
virtual bool physicallyRemoveRemoteAircraft(const BlackMisc::Aviation::CCallsign &callsign) override;
//! \copydoc BlackCore::ISimulator::removeAllRemoteAircraft
virtual void removeAllRemoteAircraft() override;
//! \copydoc BlackCore::ISimulator::physicallyRemoveAllRemoteAircraft
virtual void physicallyRemoveAllRemoteAircraft() override;
//! \copydoc ISimulator::physicallyRenderedAircraft
virtual BlackMisc::Aviation::CCallsignSet physicallyRenderedAircraft() const override;
//! \copydoc ISimulator::isPhysicallyRenderedAircraft
virtual bool isPhysicallyRenderedAircraft(const BlackMisc::Aviation::CCallsign &callsign) const override;
//! \copydoc ISimulator::updateOwnSimulatorCockpit()
virtual bool updateOwnSimulatorCockpit(const BlackMisc::Aviation::CAircraft &ownAircraft, const QString &originator) override;
@@ -84,9 +90,6 @@ namespace BlackSimPlugin
//! \copydoc ISimulator::displayTextMessage()
virtual void displayTextMessage(const BlackMisc::Network::CTextMessage &message) const override;
//! \copydoc ISimulator::isRenderedAircraft
virtual bool isRenderedAircraft(const BlackMisc::Aviation::CCallsign &callsign) const override;
protected:
//! Timer event
virtual void timerEvent(QTimerEvent *event);

View File

@@ -26,8 +26,8 @@ namespace BlackSimPlugin
namespace FsCommon
{
CSimulatorFsCommon::CSimulatorFsCommon(
const BlackMisc::Simulation::CSimulatorPluginInfo &info,
BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider,
const CSimulatorPluginInfo &info,
IOwnAircraftProvider *ownAircraftProvider,
IRemoteAircraftProvider *renderedAircraftProvider,
QObject *parent) :
CSimulatorCommon(info, ownAircraftProvider, renderedAircraftProvider, parent),
@@ -100,7 +100,8 @@ namespace BlackSimPlugin
{
// reverse lookup of ICAO
CAircraftIcao icao = mapperInstance()->getIcaoForModelString(model.getModelString());
icao.updateMissingParts(icao);
icao.updateMissingParts(model.getIcao());
model.setIcao(icao); // now best ICAO info in model
}
}
@@ -259,7 +260,7 @@ namespace BlackSimPlugin
if (originator == simulatorOriginator()) { return false; }
// remove upfront, and then enable / disable again
this->removeRemoteAircraft(aircraft.getCallsign());
this->physicallyRemoveRemoteAircraft(aircraft.getCallsign());
return this->changeRemoteAircraftEnabled(aircraft, originator);
}
@@ -268,11 +269,11 @@ namespace BlackSimPlugin
if (originator == simulatorOriginator()) { return false; }
if (aircraft.isEnabled())
{
this->addRemoteAircraft(aircraft);
this->physicallyAddRemoteAircraft(aircraft);
}
else
{
this->removeRemoteAircraft(aircraft.getCallsign());
this->physicallyRemoveRemoteAircraft(aircraft.getCallsign());
}
return true;
}

View File

@@ -12,7 +12,7 @@
#ifndef BLACKSIMPLUGIN_SIMULATOR_COMMON_H
#define BLACKSIMPLUGIN_SIMULATOR_COMMON_H
#include "blackcore/simulator.h"
#include "blackcore/simulator_common.h"
#include "blackcore/interpolator.h"
#include "blackmisc/simulation/fscommon/aircraftmapper.h"
#include "fsuipc.h"

View File

@@ -137,7 +137,7 @@ namespace BlackSimPlugin
return connect;
}
bool CSimulatorFsx::addRemoteAircraft(const Simulation::CSimulatedAircraft &newRemoteAircraft)
bool CSimulatorFsx::physicallyAddRemoteAircraft(const Simulation::CSimulatedAircraft &newRemoteAircraft)
{
CCallsign callsign = newRemoteAircraft.getCallsign();
Q_ASSERT(!callsign.isEmpty());
@@ -147,7 +147,7 @@ namespace BlackSimPlugin
if (aircraftAlreadyExistsInSim)
{
// remove first
this->removeRemoteAircraft(callsign);
this->physicallyRemoveRemoteAircraft(callsign);
CLogMessage(this).warning("Have to remove aircraft %1 before I can add it") << callsign;
}
@@ -294,11 +294,16 @@ namespace BlackSimPlugin
this->displayStatusMessage(message.asStatusMessage(true, true));
}
bool CSimulatorFsx::isRenderedAircraft(const CCallsign &callsign) const
bool CSimulatorFsx::isPhysicallyRenderedAircraft(const CCallsign &callsign) const
{
return this->m_simConnectObjects.contains(callsign);
}
CCallsignSet CSimulatorFsx::physicallyRenderedAircraft() const
{
return this->m_simConnectObjects.keys();
}
void CSimulatorFsx::onSimRunning()
{
if (m_simRunning) { return; }
@@ -511,23 +516,23 @@ namespace BlackSimPlugin
}
}
bool CSimulatorFsx::removeRemoteAircraft(const CCallsign &callsign)
bool CSimulatorFsx::physicallyRemoveRemoteAircraft(const CCallsign &callsign)
{
// only remove from sim
if (!m_simConnectObjects.contains(callsign)) { return false; }
return removeRemoteAircraft(m_simConnectObjects.value(callsign));
return physicallyRemoveRemoteAircraft(m_simConnectObjects.value(callsign));
}
void CSimulatorFsx::removeAllRemoteAircraft()
void CSimulatorFsx::physicallyRemoveAllRemoteAircraft()
{
QList<CCallsign> callsigns(m_simConnectObjects.keys());
for (const CCallsign &cs : callsigns)
{
removeRemoteAircraft(cs);
physicallyRemoveRemoteAircraft(cs);
}
}
bool CSimulatorFsx::removeRemoteAircraft(const CSimConnectObject &simObject)
bool CSimulatorFsx::physicallyRemoveRemoteAircraft(const CSimConnectObject &simObject)
{
CCallsign callsign(simObject.getCallsign());
m_simConnectObjects.remove(callsign);

View File

@@ -103,14 +103,14 @@ namespace BlackSimPlugin
//! \copydoc ISimulator::disconnectFrom()
virtual bool disconnectFrom() override;
//! \copydoc ISimulator::addRemoteAircraft()
virtual bool addRemoteAircraft(const BlackMisc::Simulation::CSimulatedAircraft &newRemoteAircraft) override;
//! \copydoc ISimulator::physicallyAddRemoteAircraft()
virtual bool physicallyAddRemoteAircraft(const BlackMisc::Simulation::CSimulatedAircraft &newRemoteAircraft) override;
//! \copydoc ISimulator::remoteRenderedAircraft()
virtual bool removeRemoteAircraft(const BlackMisc::Aviation::CCallsign &callsign) override;
//! \copydoc ISimulator::physicallyRemoveRemoteAircraft()
virtual bool physicallyRemoveRemoteAircraft(const BlackMisc::Aviation::CCallsign &callsign) override;
//! \copydoc BlackCore::ISimulator::removeAllRemoteAircraft
virtual void removeAllRemoteAircraft() override;
//! \copydoc BlackCore::ISimulator::physicallyRemoveAllRemoteAircraft
virtual void physicallyRemoveAllRemoteAircraft() override;
//! \copydoc ISimulator::updateOwnCockpit
virtual bool updateOwnSimulatorCockpit(const BlackMisc::Aviation::CAircraft &ownAircraft, const QString &originator) override;
@@ -121,8 +121,11 @@ namespace BlackSimPlugin
//! \copydoc ISimulator::displayTextMessage()
virtual void displayTextMessage(const BlackMisc::Network::CTextMessage &message) const override;
//! \copydoc ISimulator::isRenderedAircraft
virtual bool isRenderedAircraft(const BlackMisc::Aviation::CCallsign &callsign) const override;
//! \copydoc ISimulator::isPhysicallyRenderedAircraft
virtual bool isPhysicallyRenderedAircraft(const BlackMisc::Aviation::CCallsign &callsign) const override;
//! \copydoc ISimulator::physicallyRenderedAircraft
virtual BlackMisc::Aviation::CCallsignSet physicallyRenderedAircraft() const override;
//! Called when sim has started
void onSimRunning();
@@ -159,7 +162,7 @@ namespace BlackSimPlugin
private:
//! Remove a remote aircraft
bool removeRemoteAircraft(const CSimConnectObject &simObject);
bool physicallyRemoveRemoteAircraft(const CSimConnectObject &simObject);
//! Init when connected
HRESULT initWhenConnected();

View File

@@ -247,21 +247,17 @@ namespace BlackSimPlugin
void CSimulatorXPlane::displayStatusMessage(const BlackMisc::CStatusMessage &message) const
{
/* We do not assert here as status message may come because of network problems */
if (!isConnected())
return;
if (!isConnected()) { return; }
// TODO XPLMSpeakString()?
// http://www.xsquawkbox.net/xpsdk/mediawiki/XPLMSpeakString
//! \todo XP driver, display text message: XPLMSpeakString()? http://www.xsquawkbox.net/xpsdk/mediawiki/XPLMSpeakString
Q_UNUSED(message);
}
void CSimulatorXPlane::displayTextMessage(const BlackMisc::Network::CTextMessage &message) const
{
if (!isConnected())
return;
if (!isConnected()) { return; }
// TODO XPLMSpeakString()?
// http://www.xsquawkbox.net/xpsdk/mediawiki/XPLMSpeakString
//! \todo XP driver, display text message: XPLMSpeakString()? http://www.xsquawkbox.net/xpsdk/mediawiki/XPLMSpeakString
Q_UNUSED(message);
}
@@ -270,7 +266,6 @@ namespace BlackSimPlugin
Q_ASSERT(isConnected());
//! \todo XP driver, function not available
CLogMessage(this).error("Function not avialable");
return {};
}
@@ -302,7 +297,7 @@ namespace BlackSimPlugin
BlackMisc::Aviation::CAirportList CSimulatorXPlane::getAirportsInRange() const
{
auto copy = m_airportsInRange;
//! \todo Check if units match, xPlaneData has now hints what the values are
//! \todo XP driver: Check if units match, xPlaneData has now hints what the values are
copy.sortByRange(CCoordinateGeodetic(m_xplaneData.latitude, m_xplaneData.longitude, 0), true);
copy.truncate(20);
return copy;
@@ -323,10 +318,9 @@ namespace BlackSimPlugin
return CPixmap();
}
bool CSimulatorXPlane::isRenderedAircraft(const CCallsign &callsign) const
bool CSimulatorXPlane::isPhysicallyRenderedAircraft(const CCallsign &callsign) const
{
//! \todo XP implement isRenderedAircraft correctly
// work around, but not really telling me if callsign is really(!) visible in SIM
//! \todo XP implement isRenderedAircraft correctly. This work around, but not really telling me if callsign is really(!) visible in SIM
return getAircraftInRangeForCallsign(callsign).isRendered();
}
@@ -358,7 +352,7 @@ namespace BlackSimPlugin
return false;
}
bool CSimulatorXPlane::addRemoteAircraft(const CSimulatedAircraft &newRemoteAircraft)
bool CSimulatorXPlane::physicallyAddRemoteAircraft(const CSimulatedAircraft &newRemoteAircraft)
{
Q_ASSERT(isConnected());
//! \todo XPlane driver check if already exists, how?
@@ -385,7 +379,7 @@ namespace BlackSimPlugin
situation.getHeading().value(CAngleUnit::deg()));
}
void CSimulatorXPlane::ps_remoteProvideraddAircraftParts(const BlackMisc::Aviation::CAircraftParts &parts)
void CSimulatorXPlane::ps_remoteProviderAddAircraftParts(const BlackMisc::Aviation::CAircraftParts &parts)
{
Q_ASSERT(isConnected());
m_traffic->setPlaneSurfaces(parts.getCallsign().asString(), true, 0, 0, 0, 0, 0, 0, 0, 0, 0, true, true, true, true, 0); // TODO landing gear, lights, control surfaces
@@ -398,7 +392,7 @@ namespace BlackSimPlugin
//! \todo call removeRemoteAircraft or just let removeRemoteAircraft handle it?
}
bool CSimulatorXPlane::removeRemoteAircraft(const BlackMisc::Aviation::CCallsign &callsign)
bool CSimulatorXPlane::physicallyRemoveRemoteAircraft(const BlackMisc::Aviation::CCallsign &callsign)
{
Q_ASSERT(isConnected());
m_traffic->removePlane(callsign.asString());
@@ -407,13 +401,19 @@ namespace BlackSimPlugin
return true;
}
void CSimulatorXPlane::removeAllRemoteAircraft()
void CSimulatorXPlane::physicallyRemoveAllRemoteAircraft()
{
m_traffic->removeAllPlanes();
updateMarkAllAsNotRendered(simulatorOriginator());
CLogMessage(this).info("XP: Removed all aircraft");
}
CCallsignSet CSimulatorXPlane::physicallyRenderedAircraft() const
{
//! \todo XP driver, return list of callsigns really present in the simulator
return getAircraftInRange().findByRendered(true).getCallsigns(); // just a poor workaround
}
bool CSimulatorXPlane::changeRemoteAircraftModel(const CSimulatedAircraft &aircraft, const QString &originator)
{
return this->changeRemoteAircraftEnabled(aircraft, originator);
@@ -430,11 +430,11 @@ namespace BlackSimPlugin
if (originator == simulatorOriginator()) { return false; }
if (aircraft.isEnabled())
{
this->addRemoteAircraft(aircraft);
this->physicallyAddRemoteAircraft(aircraft);
}
else
{
this->removeRemoteAircraft(aircraft.getCallsign());
this->physicallyRemoveRemoteAircraft(aircraft.getCallsign());
}
return true;
}

View File

@@ -12,7 +12,7 @@
#ifndef BLACKSIMPLUGIN_SIMULATOR_XPLANE_H
#define BLACKSIMPLUGIN_SIMULATOR_XPLANE_H
#include "blackcore/simulator.h"
#include "blackcore/simulator_common.h"
#include "blackmisc/simulation/ownaircraftprovider.h"
#include "blackmisc/pixmap.h"
#include <QDBusConnection>
@@ -65,14 +65,20 @@ namespace BlackSimPlugin
//! \copydoc BlackCore::ISimulator::disconnectFrom
virtual bool disconnectFrom() override;
//! \copydoc ISimulator::addRemoteAircraft()
virtual bool addRemoteAircraft(const BlackMisc::Simulation::CSimulatedAircraft &newRemoteAircraft) override;
//! \copydoc ISimulator::physicallyAddRemoteAircraft()
virtual bool physicallyAddRemoteAircraft(const BlackMisc::Simulation::CSimulatedAircraft &newRemoteAircraft) override;
//! \copydoc BlackCore::ISimulator::removeRemoteAircraft
virtual bool removeRemoteAircraft(const BlackMisc::Aviation::CCallsign &callsign) override;
//! \copydoc BlackCore::ISimulator::physicallyRemoveRemoteAircraft
virtual bool physicallyRemoveRemoteAircraft(const BlackMisc::Aviation::CCallsign &callsign) override;
//! \copydoc BlackCore::ISimulator::removeAllRemoteAircraft
virtual void removeAllRemoteAircraft() override;
//! \copydoc BlackCore::ISimulator::physicallyRemoveAllRemoteAircraft
virtual void physicallyRemoveAllRemoteAircraft() override;
//! \copydoc ISimulator::physicallyRenderedAircraft
virtual BlackMisc::Aviation::CCallsignSet physicallyRenderedAircraft() const override;
//! \copydoc ISimulator::isPhysicallyRenderedAircraft
virtual bool isPhysicallyRenderedAircraft(const BlackMisc::Aviation::CCallsign &callsign) const override;
//! \copydoc ISimulator::changeRenderedAircraftModel
virtual bool changeRemoteAircraftModel(const BlackMisc::Simulation::CSimulatedAircraft &aircraft, const QString &originator) override;
@@ -107,15 +113,12 @@ namespace BlackSimPlugin
//! \copydoc ISimulator::iconForModel
virtual BlackMisc::CPixmap iconForModel(const QString &modelString) const override;
//! \copydoc ISimulator::isRenderedAircraft
virtual bool isRenderedAircraft(const BlackMisc::Aviation::CCallsign &callsign) const override;
protected slots:
//! \copydoc CSimulatorCommon::ps_remoteProviderAddAircraftSituation
virtual void ps_remoteProviderAddAircraftSituation(const BlackMisc::Aviation::CAircraftSituation &situation) override;
//! \copydoc CSimulatorCommon::ps_remoteProvideraddAircraftParts
virtual void ps_remoteProvideraddAircraftParts(const BlackMisc::Aviation::CAircraftParts &parts) override;
virtual void ps_remoteProviderAddAircraftParts(const BlackMisc::Aviation::CAircraftParts &parts) override;
//! \copydoc CSimulatorCommon::ps_remoteProviderRemovedAircraft
virtual void ps_remoteProviderRemovedAircraft(const BlackMisc::Aviation::CCallsign &callsign) override;