move semantics

This commit is contained in:
jadebenn 2024-12-14 19:29:22 -06:00
parent 43681b4494
commit 96f224c38c
3 changed files with 18 additions and 20 deletions

View File

@ -1253,8 +1253,8 @@ void InventoryComponent::SpawnPet(Item* item) {
Game::entityManager->ConstructEntity(pet); Game::entityManager->ConstructEntity(pet);
} }
void InventoryComponent::SetDatabasePet(LWOOBJID id, const DatabasePet& data) { void InventoryComponent::SetDatabasePet(LWOOBJID id, DatabasePet&& data) {
m_Pets.insert_or_assign(id, data); m_Pets.insert_or_assign(id, std::move(data));
} }
const DatabasePet& InventoryComponent::GetDatabasePet(LWOOBJID id) const { const DatabasePet& InventoryComponent::GetDatabasePet(LWOOBJID id) const {
@ -1580,12 +1580,13 @@ void InventoryComponent::LoadPetXml(const tinyxml2::XMLDocument& document) {
petElement->QueryAttribute("m", &moderationStatus); petElement->QueryAttribute("m", &moderationStatus);
const char* name = petElement->Attribute("n"); const char* name = petElement->Attribute("n");
DatabasePet databasePet; auto databasePet = DatabasePet{
databasePet.lot = lot; .lot = lot,
databasePet.moderationState = moderationStatus; .name = std::string(name),
databasePet.name = std::string(name); .moderationState = moderationStatus,
};
SetDatabasePet(id, databasePet); SetDatabasePet(id, std::move(databasePet));
petElement = petElement->NextSiblingElement(); petElement = petElement->NextSiblingElement();
} }

View File

@ -339,7 +339,7 @@ public:
* @param id the id of the pet to find * @param id the id of the pet to find
* @param data the data to store on the pet * @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 * Returns the database pet information for an object

View File

@ -393,15 +393,12 @@ void PetComponent::NotifyTamingBuildSuccess(const NiPoint3 position) {
auto* const inventoryComponent = tamer->GetComponent<InventoryComponent>(); auto* const inventoryComponent = tamer->GetComponent<InventoryComponent>();
if (!inventoryComponent) return; if (!inventoryComponent) return;
LWOOBJID petSubKey = ObjectIDManager::GenerateRandomObjectID(); auto petSubKey = ObjectIDManager::GenerateRandomObjectID();
GeneralUtils::SetBit(petSubKey, eObjectBits::CHARACTER); GeneralUtils::SetBit(petSubKey, eObjectBits::CHARACTER);
GeneralUtils::SetBit(petSubKey, eObjectBits::PERSISTENT); GeneralUtils::SetBit(petSubKey, eObjectBits::PERSISTENT);
m_DatabaseId = petSubKey; m_DatabaseId = petSubKey;
std::string petName = tamer->GetCharacter()->GetName(); auto petName = tamer->GetCharacter()->GetName() + "'s Pet";
petName += "'s Pet";
GameMessages::SendAddPetToPlayer(m_Tamer, 0, GeneralUtils::UTF8ToUTF16(petName), petSubKey, m_Parent->GetLOT(), tamer->GetSystemAddress()); GameMessages::SendAddPetToPlayer(m_Tamer, 0, GeneralUtils::UTF8ToUTF16(petName), petSubKey, m_Parent->GetLOT(), tamer->GetSystemAddress());
GameMessages::SendRegisterPetID(m_Tamer, m_Parent->GetObjectID(), 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); auto* const item = inventoryComponent->FindItemBySubKey(petSubKey, MODELS);
if (!item) return; if (!item) return;
DatabasePet databasePet{}; auto databasePet = DatabasePet{
.lot = m_Parent->GetLOT(),
.name = std::move(petName),
.moderationState = 1,
};
databasePet.lot = m_Parent->GetLOT(); inventoryComponent->SetDatabasePet(petSubKey, std::move(databasePet));
databasePet.moderationState = 1;
databasePet.name = petName;
inventoryComponent->SetDatabasePet(petSubKey, databasePet);
Activate(item, false, true); Activate(item, false, true);
@ -1000,7 +997,7 @@ void PetComponent::Activate(Item* item, bool registerPet, bool fromTaming) { //
databaseData.name = m_Name; databaseData.name = m_Name;
databaseData.moderationState = m_ModerationStatus; databaseData.moderationState = m_ModerationStatus;
inventoryComponent->SetDatabasePet(m_DatabaseId, databaseData); inventoryComponent->SetDatabasePet(m_DatabaseId, std::move(databaseData));
updatedModerationStatus = true; updatedModerationStatus = true;
} else { } else {