forked from teamnwah/openmw-tes3coop
[General] Rework PlayerStatsDynamic packets so they are of minimal size
(cherry picked from commit fc5e883160
)
This commit is contained in:
parent
b9520c11da
commit
a541d7df3c
4 changed files with 54 additions and 7 deletions
|
@ -357,6 +357,9 @@ void StatsFunctions::SetHealthBase(unsigned short pid, double value) noexcept
|
|||
GET_PLAYER(pid, player,);
|
||||
|
||||
player->creatureStats.mDynamic[0].mBase = value;
|
||||
|
||||
if (!Utils::vectorContains(&player->statsDynamicIndexChanges, 0))
|
||||
player->skillIndexChanges.push_back(0);
|
||||
}
|
||||
|
||||
void StatsFunctions::SetHealthCurrent(unsigned short pid, double value) noexcept
|
||||
|
@ -365,6 +368,9 @@ void StatsFunctions::SetHealthCurrent(unsigned short pid, double value) noexcept
|
|||
GET_PLAYER(pid, player,);
|
||||
|
||||
player->creatureStats.mDynamic[0].mCurrent = value;
|
||||
|
||||
if (!Utils::vectorContains(&player->statsDynamicIndexChanges, 0))
|
||||
player->skillIndexChanges.push_back(0);
|
||||
}
|
||||
|
||||
void StatsFunctions::SetMagickaBase(unsigned short pid, double value) noexcept
|
||||
|
@ -373,6 +379,9 @@ void StatsFunctions::SetMagickaBase(unsigned short pid, double value) noexcept
|
|||
GET_PLAYER(pid, player,);
|
||||
|
||||
player->creatureStats.mDynamic[1].mBase = value;
|
||||
|
||||
if (!Utils::vectorContains(&player->statsDynamicIndexChanges, 1))
|
||||
player->skillIndexChanges.push_back(1);
|
||||
}
|
||||
|
||||
void StatsFunctions::SetMagickaCurrent(unsigned short pid, double value) noexcept
|
||||
|
@ -381,6 +390,9 @@ void StatsFunctions::SetMagickaCurrent(unsigned short pid, double value) noexcep
|
|||
GET_PLAYER(pid, player,);
|
||||
|
||||
player->creatureStats.mDynamic[1].mCurrent = value;
|
||||
|
||||
if (!Utils::vectorContains(&player->statsDynamicIndexChanges, 1))
|
||||
player->skillIndexChanges.push_back(1);
|
||||
}
|
||||
|
||||
void StatsFunctions::SetFatigueBase(unsigned short pid, double value) noexcept
|
||||
|
@ -389,6 +401,9 @@ void StatsFunctions::SetFatigueBase(unsigned short pid, double value) noexcept
|
|||
GET_PLAYER(pid, player,);
|
||||
|
||||
player->creatureStats.mDynamic[2].mBase = value;
|
||||
|
||||
if (!Utils::vectorContains(&player->statsDynamicIndexChanges, 2))
|
||||
player->skillIndexChanges.push_back(2);
|
||||
}
|
||||
|
||||
void StatsFunctions::SetFatigueCurrent(unsigned short pid, double value) noexcept
|
||||
|
@ -397,6 +412,9 @@ void StatsFunctions::SetFatigueCurrent(unsigned short pid, double value) noexcep
|
|||
GET_PLAYER(pid, player,);
|
||||
|
||||
player->creatureStats.mDynamic[2].mCurrent = value;
|
||||
|
||||
if (!Utils::vectorContains(&player->statsDynamicIndexChanges, 2))
|
||||
player->skillIndexChanges.push_back(2);
|
||||
}
|
||||
|
||||
void StatsFunctions::SetAttributeBase(unsigned short pid, unsigned short attributeId, int value) noexcept
|
||||
|
@ -522,6 +540,8 @@ void StatsFunctions::SendStatsDynamic(unsigned short pid) noexcept
|
|||
mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_STATS_DYNAMIC)->setPlayer(player);
|
||||
mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_STATS_DYNAMIC)->Send(false);
|
||||
mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_STATS_DYNAMIC)->Send(true);
|
||||
|
||||
player->statsDynamicIndexChanges.clear();
|
||||
}
|
||||
|
||||
void StatsFunctions::SendAttributes(unsigned short pid) noexcept
|
||||
|
|
|
@ -212,8 +212,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;
|
||||
|
@ -225,6 +233,7 @@ void LocalPlayer::updateStatsDynamic(bool forceUpdate)
|
|||
|
||||
getNetworking()->getPlayerPacket(ID_PLAYER_STATS_DYNAMIC)->setPlayer(this);
|
||||
getNetworking()->getPlayerPacket(ID_PLAYER_STATS_DYNAMIC)->Send();
|
||||
statsDynamicIndexChanges.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -251,6 +251,10 @@ namespace mwmp
|
|||
// with the skill values themselves being stored in npcStats.mSkills
|
||||
std::vector<int> skillIndexChanges;
|
||||
|
||||
// Track only the indexes of the dynamic states that have been changed,
|
||||
// with the dynamicStats themselves being stored in creatureStats.mDynamic
|
||||
std::vector<int> statsDynamicIndexChanges;
|
||||
|
||||
// Track only the indexes of the equipment items that have been changed,
|
||||
// with the items themselves being stored in equipmentItems
|
||||
std::vector<int> equipmentIndexChanges;
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
//
|
||||
// Created by koncord on 13.01.16.
|
||||
//
|
||||
|
||||
#include "PacketPlayerStatsDynamic.hpp"
|
||||
#include <components/openmw-mp/NetworkMessages.hpp>
|
||||
|
||||
|
@ -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<uint32_t>(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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue