refs #409 Refactor matching implementation in MSFS drivers

CAircraftMapper used to be designed around FSX only. CAircraftMatcher
instead is more generic for different MSFS versions. Therefore it is
replaced with the latter. This change also gets rid of the singleton and
its drawbacks by using the plugin storage.
Last but not least it implements the first model matching for FS9.
This commit is contained in:
Roland Winklmeier
2015-05-21 13:34:53 +02:00
parent 74b6bb9756
commit 6995ad7063
6 changed files with 96 additions and 134 deletions

View File

@@ -28,10 +28,10 @@ namespace BlackSimPlugin
{
namespace Fs9
{
CFs9Client::CFs9Client(
BlackCore::IInterpolator *interpolator, QObject *owner, const BlackMisc::Aviation::CCallsign &callsign, const CTime &updateInterval) :
CFs9Client::CFs9Client(const CCallsign &callsign, const QString &modelName,
BlackCore::IInterpolator *interpolator, const CTime &updateInterval, QObject *owner) :
CDirectPlayPeer(owner, callsign),
m_updateInterval(updateInterval), m_interpolator(interpolator)
m_updateInterval(updateInterval), m_interpolator(interpolator), m_modelName(modelName)
{
}
@@ -183,8 +183,9 @@ namespace BlackSimPlugin
callsign.toQString().toWCharArray(wszPlayername.data());
wszPlayername[callsign.toQString().size()] = 0;
Q_ASSERT(!m_modelName.isEmpty());
ZeroMemory(&m_playerInfo, sizeof(PLAYER_INFO_STRUCT));
strcpy(m_playerInfo.szAircraft, "Boeing 737-400 Paint1");
strcpy(m_playerInfo.szAircraft, qPrintable(m_modelName));
m_playerInfo.dwFlags = 6;
// Prepare and set the player information structure.
@@ -222,7 +223,7 @@ namespace BlackSimPlugin
MPChangePlayerPlane mpChangePlayerPlane;
mpChangePlayerPlane.engine = CFs9Sdk::ENGINE_TYPE_JET;
mpChangePlayerPlane.aircraft_name = "Boeing 737-400";
mpChangePlayerPlane.aircraft_name = m_modelName;
QByteArray message;
MultiPlayerPacketParser::writeType(message, CFs9Sdk::MULTIPLAYER_PACKET_ID_CHANGE_PLAYER_PLANE);
MultiPlayerPacketParser::writeSize(message, mpChangePlayerPlane.size());

View File

@@ -39,7 +39,9 @@ namespace BlackSimPlugin
};
//! Constructor
CFs9Client(BlackCore::IInterpolator *interpolator, QObject *owner, const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::PhysicalQuantities::CTime &updateInterval);
CFs9Client(const BlackMisc::Aviation::CCallsign &callsign, const QString &modelName,
BlackCore::IInterpolator *interpolator, const BlackMisc::PhysicalQuantities::CTime &updateInterval,
QObject *owner);
//! Destructor
virtual ~CFs9Client();
@@ -89,6 +91,7 @@ namespace BlackSimPlugin
BlackMisc::PhysicalQuantities::CTime m_updateInterval;
BlackCore::IInterpolator *m_interpolator = nullptr;
QString m_modelName;
int m_timerId = 0;
IDirectPlay8Address *m_hostAddress = nullptr;

View File

@@ -20,6 +20,7 @@
#include "blackmisc/project.h"
#include "blackmisc/logmessage.h"
#include "blackmisc/propertyindexallclasses.h"
#include "blackmisc/simulation/fscommon/fscommonutil.h"
#include <QTimer>
#include <algorithm>
@@ -30,6 +31,7 @@ using namespace BlackMisc::Simulation;
using namespace BlackMisc::PhysicalQuantities;
using namespace BlackMisc::Geo;
using namespace BlackMisc::Simulation;
using namespace BlackMisc::Simulation::FsCommon;
using namespace BlackSimPlugin::Fs9;
using namespace BlackSimPlugin::FsCommon;
@@ -52,10 +54,17 @@ namespace BlackSimPlugin
IRemoteAircraftProvider *remoteAircraftProvider,
IPluginStorageProvider *pluginStorageProvider,
QObject *parent) :
CSimulatorFsCommon(info, ownAircraftProvider, remoteAircraftProvider, pluginStorageProvider, parent)
CSimulatorFsCommon(info, ownAircraftProvider, remoteAircraftProvider, pluginStorageProvider,
aircraftObjectsDir(), excludeDirectories(), parent)
{
connect(lobbyClient.data(), &CLobbyClient::disconnected, this, std::bind(&CSimulatorFs9::simulatorStatusChanged, this, 0));
this->m_interpolator = new BlackCore::CInterpolatorLinear(remoteAircraftProvider, this);
m_modelMatcher.setDefaultModel(CAircraftModel(
"Boeing 737-400",
CAircraftModel::TypeModelMatchingDefaultModel,
"B737-400 default model",
CAircraftIcaoData(CAircraftIcaoCode("B734", "L2J"), CAirlineIcaoCode(), "FFFFFF")
));
}
bool CSimulatorFs9::isConnected() const
@@ -111,7 +120,17 @@ namespace BlackSimPlugin
this->physicallyRemoveRemoteAircraft(callsign);
}
CFs9Client *client = new CFs9Client(m_interpolator, this, callsign, CTime(25, CTimeUnit::ms()));
CSimulatedAircraft newRemoteAircraftCopy(newRemoteAircraft);
// matched models
CAircraftModel aircraftModel = getClosestMatch(newRemoteAircraftCopy);
Q_ASSERT(newRemoteAircraft.getCallsign() == aircraftModel.getCallsign());
updateAircraftModel(newRemoteAircraft.getCallsign(), aircraftModel, simulatorOriginator());
updateAircraftRendered(newRemoteAircraft.getCallsign(), true, simulatorOriginator());
CSimulatedAircraft aircraftAfterModelApplied (getAircraftInRangeForCallsign(newRemoteAircraft.getCallsign()));
aircraftAfterModelApplied.setRendered(true);
emit modelMatchingCompleted(aircraftAfterModelApplied);
CFs9Client *client = new CFs9Client(callsign, aircraftModel.getModelString(), m_interpolator, CTime(25, CTimeUnit::ms()), this);
client->setHostAddress(fs9Host->getHostAddress());
client->setPlayerUserId(fs9Host->getPlayerUserId());