From fd8e833d6a21eaf6ea56f46a2159cf4064eb2516 Mon Sep 17 00:00:00 2001 From: Koncord Date: Sat, 3 Jun 2017 03:10:47 +0800 Subject: [PATCH] [General] Simplify WorldPackets --- .../Packets/World/PacketContainer.cpp | 39 +++----------- .../Packets/World/PacketDoorState.cpp | 44 ++------------- .../Packets/World/PacketDoorState.hpp | 2 +- .../Packets/World/PacketMusicPlay.cpp | 34 +----------- .../Packets/World/PacketMusicPlay.hpp | 2 +- .../Packets/World/PacketObjectAnimPlay.cpp | 46 ++-------------- .../Packets/World/PacketObjectAnimPlay.hpp | 2 +- .../Packets/World/PacketObjectDelete.cpp | 43 +-------------- .../Packets/World/PacketObjectDelete.hpp | 2 - .../Packets/World/PacketObjectLock.cpp | 43 ++------------- .../Packets/World/PacketObjectLock.hpp | 2 +- .../Packets/World/PacketObjectMove.cpp | 46 ++-------------- .../Packets/World/PacketObjectMove.hpp | 2 +- .../Packets/World/PacketObjectPlace.cpp | 50 +++-------------- .../Packets/World/PacketObjectPlace.hpp | 2 +- .../Packets/World/PacketObjectRotate.cpp | 48 +++-------------- .../Packets/World/PacketObjectRotate.hpp | 2 +- .../Packets/World/PacketObjectScale.cpp | 44 ++------------- .../Packets/World/PacketObjectScale.hpp | 2 +- .../Packets/World/PacketObjectSpawn.cpp | 54 ++++--------------- .../Packets/World/PacketObjectSpawn.hpp | 2 +- .../Packets/World/PacketObjectTrap.cpp | 48 +++-------------- .../Packets/World/PacketObjectTrap.hpp | 2 +- .../Packets/World/PacketScriptGlobalShort.cpp | 36 ++----------- .../Packets/World/PacketScriptGlobalShort.hpp | 2 +- .../Packets/World/PacketScriptLocalFloat.cpp | 46 ++-------------- .../Packets/World/PacketScriptLocalFloat.hpp | 2 +- .../Packets/World/PacketScriptLocalShort.cpp | 46 ++-------------- .../Packets/World/PacketScriptLocalShort.hpp | 2 +- .../Packets/World/PacketScriptMemberShort.cpp | 38 ++----------- .../Packets/World/PacketScriptMemberShort.hpp | 2 +- .../Packets/World/PacketVideoPlay.cpp | 36 ++----------- .../Packets/World/PacketVideoPlay.hpp | 2 +- .../openmw-mp/Packets/World/WorldPacket.cpp | 51 ++++++++++++++++++ .../openmw-mp/Packets/World/WorldPacket.hpp | 5 ++ 35 files changed, 148 insertions(+), 681 deletions(-) diff --git a/components/openmw-mp/Packets/World/PacketContainer.cpp b/components/openmw-mp/Packets/World/PacketContainer.cpp index 927c622d0..c3e70bd61 100644 --- a/components/openmw-mp/Packets/World/PacketContainer.cpp +++ b/components/openmw-mp/Packets/World/PacketContainer.cpp @@ -7,49 +7,29 @@ using namespace mwmp; PacketContainer::PacketContainer(RakNet::RakPeerInterface *peer) : WorldPacket(peer) { packetID = ID_CONTAINER; + hasCellData = true; } void PacketContainer::Packet(RakNet::BitStream *bs, bool send) { - WorldPacket::Packet(bs, send); - - RW(event->action, send); - - if (send) - event->worldObjectCount = (unsigned int)(event->worldObjects.size()); - else - event->worldObjects.clear(); - - RW(event->worldObjectCount, send); - - if (event->worldObjectCount > maxObjects) - { - event->isValid = false; + if(!PacketHeader(bs, send)) return; - } - RW(event->cell.mData.mFlags, send); - RW(event->cell.mData.mX, send); - RW(event->cell.mData.mY, send); - RW(event->cell.mName, send); + RW(event->action, send); WorldObject worldObject; - for (unsigned int i = 0; i < event->worldObjectCount; i++) { if (send) { worldObject = event->worldObjects.at(i); - worldObject.containerItemCount = (unsigned int)(worldObject.containerItems.size()); + worldObject.containerItemCount = (unsigned int) (worldObject.containerItems.size()); } else - { worldObject.containerItems.clear(); - } - RW(worldObject.refId, send); - RW(worldObject.refNumIndex, send); - RW(worldObject.mpNum, send); + Object(worldObject, send); + RW(worldObject.containerItemCount, send); if (worldObject.containerItemCount > maxObjects || worldObject.refId.empty() || (worldObject.refNumIndex != 0 && worldObject.mpNum != 0)) @@ -63,9 +43,7 @@ void PacketContainer::Packet(RakNet::BitStream *bs, bool send) for (unsigned int j = 0; j < worldObject.containerItemCount; j++) { if (send) - { containerItem = worldObject.containerItems.at(j); - } RW(containerItem.refId, send); RW(containerItem.count, send); @@ -73,14 +51,9 @@ void PacketContainer::Packet(RakNet::BitStream *bs, bool 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/PacketDoorState.cpp b/components/openmw-mp/Packets/World/PacketDoorState.cpp index ee40e6320..448bc2025 100644 --- a/components/openmw-mp/Packets/World/PacketDoorState.cpp +++ b/components/openmw-mp/Packets/World/PacketDoorState.cpp @@ -6,47 +6,11 @@ using namespace mwmp; PacketDoorState::PacketDoorState(RakNet::RakPeerInterface *peer) : WorldPacket(peer) { packetID = ID_DOOR_STATE; + hasCellData = true; } -void PacketDoorState::Packet(RakNet::BitStream *bs, bool send) +void PacketDoorState::Object(WorldObject &worldObject, bool send) { - WorldPacket::Packet(bs, send); - - if (send) - event->worldObjectCount = (unsigned int)(event->worldObjects.size()); - else - event->worldObjects.clear(); - - RW(event->worldObjectCount, send); - - if (event->worldObjectCount > maxObjects) - { - event->isValid = false; - return; - } - - RW(event->cell.mData.mFlags, send); - RW(event->cell.mData.mX, send); - RW(event->cell.mData.mY, send); - RW(event->cell.mName, send); - - WorldObject worldObject; - - for (unsigned int i = 0; i < event->worldObjectCount; i++) - { - if (send) - { - worldObject = event->worldObjects.at(i); - } - - RW(worldObject.refId, send); - RW(worldObject.refNumIndex, send); - RW(worldObject.mpNum, send); - RW(worldObject.doorState, send); - - if (!send) - { - event->worldObjects.push_back(worldObject); - } - } + WorldPacket::Object(worldObject, send); + RW(worldObject.doorState, send); } diff --git a/components/openmw-mp/Packets/World/PacketDoorState.hpp b/components/openmw-mp/Packets/World/PacketDoorState.hpp index 7def1cbb2..91f38f033 100644 --- a/components/openmw-mp/Packets/World/PacketDoorState.hpp +++ b/components/openmw-mp/Packets/World/PacketDoorState.hpp @@ -10,7 +10,7 @@ namespace mwmp public: PacketDoorState(RakNet::RakPeerInterface *peer); - virtual void Packet(RakNet::BitStream *bs, bool send); + virtual void Object(WorldObject &worldObject, bool send); }; } diff --git a/components/openmw-mp/Packets/World/PacketMusicPlay.cpp b/components/openmw-mp/Packets/World/PacketMusicPlay.cpp index b378ff678..45b6b2bee 100644 --- a/components/openmw-mp/Packets/World/PacketMusicPlay.cpp +++ b/components/openmw-mp/Packets/World/PacketMusicPlay.cpp @@ -8,37 +8,7 @@ PacketMusicPlay::PacketMusicPlay(RakNet::RakPeerInterface *peer) : WorldPacket(p packetID = ID_MUSIC_PLAY; } -void PacketMusicPlay::Packet(RakNet::BitStream *bs, bool send) +void PacketMusicPlay::Object(WorldObject &worldObject, bool send) { - WorldPacket::Packet(bs, send); - - if (send) - event->worldObjectCount = (unsigned int)(event->worldObjects.size()); - else - event->worldObjects.clear(); - - RW(event->worldObjectCount, send); - - if (event->worldObjectCount > maxObjects) - { - event->isValid = false; - return; - } - - WorldObject worldObject; - - for (unsigned int i = 0; i < event->worldObjectCount; i++) - { - if (send) - { - worldObject = event->worldObjects.at(i); - } - - RW(worldObject.filename, send); - - if (!send) - { - event->worldObjects.push_back(worldObject); - } - } + RW(worldObject.filename, send); } diff --git a/components/openmw-mp/Packets/World/PacketMusicPlay.hpp b/components/openmw-mp/Packets/World/PacketMusicPlay.hpp index 8da124858..748b0d1d2 100644 --- a/components/openmw-mp/Packets/World/PacketMusicPlay.hpp +++ b/components/openmw-mp/Packets/World/PacketMusicPlay.hpp @@ -10,7 +10,7 @@ namespace mwmp public: PacketMusicPlay(RakNet::RakPeerInterface *peer); - virtual void Packet(RakNet::BitStream *bs, bool send); + virtual void Object(WorldObject &worldObject, bool send); }; } diff --git a/components/openmw-mp/Packets/World/PacketObjectAnimPlay.cpp b/components/openmw-mp/Packets/World/PacketObjectAnimPlay.cpp index 23d4d96dd..af0c355ee 100644 --- a/components/openmw-mp/Packets/World/PacketObjectAnimPlay.cpp +++ b/components/openmw-mp/Packets/World/PacketObjectAnimPlay.cpp @@ -6,48 +6,12 @@ using namespace mwmp; PacketObjectAnimPlay::PacketObjectAnimPlay(RakNet::RakPeerInterface *peer) : WorldPacket(peer) { packetID = ID_OBJECT_ANIM_PLAY; + hasCellData = true; } -void PacketObjectAnimPlay::Packet(RakNet::BitStream *bs, bool send) +void PacketObjectAnimPlay::Object(WorldObject &worldObject, bool send) { - WorldPacket::Packet(bs, send); - - if (send) - event->worldObjectCount = (unsigned int)(event->worldObjects.size()); - else - event->worldObjects.clear(); - - RW(event->worldObjectCount, send); - - if (event->worldObjectCount > maxObjects) - { - event->isValid = false; - return; - } - - RW(event->cell.mData.mFlags, send); - RW(event->cell.mData.mX, send); - RW(event->cell.mData.mY, send); - RW(event->cell.mName, send); - - WorldObject worldObject; - - for (unsigned int i = 0; i < event->worldObjectCount; i++) - { - if (send) - { - worldObject = event->worldObjects.at(i); - } - - RW(worldObject.refId, send); - RW(worldObject.refNumIndex, send); - RW(worldObject.mpNum, send); - RW(worldObject.animGroup, send); - RW(worldObject.animMode, send); - - if (!send) - { - event->worldObjects.push_back(worldObject); - } - } + WorldPacket::Object(worldObject, send); + RW(worldObject.animGroup, send); + RW(worldObject.animMode, send); } diff --git a/components/openmw-mp/Packets/World/PacketObjectAnimPlay.hpp b/components/openmw-mp/Packets/World/PacketObjectAnimPlay.hpp index ee886ab2d..c6443bad4 100644 --- a/components/openmw-mp/Packets/World/PacketObjectAnimPlay.hpp +++ b/components/openmw-mp/Packets/World/PacketObjectAnimPlay.hpp @@ -10,7 +10,7 @@ namespace mwmp public: PacketObjectAnimPlay(RakNet::RakPeerInterface *peer); - virtual void Packet(RakNet::BitStream *bs, bool send); + virtual void Object(WorldObject &worldObject, bool send); }; } diff --git a/components/openmw-mp/Packets/World/PacketObjectDelete.cpp b/components/openmw-mp/Packets/World/PacketObjectDelete.cpp index 04f4d7748..c999d7072 100644 --- a/components/openmw-mp/Packets/World/PacketObjectDelete.cpp +++ b/components/openmw-mp/Packets/World/PacketObjectDelete.cpp @@ -6,46 +6,5 @@ using namespace mwmp; PacketObjectDelete::PacketObjectDelete(RakNet::RakPeerInterface *peer) : WorldPacket(peer) { packetID = ID_OBJECT_DELETE; -} - -void PacketObjectDelete::Packet(RakNet::BitStream *bs, bool send) -{ - WorldPacket::Packet(bs, send); - - if (send) - event->worldObjectCount = (unsigned int)(event->worldObjects.size()); - else - event->worldObjects.clear(); - - RW(event->worldObjectCount, send); - - if (event->worldObjectCount > maxObjects) - { - event->isValid = false; - return; - } - - RW(event->cell.mData.mFlags, send); - RW(event->cell.mData.mX, send); - RW(event->cell.mData.mY, send); - RW(event->cell.mName, send); - - WorldObject worldObject; - - for (unsigned int i = 0; i < event->worldObjectCount; i++) - { - if (send) - { - worldObject = event->worldObjects.at(i); - } - - RW(worldObject.refId, send); - RW(worldObject.refNumIndex, send); - RW(worldObject.mpNum, send); - - if (!send) - { - event->worldObjects.push_back(worldObject); - } - } + hasCellData = true; } diff --git a/components/openmw-mp/Packets/World/PacketObjectDelete.hpp b/components/openmw-mp/Packets/World/PacketObjectDelete.hpp index cb77ef2e4..4b91d348e 100644 --- a/components/openmw-mp/Packets/World/PacketObjectDelete.hpp +++ b/components/openmw-mp/Packets/World/PacketObjectDelete.hpp @@ -9,8 +9,6 @@ namespace mwmp { public: PacketObjectDelete(RakNet::RakPeerInterface *peer); - - virtual void Packet(RakNet::BitStream *bs, bool send); }; } diff --git a/components/openmw-mp/Packets/World/PacketObjectLock.cpp b/components/openmw-mp/Packets/World/PacketObjectLock.cpp index 147072439..d2e49f046 100644 --- a/components/openmw-mp/Packets/World/PacketObjectLock.cpp +++ b/components/openmw-mp/Packets/World/PacketObjectLock.cpp @@ -8,45 +8,8 @@ PacketObjectLock::PacketObjectLock(RakNet::RakPeerInterface *peer) : WorldPacket packetID = ID_OBJECT_LOCK; } -void PacketObjectLock::Packet(RakNet::BitStream *bs, bool send) +void PacketObjectLock::Object(WorldObject &worldObject, bool send) { - WorldPacket::Packet(bs, send); - - if (send) - event->worldObjectCount = (unsigned int)(event->worldObjects.size()); - else - event->worldObjects.clear(); - - RW(event->worldObjectCount, send); - - if (event->worldObjectCount > maxObjects) - { - event->isValid = false; - return; - } - - RW(event->cell.mData.mFlags, send); - RW(event->cell.mData.mX, send); - RW(event->cell.mData.mY, send); - RW(event->cell.mName, send); - - WorldObject worldObject; - - for (unsigned int i = 0; i < event->worldObjectCount; i++) - { - if (send) - { - worldObject = event->worldObjects.at(i); - } - - RW(worldObject.refId, send); - RW(worldObject.refNumIndex, send); - RW(worldObject.mpNum, send); - RW(worldObject.lockLevel, send); - - if (!send) - { - event->worldObjects.push_back(worldObject); - } - } + WorldPacket::Object(worldObject, send); + RW(worldObject.lockLevel, send); } diff --git a/components/openmw-mp/Packets/World/PacketObjectLock.hpp b/components/openmw-mp/Packets/World/PacketObjectLock.hpp index 19242d762..691b3bf84 100644 --- a/components/openmw-mp/Packets/World/PacketObjectLock.hpp +++ b/components/openmw-mp/Packets/World/PacketObjectLock.hpp @@ -10,7 +10,7 @@ namespace mwmp public: PacketObjectLock(RakNet::RakPeerInterface *peer); - virtual void Packet(RakNet::BitStream *bs, bool send); + virtual void Object(WorldObject &worldObject, bool send); }; } diff --git a/components/openmw-mp/Packets/World/PacketObjectMove.cpp b/components/openmw-mp/Packets/World/PacketObjectMove.cpp index 172cf4ff6..35fb22bfc 100644 --- a/components/openmw-mp/Packets/World/PacketObjectMove.cpp +++ b/components/openmw-mp/Packets/World/PacketObjectMove.cpp @@ -6,49 +6,11 @@ using namespace mwmp; PacketObjectMove::PacketObjectMove(RakNet::RakPeerInterface *peer) : WorldPacket(peer) { packetID = ID_OBJECT_MOVE; + hasCellData = true; } -void PacketObjectMove::Packet(RakNet::BitStream *bs, bool send) +void PacketObjectMove::Object(WorldObject &worldObject, bool send) { - WorldPacket::Packet(bs, send); - - if (send) - event->worldObjectCount = (unsigned int)(event->worldObjects.size()); - else - event->worldObjects.clear(); - - RW(event->worldObjectCount, send); - - if (event->worldObjectCount > maxObjects) - { - event->isValid = false; - return; - } - - RW(event->cell.mData.mFlags, send); - RW(event->cell.mData.mX, send); - RW(event->cell.mData.mY, send); - RW(event->cell.mName, send); - - WorldObject worldObject; - - for (unsigned int i = 0; i < event->worldObjectCount; i++) - { - if (send) - { - worldObject = event->worldObjects.at(i); - } - - RW(worldObject.refId, send); - RW(worldObject.refNumIndex, send); - RW(worldObject.mpNum, send); - RW(worldObject.position.pos[0], send); - RW(worldObject.position.pos[1], send); - RW(worldObject.position.pos[2], send); - - if (!send) - { - event->worldObjects.push_back(worldObject); - } - } + WorldPacket::Object(worldObject, send); + RW(worldObject.position.pos, send); } diff --git a/components/openmw-mp/Packets/World/PacketObjectMove.hpp b/components/openmw-mp/Packets/World/PacketObjectMove.hpp index 1d6fc814e..f92487212 100644 --- a/components/openmw-mp/Packets/World/PacketObjectMove.hpp +++ b/components/openmw-mp/Packets/World/PacketObjectMove.hpp @@ -10,7 +10,7 @@ namespace mwmp public: PacketObjectMove(RakNet::RakPeerInterface *peer); - virtual void Packet(RakNet::BitStream *bs, bool send); + virtual void Object(WorldObject &worldObject, bool send); }; } diff --git a/components/openmw-mp/Packets/World/PacketObjectPlace.cpp b/components/openmw-mp/Packets/World/PacketObjectPlace.cpp index 2b1f34c45..7a13964cb 100644 --- a/components/openmw-mp/Packets/World/PacketObjectPlace.cpp +++ b/components/openmw-mp/Packets/World/PacketObjectPlace.cpp @@ -6,50 +6,14 @@ using namespace mwmp; PacketObjectPlace::PacketObjectPlace(RakNet::RakPeerInterface *peer) : WorldPacket(peer) { packetID = ID_OBJECT_PLACE; + hasCellData = true; } -void PacketObjectPlace::Packet(RakNet::BitStream *bs, bool send) +void PacketObjectPlace::Object(WorldObject &worldObject, bool send) { - WorldPacket::Packet(bs, send); - - if (send) - event->worldObjectCount = (unsigned int)(event->worldObjects.size()); - else - event->worldObjects.clear(); - - RW(event->worldObjectCount, send); - - if (event->worldObjectCount > maxObjects) - { - event->isValid = false; - return; - } - - RW(event->cell.mData.mFlags, send); - RW(event->cell.mData.mX, send); - RW(event->cell.mData.mY, send); - RW(event->cell.mName, send); - - WorldObject worldObject; - - for (unsigned int i = 0; i < event->worldObjectCount; i++) - { - if (send) - { - worldObject = event->worldObjects.at(i); - } - - RW(worldObject.refId, send); - RW(worldObject.refNumIndex, send); - RW(worldObject.mpNum, send); - RW(worldObject.count, send); - RW(worldObject.charge, send); - RW(worldObject.goldValue, send); - RW(worldObject.position, send); - - if (!send) - { - event->worldObjects.push_back(worldObject); - } - } + WorldPacket::Object(worldObject, send); + RW(worldObject.count, send); + RW(worldObject.charge, send); + RW(worldObject.goldValue, send); + RW(worldObject.position, send); } diff --git a/components/openmw-mp/Packets/World/PacketObjectPlace.hpp b/components/openmw-mp/Packets/World/PacketObjectPlace.hpp index f1b51e3dd..d50c881df 100644 --- a/components/openmw-mp/Packets/World/PacketObjectPlace.hpp +++ b/components/openmw-mp/Packets/World/PacketObjectPlace.hpp @@ -10,7 +10,7 @@ namespace mwmp public: PacketObjectPlace(RakNet::RakPeerInterface *peer); - virtual void Packet(RakNet::BitStream *bs, bool send); + virtual void Object(WorldObject &worldObject, bool send); }; } diff --git a/components/openmw-mp/Packets/World/PacketObjectRotate.cpp b/components/openmw-mp/Packets/World/PacketObjectRotate.cpp index 5ff5bc89c..07c614654 100644 --- a/components/openmw-mp/Packets/World/PacketObjectRotate.cpp +++ b/components/openmw-mp/Packets/World/PacketObjectRotate.cpp @@ -6,49 +6,13 @@ using namespace mwmp; PacketObjectRotate::PacketObjectRotate(RakNet::RakPeerInterface *peer) : WorldPacket(peer) { packetID = ID_OBJECT_ROTATE; + hasCellData = true; } -void PacketObjectRotate::Packet(RakNet::BitStream *bs, bool send) +void PacketObjectRotate::Object(WorldObject &worldObject, bool send) { - WorldPacket::Packet(bs, send); - - if (send) - event->worldObjectCount = (unsigned int)(event->worldObjects.size()); - else - event->worldObjects.clear(); - - RW(event->worldObjectCount, send); - - if (event->worldObjectCount > maxObjects) - { - event->isValid = false; - return; - } - - RW(event->cell.mData.mFlags, send); - RW(event->cell.mData.mX, send); - RW(event->cell.mData.mY, send); - RW(event->cell.mName, send); - - WorldObject worldObject; - - for (unsigned int i = 0; i < event->worldObjectCount; i++) - { - if (send) - { - worldObject = event->worldObjects.at(i); - } - - RW(worldObject.refId, send); - RW(worldObject.refNumIndex, send); - RW(worldObject.mpNum, send); - RW(worldObject.position.rot[0], send); - RW(worldObject.position.rot[1], send); - RW(worldObject.position.rot[2], send); - - if (!send) - { - event->worldObjects.push_back(worldObject); - } - } + WorldPacket::Object(worldObject, send); + RW(worldObject.position.rot[0], send); + RW(worldObject.position.rot[1], send); + RW(worldObject.position.rot[2], send); } diff --git a/components/openmw-mp/Packets/World/PacketObjectRotate.hpp b/components/openmw-mp/Packets/World/PacketObjectRotate.hpp index a42a396dd..b438a8372 100644 --- a/components/openmw-mp/Packets/World/PacketObjectRotate.hpp +++ b/components/openmw-mp/Packets/World/PacketObjectRotate.hpp @@ -10,7 +10,7 @@ namespace mwmp public: PacketObjectRotate(RakNet::RakPeerInterface *peer); - virtual void Packet(RakNet::BitStream *bs, bool send); + virtual void Object(WorldObject &worldObject, bool send); }; } diff --git a/components/openmw-mp/Packets/World/PacketObjectScale.cpp b/components/openmw-mp/Packets/World/PacketObjectScale.cpp index 8273b4a05..8e468059d 100644 --- a/components/openmw-mp/Packets/World/PacketObjectScale.cpp +++ b/components/openmw-mp/Packets/World/PacketObjectScale.cpp @@ -6,47 +6,11 @@ using namespace mwmp; PacketObjectScale::PacketObjectScale(RakNet::RakPeerInterface *peer) : WorldPacket(peer) { packetID = ID_OBJECT_SCALE; + hasCellData = true; } -void PacketObjectScale::Packet(RakNet::BitStream *bs, bool send) +void PacketObjectScale::Object(WorldObject &worldObject, bool send) { - WorldPacket::Packet(bs, send); - - if (send) - event->worldObjectCount = (unsigned int)(event->worldObjects.size()); - else - event->worldObjects.clear(); - - RW(event->worldObjectCount, send); - - if (event->worldObjectCount > maxObjects) - { - event->isValid = false; - return; - } - - RW(event->cell.mData.mFlags, send); - RW(event->cell.mData.mX, send); - RW(event->cell.mData.mY, send); - RW(event->cell.mName, send); - - WorldObject worldObject; - - for (unsigned int i = 0; i < event->worldObjectCount; i++) - { - if (send) - { - worldObject = event->worldObjects.at(i); - } - - RW(worldObject.refId, send); - RW(worldObject.refNumIndex, send); - RW(worldObject.mpNum, send); - RW(worldObject.scale, send); - - if (!send) - { - event->worldObjects.push_back(worldObject); - } - } + WorldPacket::Object(worldObject, send); + RW(worldObject.scale, send); } diff --git a/components/openmw-mp/Packets/World/PacketObjectScale.hpp b/components/openmw-mp/Packets/World/PacketObjectScale.hpp index 46a4ef68a..8e5d2b431 100644 --- a/components/openmw-mp/Packets/World/PacketObjectScale.hpp +++ b/components/openmw-mp/Packets/World/PacketObjectScale.hpp @@ -10,7 +10,7 @@ namespace mwmp public: PacketObjectScale(RakNet::RakPeerInterface *peer); - virtual void Packet(RakNet::BitStream *bs, bool send); + virtual void Object(WorldObject &worldObject, bool send); }; } diff --git a/components/openmw-mp/Packets/World/PacketObjectSpawn.cpp b/components/openmw-mp/Packets/World/PacketObjectSpawn.cpp index 22a6ec8f5..3716679d7 100644 --- a/components/openmw-mp/Packets/World/PacketObjectSpawn.cpp +++ b/components/openmw-mp/Packets/World/PacketObjectSpawn.cpp @@ -6,56 +6,20 @@ using namespace mwmp; PacketObjectSpawn::PacketObjectSpawn(RakNet::RakPeerInterface *peer) : WorldPacket(peer) { packetID = ID_OBJECT_SPAWN; + hasCellData = true; } -void PacketObjectSpawn::Packet(RakNet::BitStream *bs, bool send) +void PacketObjectSpawn::Object(WorldObject &worldObject, bool send) { - WorldPacket::Packet(bs, send); + WorldPacket::Object(worldObject, send); + RW(worldObject.position, send); - if (send) - event->worldObjectCount = (unsigned int)(event->worldObjects.size()); - else - event->worldObjects.clear(); + RW(worldObject.hasMaster, send); - RW(event->worldObjectCount, send); - - if (event->worldObjectCount > maxObjects) + if (worldObject.hasMaster) { - event->isValid = false; - return; - } - - RW(event->cell.mData.mFlags, send); - RW(event->cell.mData.mX, send); - RW(event->cell.mData.mY, send); - RW(event->cell.mName, send); - - WorldObject worldObject; - - for (unsigned int i = 0; i < event->worldObjectCount; i++) - { - if (send) - { - worldObject = event->worldObjects.at(i); - } - - RW(worldObject.refId, send); - RW(worldObject.refNumIndex, send); - RW(worldObject.mpNum, send); - RW(worldObject.position, send); - - RW(worldObject.hasMaster, send); - - if (worldObject.hasMaster) - { - RW(worldObject.master.refNumIndex, send); - RW(worldObject.master.mpNum, send); - RW(worldObject.master.guid, send); - } - - if (!send) - { - event->worldObjects.push_back(worldObject); - } + RW(worldObject.master.refNumIndex, send); + RW(worldObject.master.mpNum, send); + RW(worldObject.master.guid, send); } } diff --git a/components/openmw-mp/Packets/World/PacketObjectSpawn.hpp b/components/openmw-mp/Packets/World/PacketObjectSpawn.hpp index c0d81a23d..1f6973268 100644 --- a/components/openmw-mp/Packets/World/PacketObjectSpawn.hpp +++ b/components/openmw-mp/Packets/World/PacketObjectSpawn.hpp @@ -10,7 +10,7 @@ namespace mwmp public: PacketObjectSpawn(RakNet::RakPeerInterface *peer); - virtual void Packet(RakNet::BitStream *bs, bool send); + virtual void Object(WorldObject &worldObject, bool send); }; } diff --git a/components/openmw-mp/Packets/World/PacketObjectTrap.cpp b/components/openmw-mp/Packets/World/PacketObjectTrap.cpp index bdf167a49..4442f3cd2 100644 --- a/components/openmw-mp/Packets/World/PacketObjectTrap.cpp +++ b/components/openmw-mp/Packets/World/PacketObjectTrap.cpp @@ -6,50 +6,14 @@ using namespace mwmp; PacketObjectTrap::PacketObjectTrap(RakNet::RakPeerInterface *peer) : WorldPacket(peer) { packetID = ID_OBJECT_TRAP; + hasCellData = true; } -void PacketObjectTrap::Packet(RakNet::BitStream *bs, bool send) +void PacketObjectTrap::Object(WorldObject &worldObject, bool send) { - WorldPacket::Packet(bs, send); + WorldPacket::Object(worldObject, send); + RW(worldObject.isDisarmed, send); - if (send) - event->worldObjectCount = (unsigned int)(event->worldObjects.size()); - else - event->worldObjects.clear(); - - RW(event->worldObjectCount, send); - - if (event->worldObjectCount > maxObjects) - { - event->isValid = false; - return; - } - - RW(event->cell.mData.mFlags, send); - RW(event->cell.mData.mX, send); - RW(event->cell.mData.mY, send); - RW(event->cell.mName, send); - - WorldObject worldObject; - - for (unsigned int i = 0; i < event->worldObjectCount; i++) - { - if (send) - { - worldObject = event->worldObjects.at(i); - } - - RW(worldObject.refId, send); - RW(worldObject.refNumIndex, send); - RW(worldObject.mpNum, send); - RW(worldObject.isDisarmed, send); - - if (!worldObject.isDisarmed) - RW(worldObject.position, send); - - if (!send) - { - event->worldObjects.push_back(worldObject); - } - } + if (!worldObject.isDisarmed) + RW(worldObject.position, send); } diff --git a/components/openmw-mp/Packets/World/PacketObjectTrap.hpp b/components/openmw-mp/Packets/World/PacketObjectTrap.hpp index 0031204cf..aadbd037d 100644 --- a/components/openmw-mp/Packets/World/PacketObjectTrap.hpp +++ b/components/openmw-mp/Packets/World/PacketObjectTrap.hpp @@ -10,7 +10,7 @@ namespace mwmp public: PacketObjectTrap(RakNet::RakPeerInterface *peer); - virtual void Packet(RakNet::BitStream *bs, bool send); + virtual void Object(WorldObject &worldObject, bool send); }; } diff --git a/components/openmw-mp/Packets/World/PacketScriptGlobalShort.cpp b/components/openmw-mp/Packets/World/PacketScriptGlobalShort.cpp index f6e1147ea..0ebd3ff7f 100644 --- a/components/openmw-mp/Packets/World/PacketScriptGlobalShort.cpp +++ b/components/openmw-mp/Packets/World/PacketScriptGlobalShort.cpp @@ -8,38 +8,8 @@ PacketScriptGlobalShort::PacketScriptGlobalShort(RakNet::RakPeerInterface *peer) packetID = ID_SCRIPT_GLOBAL_SHORT; } -void PacketScriptGlobalShort::Packet(RakNet::BitStream *bs, bool send) +void PacketScriptGlobalShort::Object(WorldObject &worldObject, bool send) { - WorldPacket::Packet(bs, send); - - if (send) - event->worldObjectCount = (unsigned int)(event->worldObjects.size()); - else - event->worldObjects.clear(); - - RW(event->worldObjectCount, send); - - if (event->worldObjectCount > maxObjects) - { - event->isValid = false; - return; - } - - WorldObject worldObject; - - for (unsigned int i = 0; i < event->worldObjectCount; i++) - { - if (send) - { - worldObject = event->worldObjects.at(i); - } - - RW(worldObject.varName, send); - RW(worldObject.shortVal, send); - - if (!send) - { - event->worldObjects.push_back(worldObject); - } - } + RW(worldObject.varName, send); + RW(worldObject.shortVal, send); } diff --git a/components/openmw-mp/Packets/World/PacketScriptGlobalShort.hpp b/components/openmw-mp/Packets/World/PacketScriptGlobalShort.hpp index f4aa1d8bc..ea2a3034f 100644 --- a/components/openmw-mp/Packets/World/PacketScriptGlobalShort.hpp +++ b/components/openmw-mp/Packets/World/PacketScriptGlobalShort.hpp @@ -10,7 +10,7 @@ namespace mwmp public: PacketScriptGlobalShort(RakNet::RakPeerInterface *peer); - virtual void Packet(RakNet::BitStream *bs, bool send); + virtual void Object(WorldObject &worldObject, bool send); }; } diff --git a/components/openmw-mp/Packets/World/PacketScriptLocalFloat.cpp b/components/openmw-mp/Packets/World/PacketScriptLocalFloat.cpp index 79f0ad565..c7109b185 100644 --- a/components/openmw-mp/Packets/World/PacketScriptLocalFloat.cpp +++ b/components/openmw-mp/Packets/World/PacketScriptLocalFloat.cpp @@ -6,48 +6,12 @@ using namespace mwmp; PacketScriptLocalFloat::PacketScriptLocalFloat(RakNet::RakPeerInterface *peer) : WorldPacket(peer) { packetID = ID_SCRIPT_LOCAL_FLOAT; + hasCellData = true; } -void PacketScriptLocalFloat::Packet(RakNet::BitStream *bs, bool send) +void PacketScriptLocalFloat::Object(WorldObject &worldObject, bool send) { - WorldPacket::Packet(bs, send); - - if (send) - event->worldObjectCount = (unsigned int)(event->worldObjects.size()); - else - event->worldObjects.clear(); - - RW(event->worldObjectCount, send); - - if (event->worldObjectCount > maxObjects) - { - event->isValid = false; - return; - } - - RW(event->cell.mData.mFlags, send); - RW(event->cell.mData.mX, send); - RW(event->cell.mData.mY, send); - RW(event->cell.mName, send); - - WorldObject worldObject; - - for (unsigned int i = 0; i < event->worldObjectCount; i++) - { - if (send) - { - worldObject = event->worldObjects.at(i); - } - - RW(worldObject.refId, send); - RW(worldObject.refNumIndex, send); - RW(worldObject.mpNum, send); - RW(worldObject.index, send); - RW(worldObject.floatVal, send); - - if (!send) - { - event->worldObjects.push_back(worldObject); - } - } + WorldPacket::Object(worldObject, send); + RW(worldObject.index, send); + RW(worldObject.floatVal, send); } diff --git a/components/openmw-mp/Packets/World/PacketScriptLocalFloat.hpp b/components/openmw-mp/Packets/World/PacketScriptLocalFloat.hpp index 3404e7159..adf57eda3 100644 --- a/components/openmw-mp/Packets/World/PacketScriptLocalFloat.hpp +++ b/components/openmw-mp/Packets/World/PacketScriptLocalFloat.hpp @@ -10,7 +10,7 @@ namespace mwmp public: PacketScriptLocalFloat(RakNet::RakPeerInterface *peer); - virtual void Packet(RakNet::BitStream *bs, bool send); + virtual void Object(WorldObject &worldObject, bool send); }; } diff --git a/components/openmw-mp/Packets/World/PacketScriptLocalShort.cpp b/components/openmw-mp/Packets/World/PacketScriptLocalShort.cpp index 41f9d1afb..fb739dc45 100644 --- a/components/openmw-mp/Packets/World/PacketScriptLocalShort.cpp +++ b/components/openmw-mp/Packets/World/PacketScriptLocalShort.cpp @@ -6,48 +6,12 @@ using namespace mwmp; PacketScriptLocalShort::PacketScriptLocalShort(RakNet::RakPeerInterface *peer) : WorldPacket(peer) { packetID = ID_SCRIPT_LOCAL_SHORT; + hasCellData = true; } -void PacketScriptLocalShort::Packet(RakNet::BitStream *bs, bool send) +void PacketScriptLocalShort::Object(WorldObject &worldObject, bool send) { - WorldPacket::Packet(bs, send); - - if (send) - event->worldObjectCount = (unsigned int)(event->worldObjects.size()); - else - event->worldObjects.clear(); - - RW(event->worldObjectCount, send); - - if (event->worldObjectCount > maxObjects) - { - event->isValid = false; - return; - } - - RW(event->cell.mData.mFlags, send); - RW(event->cell.mData.mX, send); - RW(event->cell.mData.mY, send); - RW(event->cell.mName, send); - - WorldObject worldObject; - - for (unsigned int i = 0; i < event->worldObjectCount; i++) - { - if (send) - { - worldObject = event->worldObjects.at(i); - } - - RW(worldObject.refId, send); - RW(worldObject.refNumIndex, send); - RW(worldObject.mpNum, send); - RW(worldObject.index, send); - RW(worldObject.shortVal, send); - - if (!send) - { - event->worldObjects.push_back(worldObject); - } - } + WorldPacket::Object(worldObject, send); + RW(worldObject.index, send); + RW(worldObject.shortVal, send); } diff --git a/components/openmw-mp/Packets/World/PacketScriptLocalShort.hpp b/components/openmw-mp/Packets/World/PacketScriptLocalShort.hpp index 58c01ad3c..3c767b850 100644 --- a/components/openmw-mp/Packets/World/PacketScriptLocalShort.hpp +++ b/components/openmw-mp/Packets/World/PacketScriptLocalShort.hpp @@ -10,7 +10,7 @@ namespace mwmp public: PacketScriptLocalShort(RakNet::RakPeerInterface *peer); - virtual void Packet(RakNet::BitStream *bs, bool send); + virtual void Object(WorldObject &obj, bool send); }; } diff --git a/components/openmw-mp/Packets/World/PacketScriptMemberShort.cpp b/components/openmw-mp/Packets/World/PacketScriptMemberShort.cpp index 5151059c2..c2b1c34d6 100644 --- a/components/openmw-mp/Packets/World/PacketScriptMemberShort.cpp +++ b/components/openmw-mp/Packets/World/PacketScriptMemberShort.cpp @@ -8,39 +8,9 @@ PacketScriptMemberShort::PacketScriptMemberShort(RakNet::RakPeerInterface *peer) packetID = ID_SCRIPT_MEMBER_SHORT; } -void PacketScriptMemberShort::Packet(RakNet::BitStream *bs, bool send) +void PacketScriptMemberShort::Object(WorldObject &worldObject, bool send) { - WorldPacket::Packet(bs, send); - - if (send) - event->worldObjectCount = (unsigned int)(event->worldObjects.size()); - else - event->worldObjects.clear(); - - RW(event->worldObjectCount, send); - - if (event->worldObjectCount > maxObjects) - { - event->isValid = false; - return; - } - - WorldObject worldObject; - - for (unsigned int i = 0; i < event->worldObjectCount; i++) - { - if (send) - { - worldObject = event->worldObjects.at(i); - } - - RW(worldObject.refId, send); - RW(worldObject.index, send); - RW(worldObject.shortVal, send); - - if (!send) - { - event->worldObjects.push_back(worldObject); - } - } + RW(worldObject.refId, send); + RW(worldObject.index, send); + RW(worldObject.shortVal, send); } diff --git a/components/openmw-mp/Packets/World/PacketScriptMemberShort.hpp b/components/openmw-mp/Packets/World/PacketScriptMemberShort.hpp index f554103ed..61e99b9c0 100644 --- a/components/openmw-mp/Packets/World/PacketScriptMemberShort.hpp +++ b/components/openmw-mp/Packets/World/PacketScriptMemberShort.hpp @@ -10,7 +10,7 @@ namespace mwmp public: PacketScriptMemberShort(RakNet::RakPeerInterface *peer); - virtual void Packet(RakNet::BitStream *bs, bool send); + virtual void Object(WorldObject &obj, bool send); }; } diff --git a/components/openmw-mp/Packets/World/PacketVideoPlay.cpp b/components/openmw-mp/Packets/World/PacketVideoPlay.cpp index 49c6ba506..bc5146ce8 100644 --- a/components/openmw-mp/Packets/World/PacketVideoPlay.cpp +++ b/components/openmw-mp/Packets/World/PacketVideoPlay.cpp @@ -8,38 +8,8 @@ PacketVideoPlay::PacketVideoPlay(RakNet::RakPeerInterface *peer) : WorldPacket(p packetID = ID_VIDEO_PLAY; } -void PacketVideoPlay::Packet(RakNet::BitStream *bs, bool send) +void PacketVideoPlay::Object(WorldObject &worldObject, bool send) { - WorldPacket::Packet(bs, send); - - if (send) - event->worldObjectCount = (unsigned int)(event->worldObjects.size()); - else - event->worldObjects.clear(); - - RW(event->worldObjectCount, send); - - if (event->worldObjectCount > maxObjects) - { - event->isValid = false; - return; - } - - WorldObject worldObject; - - for (unsigned int i = 0; i < event->worldObjectCount; i++) - { - if (send) - { - worldObject = event->worldObjects.at(i); - } - - RW(worldObject.filename, send); - RW(worldObject.allowSkipping, send); - - if (!send) - { - event->worldObjects.push_back(worldObject); - } - } + RW(worldObject.filename, send); + RW(worldObject.allowSkipping, send); } diff --git a/components/openmw-mp/Packets/World/PacketVideoPlay.hpp b/components/openmw-mp/Packets/World/PacketVideoPlay.hpp index bed395e03..9af2def65 100644 --- a/components/openmw-mp/Packets/World/PacketVideoPlay.hpp +++ b/components/openmw-mp/Packets/World/PacketVideoPlay.hpp @@ -10,7 +10,7 @@ namespace mwmp public: PacketVideoPlay(RakNet::RakPeerInterface *peer); - virtual void Packet(RakNet::BitStream *bs, bool send); + virtual void Object(WorldObject &obj, bool send); }; } diff --git a/components/openmw-mp/Packets/World/WorldPacket.cpp b/components/openmw-mp/Packets/World/WorldPacket.cpp index 9cf4c52e0..6317b6847 100644 --- a/components/openmw-mp/Packets/World/WorldPacket.cpp +++ b/components/openmw-mp/Packets/World/WorldPacket.cpp @@ -7,6 +7,7 @@ using namespace mwmp; WorldPacket::WorldPacket(RakNet::RakPeerInterface *peer) : BasePacket(peer) { + hasCellData = false; packetID = 0; priority = HIGH_PRIORITY; reliability = RELIABLE_ORDERED; @@ -24,3 +25,53 @@ void WorldPacket::setEvent(BaseEvent *event) this->event = event; guid = event->guid; } + +void WorldPacket::Packet(RakNet::BitStream *bs, bool send) +{ + if(!PacketHeader(bs, send)) + return; + + WorldObject worldObject; + for (unsigned int i = 0; i < event->worldObjectCount; i++) + { + if (send) + worldObject = event->worldObjects.at(i); + + Object(worldObject, send); + + if (!send) + event->worldObjects.push_back(worldObject); + } +} + +bool WorldPacket::PacketHeader(RakNet::BitStream *bs, bool send) +{ + BasePacket::Packet(bs, send); + + if (send) + event->worldObjectCount = (unsigned int)(event->worldObjects.size()); + else + event->worldObjects.clear(); + + RW(event->worldObjectCount, send); + + if (event->worldObjectCount > maxObjects) + { + event->isValid = false; + return false; + } + + if(hasCellData) + { + RW(event->cell.mData, send, 1); + RW(event->cell.mName, send, 1); + } + return true; +} + +void WorldPacket::Object(WorldObject &worldObject, bool send) +{ + RW(worldObject.refId, send); + RW(worldObject.refNumIndex, send); + RW(worldObject.mpNum, send); +} diff --git a/components/openmw-mp/Packets/World/WorldPacket.hpp b/components/openmw-mp/Packets/World/WorldPacket.hpp index 340cca7a0..4f67b9631 100644 --- a/components/openmw-mp/Packets/World/WorldPacket.hpp +++ b/components/openmw-mp/Packets/World/WorldPacket.hpp @@ -21,9 +21,14 @@ namespace mwmp void setEvent(BaseEvent *event); + virtual void Packet(RakNet::BitStream *bs, bool send); + protected: + virtual void Object(WorldObject &worldObject, bool send); + bool PacketHeader(RakNet::BitStream *bs, bool send); BaseEvent *event; static const int maxObjects = 3000; + bool hasCellData; }; }