Moved FSX specific implementation into blacksim/fsx and

converted it into a plugin.

refs #190
This commit is contained in:
Roland Winklmeier
2014-03-15 14:54:47 +01:00
parent 05d96fa48d
commit dec49dba7f
13 changed files with 132 additions and 36 deletions

View File

@@ -21,6 +21,10 @@ contains(BLACK_CONFIG, BlackGui) {
contains(BLACK_CONFIG, BlackSim) {
SUBDIRS += src/blacksim
contains(BLACK_CONFIG, FSX) {
SUBDIRS += src/blacksim/fsx/plugin_fsx.pro
}
}
contains(BLACK_CONFIG, Samples) {

View File

@@ -1,6 +1,6 @@
include (externals.pri)
LIBS *= -L../../lib
LIBS *= -L../../lib -L../../../lib
blackgui {
LIBS += -lblackgui

View File

@@ -28,12 +28,6 @@ SOURCES += *.cpp
win32 {
HEADERS += $$PWD/win/*.h
SOURCES += $$PWD/win/*.cpp
contains(BLACK_CONFIG, FSX) {
DEFINES += BLACK_WITH_FSX
HEADERS += $$PWD/fsx/*.h
SOURCES += $$PWD/fsx/*.cpp
}
}
win32:!win32-g++*: PRE_TARGETDEPS += ../../lib/blackmisc.lib ../../lib/blacksound.lib

View File

@@ -5,10 +5,7 @@
#include "context_simulator_impl.h"
#include "coreruntime.h"
#ifdef BLACK_WITH_FSX
#include "fsx/simulator_fsx.h"
#endif
#include <QPluginLoader>
using namespace BlackMisc;
using namespace BlackMisc::PhysicalQuantities;
@@ -26,10 +23,6 @@ namespace BlackCore
{
m_updateTimer = new QTimer(this);
#ifdef BLACK_WITH_FSX
m_simulator = new BlackCore::FSX::CSimulatorFSX(this);
connect(m_simulator, &ISimulator::connectionChanged, this, &CContextSimulator::setConnectionStatus);
#endif
connect(m_updateTimer, &QTimer::timeout, this, &CContextSimulator::updateOwnAircraft);
}
@@ -53,13 +46,16 @@ namespace BlackCore
void CContextSimulator::init()
{
loadPlugins();
if (!m_contextNetwork)
{
m_contextNetwork = getRuntime()->getIContextNetwork();
}
if (m_simulator)
connect(m_contextNetwork, &IContextNetwork::aircraftSituationUpdate, m_simulator, &ISimulator::addAircraftSituation);
connect(m_contextNetwork, SIGNAL(aircraftSituationUpdate(BlackMisc::Aviation::CCallsign,BlackMisc::Aviation::CAircraftSituation)),
m_simulator, SLOT(addAircraftSituation(BlackMisc::Aviation::CCallsign,BlackMisc::Aviation::CAircraftSituation)));
}
void CContextSimulator::updateOwnAircraft()
@@ -84,4 +80,30 @@ namespace BlackCore
emit connectionChanged(value);
}
void CContextSimulator::loadPlugins()
{
m_pluginsDir = QDir(qApp->applicationDirPath());
m_pluginsDir.cd("plugins");
foreach (QString fileName, m_pluginsDir.entryList(QDir::Files))
{
QPluginLoader loader(m_pluginsDir.absoluteFilePath(fileName));
QObject *plugin = loader.instance();
if (plugin)
{
ISimulatorFactory *factory = qobject_cast<ISimulatorFactory*>(plugin);
if(plugin)
{
m_simulator = factory->create(this);
connect(m_simulator, SIGNAL(connectionChanged(bool)), this, SLOT(setConnectionStatus(bool)));
}
}
else
{
qDebug() << loader.errorString();
}
}
}
} // namespace BlackCore

View File

@@ -11,6 +11,7 @@
#include "blackcore/simulator.h"
#include <QTimer>
#include <QDir>
namespace BlackCore
{
@@ -83,11 +84,21 @@ namespace BlackCore
void setConnectionStatus(bool value);
private:
/*!
* \brief Load any kind of plugins
* \todo Currently it goes through the plugins folder and creates an instance for any plugin it may find
* In case an FSX and an X-Plane are in that folder, m_simulator will always point to X-Plane in the end.
*/
void loadPlugins();
BlackMisc::Aviation::CAircraft m_ownAircraft;
BlackCore::ISimulator *m_simulator;
QTimer *m_updateTimer;
BlackCore::IContextNetwork *m_contextNetwork;
QDir m_pluginsDir;
};
} // namespace BlackCore

View File

@@ -40,6 +40,7 @@ namespace BlackCore
//! \brief Are we connected to the simulator?
virtual bool isConnected() const = 0;
public slots:
/*!
* \brief Return user aircraft object
* \return
@@ -78,6 +79,24 @@ namespace BlackCore
void ownAircraftReceived(BlackMisc::Aviation::CAircraft aircraft);
};
//! \brief Factory pattern class to create instances of ISimulator
class ISimulatorFactory
{
public:
//! \brief Virtual destructor
virtual ~ISimulatorFactory() {}
/*!
* \brief Create a new instance
* \param parent
* \return
*/
virtual ISimulator* create(QObject *parent = nullptr) = 0;
};
} // namespace BlackCore
Q_DECLARE_INTERFACE(BlackCore::ISimulatorFactory, "net.vatsim.PilotClient.BlackCore.SimulatorInterface")
#endif // BLACKCORE_SIMULATOR_H

