mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-06 10:44:08 +00:00
remove usage of xmldoc as a ptr (#1538)
resolves a memory leak in BrickDatabase, adds stability to character save doc. Tested that saving manually via force-save, logout and /crash all saved my position and my removed banana as expected. The doc was always deleted on character destruction and on any updates, so this is just a semantic change (and now we no longer have new'd tinyxml2::documents on the heap)
This commit is contained in:
@@ -65,24 +65,24 @@ Mission::Mission(MissionComponent* missionComponent, const uint32_t missionId) {
|
||||
}
|
||||
}
|
||||
|
||||
void Mission::LoadFromXml(tinyxml2::XMLElement* element) {
|
||||
void Mission::LoadFromXml(const tinyxml2::XMLElement& element) {
|
||||
// Start custom XML
|
||||
if (element->Attribute("state") != nullptr) {
|
||||
m_State = static_cast<eMissionState>(std::stoul(element->Attribute("state")));
|
||||
if (element.Attribute("state") != nullptr) {
|
||||
m_State = static_cast<eMissionState>(std::stoul(element.Attribute("state")));
|
||||
}
|
||||
// End custom XML
|
||||
|
||||
if (element->Attribute("cct") != nullptr) {
|
||||
m_Completions = std::stoul(element->Attribute("cct"));
|
||||
if (element.Attribute("cct") != nullptr) {
|
||||
m_Completions = std::stoul(element.Attribute("cct"));
|
||||
|
||||
m_Timestamp = std::stoul(element->Attribute("cts"));
|
||||
m_Timestamp = std::stoul(element.Attribute("cts"));
|
||||
|
||||
if (IsComplete()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
auto* task = element->FirstChildElement();
|
||||
auto* task = element.FirstChildElement();
|
||||
|
||||
auto index = 0U;
|
||||
|
||||
@@ -132,19 +132,19 @@ void Mission::LoadFromXml(tinyxml2::XMLElement* element) {
|
||||
}
|
||||
}
|
||||
|
||||
void Mission::UpdateXml(tinyxml2::XMLElement* element) {
|
||||
void Mission::UpdateXml(tinyxml2::XMLElement& element) {
|
||||
// Start custom XML
|
||||
element->SetAttribute("state", static_cast<unsigned int>(m_State));
|
||||
element.SetAttribute("state", static_cast<unsigned int>(m_State));
|
||||
// End custom XML
|
||||
|
||||
element->DeleteChildren();
|
||||
element.DeleteChildren();
|
||||
|
||||
element->SetAttribute("id", static_cast<unsigned int>(info.id));
|
||||
element.SetAttribute("id", static_cast<unsigned int>(info.id));
|
||||
|
||||
if (m_Completions > 0) {
|
||||
element->SetAttribute("cct", static_cast<unsigned int>(m_Completions));
|
||||
element.SetAttribute("cct", static_cast<unsigned int>(m_Completions));
|
||||
|
||||
element->SetAttribute("cts", static_cast<unsigned int>(m_Timestamp));
|
||||
element.SetAttribute("cts", static_cast<unsigned int>(m_Timestamp));
|
||||
|
||||
if (IsComplete()) {
|
||||
return;
|
||||
@@ -155,27 +155,27 @@ void Mission::UpdateXml(tinyxml2::XMLElement* element) {
|
||||
if (task->GetType() == eMissionTaskType::COLLECTION ||
|
||||
task->GetType() == eMissionTaskType::VISIT_PROPERTY) {
|
||||
|
||||
auto* child = element->GetDocument()->NewElement("sv");
|
||||
auto* child = element.GetDocument()->NewElement("sv");
|
||||
|
||||
child->SetAttribute("v", static_cast<unsigned int>(task->GetProgress()));
|
||||
|
||||
element->LinkEndChild(child);
|
||||
element.LinkEndChild(child);
|
||||
|
||||
for (auto unique : task->GetUnique()) {
|
||||
auto* uniqueElement = element->GetDocument()->NewElement("sv");
|
||||
auto* uniqueElement = element.GetDocument()->NewElement("sv");
|
||||
|
||||
uniqueElement->SetAttribute("v", static_cast<unsigned int>(unique));
|
||||
|
||||
element->LinkEndChild(uniqueElement);
|
||||
element.LinkEndChild(uniqueElement);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
auto* child = element->GetDocument()->NewElement("sv");
|
||||
auto* child = element.GetDocument()->NewElement("sv");
|
||||
|
||||
child->SetAttribute("v", static_cast<unsigned int>(task->GetProgress()));
|
||||
|
||||
element->LinkEndChild(child);
|
||||
element.LinkEndChild(child);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -28,8 +28,8 @@ public:
|
||||
Mission(MissionComponent* missionComponent, uint32_t missionId);
|
||||
~Mission();
|
||||
|
||||
void LoadFromXml(tinyxml2::XMLElement* element);
|
||||
void UpdateXml(tinyxml2::XMLElement* element);
|
||||
void LoadFromXml(const tinyxml2::XMLElement& element);
|
||||
void UpdateXml(tinyxml2::XMLElement& element);
|
||||
|
||||
/**
|
||||
* Returns the ID of this mission
|
||||
|
Reference in New Issue
Block a user