From 5548d8af2d4a99c6e4eed0d46e5049390782a04d Mon Sep 17 00:00:00 2001 From: Mat Sutcliffe Date: Sat, 30 May 2020 15:42:08 +0100 Subject: [PATCH] Issue #17 Udjust to model string changes in xplanemp2 --- .../xplane/aircraftmodelloaderxplane.cpp | 16 +++++----------- src/xswiftbus/traffic.cpp | 14 ++++++++++++-- src/xswiftbus/traffic.h | 1 + 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/blackmisc/simulation/xplane/aircraftmodelloaderxplane.cpp b/src/blackmisc/simulation/xplane/aircraftmodelloaderxplane.cpp index 3d18b2d51..082d3e0eb 100644 --- a/src/blackmisc/simulation/xplane/aircraftmodelloaderxplane.cpp +++ b/src/blackmisc/simulation/xplane/aircraftmodelloaderxplane.cpp @@ -158,8 +158,8 @@ namespace BlackMisc { QString modelName = dirNames.join(' ') % - u' ' % objectName % - u' ' % textureName; + u' ' % objectName; + if (objectVersion == OBJ7) { modelName += u' ' % textureName; } return std::move(modelName).trimmed(); } @@ -514,6 +514,9 @@ namespace BlackMisc return false; } } + + package.planes.back().objectName = tokens[1]; + package.planes.back().objectVersion = CSLPlane::OBJ8; return true; } @@ -547,17 +550,8 @@ namespace BlackMisc // Remove the last one being the obj itself dirNames.removeLast(); - QFileInfo fileInfo(fullPath); - if (! fileInfo.exists()) - { - const CStatusMessage m = CStatusMessage(this).error(u"XPlane object '%1' does not exist.") << fullPath; - m_loadingMessages.push_back(m); - return false; - } package.planes.back().dirNames = dirNames; - package.planes.back().objectName = fileInfo.completeBaseName(); package.planes.back().filePath = fullPath; - package.planes.back().objectVersion = CSLPlane::OBJ8; if (tokens.size() >= 5) { diff --git a/src/xswiftbus/traffic.cpp b/src/xswiftbus/traffic.cpp index f6f741a32..3185c2d6f 100644 --- a/src/xswiftbus/traffic.cpp +++ b/src/xswiftbus/traffic.cpp @@ -233,6 +233,16 @@ namespace XSwiftBus auto err = XPMPMultiplayerLoadCSLPackages(path.c_str()); if (*err) { return err; } + + for (int i = 0, end = XPMPGetNumberOfInstalledModels(); i < end; ++i) + { + const char *mixedcase; + XPMPGetModelInfo(i, &mixedcase, nullptr, nullptr, nullptr); + std::string uppercase(mixedcase); + std::transform(uppercase.begin(), uppercase.end(), uppercase.begin(), [](char c) { return static_cast(std::toupper(c)); }); + m_modelStrings[uppercase] = mixedcase; + } + return {}; } @@ -259,13 +269,13 @@ namespace XSwiftBus if (planeIt != m_planesByCallsign.end()) { return; } XPMPPlaneID id = nullptr; - if (modelName.empty()) + if (modelName.empty() || m_modelStrings.count(modelName) == 0) { id = XPMPCreatePlane(aircraftIcao.c_str(), airlineIcao.c_str(), livery.c_str()); } else { - id = XPMPCreatePlaneWithModelName(modelName.c_str(), aircraftIcao.c_str(), airlineIcao.c_str(), livery.c_str()); + id = XPMPCreatePlaneWithModelName(m_modelStrings[modelName].c_str(), aircraftIcao.c_str(), airlineIcao.c_str(), livery.c_str()); } if (!id) diff --git a/src/xswiftbus/traffic.h b/src/xswiftbus/traffic.h index afbacff61..824465b32 100644 --- a/src/xswiftbus/traffic.h +++ b/src/xswiftbus/traffic.h @@ -207,6 +207,7 @@ namespace XSwiftBus static std::string pos2String(const XPLMCameraPosition_t *camPos); //! @} + std::unordered_map m_modelStrings; // mapping uppercase to mixedcase std::unordered_map m_planesByCallsign; std::unordered_map m_planesById; std::vector m_followPlaneViewSequence;