From 2ab6a96d57939043eab7f14d74d922c420de948d Mon Sep 17 00:00:00 2001 From: Roland Winklmeier Date: Thu, 22 Feb 2018 16:35:10 +0100 Subject: [PATCH] Adapt to libxplanemp improvements * XPMPMultiplayerInit API change * New CSL command 'VERT_OFFSET' * OBJ8 objects can have multiple textures now. Therefore use the same model name convention as with OBJ7. --- .../xplane/aircraftmodelloaderxplane.cpp | 59 ++++++++++++++++--- src/xswiftbus/libxplanemp | 2 +- src/xswiftbus/traffic.cpp | 3 +- 3 files changed, 53 insertions(+), 11 deletions(-) diff --git a/src/blackmisc/simulation/xplane/aircraftmodelloaderxplane.cpp b/src/blackmisc/simulation/xplane/aircraftmodelloaderxplane.cpp index d1938856c..747214d9a 100644 --- a/src/blackmisc/simulation/xplane/aircraftmodelloaderxplane.cpp +++ b/src/blackmisc/simulation/xplane/aircraftmodelloaderxplane.cpp @@ -542,7 +542,6 @@ namespace BlackMisc bool CAircraftModelLoaderXPlane::parseObj8AircraftCommand(const QStringList &tokens, CSLPackage &package, const QString &path, int lineNum) { - Q_UNUSED(package) // OBJ8_AIRCRAFT if (tokens.size() != 2) { @@ -550,9 +549,6 @@ namespace BlackMisc } package.planes.push_back(CSLPlane()); - package.planes.back().dirNames << package.path.mid(package.path.lastIndexOf('/') + 1); - package.planes.back().objectName = tokens[1]; - package.planes.back().filePath = package.path; // Package name and object name uniquely identify an OBJ8 aircraft. // File path just points to the package root. return true; @@ -560,14 +556,58 @@ namespace BlackMisc bool CAircraftModelLoaderXPlane::parseObj8Command(const QStringList &tokens, CSLPackage &package, const QString &path, int lineNum) { - Q_UNUSED(package) - // OBJ8 - if (tokens.size() != 4) + // OBJ8 { {}} + if (tokens.size() < 4 || tokens.size() > 6) { - CLogMessage(this).warning("%1 - %2: OBJ8 command requires 3 arguments.") << path << lineNum; + CLogMessage(this).warning("%1 - %2: OBJ8 command takes 3-5 arguments.") << path << lineNum; } - // command contains no useful information for us + if (tokens[1] != "SOLID") { return true; } + + QString relativePath(tokens[3]); + normalizePath(relativePath); + QString fullPath(relativePath); + if (!doPackageSub(fullPath)) + { + CLogMessage(this).warning("%1 - %2: package not found.") << path << lineNum; + return false; + } + + QStringList dirNames; + dirNames.append(relativePath.split('/', QString::SkipEmptyParts)); + // Replace the first one being the package name with the package root dir + QString packageRootDir = package.path.mid(package.path.lastIndexOf('/') + 1); + dirNames.replace(0, packageRootDir); + // Remove the last one being the obj itself + dirNames.removeLast(); + + QFileInfo fileInfo(fullPath); + package.planes.back().dirNames = dirNames; + package.planes.back().objectName = fileInfo.completeBaseName(); + package.planes.back().filePath = fullPath; + + if (tokens.size() >= 5) + { + // Load regular texture + QString relativeTexPath = dirNames.join('/') + '/' + tokens[4]; + normalizePath(relativeTexPath); + QString absoluteTexPath(relativeTexPath); + + if (!doPackageSub(absoluteTexPath)) + { + CLogMessage(this).warning("%1 - %2: package not found.") << path << lineNum; + return false; + } + + QFileInfo fileInfo(absoluteTexPath); + if (!fileInfo.exists()) + { + CLogMessage(this).warning("Texture %1 does not exist.") << absoluteTexPath; + return false; + } + + package.planes.back().textureName = fileInfo.completeBaseName(); + } return true; } @@ -685,6 +725,7 @@ namespace BlackMisc { "ICAO", std::bind(&CAircraftModelLoaderXPlane::parseIcaoCommand, this, _1, _2, _3, _4) }, { "AIRLINE", std::bind(&CAircraftModelLoaderXPlane::parseAirlineCommand, this, _1, _2, _3, _4) }, { "LIVERY", std::bind(&CAircraftModelLoaderXPlane::parseLiveryCommand, this, _1, _2, _3, _4) }, + { "VERT_OFFSET", std::bind(&CAircraftModelLoaderXPlane::parseDummyCommand, this, _1, _2, _3, _4) }, }; int lineNum = 0; diff --git a/src/xswiftbus/libxplanemp b/src/xswiftbus/libxplanemp index 5bb46df73..5faac3dd5 160000 --- a/src/xswiftbus/libxplanemp +++ b/src/xswiftbus/libxplanemp @@ -1 +1 @@ -Subproject commit 5bb46df730be8e00a0a412bc274cb07812b1a96b +Subproject commit 5faac3dd500f5578b15b6b9f28b029a344a8bd45 diff --git a/src/xswiftbus/traffic.cpp b/src/xswiftbus/traffic.cpp index 8c7f0eda0..6bea1ed1a 100644 --- a/src/xswiftbus/traffic.cpp +++ b/src/xswiftbus/traffic.cpp @@ -99,7 +99,8 @@ namespace XSwiftBus { if (! s_legacyDataOK) { return false; } - auto err = XPMPMultiplayerInit(preferences, preferences); + auto dir = g_xplanePath + "Resources" + g_sep + "plugins" + g_sep + "xswiftbus" + g_sep; + auto err = XPMPMultiplayerInit(preferences, preferences, qPrintable(dir)); if (*err) { cleanup(); return false; } m_initialized = true;