refs #369, adjusted plugins

* common base class for FS drivers
* moved mapper into common base class
* reflect changes for own aircraft provider
** removed member functions
** removed unused members
This commit is contained in:
Klaus Basan
2015-02-01 20:51:56 +01:00
parent 24e6dcef54
commit 1b04205584
14 changed files with 559 additions and 506 deletions

View File

@@ -7,6 +7,8 @@
* contained in the LICENSE file.
*/
//! \file
#ifndef BLACKSIMPLUGIN_FS9_FS9SDK_H
#define BLACKSIMPLUGIN_FS9_FS9SDK_H
@@ -19,8 +21,6 @@
#endif
#include <dplay8.h>
//! \file
namespace BlackSimPlugin
{
namespace Fs9

View File

@@ -1,7 +1,7 @@
include (../../../../config.pri)
include (../../../../build.pri)
QT += core dbus gui network
QT += core dbus gui network concurrent xml
TARGET = simulator_fs9
TEMPLATE = lib

View File

@@ -28,15 +28,17 @@ using namespace BlackMisc::PhysicalQuantities;
using namespace BlackMisc::Geo;
using namespace BlackSim;
using namespace BlackSimPlugin::Fs9;
using namespace BlackSimPlugin::FsCommon;
namespace BlackSimPlugin
{
namespace Fs9
{
BlackCore::ISimulator *CSimulatorFs9Factory::create(QObject *parent)
BlackCore::ISimulator *CSimulatorFs9Factory::create(IOwnAircraftProvider *ownAircraft, QObject *parent)
{
registerMetadata();
return new Fs9::CSimulatorFs9(parent);
return new Fs9::CSimulatorFs9(ownAircraft, parent);
}
BlackSim::CSimulatorInfo CSimulatorFs9Factory::getSimulatorInfo() const
@@ -44,12 +46,10 @@ namespace BlackSimPlugin
return CSimulatorInfo::FS9();
}
CSimulatorFs9::CSimulatorFs9(QObject *parent) :
ISimulator(parent),
CSimulatorFs9::CSimulatorFs9(IOwnAircraftProvider *ownAircraft, QObject *parent) :
CSimulatorFsCommon(CSimulatorInfo::FS9(), ownAircraft, parent),
m_fs9Host(new CFs9Host(this)),
m_lobbyClient(new CLobbyClient(this)),
m_simulatorInfo(CSimulatorInfo::FS9()),
m_fsuipc(new FsCommon::CFsuipc())
m_lobbyClient(new CLobbyClient(this))
{
connect(m_fs9Host.data(), &CFs9Host::customPacketReceived, this, &CSimulatorFs9::ps_processFs9Message);
connect(m_fs9Host.data(), &CFs9Host::statusChanged, this, &CSimulatorFs9::ps_changeHostStatus);
@@ -68,13 +68,19 @@ namespace BlackSimPlugin
bool CSimulatorFs9::connectTo()
{
Q_ASSERT(m_fsuipc);
m_fsuipc->connect(); // connect FSUIPC too
// If we are already hosting, connect FS0 through lobby connection
if (m_isHosting) m_lobbyClient->connectFs9ToHost(m_fs9Host->getHostAddress());
if (m_isHosting)
{
m_lobbyClient->connectFs9ToHost(m_fs9Host->getHostAddress());
}
// If not, deferre connection until host is setup
else m_startedLobbyConnection = true;
else
{
m_startedLobbyConnection = true;
}
return true;
}
@@ -90,10 +96,8 @@ namespace BlackSimPlugin
emit connectionStatusChanged(ISimulator::Disconnected);
if (m_fs9Host) { m_fs9Host->quit(); }
m_fsuipc->disconnect();
CSimulatorFsCommon::disconnectFrom();
m_isHosting = false;
return true;
}
@@ -137,62 +141,55 @@ namespace BlackSimPlugin
//! \todo really update aircraft in SIM
}
bool CSimulatorFs9::updateOwnSimulatorCockpit(const CAircraft &ownAircraft)
bool CSimulatorFs9::updateOwnSimulatorCockpit(const CAircraft &ownAircraft, const QString &originator)
{
if (originator == this->simulatorOriginator()) { return false; }
if (!this->isSimulating()) { return false; }
// actually those data should be the same as ownAircraft
CComSystem newCom1 = ownAircraft.getCom1System();
CComSystem newCom2 = ownAircraft.getCom2System();
CTransponder newTransponder = ownAircraft.getTransponder();
bool changed = false;
if (newCom1 != this->m_ownAircraft.getCom1System())
if (newCom1.getFrequencyActive() != this->m_simCom1.getFrequencyActive())
{
if (newCom1.getFrequencyActive() != this->m_ownAircraft.getCom1System().getFrequencyActive())
{
// CFrequency newFreq = newCom1.getFrequencyActive();
changed = true;
}
if (newCom1.getFrequencyStandby() != this->m_ownAircraft.getCom1System().getFrequencyStandby())
{
}
this->m_ownAircraft.setCom1System(newCom1);
}
if (newCom1.getFrequencyStandby() != this->m_simCom1.getFrequencyStandby())
{
// CFrequency newFreq = newCom1.getFrequencyStandby();
changed = true;
}
if (newCom2 != this->m_ownAircraft.getCom2System())
if (newCom2.getFrequencyActive() != this->m_simCom2.getFrequencyActive())
{
if (newCom2.getFrequencyActive() != this->m_ownAircraft.getCom2System().getFrequencyActive())
{
}
if (newCom2.getFrequencyStandby() != this->m_ownAircraft.getCom2System().getFrequencyStandby())
{
}
this->m_ownAircraft.setCom2System(newCom2);
// CFrequency newFreq = newCom2.getFrequencyActive();
changed = true;
}
if (newCom2.getFrequencyStandby() != this->m_simCom2.getFrequencyStandby())
{
// CFrequency newFreq = newCom2.getFrequencyStandby();
changed = true;
}
if (newTransponder != this->m_ownAircraft.getTransponder())
if (newTransponder.getTransponderCode() != this->m_simTransponder.getTransponderCode())
{
if (newTransponder.getTransponderCode() != this->m_ownAircraft.getTransponder().getTransponderCode())
{
changed = true;
}
this->m_ownAircraft.setTransponder(newTransponder);
changed = true;
}
if (newTransponder.getTransponderMode() != this->m_simTransponder.getTransponderMode())
{
}
// avoid changes of cockpit back to old values due to an outdated read back value
// bye
return changed;
}
CSimulatorInfo CSimulatorFs9::getSimulatorInfo() const
{
return this->m_simulatorInfo;
}
void CSimulatorFs9::displayStatusMessage(const BlackMisc::CStatusMessage &message) const
{
if (message.getSeverity() != BlackMisc::CStatusMessage::SeverityDebug)
@@ -207,23 +204,6 @@ namespace BlackSimPlugin
this->displayStatusMessage(message.asStatusMessage(true, true));
}
CAirportList CSimulatorFs9::getAirportsInRange() const
{
return this->m_airportsInRange;
}
void CSimulatorFs9::setTimeSynchronization(bool enable, BlackMisc::PhysicalQuantities::CTime offset)
{
this->m_syncTime = enable;
this->m_syncTimeOffset = offset;
}
CPixmap CSimulatorFs9::iconForModel(const QString &modelString) const
{
Q_UNUSED(modelString);
return CPixmap();
}
void CSimulatorFs9::timerEvent(QTimerEvent * /* event */)
{
ps_dispatch();
@@ -231,14 +211,20 @@ namespace BlackSimPlugin
void CSimulatorFs9::ps_dispatch()
{
if (m_fsuipc) m_fsuipc->process();
updateOwnAircraftFromSim(m_fsuipc->getOwnAircraft());
if (m_fsuipc)
{
CSimulatedAircraft fsuipcAircraft(ownAircraft());
bool ok = m_fsuipc->read(fsuipcAircraft);
if (ok)
{
updateOwnAircraftFromSimulator(fsuipcAircraft);
}
}
}
void CSimulatorFs9::ps_processFs9Message(const QByteArray &message)
{
CFs9Sdk::MULTIPLAYER_PACKET_ID messageType = MultiPlayerPacketParser::readType(message);
switch (messageType)
{
case CFs9Sdk::MULTIPLAYER_PACKET_ID_PARAMS:
@@ -249,14 +235,14 @@ namespace BlackSimPlugin
{
MPChangePlayerPlane mpChangePlayerPlane;
MultiPlayerPacketParser::readMessage(message, mpChangePlayerPlane);
ps_changeOwnAircraftModel(mpChangePlayerPlane.aircraft_name);
setOwnAircraftModel(mpChangePlayerPlane.aircraft_name);
break;
}
case CFs9Sdk::MULTIPLAYER_PACKET_ID_POSITION_VELOCITY:
{
MPPositionVelocity mpPositionVelocity;
MultiPlayerPacketParser::readMessage(message, mpPositionVelocity);
m_ownAircraft.setSituation(aircraftSituationfromFS9(mpPositionVelocity));
ownAircraft().setSituation(aircraftSituationfromFS9(mpPositionVelocity));
break;
}
case CFs9Sdk::MPCHAT_PACKET_ID_CHAT_TEXT_SEND:
@@ -271,14 +257,6 @@ namespace BlackSimPlugin
}
}
void CSimulatorFs9::ps_changeOwnAircraftModel(const QString &modelname)
{
CAircraftModel model = m_ownAircraft.getModel();
model.setModelString(modelname);
m_ownAircraft.setModel(model);
emit ownAircraftModelChanged(m_ownAircraft);
}
void CSimulatorFs9::ps_changeHostStatus(BlackSimPlugin::Fs9::CFs9Host::HostStatus status)
{
switch (status)
@@ -306,11 +284,13 @@ namespace BlackSimPlugin
}
}
void CSimulatorFs9::updateOwnAircraftFromSim(const CAircraft &ownAircraft)
void CSimulatorFs9::updateOwnAircraftFromSimulator(const CAircraft &simDataOwnAircraft)
{
m_ownAircraft.setCom1System(ownAircraft.getCom1System());
m_ownAircraft.setCom2System(ownAircraft.getCom2System());
m_ownAircraft.setTransponder(ownAircraft.getTransponder());
this->providerUpdateCockpit(
simDataOwnAircraft.getCom1System(),
simDataOwnAircraft.getCom2System(),
simDataOwnAircraft.getTransponder(),
this->simulatorOriginator());
}
void CSimulatorFs9::disconnectAllClients()

View File

@@ -7,13 +7,15 @@
* contained in the LICENSE file.
*/
//! \file
#ifndef BLACKSIMPLUGIN_SIMULATOR_FS9_H
#define BLACKSIMPLUGIN_SIMULATOR_FS9_H
#include "fs9_host.h"
#include "fs9_client.h"
#include "lobby_client.h"
#include "../fscommon/fsuipc.h"
#include "../fscommon/simulator_fscommon.h"
#include "blackcore/simulator.h"
#include "blackcore/interpolator_linear.h"
#include "blackmisc/simulation/aircraftmodel.h"
@@ -26,8 +28,6 @@
#include <QThread>
#include <QHash>
//! \file
namespace BlackSimPlugin
{
namespace Fs9
@@ -41,20 +41,20 @@ namespace BlackSimPlugin
public:
//! \copydoc BlackCore::ISimulatorFactory::create()
virtual BlackCore::ISimulator *create(QObject *parent) override;
virtual BlackCore::ISimulator *create(BlackMisc::Simulation::IOwnAircraftProvider *ownAircraft, QObject *parent) override;
//! Simulator info
virtual BlackSim::CSimulatorInfo getSimulatorInfo() const override;
};
//! FSX Simulator Implementation
class CSimulatorFs9 : public BlackCore::ISimulator
class CSimulatorFs9 : public BlackSimPlugin::FsCommon::CSimulatorFsCommon
{
Q_OBJECT
public:
//! Constructor
CSimulatorFs9(QObject *parent = nullptr);
CSimulatorFs9(BlackMisc::Simulation::IOwnAircraftProvider *ownAircraft, QObject *parent);
//! Destructor
virtual ~CSimulatorFs9();
@@ -65,15 +65,9 @@ namespace BlackSimPlugin
//! \copydoc ISimulator::canConnect()
virtual bool canConnect() const override { return true; }
//! \copydoc ISimulator::isPaused
virtual bool isPaused() const override { return m_simPaused; }
//! \copydoc ISimulator::isSimulating
virtual bool isSimulating() const override { return isConnected(); }
//! Is time synchronization on?
virtual bool isTimeSynchronized() const override { return m_syncTime; }
public slots:
//! \copydoc ISimulator::connectTo()
@@ -85,9 +79,6 @@ namespace BlackSimPlugin
//! \copydoc ISimulator::disconnectFrom()
virtual bool disconnectFrom() override;
//! \copydoc ISimulator::getOwnAircraft()
virtual BlackMisc::Simulation::CSimulatedAircraft getOwnAircraft() const override { return m_ownAircraft; }
//! \copydoc ISimulator::addRemoteAircraft()
virtual void addRemoteAircraft(const BlackMisc::Simulation::CSimulatedAircraft &remoteAircraft) override;
@@ -104,10 +95,7 @@ namespace BlackSimPlugin
virtual int changeRemoteAircraft(const BlackMisc::Simulation::CSimulatedAircraft &changedAircraft, const BlackMisc::CPropertyIndexVariantMap &changeValues) override;
//! \copydoc ISimulator::updateOwnSimulatorCockpit()
virtual bool updateOwnSimulatorCockpit(const BlackMisc::Aviation::CAircraft &ownAircraft) override;
//! \copydoc ISimulator::getSimulatorInfo()
virtual BlackSim::CSimulatorInfo getSimulatorInfo() const override;
virtual bool updateOwnSimulatorCockpit(const BlackMisc::Aviation::CAircraft &ownAircraft, const QString &originator) override;
//! \copydoc ISimulator::displayStatusMessage()
virtual void displayStatusMessage(const BlackMisc::CStatusMessage &message) const override;
@@ -115,25 +103,6 @@ namespace BlackSimPlugin
//! \copydoc ISimulator::displayTextMessage()
virtual void displayTextMessage(const BlackMisc::Network::CTextMessage &message) const override;
//! \copydoc ISimulator::getAircraftModel()
virtual BlackMisc::Simulation::CAircraftModel getOwnAircraftModel() const override { return m_ownAircraft.getModel(); }
//! \copydoc BlackCore::ISimulator::getInstalledModels
virtual BlackMisc::Simulation::CAircraftModelList getInstalledModels() const override { return {}; }
//! Airports in range
virtual BlackMisc::Aviation::CAirportList getAirportsInRange() const override;
//! Set time synchronization between simulator and user's computer time
//! \remarks not all drivers implement this, e.g. if it is an intrinsic simulator feature
virtual void setTimeSynchronization(bool enable, BlackMisc::PhysicalQuantities::CTime offset) override;
//! Time synchronization offset
virtual BlackMisc::PhysicalQuantities::CTime getTimeSynchronizationOffset() const override { return m_syncTimeOffset; }
//! \copydoc ISimulator::iconForModel
virtual BlackMisc::CPixmap iconForModel(const QString &modelString) const override;
protected:
//! Timer event
virtual void timerEvent(QTimerEvent *event);
@@ -146,38 +115,22 @@ namespace BlackSimPlugin
//! Process incoming FS9 message
void ps_processFs9Message(const QByteArray &message);
//! Change own aircraft model string
void ps_changeOwnAircraftModel(const QString &modelname);
//! Change DirectPlay host status
void ps_changeHostStatus(BlackSimPlugin::Fs9::CFs9Host::HostStatus status);
private:
//! Called when data about our own aircraft are received
void updateOwnAircraftFromSim(const BlackMisc::Aviation::CAircraft &ownAircraft);
void updateOwnAircraftFromSimulator(const BlackMisc::Aviation::CAircraft &ownAircraft);
void disconnectAllClients();
// DirectPlay object handling
QPointer<CFs9Host> m_fs9Host;
bool m_isHosting = false; //!< Is sim connected
bool m_startedLobbyConnection = false;
bool m_syncTime = false; //!< Time synchronized?
int m_syncDeferredCounter = 0; //!< Set when synchronized, used to wait some time
bool m_simPaused = false; //!< Simulator paused?
bool m_isHosting = false; //!< Is sim connected
bool m_startedLobbyConnection = false;
QHash<BlackMisc::Aviation::CCallsign, QPointer<CFs9Client>> m_hashFs9Clients;
CLobbyClient *m_lobbyClient;
BlackSim::CSimulatorInfo m_simulatorInfo;
BlackMisc::Simulation::CSimulatedAircraft m_ownAircraft; //!< Object representing our own aircraft from simulator
BlackMisc::Aviation::CAirportList m_airportsInRange;
BlackMisc::PhysicalQuantities::CTime m_syncTimeOffset;
BlackMisc::Simulation::CSimulatedAircraftList m_remoteAircraft;
QScopedPointer<FsCommon::CFsuipc> m_fsuipc;
};
} // namespace
} // namespace