diff --git a/apps/openmw-mp/Script/Functions/Stats.cpp b/apps/openmw-mp/Script/Functions/Stats.cpp index 8e63067bd..2518ed11d 100644 --- a/apps/openmw-mp/Script/Functions/Stats.cpp +++ b/apps/openmw-mp/Script/Functions/Stats.cpp @@ -409,8 +409,8 @@ void StatsFunctions::SetAttributeBase(unsigned short pid, unsigned short attribu player->creatureStats.mAttributes[attributeId].mBase = value; - if (!Utils::vectorContains(&player->attributeChanges.attributeIndexes, attributeId)) - player->attributeChanges.attributeIndexes.push_back(attributeId); + if (!Utils::vectorContains(&player->attributeIndexChanges, attributeId)) + player->attributeIndexChanges.push_back(attributeId); } void StatsFunctions::ClearAttributeModifier(unsigned short pid, unsigned short attributeId) noexcept @@ -423,8 +423,8 @@ void StatsFunctions::ClearAttributeModifier(unsigned short pid, unsigned short a player->creatureStats.mAttributes[attributeId].mMod = 0; - if (!Utils::vectorContains(&player->attributeChanges.attributeIndexes, attributeId)) - player->attributeChanges.attributeIndexes.push_back(attributeId); + if (!Utils::vectorContains(&player->attributeIndexChanges, attributeId)) + player->attributeIndexChanges.push_back(attributeId); } void StatsFunctions::SetSkillBase(unsigned short pid, unsigned short skillId, int value) noexcept @@ -437,8 +437,8 @@ void StatsFunctions::SetSkillBase(unsigned short pid, unsigned short skillId, in player->npcStats.mSkills[skillId].mBase = value; - if (!Utils::vectorContains(&player->skillChanges.skillIndexes, skillId)) - player->skillChanges.skillIndexes.push_back(skillId); + if (!Utils::vectorContains(&player->skillIndexChanges, skillId)) + player->skillIndexChanges.push_back(skillId); } void StatsFunctions::ClearSkillModifier(unsigned short pid, unsigned short skillId) noexcept @@ -451,8 +451,8 @@ void StatsFunctions::ClearSkillModifier(unsigned short pid, unsigned short skill player->npcStats.mSkills[skillId].mMod = 0; - if (!Utils::vectorContains(&player->skillChanges.skillIndexes, skillId)) - player->skillChanges.skillIndexes.push_back(skillId); + if (!Utils::vectorContains(&player->skillIndexChanges, skillId)) + player->skillIndexChanges.push_back(skillId); } void StatsFunctions::SetSkillProgress(unsigned short pid, unsigned short skillId, double value) noexcept @@ -465,8 +465,8 @@ void StatsFunctions::SetSkillProgress(unsigned short pid, unsigned short skillId player->npcStats.mSkills[skillId].mProgress = value; - if (!Utils::vectorContains(&player->skillChanges.skillIndexes, skillId)) - player->skillChanges.skillIndexes.push_back(skillId); + if (!Utils::vectorContains(&player->skillIndexChanges, skillId)) + player->skillIndexChanges.push_back(skillId); } void StatsFunctions::SetSkillIncrease(unsigned short pid, unsigned int attributeId, int value) noexcept @@ -479,8 +479,8 @@ void StatsFunctions::SetSkillIncrease(unsigned short pid, unsigned int attribute player->npcStats.mSkillIncrease[attributeId] = value; - if (!Utils::vectorContains(&player->attributeChanges.attributeIndexes, attributeId)) - player->attributeChanges.attributeIndexes.push_back(attributeId); + if (!Utils::vectorContains(&player->attributeIndexChanges, attributeId)) + player->attributeIndexChanges.push_back(attributeId); } void StatsFunctions::SetBounty(unsigned short pid, int value) noexcept @@ -533,7 +533,7 @@ void StatsFunctions::SendAttributes(unsigned short pid) noexcept mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_ATTRIBUTE)->Send(false); mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_ATTRIBUTE)->Send(true); - player->attributeChanges.attributeIndexes.clear(); + player->attributeIndexChanges.clear(); } void StatsFunctions::SendSkills(unsigned short pid) noexcept @@ -545,7 +545,7 @@ void StatsFunctions::SendSkills(unsigned short pid) noexcept mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_SKILL)->Send(false); mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_SKILL)->Send(true); - player->skillChanges.skillIndexes.clear(); + player->skillIndexChanges.clear(); } void StatsFunctions::SendLevel(unsigned short pid) noexcept diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index 6b95cc715..f449ff4d5 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -246,15 +246,15 @@ void LocalPlayer::updateAttributes(bool forceUpdate) { ptrNpcStats.getAttribute(i).writeState(creatureStats.mAttributes[i]); npcStats.mSkillIncrease[i] = ptrNpcStats.getSkillIncrease(i); - attributeChanges.attributeIndexes.push_back(i); + attributeIndexChanges.push_back(i); } } - if (attributeChanges.attributeIndexes.size() > 0) + if (attributeIndexChanges.size() > 0) { getNetworking()->getPlayerPacket(ID_PLAYER_ATTRIBUTE)->setPlayer(this); getNetworking()->getPlayerPacket(ID_PLAYER_ATTRIBUTE)->Send(); - attributeChanges.attributeIndexes.clear(); + attributeIndexChanges.clear(); } } @@ -275,15 +275,15 @@ void LocalPlayer::updateSkills(bool forceUpdate) forceUpdate) { ptrNpcStats.getSkill(i).writeState(npcStats.mSkills[i]); - skillChanges.skillIndexes.push_back(i); + skillIndexChanges.push_back(i); } } - if (skillChanges.skillIndexes.size() > 0) + if (skillIndexChanges.size() > 0) { getNetworking()->getPlayerPacket(ID_PLAYER_SKILL)->setPlayer(this); getNetworking()->getPlayerPacket(ID_PLAYER_SKILL)->Send(); - skillChanges.skillIndexes.clear(); + skillIndexChanges.clear(); } } diff --git a/components/openmw-mp/Base/BasePlayer.hpp b/components/openmw-mp/Base/BasePlayer.hpp index bc11fcc82..69bde88f8 100644 --- a/components/openmw-mp/Base/BasePlayer.hpp +++ b/components/openmw-mp/Base/BasePlayer.hpp @@ -95,22 +95,6 @@ namespace mwmp int type; // 0 - Cell load, 1 - Cell unload }; - // Track only the indexes of the attributes that have been changed, - // with the attribute values themselves being stored in creatureStats.mAttributes - struct AttributeChanges - { - std::vector attributeIndexes; - unsigned int count; - }; - - // Track only the indexes of the skills that have been changed, - // with the skill values themselves being stored in npcStats.mSkills - struct SkillChanges - { - std::vector skillIndexes; - unsigned int count; - }; - struct JournalChanges { std::vector journalItems; @@ -259,8 +243,13 @@ namespace mwmp int day; double hour; - AttributeChanges attributeChanges; - SkillChanges skillChanges; + // Track only the indexes of the attributes that have been changed, + // with the attribute values themselves being stored in creatureStats.mAttributes + std::vector attributeIndexChanges; + + // Track only the indexes of the skills that have been changed, + // with the skill values themselves being stored in npcStats.mSkills + std::vector skillIndexChanges; InventoryChanges inventoryChanges; SpellbookChanges spellbookChanges; diff --git a/components/openmw-mp/Packets/Player/PacketPlayerAttribute.cpp b/components/openmw-mp/Packets/Player/PacketPlayerAttribute.cpp index 0ba1fc1db..e99e69d03 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerAttribute.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerAttribute.cpp @@ -13,23 +13,23 @@ void PacketPlayerAttribute::Packet(RakNet::BitStream *bs, bool send) { PlayerPacket::Packet(bs, send); + uint32_t count; if (send) - player->attributeChanges.count = (unsigned int)(player->attributeChanges.attributeIndexes.size()); - else - player->attributeChanges.attributeIndexes.clear(); + count = static_cast(player->attributeIndexChanges.size()); - RW(player->attributeChanges.count, send); + RW(count, send); - for (unsigned int i = 0; i < player->attributeChanges.count; i++) + if (!send) { - int attributeId; - - if (send) - attributeId = player->attributeChanges.attributeIndexes.at(i); + player->attributeIndexChanges.clear(); + player->attributeIndexChanges.resize(count); + } - RW(attributeId, send); + for (auto &&attributeIndex : player->attributeIndexChanges) + { + RW(attributeIndex, send); - RW(player->creatureStats.mAttributes[attributeId], send); - RW(player->npcStats.mSkillIncrease[attributeId], send); + RW(player->creatureStats.mAttributes[attributeIndex], send); + RW(player->npcStats.mSkillIncrease[attributeIndex], send); } } diff --git a/components/openmw-mp/Packets/Player/PacketPlayerSkill.cpp b/components/openmw-mp/Packets/Player/PacketPlayerSkill.cpp index 68ee97981..157506074 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerSkill.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerSkill.cpp @@ -14,22 +14,22 @@ void PacketPlayerSkill::Packet(RakNet::BitStream *bs, bool send) { PlayerPacket::Packet(bs, send); + uint32_t count; + if (send) - player->skillChanges.count = (unsigned int)(player->skillChanges.skillIndexes.size()); - else - player->skillChanges.skillIndexes.clear(); + count = static_cast(player->skillIndexChanges.size()); - RW(player->skillChanges.count, send); + RW(count, send); - for (unsigned int i = 0; i < player->skillChanges.count; i++) + if (!send) { - int skillId; - - if (send) - skillId = player->skillChanges.skillIndexes.at(i); + player->skillIndexChanges.clear(); + player->skillIndexChanges.resize(count); + } + for (auto &&skillId : player->skillIndexChanges) + { RW(skillId, send); - RW(player->npcStats.mSkills[skillId], send); } }