1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-21 11:23:51 +00:00
openmw-tes3mp/components/openmw-mp/Packets/Object/ObjectPacket.cpp
David Cernat 8a393d2984 Merge pull request #430 from TES3MP/0.6.3 while resolving conflicts
# Conflicts:
#	apps/openmw-mp/Networking.cpp
#	apps/openmw-mp/Networking.hpp
#	components/CMakeLists.txt
2018-05-18 08:12:28 +03:00

72 lines
1.5 KiB
C++

#include <components/openmw-mp/NetworkMessages.hpp>
#include <PacketPriority.h>
#include <RakPeer.h>
#include "ObjectPacket.hpp"
using namespace mwmp;
ObjectPacket::ObjectPacket(RakNet::RakPeerInterface *peer) : BasePacket(peer)
{
hasCellData = false;
packetID = 0;
priority = HIGH_PRIORITY;
reliability = RELIABLE_ORDERED;
orderChannel = CHANNEL_OBJECT;
this->peer = peer;
}
void ObjectPacket::setObjectList(BaseObjectList *objectList)
{
this->objectList = objectList;
guid = objectList->guid;
}
void ObjectPacket::Packet(RakNet::BitStream *bs, bool send)
{
if (!PacketHeader(bs, send))
return;
for (auto &&baseObject : objectList->baseObjects)
{
Object(baseObject, send);
}
}
bool ObjectPacket::PacketHeader(RakNet::BitStream *bs, bool send)
{
BasePacket::Packet(bs, send);
uint32_t baseObjectCount;
if (send)
baseObjectCount = (uint32_t) (objectList->baseObjects.size());
RW(baseObjectCount, send);
if (baseObjectCount > maxObjects)
{
objectList->isValid = false;
return false;
}
if (!send)
{
objectList->baseObjects.clear();
objectList->baseObjects.resize(baseObjectCount);
}
if (hasCellData)
{
RW(objectList->cell.mData, send, true);
RW(objectList->cell.mName, send, true);
}
return true;
}
void ObjectPacket::Object(BaseObject &baseObject, bool send)
{
RW(baseObject.refId, send);
RW(baseObject.refNumIndex, send);
RW(baseObject.mpNum, send);
}