diff --git a/apps/openmw-mp/NetActor.cpp b/apps/openmw-mp/NetActor.cpp index 9908c09b3..1b73f60db 100644 --- a/apps/openmw-mp/NetActor.cpp +++ b/apps/openmw-mp/NetActor.cpp @@ -61,6 +61,10 @@ void NetActor::setHealth(float base, float current) { netCreature->creatureStats.mDynamic[0].mBase = base; netCreature->creatureStats.mDynamic[0].mCurrent = current; + + if (!Utils::vectorContains(&netCreature->statsDynamicIndexChanges, 0)) + netCreature->statsDynamicIndexChanges.push_back(0); + statsChanged = true; } @@ -73,6 +77,10 @@ void NetActor::setMagicka(float base, float current) { netCreature->creatureStats.mDynamic[1].mBase = base; netCreature->creatureStats.mDynamic[1].mCurrent = current; + + if (!Utils::vectorContains(&netCreature->statsDynamicIndexChanges, 1)) + netCreature->statsDynamicIndexChanges.push_back(1); + statsChanged = true; } @@ -85,6 +93,10 @@ void NetActor::setFatigue(float base, float current) { netCreature->creatureStats.mDynamic[2].mBase = base; netCreature->creatureStats.mDynamic[2].mCurrent = current; + + if (!Utils::vectorContains(&netCreature->statsDynamicIndexChanges, 2)) + netCreature->statsDynamicIndexChanges.push_back(2); + statsChanged = true; } diff --git a/apps/openmw-mp/Player.cpp b/apps/openmw-mp/Player.cpp index 7b4f6dad9..9e37b6f82 100644 --- a/apps/openmw-mp/Player.cpp +++ b/apps/openmw-mp/Player.cpp @@ -156,6 +156,8 @@ void Player::update() packet->setPlayer(basePlayer); packet->Send(false); packet->Send(true); + + statsDynamicIndexChanges.clear(); } if (attributesChanged) diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index 89c76c853..2a32856c1 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -204,8 +204,16 @@ void LocalPlayer::updateStatsDynamic(bool forceUpdate) || abs(oldVal.getCurrent() - newVal.getCurrent()) >= limit); }; - if (forceUpdate || needUpdate(oldHealth, health, 3) || needUpdate(oldMagicka, magicka, 7) || - needUpdate(oldFatigue, fatigue, 7)) + if (needUpdate(oldHealth, health, 2)) + statsDynamicIndexChanges.push_back(0); + + if (needUpdate(oldMagicka, magicka, 4)) + statsDynamicIndexChanges.push_back(1); + + if (needUpdate(oldFatigue, fatigue, 4)) + statsDynamicIndexChanges.push_back(2); + + if (statsDynamicIndexChanges.size() > 0 || forceUpdate) { oldHealth = health; oldMagicka = magicka; @@ -217,6 +225,7 @@ void LocalPlayer::updateStatsDynamic(bool forceUpdate) getNetworking()->getPlayerPacket(ID_PLAYER_STATS_DYNAMIC)->setPlayer(this); getNetworking()->getPlayerPacket(ID_PLAYER_STATS_DYNAMIC)->Send(); + statsDynamicIndexChanges.clear(); } } diff --git a/components/openmw-mp/Base/BaseNetCreature.hpp b/components/openmw-mp/Base/BaseNetCreature.hpp index 6937eae41..7db61eb1c 100644 --- a/components/openmw-mp/Base/BaseNetCreature.hpp +++ b/components/openmw-mp/Base/BaseNetCreature.hpp @@ -27,6 +27,10 @@ namespace mwmp Attack attack; + // Track only the indexes of the dynamic states that have been changed, + // with the dynamicStats themselves being stored in creatureStats.mDynamic + std::vector statsDynamicIndexChanges; + // Track only the indexes of the equipment items that have been changed, // with the items themselves being stored in equipmentItems std::vector equipmentIndexChanges; diff --git a/components/openmw-mp/Packets/Player/PacketPlayerStatsDynamic.cpp b/components/openmw-mp/Packets/Player/PacketPlayerStatsDynamic.cpp index 97b1c5846..97b1fe589 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerStatsDynamic.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerStatsDynamic.cpp @@ -1,7 +1,3 @@ -// -// Created by koncord on 13.01.16. -// - #include "PacketPlayerStatsDynamic.hpp" #include @@ -15,5 +11,23 @@ PacketPlayerStatsDynamic::PacketPlayerStatsDynamic(RakNet::RakPeerInterface *pee void PacketPlayerStatsDynamic::Packet(RakNet::BitStream *bs, bool send) { PlayerPacket::Packet(bs, send); - RW(player->creatureStats.mDynamic, send); + + uint32_t count; + if (send) + count = static_cast(player->statsDynamicIndexChanges.size()); + + RW(count, send); + + if (!send) + { + player->statsDynamicIndexChanges.clear(); + player->statsDynamicIndexChanges.resize(count); + } + + for (auto &&statsDynamicIndex : player->statsDynamicIndexChanges) + { + RW(statsDynamicIndex, send); + + RW(player->creatureStats.mDynamic[statsDynamicIndex], send); + } }