From 1a28b963f25b7f84636551f491d0475ad2dd2999 Mon Sep 17 00:00:00 2001 From: Pepe20129 <72659707+Pepe20129@users.noreply.github.com> Date: Sun, 5 May 2024 21:10:17 +0200 Subject: [PATCH 1/2] Add path XML parser --- soh/soh/resource/importer/PathFactory.cpp | 55 +++++++++++++++++++++++ soh/soh/resource/importer/PathFactory.h | 6 +++ soh/soh/resource/logging/PathLogger.cpp | 33 ++++++++++++++ soh/soh/resource/logging/PathLogger.h | 6 +++ 4 files changed, 100 insertions(+) create mode 100644 soh/soh/resource/logging/PathLogger.cpp create mode 100644 soh/soh/resource/logging/PathLogger.h diff --git a/soh/soh/resource/importer/PathFactory.cpp b/soh/soh/resource/importer/PathFactory.cpp index 00807b75afa..f0f92be0221 100644 --- a/soh/soh/resource/importer/PathFactory.cpp +++ b/soh/soh/resource/importer/PathFactory.cpp @@ -1,5 +1,6 @@ #include "soh/resource/importer/PathFactory.h" #include "soh/resource/type/Path.h" +#include "soh/resource/logging/PathLogger.h" #include "spdlog/spdlog.h" namespace SOH { @@ -35,6 +36,60 @@ std::shared_ptr ResourceFactoryBinaryPathV0::ReadResource(std:: path->pathData.push_back(pathDataEntry); } + if (CVarGetInteger(CVAR_DEVELOPER_TOOLS("ResourceLogging"), 0)) { + LogPathAsXML(path); + } + return path; } + +std::shared_ptr ResourceFactoryXMLPathV0::ReadResource(std::shared_ptr file) { + if (!FileHasValidFormatAndReader(file)) { + return nullptr; + } + + auto path = std::make_shared(file->InitData); + auto reader = std::get>(file->Reader); + + auto pathElement = reader->RootElement(); + + //path->numPaths = pathElement->IntAttribute("NumPaths"); + //path->paths.reserve(path->numPaths); + + auto pathDataElement = pathElement->FirstChildElement(); + + while (pathDataElement != nullptr) { + std::vector points; + //uint32_t pointCount = pathDataElement->IntAttribute("NumPoints"); + //points.reserve(pointCount); + + auto pointElement = pathDataElement->FirstChildElement(); + + while (pointElement != nullptr) { + Vec3s point; + point.x = pointElement->IntAttribute("X"); + point.y = pointElement->IntAttribute("Y"); + point.z = pointElement->IntAttribute("Z"); + + points.push_back(point); + + pointElement = pointElement->NextSiblingElement(); + } + + PathData pathDataEntry; + //pathDataEntry.count = pointCount; + pathDataEntry.count = points.size(); + + path->paths.push_back(points); + pathDataEntry.points = path->paths.back().data(); + + path->pathData.push_back(pathDataEntry); + + pathDataElement = pathDataElement->NextSiblingElement(); + } + + path->numPaths = path->paths.size(); + + return path; +}; } // namespace SOH diff --git a/soh/soh/resource/importer/PathFactory.h b/soh/soh/resource/importer/PathFactory.h index ddbee772df4..9dd73b11025 100644 --- a/soh/soh/resource/importer/PathFactory.h +++ b/soh/soh/resource/importer/PathFactory.h @@ -2,10 +2,16 @@ #include "Resource.h" #include "ResourceFactoryBinary.h" +#include "ResourceFactoryXML.h" namespace SOH { class ResourceFactoryBinaryPathV0 : public Ship::ResourceFactoryBinary { public: std::shared_ptr ReadResource(std::shared_ptr file) override; }; + +class ResourceFactoryXMLPathV0 : public Ship::ResourceFactoryXML { + public: + std::shared_ptr ReadResource(std::shared_ptr file) override; +}; } // namespace SOH diff --git a/soh/soh/resource/logging/PathLogger.cpp b/soh/soh/resource/logging/PathLogger.cpp new file mode 100644 index 00000000000..5c216c9ff96 --- /dev/null +++ b/soh/soh/resource/logging/PathLogger.cpp @@ -0,0 +1,33 @@ +#include "soh/resource/type/Path.h" +#include "spdlog/spdlog.h" + +namespace SOH { + void LogPathAsXML(std::shared_ptr resource) { + std::shared_ptr path = std::static_pointer_cast(resource); + + tinyxml2::XMLDocument doc; + tinyxml2::XMLElement* root = doc.NewElement("Path"); + doc.InsertFirstChild(root); + + for (size_t i = 0; i < path->paths.size(); i += 1) { + tinyxml2::XMLElement* pathData = doc.NewElement("PathData"); + + for (size_t j = 0; j < path->paths[i].size(); j += 1) { + tinyxml2::XMLElement* pathPoint = doc.NewElement("PathPoint"); + + pathPoint->SetAttribute("X", path->paths[i][j].x); + pathPoint->SetAttribute("Y", path->paths[i][j].y); + pathPoint->SetAttribute("Z", path->paths[i][j].z); + + pathData->InsertEndChild(pathPoint); + } + + root->InsertEndChild(pathData); + } + + tinyxml2::XMLPrinter printer; + doc.Accept(&printer); + + SPDLOG_INFO("{}: {}", resource->GetInitData()->Path, printer.CStr()); + } +} \ No newline at end of file diff --git a/soh/soh/resource/logging/PathLogger.h b/soh/soh/resource/logging/PathLogger.h new file mode 100644 index 00000000000..a5e42aeaf85 --- /dev/null +++ b/soh/soh/resource/logging/PathLogger.h @@ -0,0 +1,6 @@ +#include "Resource.h" +#include "soh/OTRGlobals.h" + +namespace SOH { + void LogPathAsXML(std::shared_ptr resource); +} \ No newline at end of file From d7125a3f56dfb11b2c9584a39604d9b66f9d5320 Mon Sep 17 00:00:00 2001 From: Pepe20129 <72659707+Pepe20129@users.noreply.github.com> Date: Sun, 5 May 2024 21:40:58 +0200 Subject: [PATCH 2/2] Update SetPathwaysFactory.cpp --- soh/soh/resource/importer/scenecommand/SetPathwaysFactory.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/soh/soh/resource/importer/scenecommand/SetPathwaysFactory.cpp b/soh/soh/resource/importer/scenecommand/SetPathwaysFactory.cpp index 65af2e0de31..ed368123536 100644 --- a/soh/soh/resource/importer/scenecommand/SetPathwaysFactory.cpp +++ b/soh/soh/resource/importer/scenecommand/SetPathwaysFactory.cpp @@ -17,6 +17,7 @@ SetPathwaysFactory::ReadResource(std::shared_ptr initDat std::string pathFileName = reader->ReadString(); auto path = std::static_pointer_cast(Ship::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(pathFileName.c_str())); setPathways->paths.push_back(path->GetPointer()); + setPathways->pathFileNames.push_back(pathFileName); } if (CVarGetInteger(CVAR_DEVELOPER_TOOLS("ResourceLogging"), 0)) {