From 2cf0eac8f2bdced322c8e24702df45919c3f3c4e Mon Sep 17 00:00:00 2001 From: David Markowitz Date: Thu, 10 Apr 2025 18:56:38 -0700 Subject: [PATCH] add some notes and remove some logs --- dCommon/Lxfml.cpp | 9 ++++----- dCommon/Lxfml.h | 2 ++ dCommon/Sd0.h | 6 +++--- dCommon/TinyXmlUtils.h | 16 ++++++++-------- dGame/dGameMessages/GameMessages.cpp | 1 - dWorldServer/WorldServer.cpp | 2 ++ 6 files changed, 19 insertions(+), 17 deletions(-) diff --git a/dCommon/Lxfml.cpp b/dCommon/Lxfml.cpp index fb4dcfde..f713bcab 100644 --- a/dCommon/Lxfml.cpp +++ b/dCommon/Lxfml.cpp @@ -40,9 +40,9 @@ Lxfml::Result Lxfml::NormalizePosition(const std::string_view data) { } // These points are well out of bounds for an actual player - NiPoint3 lowest{10'000, 10'000, 10'000}; - NiPoint3 highest{-10'000, -10'000, -10'000}; - + NiPoint3 lowest{ 10'000.0f, 10'000.0f, 10'000.0f }; + NiPoint3 highest{ -10'000.0f, -10'000.0f, -10'000.0f }; + // Calculate the lowest and highest points on the entire model for (const auto& transformation : transformations | std::views::values) { auto split = GeneralUtils::SplitString(transformation, ','); @@ -100,7 +100,7 @@ Lxfml::Result Lxfml::NormalizePosition(const std::string_view data) { auto* refID = bone->Attribute("refID"); if (refID) { bone->SetAttribute("transformation", transformations[refID].c_str()); - } + } } } } @@ -109,7 +109,6 @@ Lxfml::Result Lxfml::NormalizePosition(const std::string_view data) { tinyxml2::XMLPrinter printer; doc.Print(&printer); - LOG("root pos %f %f %f", newRootPos.x, newRootPos.y, newRootPos.z); toReturn.lxfml = printer.CStr(); toReturn.center = newRootPos; return toReturn; diff --git a/dCommon/Lxfml.h b/dCommon/Lxfml.h index ab796473..3f5f4d4a 100644 --- a/dCommon/Lxfml.h +++ b/dCommon/Lxfml.h @@ -15,6 +15,8 @@ namespace Lxfml { NiPoint3 center; }; + // Normalizes a LXFML model to be positioned relative to its local 0, 0, 0 rather than a game worlds 0, 0, 0. + // Returns a struct of its new center and the updated LXFML containing these edits. [[nodiscard]] Result NormalizePosition(const std::string_view data); }; diff --git a/dCommon/Sd0.h b/dCommon/Sd0.h index ec0c4854..6340c78c 100644 --- a/dCommon/Sd0.h +++ b/dCommon/Sd0.h @@ -23,13 +23,13 @@ public: Sd0(std::istream& buffer); // Uncompresses the entire Sd0 buffer and returns it as a string - std::string GetAsStringUncompressed() const; + [[nodiscard]] std::string GetAsStringUncompressed() const; // Gets the Sd0 buffer as a stream in its raw compressed form - std::stringstream GetAsStream() const; + [[nodiscard]] std::stringstream GetAsStream() const; // Gets the Sd0 buffer as a vector in its raw compressed form - const std::vector& GetAsVector() const; + [[nodiscard]] const std::vector& GetAsVector() const; // Compress data into a Sd0 buffer void FromData(const uint8_t* data, size_t bufferSize); diff --git a/dCommon/TinyXmlUtils.h b/dCommon/TinyXmlUtils.h index 1a7cf33e..e7740f04 100644 --- a/dCommon/TinyXmlUtils.h +++ b/dCommon/TinyXmlUtils.h @@ -16,8 +16,8 @@ namespace TinyXmlUtils { ElementIterator(tinyxml2::XMLElement* elem); ElementIterator& operator++(); - tinyxml2::XMLElement* operator->() { DluAssert(m_CurElem); return m_CurElem; } - tinyxml2::XMLElement& operator*() { DluAssert(m_CurElem); return *m_CurElem; } + [[nodiscard]] tinyxml2::XMLElement* operator->() { DluAssert(m_CurElem); return m_CurElem; } + [[nodiscard]] tinyxml2::XMLElement& operator*() { DluAssert(m_CurElem); return *m_CurElem; } bool operator==(const ElementIterator& other) const { return other.m_CurElem == m_CurElem; } @@ -32,21 +32,21 @@ namespace TinyXmlUtils { Element(tinyxml2::XMLElement* xmlElem, const std::string_view elem); // The first child element of this element. - ElementIterator begin(); + [[nodiscard]] ElementIterator begin(); // Always returns an ElementIterator which points to nullptr. // TinyXml2 return NULL when you've reached the last child element so // you can't do any funny one past end logic here. - ElementIterator end(); + [[nodiscard]] ElementIterator end(); // Get a child element - Element operator[](const std::string_view elem) const; - Element operator[](const char* elem) const { return operator[](std::string_view(elem)); }; + [[nodiscard]] Element operator[](const std::string_view elem) const; + [[nodiscard]] Element operator[](const char* elem) const { return operator[](std::string_view(elem)); }; // Whether or not data exists for this element operator bool() const { return m_Elem != nullptr; } - const tinyxml2::XMLElement* operator->() const { return m_Elem; } + [[nodiscard]] const tinyxml2::XMLElement* operator->() const { return m_Elem; } private: const char* GetElementName() const { return m_IteratedName.empty() ? nullptr : m_IteratedName.c_str(); } const std::string m_IteratedName; @@ -57,7 +57,7 @@ namespace TinyXmlUtils { public: DocumentReader(tinyxml2::XMLDocument& doc) : m_Doc{ doc } {} - Element operator[](const std::string_view elem) const; + [[nodiscard]] Element operator[](const std::string_view elem) const; private: tinyxml2::XMLDocument& m_Doc; }; diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index 5b1a381b..af83425a 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -2611,7 +2611,6 @@ void GameMessages::HandleBBBSaveRequest(RakNet::BitStream& inStream, Entity* ent // Uncompress the data and normalize the position const auto asStr = sd0.GetAsStringUncompressed(); const auto [newLxfml, newCenter] = Lxfml::NormalizePosition(asStr); - auto [x, y, z] = newCenter; // Recompress the data and save to the database sd0.FromData(reinterpret_cast(newLxfml.data()), newLxfml.size()); diff --git a/dWorldServer/WorldServer.cpp b/dWorldServer/WorldServer.cpp index 643c85d2..5a7be387 100644 --- a/dWorldServer/WorldServer.cpp +++ b/dWorldServer/WorldServer.cpp @@ -1118,6 +1118,8 @@ void HandlePacket(Packet* packet) { GeneralUtils::SetBit(blueprintID, eObjectBits::CHARACTER); GeneralUtils::SetBit(blueprintID, eObjectBits::PERSISTENT); + // Workaround for not having a UGC server to get model LXFML onto the client so it + // can generate the physics and nif for the object. CBITSTREAM; BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::BLUEPRINT_SAVE_RESPONSE); bitStream.Write(LWOOBJID_EMPTY); //always zero so that a check on the client passes