add some notes and remove some logs

This commit is contained in:
David Markowitz 2025-04-10 18:56:38 -07:00
parent a4295a26f7
commit 2cf0eac8f2
6 changed files with 19 additions and 17 deletions

View File

@ -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;

View File

@ -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);
};

View File

@ -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<BinaryBuffer>& GetAsVector() const;
[[nodiscard]] const std::vector<BinaryBuffer>& GetAsVector() const;
// Compress data into a Sd0 buffer
void FromData(const uint8_t* data, size_t bufferSize);

View File

@ -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;
};

View File

@ -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<const uint8_t*>(newLxfml.data()), newLxfml.size());

View File

@ -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>(LWOOBJID_EMPTY); //always zero so that a check on the client passes