mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-30 05:51:23 +08:00
merge with master
This commit is contained in:
@@ -2,6 +2,8 @@ FILE(GLOB blackcore_SOURCES *.cpp)
|
||||
FILE(GLOB blackcore_HEADERS *.h)
|
||||
SET(blackcore_HEADERS_QOBJECT
|
||||
fsd_client.h)
|
||||
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||
|
||||
QT4_WRAP_CPP(blackcore_HEADERS_MOC ${blackcore_HEADERS_QOBJECT})
|
||||
|
||||
|
||||
@@ -8,6 +8,10 @@ INCLUDEPATH += ..
|
||||
|
||||
DEPENDPATH += . ..
|
||||
|
||||
linux-g++* {
|
||||
QMAKE_CXXFLAGS += -std=c++0x
|
||||
}
|
||||
|
||||
#PRECOMPILED_HEADER = stdpch.h
|
||||
|
||||
precompile_header:!isEmpty(PRECOMPILED_HEADER) {
|
||||
@@ -16,37 +20,9 @@ precompile_header:!isEmpty(PRECOMPILED_HEADER) {
|
||||
|
||||
DEFINES += LOG_IN_FILE
|
||||
|
||||
HEADERS += \
|
||||
sim_callbacks.h \
|
||||
constants.h \
|
||||
fsd_protocol.h \
|
||||
ecef.h \
|
||||
fsd_client.h \
|
||||
fsd_messages.h \
|
||||
interpolator.h \
|
||||
mathematics.h \
|
||||
matrix_3d.h \
|
||||
multiplayer.h \
|
||||
ned.h \
|
||||
plane.h \
|
||||
simulator.h \
|
||||
vector_3d.h \
|
||||
vector_geo.h \
|
||||
blackcore.h
|
||||
HEADERS += *.h
|
||||
|
||||
SOURCES += \
|
||||
ecef.cpp \
|
||||
fsd_client.cpp \
|
||||
fsd_messages.cpp \
|
||||
interpolator.cpp \
|
||||
mathematics.cpp \
|
||||
matrix_3d.cpp \
|
||||
multiplayer.cpp \
|
||||
ned.cpp \
|
||||
plane.cpp \
|
||||
simulator.cpp \
|
||||
vector_3d.cpp \
|
||||
vector_geo.cpp \
|
||||
SOURCES += *.cpp
|
||||
|
||||
DESTDIR = ../../lib
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
|
||||
#include "mathematics.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
namespace Constants
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
#include <blackmisc/context.h>
|
||||
#include <blackmisc/debug.h>
|
||||
|
||||
#include <QStringList>
|
||||
#include <QTextStream>
|
||||
|
||||
#include "blackcore/fsd_client.h"
|
||||
#include "blackcore/fsd_messages.h"
|
||||
#include <blackmisc/context.h>
|
||||
#include <blackmisc/debug.h>
|
||||
#include <QStringList>
|
||||
#include <QTextStream>
|
||||
|
||||
namespace FSD
|
||||
{
|
||||
@@ -13,8 +11,8 @@ namespace FSD
|
||||
using namespace BlackMisc;
|
||||
|
||||
|
||||
CFSDClient::CFSDClient()
|
||||
: m_tcp_socket(NULL), m_port(0), m_simType(FSD::SIM_UNKNOWN)
|
||||
CFSDClient::CFSDClient(IContext &context)
|
||||
: m_context(context), m_tcp_socket(NULL), m_port(0), m_simType(FSD::SIM_UNKNOWN)
|
||||
{
|
||||
init();
|
||||
}
|
||||
@@ -27,14 +25,14 @@ namespace FSD
|
||||
if ( isConnected() )
|
||||
return;
|
||||
|
||||
bDebug << "Connecting to FSD server: " << m_host << ":" << m_port;
|
||||
bDebug(m_context) << "Connecting to FSD server: " << m_host << ":" << m_port;
|
||||
|
||||
m_tcp_socket->connectToHost(m_host, m_port);
|
||||
}
|
||||
|
||||
void CFSDClient::disconnectFrom()
|
||||
{
|
||||
bDebug << "Disconnecting from host.";
|
||||
bDebug(m_context) << "Disconnecting from host.";
|
||||
|
||||
m_tcp_socket->disconnectFromHost();
|
||||
m_port = 0;
|
||||
@@ -69,8 +67,8 @@ namespace FSD
|
||||
|
||||
void CFSDClient::onConnected()
|
||||
{
|
||||
bDebug << "Connected successfully to remote host.";
|
||||
bDebug << "Sending #AP now...";
|
||||
bDebug(m_context) << "Connected successfully to remote host.";
|
||||
bDebug(m_context) << "Sending #AP now...";
|
||||
|
||||
QString line;
|
||||
|
||||
@@ -92,7 +90,7 @@ namespace FSD
|
||||
|
||||
void CFSDClient::onDisconnected()
|
||||
{
|
||||
bDebug << "Disconnected successfully from remote host.";
|
||||
bDebug(m_context) << "Disconnected successfully from remote host.";
|
||||
emit doDisconnected();
|
||||
}
|
||||
|
||||
@@ -101,7 +99,7 @@ namespace FSD
|
||||
|
||||
if ( error != 0 )
|
||||
{
|
||||
bError << "Received socket error: " << error << " - Disconnecting...";
|
||||
bError(m_context) << "Received socket error: " << error << " - Disconnecting...";
|
||||
}
|
||||
|
||||
disconnectFrom();
|
||||
@@ -125,7 +123,7 @@ namespace FSD
|
||||
{
|
||||
if (!isConnected())
|
||||
{
|
||||
bError << "Cannot send data in disconnected state!";
|
||||
bError(m_context) << "Cannot send data in disconnected state!";
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -134,7 +132,7 @@ namespace FSD
|
||||
qint64 bytes = m_tcp_socket->write(message.toAscii());
|
||||
if (bytes < 0 || bytes != message_size)
|
||||
{
|
||||
bWarning << "Error writing to socket!";
|
||||
bWarning(m_context) << "Error writing to socket!";
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -144,13 +142,13 @@ namespace FSD
|
||||
void CFSDClient::init()
|
||||
{
|
||||
m_tcp_socket = new QTcpSocket(this);
|
||||
bAssert(m_tcp_socket);
|
||||
Q_ASSERT(m_tcp_socket);
|
||||
|
||||
bAssert ( QObject::connect( m_tcp_socket, SIGNAL( connected() ), this, SLOT( onConnected() ) ) );
|
||||
bAssert ( QObject::connect( m_tcp_socket, SIGNAL( disconnected() ), this, SLOT( onDisconnected() ) ) );
|
||||
bAssert ( QObject::connect( m_tcp_socket, SIGNAL( error(QAbstractSocket::SocketError) ), this, SLOT( onError(QAbstractSocket::SocketError) ) ) );
|
||||
Q_ASSERT ( QObject::connect( m_tcp_socket, SIGNAL( connected() ), this, SLOT( onConnected() ) ) );
|
||||
Q_ASSERT ( QObject::connect( m_tcp_socket, SIGNAL( disconnected() ), this, SLOT( onDisconnected() ) ) );
|
||||
Q_ASSERT ( QObject::connect( m_tcp_socket, SIGNAL( error(QAbstractSocket::SocketError) ), this, SLOT( onError(QAbstractSocket::SocketError) ) ) );
|
||||
|
||||
bAssert ( QObject::connect( m_tcp_socket, SIGNAL( readyRead() ), this, SLOT( onReceivingData() ) ) );
|
||||
Q_ASSERT ( QObject::connect( m_tcp_socket, SIGNAL( readyRead() ), this, SLOT( onReceivingData() ) ) );
|
||||
|
||||
registerMessages();
|
||||
}
|
||||
@@ -178,7 +176,7 @@ namespace FSD
|
||||
|
||||
QTextStream stream(&line);
|
||||
IMessage* fsd_message = CMessageFactory::getInstance().create(header);
|
||||
bAssert(fsd_message);
|
||||
Q_ASSERT(fsd_message);
|
||||
*fsd_message << stream;
|
||||
|
||||
CMessageDispatcher::getInstance().append(fsd_message);
|
||||
|
||||
@@ -6,13 +6,16 @@
|
||||
#ifndef FSD_CLIENT_H
|
||||
#define FSD_CLIENT_H
|
||||
|
||||
#include <blackcore/fsd_protocol.h>
|
||||
#include <QObject>
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
#include <QTcpSocket>
|
||||
|
||||
#include <blackcore/fsd_protocol.h>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
class IContext;
|
||||
}
|
||||
|
||||
namespace FSD
|
||||
{
|
||||
@@ -32,7 +35,7 @@ class CFSDClient : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CFSDClient();
|
||||
CFSDClient(BlackMisc::IContext &context);
|
||||
|
||||
void connectTo(const QString &host, quint16 port);
|
||||
void disconnectFrom();
|
||||
@@ -107,6 +110,8 @@ private:
|
||||
|
||||
void processLine(QString &line);
|
||||
|
||||
BlackMisc::IContext& m_context;
|
||||
|
||||
QTcpSocket* m_tcp_socket;
|
||||
|
||||
QString m_host;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include "blackmisc/debug.h"
|
||||
|
||||
#include "blackcore/fsd_messages.h"
|
||||
#include "blackmisc/debug.h"
|
||||
|
||||
using namespace BlackMisc;
|
||||
|
||||
@@ -27,7 +26,7 @@ namespace FSD
|
||||
}
|
||||
else
|
||||
{
|
||||
bError << "Cannot split message. Vector is to small";
|
||||
bAppError << "Cannot split message. Vector is to small";
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -84,7 +83,7 @@ namespace FSD
|
||||
{
|
||||
QString message = in.readAll();
|
||||
qint32 size = unpack(message, m_message_tokens);
|
||||
bAssert ( size == 10 );
|
||||
Q_ASSERT ( size == 10 );
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace FSD
|
||||
class FSD_MSG : public BlackMisc::IMessage
|
||||
{
|
||||
public:
|
||||
FSD_MSG(QString& id) : IMessage(id)
|
||||
FSD_MSG(QString id) : IMessage(id)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -40,7 +40,7 @@ namespace FSD
|
||||
class FSD_MSG_AddPilot : public FSD_MSG
|
||||
{
|
||||
public:
|
||||
FSD_MSG_AddPilot() : FSD_MSG(QString("#AP")), m_revision(VATSIM_PROTOCOL_REV),
|
||||
FSD_MSG_AddPilot() : FSD_MSG("#AP"), m_revision(VATSIM_PROTOCOL_REV),
|
||||
m_rating(1)
|
||||
{
|
||||
}
|
||||
@@ -98,7 +98,7 @@ namespace FSD
|
||||
QString m_textmessage;
|
||||
for ( int ii = 2; ii < tokens.size(); ++ii)
|
||||
m_textmessage += tokens.at(ii);
|
||||
bInfo << m_textmessage;
|
||||
bAppInfo << m_textmessage;
|
||||
return in;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ double CMath::hypot(double x, double y)
|
||||
double CMath::cubicRootReal(const double x)
|
||||
{
|
||||
double result;
|
||||
result = std::pow(std::abs(x), (double)1/3);
|
||||
result = pow(abs(x), (double)1/3);
|
||||
|
||||
return x < 0 ? -result : result;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
#ifndef MATH_H
|
||||
#define MATH_H
|
||||
|
||||
#include <math.h>
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <iostream>
|
||||
#include "blackmisc/debug.h"
|
||||
#include "blackcore/vector_3d.h"
|
||||
#include "blackcore/matrix_3d.h"
|
||||
#include "blackcore/vector_3d.h"
|
||||
#include "blackmisc/debug.h"
|
||||
#include <iostream>
|
||||
|
||||
/* TODO
|
||||
*
|
||||
@@ -112,14 +112,14 @@ void CMatrix3D::print()
|
||||
|
||||
double CMatrix3D::getElement(qint8 row, qint8 column) const
|
||||
{
|
||||
bAssert (row < 3 || column < 3);
|
||||
Q_ASSERT (row < 3 || column < 3);
|
||||
|
||||
return m[row][column];
|
||||
}
|
||||
|
||||
void CMatrix3D::setElement(qint8 row, qint8 column, double value)
|
||||
{
|
||||
bAssert (row < 3 || column < 3);
|
||||
Q_ASSERT (row < 3 || column < 3);
|
||||
|
||||
m[row][column] = value;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "blackcore/plane.h"
|
||||
#include "blackcore/interpolator.h"
|
||||
#include "blackcore/simulator.h"
|
||||
#include "blackmisc/debug.h"
|
||||
#include "blackcore/plane.h"
|
||||
|
||||
namespace BlackCore {
|
||||
|
||||
@@ -15,13 +15,13 @@ namespace BlackCore {
|
||||
{
|
||||
m_interpolator = new CInterpolator();
|
||||
|
||||
bAssert(m_interpolator);
|
||||
bAssert(driver);
|
||||
Q_ASSERT(m_interpolator);
|
||||
Q_ASSERT(driver);
|
||||
}
|
||||
|
||||
void CPlane::addPosition(const CVectorGeo &position, double groundVelocity, double heading, double pitch, double bank)
|
||||
{
|
||||
bAssert(m_interpolator);
|
||||
Q_ASSERT(m_interpolator);
|
||||
|
||||
m_interpolator->pushUpdate(position, groundVelocity, heading, pitch, bank);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ namespace BlackCore {
|
||||
|
||||
class ISimulator;
|
||||
class CInterpolator;
|
||||
class CVectorGeo;
|
||||
|
||||
class CPlane
|
||||
{
|
||||
|
||||
104
src/blackcore/pluginmgr.cpp
Normal file
104
src/blackcore/pluginmgr.cpp
Normal file
@@ -0,0 +1,104 @@
|
||||
/* Copyright (C) 2013 VATSIM Community / authors
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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/. */
|
||||
|
||||
#include "blackcore/pluginmgr.h"
|
||||
#include "blackmisc/plugins.h"
|
||||
#include "blackmisc/context.h"
|
||||
#include <QDirIterator>
|
||||
#include <iostream>
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
|
||||
CPluginManager::~CPluginManager()
|
||||
{
|
||||
for (QVector<PluginEntry>::iterator it = m_plugins.begin(); it != m_plugins.end(); ++it)
|
||||
{
|
||||
Q_ASSERT_X(it->loader, "Plugin manager", "Previously loaded plugin's loader ptr is null");
|
||||
|
||||
it->loader->unload();
|
||||
}
|
||||
}
|
||||
|
||||
void CPluginManager::loadAllPlugins(const QString &pluginsPath)
|
||||
{
|
||||
//TODO should we use a custom extension, so we don't attempt to load non-plugin .dll/.so files?
|
||||
#ifdef Q_OS_WIN
|
||||
static const QStringList pluginsFilter("*.dll");
|
||||
#else
|
||||
static const QStringList pluginsFilter("*.so");
|
||||
#endif
|
||||
|
||||
QDirIterator iter (pluginsPath, pluginsFilter, QDir::Files);
|
||||
while (iter.hasNext())
|
||||
{
|
||||
QString filename = iter.next();
|
||||
|
||||
QSharedPointer<QPluginLoader> loader (new QPluginLoader (filename));
|
||||
try
|
||||
{
|
||||
if (! loader->load())
|
||||
{
|
||||
throw;
|
||||
}
|
||||
|
||||
PluginEntry entry;
|
||||
entry.loader = loader;
|
||||
entry.factory = qobject_cast<BlackMisc::IPluginFactory*>(loader->instance());
|
||||
|
||||
if (! entry.factory)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
|
||||
m_plugins.push_back(entry);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
//TODO warning
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const CPluginManager::PluginEntry &CPluginManager::getEntry(size_t index) const
|
||||
{
|
||||
Q_ASSERT_X(index < getPluginCount(), "Plugin manager", "Plugin index out of bounds");
|
||||
|
||||
const PluginEntry &entry = m_plugins[index];
|
||||
|
||||
Q_ASSERT_X(entry.factory, "Plugin manager", "Previously loaded plugin's factory ptr is null");
|
||||
Q_ASSERT_X(entry.loader, "Plugin manager", "Previously loaded plugin's loader ptr is null");
|
||||
|
||||
if (! entry.loader->isLoaded())
|
||||
{
|
||||
//TODO throw plugin loader unexpectedly unloaded
|
||||
}
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
const QString CPluginManager::getName(size_t index) const
|
||||
{
|
||||
return getFactory(index)->getName();
|
||||
}
|
||||
|
||||
const QString CPluginManager::getDescription(size_t index) const
|
||||
{
|
||||
return getFactory(index)->getDescription();
|
||||
}
|
||||
|
||||
BlackMisc::IPlugin *CPluginManager::constructPlugin(size_t index)
|
||||
{
|
||||
BlackMisc::IPlugin *plugin = getFactory(index)->create(BlackMisc::IContext::getInstance());
|
||||
if (! plugin->isValid())
|
||||
{
|
||||
delete plugin;
|
||||
plugin = 0;
|
||||
//TODO throw plugin construction failed
|
||||
}
|
||||
return plugin;
|
||||
}
|
||||
|
||||
} // namespace BlackCore
|
||||
136
src/blackcore/pluginmgr.h
Normal file
136
src/blackcore/pluginmgr.h
Normal file
@@ -0,0 +1,136 @@
|
||||
/* Copyright (C) 2013 VATSIM Community / authors
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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/. */
|
||||
|
||||
/*!
|
||||
\file
|
||||
*/
|
||||
|
||||
#ifndef BLACKCORE_PLUGINMGR_H
|
||||
#define BLACKCORE_PLUGINMGR_H
|
||||
|
||||
#include <QPluginLoader>
|
||||
#include <QVector>
|
||||
#include <QSharedPointer>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
class IPlugin;
|
||||
class IPluginFactory;
|
||||
}
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
|
||||
/*!
|
||||
Plugin manager.
|
||||
Loads plugins and allows them to be queried and instantiated.
|
||||
*/
|
||||
class CPluginManager
|
||||
{
|
||||
public:
|
||||
/*!
|
||||
Destructor.
|
||||
*/
|
||||
virtual ~CPluginManager();
|
||||
|
||||
/*!
|
||||
Attempt to load all plugins found at the given path.
|
||||
\param pluginsPath
|
||||
*/
|
||||
void loadAllPlugins(const QString &pluginsPath);
|
||||
|
||||
/*!
|
||||
Return the total number of plugins loaded so far.
|
||||
\return
|
||||
*/
|
||||
size_t getPluginCount() const
|
||||
{
|
||||
return m_plugins.size();
|
||||
}
|
||||
|
||||
/*!
|
||||
Return the name of a plugin.
|
||||
\param index the plugin's index in the vector of plugins.
|
||||
\return
|
||||
*/
|
||||
const QString getName(size_t index) const;
|
||||
|
||||
/*!
|
||||
Return the description of a plugin.
|
||||
\param index the plugin's index in the vector of plugins.
|
||||
\return
|
||||
*/
|
||||
const QString getDescription(size_t index) const;
|
||||
|
||||
/*!
|
||||
Construct a plugin.
|
||||
\param index the plugin's index in the vector of plugins.
|
||||
\return a pointer to the newly created plugin.
|
||||
\warning You must release this pointer with IPluginFactory::destroy().
|
||||
*/
|
||||
BlackMisc::IPlugin *constructPlugin(size_t index);
|
||||
|
||||
/*!
|
||||
Direct access to the factory. You don't usually need this.
|
||||
\param index
|
||||
\return
|
||||
*/
|
||||
BlackMisc::IPluginFactory *getFactory(size_t index)
|
||||
{
|
||||
return const_cast<BlackMisc::IPluginFactory*>(static_cast<const CPluginManager*>(this)->getFactory(index));
|
||||
}
|
||||
|
||||
/*!
|
||||
Direct access to the factory. You don't usually need this.
|
||||
\param index
|
||||
\return
|
||||
*/
|
||||
const BlackMisc::IPluginFactory *getFactory(size_t index) const
|
||||
{
|
||||
return getEntry(index).factory;
|
||||
}
|
||||
|
||||
/*!
|
||||
Direct access to the QPluginLoader. You don't usually need this.
|
||||
\param index
|
||||
\return
|
||||
*/
|
||||
QPluginLoader *getLoader(size_t index)
|
||||
{
|
||||
return const_cast<QPluginLoader*>(static_cast<const CPluginManager*>(this)->getLoader(index));
|
||||
}
|
||||
|
||||
/*!
|
||||
Direct access to the QPluginLoader. You don't usually need this.
|
||||
\param index
|
||||
\return
|
||||
*/
|
||||
const QPluginLoader *getLoader(size_t index) const
|
||||
{
|
||||
return getEntry(index).loader.data();
|
||||
}
|
||||
|
||||
private:
|
||||
class PluginEntry
|
||||
{
|
||||
public:
|
||||
PluginEntry() : factory(0) {}
|
||||
BlackMisc::IPluginFactory *factory;
|
||||
QSharedPointer<QPluginLoader> loader;
|
||||
};
|
||||
|
||||
QVector<PluginEntry> m_plugins;
|
||||
|
||||
PluginEntry &getEntry(size_t index)
|
||||
{
|
||||
return const_cast<PluginEntry&>(static_cast<const CPluginManager*>(this)->getEntry(index));
|
||||
}
|
||||
|
||||
const PluginEntry &getEntry(size_t index) const;
|
||||
};
|
||||
|
||||
} // namespace BlackCore
|
||||
|
||||
#endif //BLACKCORE_PLUGINMGR_H
|
||||
@@ -43,7 +43,7 @@ namespace BlackCore {
|
||||
ISimulator *result = NULL;
|
||||
|
||||
getDriverVersionMajor driverVersionMajor;
|
||||
getDriverVersionMinor driverVersionMinor;
|
||||
//getDriverVersionMinor driverVersionMinor;
|
||||
createISimulatorInstance createDriver;
|
||||
|
||||
switch (sim)
|
||||
@@ -52,18 +52,24 @@ namespace BlackCore {
|
||||
case FS9:
|
||||
{
|
||||
myLib.setFileName(SHARED_LIBRARY_NAME_FS9);
|
||||
bAssertstr(myLib.load(), myLib.errorString());
|
||||
driverVersionMajor = (getDriverVersionMajor) myLib.resolve(DRIVER_VERSION_MAJOR);
|
||||
if (! myLib.load())
|
||||
{
|
||||
//TODO throw
|
||||
}
|
||||
|
||||
if (driverVersionMajor != NULL)
|
||||
driverVersionMajor = (getDriverVersionMajor) myLib.resolve(DRIVER_VERSION_MAJOR);
|
||||
if (driverVersionMajor)
|
||||
{
|
||||
bAssertstr(driverVersionMajor() == ISimulator::InterfaceVersionMajor, QString("Wrong version of the driver. Try to reinstall!"));
|
||||
if (driverVersionMajor() != ISimulator::InterfaceVersionMajor)
|
||||
{
|
||||
//TODO throw
|
||||
}
|
||||
}
|
||||
|
||||
createDriver = (createISimulatorInstance) myLib.resolve(IDRV_CREATE_SIM_INTERFACE);
|
||||
if (createDriver)
|
||||
{
|
||||
bInfo << "Loaded successfully shared library 'bb_driver_fs9'";
|
||||
bAppInfo << "Loaded successfully shared library 'bb_driver_fs9'";
|
||||
result = createDriver();
|
||||
}
|
||||
}
|
||||
@@ -71,38 +77,48 @@ namespace BlackCore {
|
||||
|
||||
case FSX:
|
||||
myLib.setFileName(SHARED_LIBRARY_NAME_FSX);
|
||||
bAssertstr(myLib.load(), myLib.errorString());
|
||||
if (! myLib.load())
|
||||
{
|
||||
//TODO throw
|
||||
}
|
||||
|
||||
driverVersionMajor = (getDriverVersionMajor) myLib.resolve(DRIVER_VERSION_MAJOR);
|
||||
|
||||
if (driverVersionMajor != NULL)
|
||||
if (driverVersionMajor)
|
||||
{
|
||||
bAssertstr(driverVersionMajor() == ISimulator::InterfaceVersionMajor, QString("Wrong version of the driver. Try to reinstall!"));
|
||||
if (driverVersionMajor() != ISimulator::InterfaceVersionMajor)
|
||||
{
|
||||
//TODO throw
|
||||
}
|
||||
}
|
||||
|
||||
createDriver = (createISimulatorInstance) myLib.resolve(IDRV_CREATE_SIM_INTERFACE);
|
||||
if (createDriver)
|
||||
{
|
||||
bInfo << "Loaded successfully shared library 'bb_driver_fsx'";
|
||||
bAppInfo << "Loaded successfully shared library 'bb_driver_fsx'";
|
||||
result = createDriver();
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
case XPLANE:
|
||||
myLib.setFileName(SHARED_LIBRARY_NAME_XPLANE);
|
||||
bAssertstr(myLib.load(), myLib.errorString());
|
||||
if (! myLib.load())
|
||||
{
|
||||
//TODO throw
|
||||
}
|
||||
|
||||
driverVersionMajor = (getDriverVersionMajor) myLib.resolve(DRIVER_VERSION_MAJOR);
|
||||
|
||||
if (driverVersionMajor != NULL)
|
||||
if (driverVersionMajor)
|
||||
{
|
||||
bAssertstr(driverVersionMajor() == ISimulator::InterfaceVersionMajor, QString("Wrong version of the driver. Try to reinstall!"));
|
||||
if (driverVersionMajor() != ISimulator::InterfaceVersionMajor)
|
||||
{
|
||||
//TODO throw
|
||||
}
|
||||
}
|
||||
|
||||
createDriver = (createISimulatorInstance) myLib.resolve(IDRV_CREATE_SIM_INTERFACE);
|
||||
if (createDriver)
|
||||
{
|
||||
bInfo << "Loaded successfully shared library 'bb_driver_xplane'";
|
||||
bAppInfo << "Loaded successfully shared library 'bb_driver_xplane'";
|
||||
result = createDriver();
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -6,17 +6,21 @@
|
||||
#ifndef SIMULATOR_H
|
||||
#define SIMULATOR_H
|
||||
|
||||
#include <QString>
|
||||
#include <functional>
|
||||
|
||||
#include "blackcore/sim_callbacks.h"
|
||||
#include "blackcore/vector_geo.h"
|
||||
#include "blackcore/vector_3d.h"
|
||||
|
||||
#include <QString>
|
||||
#include <functional>
|
||||
|
||||
#define SHARED_LIBRARY_NAME_FS9 "bb_driver_fs9"
|
||||
#define SHARED_LIBRARY_NAME_FSX "bb_driver_fsx"
|
||||
#define SHARED_LIBRARY_NAME_XPLANE "bb_driver_xplane"
|
||||
|
||||
/*!
|
||||
* \file Simulator driver interface.
|
||||
*/
|
||||
|
||||
namespace BlackMisc {
|
||||
|
||||
class IContext;
|
||||
@@ -25,144 +29,220 @@ namespace BlackMisc {
|
||||
|
||||
namespace BlackCore {
|
||||
|
||||
/*!
|
||||
* A struct to hold data about an aircraft model and repaint.
|
||||
*/
|
||||
class CPlaneModel
|
||||
{
|
||||
public:
|
||||
QString name;
|
||||
QString typeCode;
|
||||
QString airlineCode;
|
||||
QString name; //!< full name of the aircraft model, arbitrary string (hopefully unique)
|
||||
QString typeCode; //!< ICAO aircraft type code
|
||||
QString airlineCode; //!< ICAO air operator code
|
||||
};
|
||||
|
||||
/*!
|
||||
* A struct for passing around the physical state of an aircraft.
|
||||
*/
|
||||
class CPhysicalState
|
||||
{
|
||||
public:
|
||||
//! Constructor, initialize to zero.
|
||||
CPhysicalState() : headingDegrees(0), pitchDegrees(0), bankDegrees(0), groundSpeedKnots(0)
|
||||
{}
|
||||
CVectorGeo position;
|
||||
float headingDegrees;
|
||||
float pitchDegrees;
|
||||
float bankDegrees;
|
||||
float groundSpeedKnots;
|
||||
CVector3D trueSpeedMetersPerSec;
|
||||
CVectorGeo position; //!< geographical position
|
||||
float headingDegrees; //!< heading in degrees
|
||||
float pitchDegrees; //!< pitch in degrees
|
||||
float bankDegrees; //!< bank in degrees
|
||||
float groundSpeedKnots; //!< ground speed in knots
|
||||
CVector3D trueSpeedMetersPerSec; //!< needed by FSX
|
||||
};
|
||||
|
||||
/*!
|
||||
* A struct for passing around the avionics state of an aircraft.
|
||||
*/
|
||||
class CAvionicsState
|
||||
{
|
||||
//! Constructor, initialize to zero.
|
||||
CAvionicsState() : squawkCode(0), squawkModeC(false), squawkIdent(false),
|
||||
com1FreqHz(0), com2FreqHz(0)
|
||||
{}
|
||||
qint16 squawkCode;
|
||||
bool squawkModeC;
|
||||
bool squawkIdent;
|
||||
qint32 com1FreqHz;
|
||||
qint32 com2FreqHz;
|
||||
qint16 squawkCode; //!< decimal squawk code
|
||||
bool squawkModeC; //!< true if squawking mode C
|
||||
bool squawkIdent; //!< true if squawking ident
|
||||
qint32 com1FreqHz; //!< COM1 radio frequency in Hz
|
||||
qint32 com2FreqHz; //!< COM2 radio frequency in Hz
|
||||
};
|
||||
|
||||
/*!
|
||||
* A struct for passing around the animation state of an aircraft.
|
||||
*/
|
||||
class CAnimationState
|
||||
{
|
||||
public:
|
||||
//! Constructor, initialize to zero.
|
||||
CAnimationState() : gearPercent(0), flapsPercent(0), landingLights(false),
|
||||
taxiLights(false), navLights(false), strobeLights(false), beaconLights(false)
|
||||
{}
|
||||
qint8 gearPercent;
|
||||
qint8 flapsPercent;
|
||||
bool landingLights;
|
||||
bool taxiLights;
|
||||
bool navLights;
|
||||
bool strobeLights;
|
||||
bool beaconLights;
|
||||
qint8 gearPercent; //!< 0 = retracted, 100 = extended
|
||||
qint8 flapsPercent; //!< 0 = ratracted, 100 = extended
|
||||
bool landingLights; //!< true if landing lights on
|
||||
bool taxiLights; //!< true if taxi lights on
|
||||
bool navLights; //!< true if nav lights on
|
||||
bool strobeLights; //!< true if strobe lights on
|
||||
bool beaconLights; //!< true if beacon lights on
|
||||
};
|
||||
|
||||
typedef std::tr1::function<void(const bool status)> cbSimStarted;
|
||||
typedef std::tr1::function<void(const CAvionicsState &state)> cbChangedAvionicsState;
|
||||
typedef std::tr1::function<void(const CAnimationState &state)> cbChangedAnimationState;
|
||||
typedef std::tr1::function<void(const CPlaneModel &model)> cbChangedModel;
|
||||
typedef std::tr1::function<void(const QString &message)> cbSendTextMessage;
|
||||
#ifdef Q_OS_WIN
|
||||
|
||||
//! A callback that is called when the simulator is started.
|
||||
typedef std::tr1::function<void(const bool status)> cbSimStarted;
|
||||
|
||||
//! A callback that is called when the user's plane changes its avionics state.
|
||||
typedef std::tr1::function<void(const CAvionicsState &state)> cbChangedAvionicsState;
|
||||
|
||||
//! A callback that is called when the user's plane changes its animation state.
|
||||
typedef std::tr1::function<void(const CAnimationState &state)> cbChangedAnimationState;
|
||||
|
||||
//! A callback that is called when the user's plane changes its model.
|
||||
typedef std::tr1::function<void(const CPlaneModel &model)> cbChangedModel;
|
||||
|
||||
#else
|
||||
//! A callback that is called when the simulator is started.
|
||||
typedef std::function<void(const bool status)> cbSimStarted;
|
||||
|
||||
//! A callback that is called when the user's plane changes its avionics state.
|
||||
typedef std::function<void(const CAvionicsState &state)> cbChangedAvionicsState;
|
||||
|
||||
//! A callback that is called when the user's plane changes its animation state.
|
||||
typedef std::function<void(const CAnimationState &state)> cbChangedAnimationState;
|
||||
|
||||
//! A callback that is called when the user's plane changes its model.
|
||||
typedef std::function<void(const CPlaneModel &model)> cbChangedModel;
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* The interface that is implemented by each simulator driver.
|
||||
*
|
||||
* Simulator drivers are responsible for communicating with the simulator on the user's
|
||||
* computer and keeping it in sync with the client.
|
||||
*/
|
||||
class ISimulator
|
||||
{
|
||||
public:
|
||||
|
||||
/// Version of the driver interface. To increment when the interface change.
|
||||
// Version of the driver interface. To increment when the interface change.
|
||||
static const quint32 InterfaceVersionMajor;
|
||||
static const quint32 InterfaceVersionMinor;
|
||||
|
||||
//! Enumeration to describe which simulator is desired.
|
||||
enum ESimulator {
|
||||
FS9 = 0,
|
||||
FSX,
|
||||
XPLANE,
|
||||
FS9 = 0, //!< Microsoft Flight Simulator 9
|
||||
FSX, //!< Microsoft Flight Simulator 10
|
||||
XPLANE, //!< X-Plane
|
||||
};
|
||||
|
||||
//! Constructor.
|
||||
ISimulator() {}
|
||||
|
||||
//! Destructor.
|
||||
virtual ~ISimulator() {}
|
||||
|
||||
//! Provide the driver with a pointer to the global context.
|
||||
virtual void setLibraryContext(BlackMisc::IContext *context);
|
||||
|
||||
//! Factory method.
|
||||
static ISimulator *createDriver(ESimulator sim);
|
||||
|
||||
////////////////////////////////
|
||||
// Global section
|
||||
////////////////////////////////
|
||||
|
||||
//! Initialize the driver.
|
||||
virtual int init() = 0;
|
||||
|
||||
//! Connect to the simulator.
|
||||
virtual int connect() = 0;
|
||||
|
||||
// Callback when the Simulation starts
|
||||
//! Provide a callback to be called when the simulation starts.
|
||||
virtual void setcbSimStarted(const cbSimStarted &func);
|
||||
|
||||
//! Query whether the driver is connected to the simulator.
|
||||
virtual bool isConnected() = 0;
|
||||
|
||||
//! If there has been an error, return the associated message.
|
||||
virtual QString getLastErrorMessage() = 0;
|
||||
|
||||
////////////////////////////////
|
||||
// User plane section
|
||||
////////////////////////////////
|
||||
|
||||
// Callback avionics state
|
||||
//! Provide a callback to be called when the user plane changes avionics state.
|
||||
virtual void setcbChangedAvionicsState(const cbChangedAvionicsState &func);
|
||||
|
||||
// Callback animation state
|
||||
//! Provide a callback to be called when the user plane changes animation state.
|
||||
virtual void setcbChangedAnimationState(const cbChangedAnimationState &func);
|
||||
|
||||
// Callback, when the Aircraft is set or gets changed
|
||||
//! Provide a callback to be called when the user plane changes model.
|
||||
virtual void setcbChangedModel(const cbChangedModel &func);
|
||||
|
||||
// Not const because it may need to mutate state in order to communicate with the sim
|
||||
//! Returns true if the user plane is in contact with the ground.
|
||||
virtual bool isOnGround() = 0;
|
||||
|
||||
// This might block - use QtConcurrent::run if that is a problem
|
||||
/*!
|
||||
* Returns the physical state of the user plane.
|
||||
* \warning This might block - use QtConcurrent::run if that is a problem.
|
||||
*/
|
||||
virtual CPhysicalState getPhysicalState() = 0;
|
||||
|
||||
////////////////////////////////
|
||||
// Remote plane section
|
||||
////////////////////////////////
|
||||
|
||||
// This might block - use QtConcurrent::run if that is a problem
|
||||
/*!
|
||||
* Adds a plane to the simulator traffic and returns its handle.
|
||||
* \warning This might block - use QtConcurrent::run if that is a problem
|
||||
*/
|
||||
virtual qint32 addPlane(const QString &callsign) = 0;
|
||||
|
||||
/*!
|
||||
* Remove a plane from the simulator traffic.
|
||||
* \param planeID a handle that was returned by addPlane().
|
||||
*/
|
||||
virtual bool removePlane(const qint32 planeID) = 0;
|
||||
|
||||
/*!
|
||||
* Set the model of an aircraft in the simulator traffic.
|
||||
* \param planeID a handle that was returned by addPlane().
|
||||
*/
|
||||
virtual void setModel(const qint32 planeID, const CPlaneModel &model) = 0;
|
||||
|
||||
/*!
|
||||
* Set the physical state of an aircraft in the simulator traffic.
|
||||
* \param planeID a handle that was returned by addPlane().
|
||||
*/
|
||||
virtual bool setPhysicalState(const qint32 planeID, const CPhysicalState &state) = 0;
|
||||
|
||||
/*!
|
||||
* Set the animation state of an aircraft in the simulator traffic.
|
||||
* \param planeID a handle that was returned by addPlane().
|
||||
*/
|
||||
virtual bool setAnimationState(const qint32 planeID, const CAnimationState &state) = 0;
|
||||
|
||||
// Calls the supplied visitor function once for every model available in the simulator.
|
||||
virtual void visitAllModels(const std::tr1::function<void(const CPlaneModel &)> &visitor) = 0;
|
||||
//! Calls the supplied visitor function once for every model available in the simulator.
|
||||
|
||||
// Fills container with all models. Works for any container that supports push_back.
|
||||
#ifdef Q_OS_WIN
|
||||
virtual void visitAllModels(const std::tr1::function<void(const CPlaneModel &)> &visitor) = 0;
|
||||
#else
|
||||
virtual void visitAllModels(const std::function<void(const CPlaneModel &)> &visitor) = 0;
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* Fills container with all models.
|
||||
* Class T must be a container of CPlaneModel objects and must support push_back.
|
||||
*/
|
||||
#ifdef Q_OS_WIN
|
||||
template <class T>
|
||||
void getAllModels(T &container) { visitAllModels(std::tr1::bind(T::push_back, container)); }
|
||||
#else
|
||||
template <class T>
|
||||
void getAllModels(T &container) { visitAllModels(std::bind(T::push_back, container)); }
|
||||
#endif
|
||||
|
||||
|
||||
protected:
|
||||
BlackMisc::IContext *m_libraryContext;
|
||||
BlackMisc::IContext *m_libraryContext; //!< The global context.
|
||||
|
||||
cbSimStarted m_cbSimStarted;
|
||||
cbChangedAvionicsState m_cbChangedAvionicsState;
|
||||
cbChangedAnimationState m_cbChangedAnimationState;
|
||||
cbChangedModel m_cbChangedModel;
|
||||
cbSimStarted m_cbSimStarted; //!< Callback to call when the sim starts.
|
||||
cbChangedAvionicsState m_cbChangedAvionicsState; //!< Callback to call when the user plane changes avionics state.
|
||||
cbChangedAnimationState m_cbChangedAnimationState; //!< Callback to call when the user plane changes animation state.
|
||||
cbChangedModel m_cbChangedModel; //!< Callback to call when the user plane changes model.
|
||||
};
|
||||
|
||||
} //! namespace BlackCore
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
|
||||
#include "blackcore/vector_3d.h"
|
||||
#include "blackcore/matrix_3d.h"
|
||||
#include "blackcore/vector_geo.h"
|
||||
#include "blackcore/constants.h"
|
||||
#include "blackmisc/debug.h"
|
||||
#include <iostream>
|
||||
#include <math.h>
|
||||
|
||||
#include "blackmisc/debug.h"
|
||||
|
||||
#include "blackcore/matrix_3d.h"
|
||||
#include "blackcore/vector_3d.h"
|
||||
#include "blackcore/vector_geo.h"
|
||||
|
||||
#include "blackcore/constants.h"
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
|
||||
@@ -59,7 +57,7 @@ double CVector3D::magnitude()
|
||||
|
||||
double CVector3D::getElement(qint8 row) const
|
||||
{
|
||||
bAssert(row < 3);
|
||||
Q_ASSERT(row < 3);
|
||||
|
||||
return v[row];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user