From 1841562553c0b4c0ceb64070915219d6e03fa96d Mon Sep 17 00:00:00 2001 From: Koncord Date: Tue, 28 Nov 2017 22:05:10 +0800 Subject: [PATCH] [General] Minor cleanup of the World Packets --- .../Controllers/WorldPacketController.cpp | 2 +- .../Controllers/WorldPacketController.hpp | 2 +- .../Packets/World/PacketContainer.cpp | 31 +++++++------------ .../openmw-mp/Packets/World/WorldPacket.cpp | 18 +++++------ 4 files changed, 22 insertions(+), 31 deletions(-) diff --git a/components/openmw-mp/Controllers/WorldPacketController.cpp b/components/openmw-mp/Controllers/WorldPacketController.cpp index eb0c7292f..dad5242a0 100644 --- a/components/openmw-mp/Controllers/WorldPacketController.cpp +++ b/components/openmw-mp/Controllers/WorldPacketController.cpp @@ -58,7 +58,7 @@ mwmp::WorldPacketController::WorldPacketController(RakNet::RakPeerInterface *pee mwmp::WorldPacket *mwmp::WorldPacketController::GetPacket(RakNet::MessageID id) { - return packets[(unsigned char)id].get(); + return packets[(RakNet::MessageID)id].get(); } void mwmp::WorldPacketController::SetStream(RakNet::BitStream *inStream, RakNet::BitStream *outStream) diff --git a/components/openmw-mp/Controllers/WorldPacketController.hpp b/components/openmw-mp/Controllers/WorldPacketController.hpp index a542a397b..f3fb797aa 100644 --- a/components/openmw-mp/Controllers/WorldPacketController.hpp +++ b/components/openmw-mp/Controllers/WorldPacketController.hpp @@ -18,7 +18,7 @@ namespace mwmp bool ContainsPacket(RakNet::MessageID id); - typedef std::unordered_map > packets_t; + typedef std::unordered_map > packets_t; private: packets_t packets; }; diff --git a/components/openmw-mp/Packets/World/PacketContainer.cpp b/components/openmw-mp/Packets/World/PacketContainer.cpp index e35af088a..6aa763cbd 100644 --- a/components/openmw-mp/Packets/World/PacketContainer.cpp +++ b/components/openmw-mp/Packets/World/PacketContainer.cpp @@ -17,43 +17,36 @@ void PacketContainer::Packet(RakNet::BitStream *bs, bool send) RW(event->action, send); - WorldObject worldObject; - for (unsigned int i = 0; i < event->worldObjectCount; i++) + for (auto &&worldObject : event->worldObjects) { + Object(worldObject, send); + if (send) { - worldObject = event->worldObjects.at(i); worldObject.containerItemCount = (unsigned int) (worldObject.containerItems.size()); } - else - worldObject.containerItems.clear(); - - Object(worldObject, send); RW(worldObject.containerItemCount, send); - if (worldObject.containerItemCount > maxObjects || worldObject.refId.empty() || (worldObject.refNumIndex != 0 && worldObject.mpNum != 0)) + if(!send) + { + worldObject.containerItems.clear(); + worldObject.containerItems.resize(worldObject.containerItemCount); + } + + if (worldObject.containerItemCount > maxObjects || worldObject.refId.empty() + || (worldObject.refNumIndex != 0 && worldObject.mpNum != 0)) { event->isValid = false; return; } - ContainerItem containerItem; - - for (unsigned int j = 0; j < worldObject.containerItemCount; j++) + for(auto &&containerItem: worldObject.containerItems) { - if (send) - containerItem = worldObject.containerItems.at(j); - RW(containerItem.refId, send); RW(containerItem.count, send); RW(containerItem.charge, send); RW(containerItem.actionCount, send); - - if (!send) - worldObject.containerItems.push_back(containerItem); } - if (!send) - event->worldObjects.push_back(worldObject); } } diff --git a/components/openmw-mp/Packets/World/WorldPacket.cpp b/components/openmw-mp/Packets/World/WorldPacket.cpp index 7a3c96663..9aae8c31d 100644 --- a/components/openmw-mp/Packets/World/WorldPacket.cpp +++ b/components/openmw-mp/Packets/World/WorldPacket.cpp @@ -31,16 +31,9 @@ void WorldPacket::Packet(RakNet::BitStream *bs, bool send) if (!PacketHeader(bs, send)) return; - WorldObject worldObject; - for (unsigned int i = 0; i < event->worldObjectCount; i++) + for (auto &&worldObject : event->worldObjects) { - if (send) - worldObject = event->worldObjects.at(i); - Object(worldObject, send); - - if (!send) - event->worldObjects.push_back(worldObject); } } @@ -61,10 +54,15 @@ bool WorldPacket::PacketHeader(RakNet::BitStream *bs, bool send) return false; } + if(!send) + { + event->worldObjects.resize(event->worldObjectCount); + } + if (hasCellData) { - RW(event->cell.mData, send, 1); - RW(event->cell.mName, send, 1); + RW(event->cell.mData, send, true); + RW(event->cell.mName, send, true); } return true;