View File

@@ -0,0 +1,26 @@
include (../../../config.pri)
include (../../../build.pri)
QT += core dbus gui network
TARGET = simulator_fsx
TEMPLATE = lib
CONFIG += plugin shared
CONFIG += blackmisc blackcore
LIBS += -lSimConnect
DEPENDPATH += . ../../../src
INCLUDEPATH += . ../../../src
SOURCES += *.cpp
HEADERS += *.h
win32:!win32-g++*: PRE_TARGETDEPS += ../../../lib/blackmisc.lib
win32:!win32-g++*: PRE_TARGETDEPS += ../../../lib/blackcore.lib
DESTDIR = ../../../bin/plugins
include (../../../libraries.pri)

View File

@@ -6,7 +6,7 @@
#include "simconnect_datadefinition.h"
#include "simconnect/SimConnect.h"
namespace BlackCore
namespace BlackSimPlugin
{
namespace FSX
{

View File

@@ -3,12 +3,12 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef BLACKCORE_FSX_SIMCONNECT_DATADEFINITION_H
#define BLACKCORE_FSX_SIMCONNECT_DATADEFINITION_H
#ifndef BLACKSIMPLUGIN_FSX_SIMCONNECT_DATADEFINITION_H
#define BLACKSIMPLUGIN_FSX_SIMCONNECT_DATADEFINITION_H
#include <windows.h>
namespace BlackCore
namespace BlackSimPlugin
{
namespace FSX
{
@@ -102,4 +102,4 @@ namespace BlackCore
}
}
#endif // BLACKCORE__FSX_SIMCONNECT_DATADEFINITION_H
#endif // BLACKSIMPLUGIN_FSX_SIMCONNECT_DATADEFINITION_H

View File

@@ -6,7 +6,7 @@
#include "simconnect_exception.h"
#include <QDebug>
namespace BlackCore
namespace BlackSimPlugin
{
namespace FSX
{

View File

@@ -3,12 +3,12 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef BLACKCORE_FSX_SIMCONNECT_EXCEPTION_H
#define BLACKCORE_FSX_SIMCONNECT_EXCEPTION_H
#ifndef BLACKSIMPLUGIN_FSX_SIMCONNECT_EXCEPTION_H
#define BLACKSIMPLUGIN_FSX_SIMCONNECT_EXCEPTION_H
#include "simconnect/SimConnect.h"
namespace BlackCore
namespace BlackSimPlugin
{
namespace FSX
{
@@ -27,4 +27,4 @@ namespace BlackCore
}
}
#endif // BLACKCORE_FSX_SIMCONNECT_EXCEPTION_H
#endif // BLACKSIMPLUGIN_FSX_SIMCONNECT_EXCEPTION_H

View File

@@ -6,16 +6,22 @@
#include "simulator_fsx.h"
#include "simconnect_datadefinition.h"
#include "simconnect_exception.h"
#include <QTimer>
using namespace BlackMisc::Aviation;
using namespace BlackMisc::PhysicalQuantities;
using namespace BlackMisc::Geo;
namespace BlackCore
namespace BlackSimPlugin
{
namespace FSX
{
BlackCore::ISimulator *CSimulatorFsxFactory::create(QObject *parent)
{
return new FSX::CSimulatorFSX(parent);
}
CSimulatorFSX::CSimulatorFSX(QObject *parent) :
ISimulator(parent),
m_isConnected(false),
@@ -57,7 +63,7 @@ namespace BlackCore
hr = SimConnect_AICreateNonATCAircraft(m_hSimConnect, "Boeing 737-800 Paint1", callsign.toQString().left(12).toLatin1().constData(), initialPosition, simObj.m_requestId);
}
void CSimulatorFSX::addAircraftSituation(const CCallsign &callsign, const CAircraftSituation & situation)
void CSimulatorFSX::addAircraftSituation(const CCallsign &callsign, const CAircraftSituation &situation)
{
if (!m_simConnectObjects.contains(callsign))
{
@@ -70,7 +76,7 @@ namespace BlackCore
m_simConnectObjects.insert(callsign, simObj);
}
void CSimulatorFSX::removeRemoteAircraft(const CCallsign &callsign)
void CSimulatorFSX::removeRemoteAircraft(const CCallsign &/*callsign*/)
{
// TODO
}
@@ -194,7 +200,7 @@ namespace BlackCore
com2.setFrequencyActive(CFrequency(aircraft.com2ActiveMHz, CFrequencyUnit::MHz()));
com2.setFrequencyStandby(CFrequency(aircraft.com2StandbyMHz, CFrequencyUnit::MHz()));
CTransponder transponder("Transponder", aircraft.transponderCode, CTransponder::ModeC);
CTransponder transponder("Transponder", aircraft.transponderCode, CTransponder::ModeS);
m_ownAircraft.setSituation(aircraftSituation);
m_ownAircraft.setCom1System(com1);
@@ -218,7 +224,7 @@ namespace BlackCore
configuration.gearRight = 100.0;
configuration.gearTail = 100.0;
configuration.gearAux = 100.0;
SimConnect_SetDataOnSimObject(m_hSimConnect, CSimConnectDataDefinition::DataAircraftConfiguration, simObj.m_objectId, SIMCONNECT_DATA_SET_FLAG_DEFAULT, 0, sizeof(DataDefinitionAircraftConfiguration), &configuration);
SimConnect_SetDataOnSimObject(m_hSimConnect, CSimConnectDataDefinition::DataAircraftConfiguration, objectID, SIMCONNECT_DATA_SET_FLAG_DEFAULT, 0, sizeof(DataDefinitionAircraftConfiguration), &configuration);
SimConnectObject simObject;
foreach (simObject, m_simConnectObjects)
@@ -304,6 +310,8 @@ namespace BlackCore
if (simObj.m_objectId != 0)
{
SimConnect_SetDataOnSimObject(m_hSimConnect, CSimConnectDataDefinition::DataAircraftPosition, simObj.m_objectId, SIMCONNECT_DATA_SET_FLAG_DEFAULT, 0, sizeof(DataDefinitionAircraftPosition), &position);
// With the following SimConnect call all aircrafts loose their red tag. No idea why though.
SimConnect_SetDataOnSimObject(m_hSimConnect, CSimConnectDataDefinition::DataAircraftConfiguration, simObj.m_objectId, SIMCONNECT_DATA_SET_FLAG_DEFAULT, 0, sizeof(DataDefinitionAircraftConfiguration), &configuration);
}
}

View File

@@ -3,8 +3,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef BLACKCORE_SIMULATOR_FSX_H
#define BLACKCORE_SIMULATOR_FSX_H
#ifndef BLACKSIMPLUGIN_SIMULATOR_FSX_H
#define BLACKSIMPLUGIN_SIMULATOR_FSX_H
#define NOMINMAX
@@ -15,14 +15,26 @@
#include "blackmisc/avaircraft.h"
#include <simconnect/SimConnect.h>
#include <QObject>
#include <QtPlugin>
#include <QHash>
#include <windows.h>
namespace BlackCore
namespace BlackSimPlugin
{
namespace FSX
{
//! \brief Factory implementation to create CSimulatorFSX instances
class Q_DECL_EXPORT CSimulatorFsxFactory : public QObject, public BlackCore::ISimulatorFactory
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "net.vatsim.PilotClient.BlackCore.SimulatorInterface")
Q_INTERFACES(BlackCore::ISimulatorFactory)
public:
//! \copydoc BlackCore::ISimulatorFactory::create()
virtual BlackCore::ISimulator* create(QObject *parent) override;
};
//! \brief SimConnect Event ID's
enum EVENT_ID {
EVENT_SIM_STATUS,
@@ -36,7 +48,7 @@ namespace BlackCore
};
//! \brief FSX Simulator Implementation
class CSimulatorFSX : public ISimulator
class CSimulatorFSX : public BlackCore::ISimulator
{
Q_OBJECT
public:
@@ -140,4 +152,4 @@ namespace BlackCore
} // namespace BlackCore
#endif // BLACKCORE_SIMULATOR_FSX_H
#endif // BLACKSIMPLUGIN_SIMULATOR_FSX_H