diff --git a/apps/openmw-mp/Script/Functions/GUI.cpp b/apps/openmw-mp/Script/Functions/GUI.cpp index 9b27b53e3..5080b0351 100644 --- a/apps/openmw-mp/Script/Functions/GUI.cpp +++ b/apps/openmw-mp/Script/Functions/GUI.cpp @@ -89,7 +89,7 @@ void GUIFunctions::ClearQuickKeyChanges(unsigned short pid) noexcept Player *player; GET_PLAYER(pid, player, ); - player->quickKeyChanges.quickKeys.clear(); + player->quickKeyChanges.clear(); } unsigned int GUIFunctions::GetQuickKeyChangesSize(unsigned short pid) noexcept @@ -97,7 +97,7 @@ unsigned int GUIFunctions::GetQuickKeyChangesSize(unsigned short pid) noexcept Player *player; GET_PLAYER(pid, player, 0); - return player->quickKeyChanges.count; + return player->quickKeyChanges.size(); } int GUIFunctions::GetQuickKeySlot(unsigned short pid, unsigned int index) noexcept @@ -105,10 +105,10 @@ int GUIFunctions::GetQuickKeySlot(unsigned short pid, unsigned int index) noexce Player *player; GET_PLAYER(pid, player, 0); - if (index >= player->quickKeyChanges.count) + if (index >= player->quickKeyChanges.size()) return 0; - return player->quickKeyChanges.quickKeys.at(index).slot; + return player->quickKeyChanges.at(index).slot; } int GUIFunctions::GetQuickKeyType(unsigned short pid, unsigned int index) noexcept @@ -116,10 +116,10 @@ int GUIFunctions::GetQuickKeyType(unsigned short pid, unsigned int index) noexce Player *player; GET_PLAYER(pid, player, 0); - if (index >= player->quickKeyChanges.count) + if (index >= player->quickKeyChanges.size()) return 0; - return player->quickKeyChanges.quickKeys.at(index).type; + return player->quickKeyChanges.at(index).type; } const char *GUIFunctions::GetQuickKeyItemId(unsigned short pid, unsigned int index) noexcept @@ -127,10 +127,10 @@ const char *GUIFunctions::GetQuickKeyItemId(unsigned short pid, unsigned int ind Player *player; GET_PLAYER(pid, player, ""); - if (index >= player->quickKeyChanges.count) + if (index >= player->quickKeyChanges.size()) return "invalid"; - return player->quickKeyChanges.quickKeys.at(index).itemId.c_str(); + return player->quickKeyChanges.at(index).itemId.c_str(); } void GUIFunctions::AddQuickKey(unsigned short pid, unsigned short slot, int type, const char* itemId) noexcept @@ -143,7 +143,7 @@ void GUIFunctions::AddQuickKey(unsigned short pid, unsigned short slot, int type quickKey.type = type; quickKey.itemId = itemId; - player->quickKeyChanges.quickKeys.push_back(quickKey); + player->quickKeyChanges.push_back(quickKey); } void GUIFunctions::SendQuickKeyChanges(unsigned short pid) noexcept diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index 676a0ddd0..f910d0e5b 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -1232,7 +1232,7 @@ void LocalPlayer::setQuickKeys() LOG_MESSAGE_SIMPLE(TimedLog::LOG_INFO, "Received ID_PLAYER_QUICKKEYS from server"); - for (const auto &quickKey : quickKeyChanges.quickKeys) + for (const auto &quickKey : quickKeyChanges) { LOG_APPEND(TimedLog::LOG_INFO, "- slot: %i, type: %i, itemId: %s", quickKey.slot, quickKey.type, quickKey.itemId.c_str()); @@ -1494,7 +1494,7 @@ void LocalPlayer::sendSpellChange(std::string id, unsigned int action) void LocalPlayer::sendQuickKey(unsigned short slot, int type, const std::string& itemId) { - quickKeyChanges.quickKeys.clear(); + quickKeyChanges.clear(); mwmp::QuickKey quickKey; quickKey.slot = slot; @@ -1504,7 +1504,7 @@ void LocalPlayer::sendQuickKey(unsigned short slot, int type, const std::string& LOG_MESSAGE_SIMPLE(TimedLog::LOG_INFO, "Sending ID_PLAYER_QUICKKEYS", itemId.c_str()); LOG_APPEND(TimedLog::LOG_INFO, "- slot: %i, type: %i, itemId: %s", quickKey.slot, quickKey.type, quickKey.itemId.c_str()); - quickKeyChanges.quickKeys.push_back(quickKey); + quickKeyChanges.push_back(quickKey); getNetworking()->getPlayerPacket(ID_PLAYER_QUICKKEYS)->setPlayer(this); getNetworking()->getPlayerPacket(ID_PLAYER_QUICKKEYS)->Send(); diff --git a/components/openmw-mp/Base/BasePlayer.hpp b/components/openmw-mp/Base/BasePlayer.hpp index cc5ea02d9..a277ac2a6 100644 --- a/components/openmw-mp/Base/BasePlayer.hpp +++ b/components/openmw-mp/Base/BasePlayer.hpp @@ -141,12 +141,6 @@ namespace mwmp int action; // 0 - Clear and set in entirety, 1 - Add spell, 2 - Remove spell }; - struct QuickKeyChanges - { - std::vector quickKeys; - unsigned int count; - }; - struct CellStateChanges { std::vector cellStates; @@ -238,7 +232,7 @@ namespace mwmp InventoryChanges inventoryChanges; SpellbookChanges spellbookChanges; - QuickKeyChanges quickKeyChanges; + std::vector quickKeyChanges; std::vector journalChanges; FactionChanges factionChanges; TopicChanges topicChanges; diff --git a/components/openmw-mp/Packets/Player/PacketPlayerQuickKeys.cpp b/components/openmw-mp/Packets/Player/PacketPlayerQuickKeys.cpp index 0be42e565..7756fb3c3 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerQuickKeys.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerQuickKeys.cpp @@ -13,28 +13,25 @@ void PacketPlayerQuickKeys::Packet(RakNet::BitStream *bs, bool send) { PlayerPacket::Packet(bs, send); + uint32_t count; + if (send) - player->quickKeyChanges.count = (unsigned int) (player->quickKeyChanges.quickKeys.size()); - else - player->quickKeyChanges.quickKeys.clear(); + count = static_cast(player->quickKeyChanges.size()); - RW(player->quickKeyChanges.count, send); + RW(count, send); - for (unsigned int i = 0; i < player->quickKeyChanges.count; i++) + if (!send) { - QuickKey quickKey; - - if (send) - quickKey = player->quickKeyChanges.quickKeys.at(i); + player->quickKeyChanges.clear(); + player->quickKeyChanges.resize(count); + } + for (auto &&quickKey : player->quickKeyChanges) + { RW(quickKey.type, send); RW(quickKey.slot, send); if (quickKey.type != QuickKey::UNASSIGNED) RW(quickKey.itemId, send); - - if (!send) - player->quickKeyChanges.quickKeys.push_back(quickKey); } - }