From 96f224c38c6aead561ffc19df1e815ec7fb1ea4d Mon Sep 17 00:00:00 2001 From: jadebenn Date: Sat, 14 Dec 2024 19:29:22 -0600 Subject: [PATCH] move semantics --- dGame/dComponents/InventoryComponent.cpp | 15 ++++++++------- dGame/dComponents/InventoryComponent.h | 2 +- dGame/dComponents/PetComponent.cpp | 21 +++++++++------------ 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/dGame/dComponents/InventoryComponent.cpp b/dGame/dComponents/InventoryComponent.cpp index 366051ab..f108e13c 100644 --- a/dGame/dComponents/InventoryComponent.cpp +++ b/dGame/dComponents/InventoryComponent.cpp @@ -1253,8 +1253,8 @@ void InventoryComponent::SpawnPet(Item* item) { Game::entityManager->ConstructEntity(pet); } -void InventoryComponent::SetDatabasePet(LWOOBJID id, const DatabasePet& data) { - m_Pets.insert_or_assign(id, data); +void InventoryComponent::SetDatabasePet(LWOOBJID id, DatabasePet&& data) { + m_Pets.insert_or_assign(id, std::move(data)); } const DatabasePet& InventoryComponent::GetDatabasePet(LWOOBJID id) const { @@ -1580,12 +1580,13 @@ void InventoryComponent::LoadPetXml(const tinyxml2::XMLDocument& document) { petElement->QueryAttribute("m", &moderationStatus); const char* name = petElement->Attribute("n"); - DatabasePet databasePet; - databasePet.lot = lot; - databasePet.moderationState = moderationStatus; - databasePet.name = std::string(name); + auto databasePet = DatabasePet{ + .lot = lot, + .name = std::string(name), + .moderationState = moderationStatus, + }; - SetDatabasePet(id, databasePet); + SetDatabasePet(id, std::move(databasePet)); petElement = petElement->NextSiblingElement(); } diff --git a/dGame/dComponents/InventoryComponent.h b/dGame/dComponents/InventoryComponent.h index 0055fcea..46ddf775 100644 --- a/dGame/dComponents/InventoryComponent.h +++ b/dGame/dComponents/InventoryComponent.h @@ -339,7 +339,7 @@ public: * @param id the id of the pet to find * @param data the data to store on the pet */ - void SetDatabasePet(LWOOBJID id, const DatabasePet& data); + void SetDatabasePet(LWOOBJID id, DatabasePet&& data); /** * Returns the database pet information for an object diff --git a/dGame/dComponents/PetComponent.cpp b/dGame/dComponents/PetComponent.cpp index 0e18800b..8aab9393 100644 --- a/dGame/dComponents/PetComponent.cpp +++ b/dGame/dComponents/PetComponent.cpp @@ -393,15 +393,12 @@ void PetComponent::NotifyTamingBuildSuccess(const NiPoint3 position) { auto* const inventoryComponent = tamer->GetComponent(); if (!inventoryComponent) return; - LWOOBJID petSubKey = ObjectIDManager::GenerateRandomObjectID(); - + auto petSubKey = ObjectIDManager::GenerateRandomObjectID(); GeneralUtils::SetBit(petSubKey, eObjectBits::CHARACTER); GeneralUtils::SetBit(petSubKey, eObjectBits::PERSISTENT); - m_DatabaseId = petSubKey; - std::string petName = tamer->GetCharacter()->GetName(); - petName += "'s Pet"; + auto petName = tamer->GetCharacter()->GetName() + "'s Pet"; GameMessages::SendAddPetToPlayer(m_Tamer, 0, GeneralUtils::UTF8ToUTF16(petName), petSubKey, m_Parent->GetLOT(), tamer->GetSystemAddress()); GameMessages::SendRegisterPetID(m_Tamer, m_Parent->GetObjectID(), tamer->GetSystemAddress()); @@ -412,13 +409,13 @@ void PetComponent::NotifyTamingBuildSuccess(const NiPoint3 position) { auto* const item = inventoryComponent->FindItemBySubKey(petSubKey, MODELS); if (!item) return; - DatabasePet databasePet{}; + auto databasePet = DatabasePet{ + .lot = m_Parent->GetLOT(), + .name = std::move(petName), + .moderationState = 1, + }; - databasePet.lot = m_Parent->GetLOT(); - databasePet.moderationState = 1; - databasePet.name = petName; - - inventoryComponent->SetDatabasePet(petSubKey, databasePet); + inventoryComponent->SetDatabasePet(petSubKey, std::move(databasePet)); Activate(item, false, true); @@ -1000,7 +997,7 @@ void PetComponent::Activate(Item* item, bool registerPet, bool fromTaming) { // databaseData.name = m_Name; databaseData.moderationState = m_ModerationStatus; - inventoryComponent->SetDatabasePet(m_DatabaseId, databaseData); + inventoryComponent->SetDatabasePet(m_DatabaseId, std::move(databaseData)); updatedModerationStatus = true; } else {