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

Moreover, rename BaseNetCreature's equipedItems into equipmentItems.

(cherry picked from commit d1ad0c91f8)
0.6.3
David Cernat 7 years ago
parent c5b08d6109
commit b9520c11da

@ -150,22 +150,22 @@ double ActorFunctions::GetActorFatigueModified(unsigned int i) noexcept
const char *ActorFunctions::GetActorEquipmentItemRefId(unsigned int i, unsigned short slot) noexcept
{
return readActorList->baseActors.at(i).equipedItems[slot].refId.c_str();
return readActorList->baseActors.at(i).equipmentItems[slot].refId.c_str();
}
int ActorFunctions::GetActorEquipmentItemCount(unsigned int i, unsigned short slot) noexcept
{
return readActorList->baseActors.at(i).equipedItems[slot].count;
return readActorList->baseActors.at(i).equipmentItems[slot].count;
}
int ActorFunctions::GetActorEquipmentItemCharge(unsigned int i, unsigned short slot) noexcept
{
return readActorList->baseActors.at(i).equipedItems[slot].charge;
return readActorList->baseActors.at(i).equipmentItems[slot].charge;
}
double ActorFunctions::GetActorEquipmentItemEnchantmentCharge(unsigned int i, unsigned short slot) noexcept
{
return readActorList->baseActors.at(i).equipedItems[slot].enchantmentCharge;
return readActorList->baseActors.at(i).equipmentItems[slot].enchantmentCharge;
}
bool ActorFunctions::DoesActorHavePosition(unsigned int i) noexcept
@ -269,10 +269,10 @@ void ActorFunctions::SetActorFatigueModified(double value) noexcept
void ActorFunctions::EquipActorItem(unsigned short slot, const char *refId, unsigned int count, int charge, double enchantmentCharge) noexcept
{
tempActor.equipedItems[slot].refId = refId;
tempActor.equipedItems[slot].count = count;
tempActor.equipedItems[slot].charge = charge;
tempActor.equipedItems[slot].enchantmentCharge = enchantmentCharge;
tempActor.equipmentItems[slot].refId = refId;
tempActor.equipmentItems[slot].count = count;
tempActor.equipmentItems[slot].charge = charge;
tempActor.equipmentItems[slot].enchantmentCharge = enchantmentCharge;
}
void ActorFunctions::UnequipActorItem(unsigned short slot) noexcept

@ -40,10 +40,13 @@ void ItemFunctions::EquipItem(unsigned short pid, unsigned short slot, const cha
Player *player;
GET_PLAYER(pid, player,);
player->equipedItems[slot].refId = refId;
player->equipedItems[slot].count = count;
player->equipedItems[slot].charge = charge;
player->equipedItems[slot].enchantmentCharge = enchantmentCharge;
player->equipmentItems[slot].refId = refId;
player->equipmentItems[slot].count = count;
player->equipmentItems[slot].charge = charge;
player->equipmentItems[slot].enchantmentCharge = enchantmentCharge;
if (!Utils::vectorContains(&player->equipmentIndexChanges, slot))
player->equipmentIndexChanges.push_back(slot);
}
void ItemFunctions::UnequipItem(unsigned short pid, unsigned short slot) noexcept
@ -88,7 +91,7 @@ bool ItemFunctions::HasItemEquipped(unsigned short pid, const char* refId)
GET_PLAYER(pid, player, false);
for (int slot = 0; slot < MWWorld::InventoryStore::Slots; slot++)
if (Misc::StringUtils::ciEqual(player->equipedItems[slot].refId, refId))
if (Misc::StringUtils::ciEqual(player->equipmentItems[slot].refId, refId))
return true;
return false;
}
@ -98,7 +101,7 @@ const char *ItemFunctions::GetEquipmentItemRefId(unsigned short pid, unsigned sh
Player *player;
GET_PLAYER(pid, player, 0);
return player->equipedItems[slot].refId.c_str();
return player->equipmentItems[slot].refId.c_str();
}
int ItemFunctions::GetEquipmentItemCount(unsigned short pid, unsigned short slot) noexcept
@ -106,7 +109,7 @@ int ItemFunctions::GetEquipmentItemCount(unsigned short pid, unsigned short slot
Player *player;
GET_PLAYER(pid, player, 0);
return player->equipedItems[slot].count;
return player->equipmentItems[slot].count;
}
int ItemFunctions::GetEquipmentItemCharge(unsigned short pid, unsigned short slot) noexcept
@ -114,7 +117,7 @@ int ItemFunctions::GetEquipmentItemCharge(unsigned short pid, unsigned short slo
Player *player;
GET_PLAYER(pid, player, 0);
return player->equipedItems[slot].charge;
return player->equipmentItems[slot].charge;
}
double ItemFunctions::GetEquipmentItemEnchantmentCharge(unsigned short pid, unsigned short slot) noexcept
@ -122,7 +125,7 @@ double ItemFunctions::GetEquipmentItemEnchantmentCharge(unsigned short pid, unsi
Player *player;
GET_PLAYER(pid, player, 0);
return player->equipedItems[slot].enchantmentCharge;
return player->equipmentItems[slot].enchantmentCharge;
}
const char *ItemFunctions::GetInventoryItemRefId(unsigned short pid, unsigned int i) noexcept
@ -168,6 +171,8 @@ void ItemFunctions::SendEquipment(unsigned short pid) noexcept
mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_EQUIPMENT)->setPlayer(player);
mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_EQUIPMENT)->Send(false);
mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_EQUIPMENT)->Send(true);
player->equipmentIndexChanges.clear();
}
void ItemFunctions::SendInventoryChanges(unsigned short pid, bool toOthers) noexcept

