[General] Rework PlayerStatsDynamic packets so they are of minimal size

new-script-api
David Cernat 7 years ago
parent 993cc3dfd6
commit fc5e883160

@ -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;
}

@ -156,6 +156,8 @@ void Player::update()
packet->setPlayer(basePlayer);
packet->Send(false);
packet->Send(true);
statsDynamicIndexChanges.clear();
}
if (attributesChanged)

@ -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();
}
}

@ -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<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…
Cancel
Save