@ -223,7 +223,7 @@ void Cell::readEquipment(ActorList& actorList)
DedicatedActor *actor = dedicatedActors[mapIndex];
for (int slot = 0; slot < 19; ++slot)
actor->equipedItems[slot] = baseActor.equipedItems[slot];
actor->equipmentItems[slot] = baseActor.equipmentItems[slot];
actor->setEquipment();
}

@ -168,15 +168,15 @@ void DedicatedActor::setEquipment()
for (int slot = 0; slot < MWWorld::InventoryStore::Slots; ++slot)
{
int count = equipedItems[slot].count;
int count = equipmentItems[slot].count;
// If we've somehow received a corrupted item with a count lower than 0, ignore it
if (count < 0) continue;
MWWorld::ContainerStoreIterator it = invStore.getSlot(slot);
const string &packetRefId = equipedItems[slot].refId;
int packetCharge = equipedItems[slot].charge;
const string &packetRefId = equipmentItems[slot].refId;
int packetCharge = equipmentItems[slot].charge;
std::string storeRefId = "";
bool equal = false;

@ -312,7 +312,7 @@ void DedicatedPlayer::setEquipment()
{
MWWorld::ContainerStoreIterator it = invStore.getSlot(slot);
const string &dedicItem = equipedItems[slot].refId;
const string &dedicItem = equipmentItems[slot].refId;
std::string item = "";
bool equal = false;
if (it != invStore.end())
@ -330,7 +330,7 @@ void DedicatedPlayer::setEquipment()
if (dedicItem.empty() || equal)
continue;
const int count = equipedItems[slot].count;
const int count = equipmentItems[slot].count;
ptr.getClass().getContainerStore(ptr).add(dedicItem, count, ptr);
for (const auto &ptr : invStore)

@ -193,7 +193,7 @@ void LocalActor::updateEquipment(bool forceUpdate)
MWWorld::InventoryStore &invStore = ptr.getClass().getInventoryStore(ptr);
for (int slot = 0; slot < MWWorld::InventoryStore::Slots; slot++)
{
auto &item = equipedItems[slot];
auto &item = equipmentItems[slot];
MWWorld::ContainerStoreIterator it = invStore.getSlot(slot);
if (it != invStore.end())

@ -244,9 +244,9 @@ void LocalPlayer::updateAttributes(bool forceUpdate)
ptrNpcStats.getSkillIncrease(i) != npcStats.mSkillIncrease[i] ||
forceUpdate)
{
attributeIndexChanges.push_back(i);
ptrNpcStats.getAttribute(i).writeState(creatureStats.mAttributes[i]);
npcStats.mSkillIncrease[i] = ptrNpcStats.getSkillIncrease(i);
attributeIndexChanges.push_back(i);
}
}
@ -274,8 +274,8 @@ void LocalPlayer::updateSkills(bool forceUpdate)
ptrNpcStats.getSkill(i).getProgress() != npcStats.mSkills[i].mProgress ||
forceUpdate)
{
ptrNpcStats.getSkill(i).writeState(npcStats.mSkills[i]);
skillIndexChanges.push_back(i);
ptrNpcStats.getSkill(i).writeState(npcStats.mSkills[i]);
}
}
@ -424,22 +424,17 @@ void LocalPlayer::updateEquipment(bool forceUpdate)
{
MWWorld::Ptr ptrPlayer = getPlayerPtr();
static bool equipmentChanged = false;
if (forceUpdate)
equipmentChanged = true;
MWWorld::InventoryStore &invStore = ptrPlayer.getClass().getInventoryStore(ptrPlayer);
for (int slot = 0; slot < MWWorld::InventoryStore::Slots; slot++)
{
auto &item = equipedItems[slot];
auto &item = equipmentItems[slot];
MWWorld::ContainerStoreIterator it = invStore.getSlot(slot);
if (it != invStore.end())
{
if (!::Misc::StringUtils::ciEqual(it->getCellRef().getRefId(), equipedItems[slot].refId))
if (!::Misc::StringUtils::ciEqual(it->getCellRef().getRefId(), equipmentItems[slot].refId) || forceUpdate)
{
equipmentChanged = true;
equipmentIndexChanges.push_back(slot);
item.refId = it->getCellRef().getRefId();
item.charge = it->getCellRef().getCharge();
@ -449,7 +444,7 @@ void LocalPlayer::updateEquipment(bool forceUpdate)
}
else if (!item.refId.empty())
{
equipmentChanged = true;
equipmentIndexChanges.push_back(slot);
item.refId = "";
item.count = 0;
item.charge = -1;
@ -457,11 +452,11 @@ void LocalPlayer::updateEquipment(bool forceUpdate)
}
}
if (equipmentChanged)
if (equipmentIndexChanges.size() > 0)
{
getNetworking()->getPlayerPacket(ID_PLAYER_EQUIPMENT)->setPlayer(this);
getNetworking()->getPlayerPacket(ID_PLAYER_EQUIPMENT)->Send();
equipmentChanged = false;
equipmentIndexChanges.clear();
}
}
@ -1061,7 +1056,7 @@ void LocalPlayer::setEquipment()
for (int slot = 0; slot < MWWorld::InventoryStore::Slots; slot++)
{
mwmp::Item &currentItem = equipedItems[slot];
mwmp::Item &currentItem = equipmentItems[slot];
if (!currentItem.refId.empty())
{
@ -1071,16 +1066,16 @@ void LocalPlayer::setEquipment()
if (it == ptrInventory.end()) // If the item is not in our inventory, add it
{
auto equipped = equipedItems[slot];
auto equipmentItem = equipmentItems[slot];
try
{
auto addIter = ptrInventory.ContainerStore::add(equipped.refId.c_str(), equipped.count, ptrPlayer);
auto addIter = ptrInventory.ContainerStore::add(equipmentItem.refId.c_str(), equipmentItem.count, ptrPlayer);
ptrInventory.equip(slot, addIter, ptrPlayer);
}
catch (std::exception&)
{
LOG_APPEND(Log::LOG_INFO, "- Ignored addition of invalid equipment item %s", equipped.refId.c_str());
LOG_APPEND(Log::LOG_INFO, "- Ignored addition of invalid equipment item %s", equipmentItem.refId.c_str());
}
}
else

@ -42,7 +42,7 @@ namespace mwmp
bool hasPositionData;
bool hasStatsDynamicData;
Item equipedItems[19];
Item equipmentItems[19];
};
class BaseActorList

@ -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 equipment items that have been changed,
// with the items themselves being stored in equipmentItems
std::vector<int> equipmentIndexChanges;
InventoryChanges inventoryChanges;
SpellbookChanges spellbookChanges;
QuickKeyChanges quickKeyChanges;
@ -289,7 +293,7 @@ namespace mwmp
ESM::Creature creature;
ESM::CreatureStats creatureStats;
ESM::Class charClass;
Item equipedItems[19];
Item equipmentItems[19];
Attack attack;
std::string birthsign;
std::string chatMessage;

@ -11,11 +11,11 @@ PacketActorEquipment::PacketActorEquipment(RakNet::RakPeerInterface *peer) : Act
void PacketActorEquipment::Actor(BaseActor &actor, bool send)
{
for (int j = 0; j < 19; j++)
for (auto &&equipmentItem : actor.equipmentItems)
{
RW(actor.equipedItems[j].refId, send);
RW(actor.equipedItems[j].count, send);
RW(actor.equipedItems[j].charge, send);
RW(actor.equipedItems[j].enchantmentCharge, send);
RW(equipmentItem.refId, send);
RW(equipmentItem.count, send);
RW(equipmentItem.charge, send);
RW(equipmentItem.enchantmentCharge, send);
}
}

@ -1,11 +1,6 @@
//
// Created by koncord on 07.01.16.
//
#include "PacketPlayerEquipment.hpp"
#include <components/openmw-mp/NetworkMessages.hpp>
using namespace mwmp;
PacketPlayerEquipment::PacketPlayerEquipment(RakNet::RakPeerInterface *peer) : PlayerPacket(peer)
@ -17,11 +12,25 @@ void PacketPlayerEquipment::Packet(RakNet::BitStream *bs, bool send)
{
PlayerPacket::Packet(bs, send);
for (int i = 0; i < 19; i++)
uint32_t count;
if (send)
count = static_cast<uint32_t>(player->equipmentIndexChanges.size());
RW(count, send);
if (!send)
{
RW(player->equipedItems[i].refId, send, 1);
RW(player->equipedItems[i].count, send);
RW(player->equipedItems[i].charge, send);
RW(player->equipedItems[i].enchantmentCharge, send);
player->equipmentIndexChanges.clear();
player->equipmentIndexChanges.resize(count);
}
for (auto &&equipmentIndex : player->equipmentIndexChanges)
{
RW(equipmentIndex, send);
RW(player->equipmentItems[equipmentIndex].refId, send);
RW(player->equipmentItems[equipmentIndex].count, send);
RW(player->equipmentItems[equipmentIndex].charge, send);
RW(player->equipmentItems[equipmentIndex].enchantmentCharge, send);
}
}

Loading…
Cancel
Save