From 2ed1bfe4275d82f4a1ef9763982068fb2ee4a92e Mon Sep 17 00:00:00 2001 From: Koncord Date: Sat, 3 Jun 2017 03:42:10 +0800 Subject: [PATCH] [General] Simplify ActorPackets --- .../openmw-mp/Packets/Actor/ActorPacket.cpp | 40 +++++++++++++ .../openmw-mp/Packets/Actor/ActorPacket.hpp | 4 +- .../openmw-mp/Packets/Actor/PacketActorAI.cpp | 37 +----------- .../openmw-mp/Packets/Actor/PacketActorAI.hpp | 2 +- .../Packets/Actor/PacketActorAnimFlags.cpp | 41 ++----------- .../Packets/Actor/PacketActorAnimFlags.hpp | 2 +- .../Packets/Actor/PacketActorAnimPlay.cpp | 42 ++----------- .../Packets/Actor/PacketActorAnimPlay.hpp | 2 +- .../Packets/Actor/PacketActorAttack.cpp | 59 ++++--------------- .../Packets/Actor/PacketActorAttack.hpp | 2 +- .../Packets/Actor/PacketActorAuthority.cpp | 5 +- .../Packets/Actor/PacketActorCellChange.cpp | 39 ++---------- .../Packets/Actor/PacketActorCellChange.hpp | 2 +- .../Packets/Actor/PacketActorDeath.cpp | 35 +---------- .../Packets/Actor/PacketActorDeath.hpp | 2 +- .../Packets/Actor/PacketActorEquipment.cpp | 43 ++------------ .../Packets/Actor/PacketActorEquipment.hpp | 2 +- .../Packets/Actor/PacketActorList.cpp | 20 +------ .../Packets/Actor/PacketActorPosition.cpp | 37 ++---------- .../Packets/Actor/PacketActorPosition.hpp | 2 +- .../Packets/Actor/PacketActorSpeech.cpp | 39 +----------- .../Packets/Actor/PacketActorSpeech.hpp | 2 +- .../Packets/Actor/PacketActorStatsDynamic.cpp | 41 +------------ .../Packets/Actor/PacketActorStatsDynamic.hpp | 2 +- .../Packets/Actor/PacketActorTest.cpp | 33 +---------- .../Packets/Actor/PacketActorTest.hpp | 2 +- 26 files changed, 106 insertions(+), 431 deletions(-) diff --git a/components/openmw-mp/Packets/Actor/ActorPacket.cpp b/components/openmw-mp/Packets/Actor/ActorPacket.cpp index 52a31e3dd..715168a26 100644 --- a/components/openmw-mp/Packets/Actor/ActorPacket.cpp +++ b/components/openmw-mp/Packets/Actor/ActorPacket.cpp @@ -26,9 +26,49 @@ void ActorPacket::setActorList(BaseActorList *actorList) } void ActorPacket::Packet(RakNet::BitStream *bs, bool send) +{ + if(!PacketHeader(bs, send)) + return; + + BaseActor actor; + + for (unsigned int i = 0; i < actorList->count; i++) + { + if (send) + actor = actorList->baseActors[i]; + + RW(actor.refNumIndex, send); + RW(actor.mpNum, send); + + Actor(actor, send); + + if (!send) + actorList->baseActors.push_back(actor); + } +} + +bool ActorPacket::PacketHeader(RakNet::BitStream *bs, bool send) { BasePacket::Packet(bs, send); RW(actorList->cell.mData, send, 1); RW(actorList->cell.mName, send, 1); + + if (send) + actorList->count = (unsigned int)(actorList->baseActors.size()); + else + actorList->baseActors.clear(); + + RW(actorList->count, send); + + if (actorList->count > maxActors) + actorList->isValid = false; + + return actorList->isValid; +} + + +void ActorPacket::Actor(BaseActor &actor, bool send) +{ + } diff --git a/components/openmw-mp/Packets/Actor/ActorPacket.hpp b/components/openmw-mp/Packets/Actor/ActorPacket.hpp index ef8480ff8..89ebeaec9 100644 --- a/components/openmw-mp/Packets/Actor/ActorPacket.hpp +++ b/components/openmw-mp/Packets/Actor/ActorPacket.hpp @@ -20,9 +20,11 @@ namespace mwmp ~ActorPacket(); void setActorList(BaseActorList *actorList); - virtual void Packet(RakNet::BitStream *bs, bool send); + virtual void Packet(RakNet::BitStream *bs, bool send); protected: + bool PacketHeader(RakNet::BitStream *bs, bool send); + virtual void Actor(BaseActor &actor, bool send); BaseActorList *actorList; static const int maxActors = 3000; }; diff --git a/components/openmw-mp/Packets/Actor/PacketActorAI.cpp b/components/openmw-mp/Packets/Actor/PacketActorAI.cpp index 2bb2edfde..774536460 100644 --- a/components/openmw-mp/Packets/Actor/PacketActorAI.cpp +++ b/components/openmw-mp/Packets/Actor/PacketActorAI.cpp @@ -9,40 +9,7 @@ PacketActorAI::PacketActorAI(RakNet::RakPeerInterface *peer) : ActorPacket(peer) packetID = ID_ACTOR_AI; } -void PacketActorAI::Packet(RakNet::BitStream *bs, bool send) +void PacketActorAI::Actor(BaseActor &actor, bool send) { - ActorPacket::Packet(bs, send); - - if (send) - actorList->count = (unsigned int)(actorList->baseActors.size()); - else - actorList->baseActors.clear(); - - RW(actorList->count, send); - - if (actorList->count > maxActors) - { - actorList->isValid = false; - return; - } - - BaseActor actor; - - for (unsigned int i = 0; i < actorList->count; i++) - { - if (send) - { - actor = actorList->baseActors.at(i); - } - - RW(actor.refNumIndex, send); - RW(actor.mpNum, send); - - // Placeholder to be filled in later - - if (!send) - { - actorList->baseActors.push_back(actor); - } - } + // Placeholder to be filled in later } diff --git a/components/openmw-mp/Packets/Actor/PacketActorAI.hpp b/components/openmw-mp/Packets/Actor/PacketActorAI.hpp index a4c4d87de..c1c187a9c 100644 --- a/components/openmw-mp/Packets/Actor/PacketActorAI.hpp +++ b/components/openmw-mp/Packets/Actor/PacketActorAI.hpp @@ -10,7 +10,7 @@ namespace mwmp public: PacketActorAI(RakNet::RakPeerInterface *peer); - virtual void Packet(RakNet::BitStream *bs, bool send); + virtual void Actor(BaseActor &actor, bool send); }; } diff --git a/components/openmw-mp/Packets/Actor/PacketActorAnimFlags.cpp b/components/openmw-mp/Packets/Actor/PacketActorAnimFlags.cpp index c2ab1f8e9..3fd2ed64e 100644 --- a/components/openmw-mp/Packets/Actor/PacketActorAnimFlags.cpp +++ b/components/openmw-mp/Packets/Actor/PacketActorAnimFlags.cpp @@ -9,42 +9,9 @@ PacketActorAnimFlags::PacketActorAnimFlags(RakNet::RakPeerInterface *peer) : Act packetID = ID_ACTOR_ANIM_FLAGS; } -void PacketActorAnimFlags::Packet(RakNet::BitStream *bs, bool send) +void PacketActorAnimFlags::Actor(BaseActor &actor, bool send) { - ActorPacket::Packet(bs, send); - - if (send) - actorList->count = (unsigned int)(actorList->baseActors.size()); - else - actorList->baseActors.clear(); - - RW(actorList->count, send); - - if (actorList->count > maxActors) - { - actorList->isValid = false; - return; - } - - BaseActor actor; - - for (unsigned int i = 0; i < actorList->count; i++) - { - if (send) - { - actor = actorList->baseActors.at(i); - } - - RW(actor.refNumIndex, send); - RW(actor.mpNum, send); - - RW(actor.movementFlags, send); - RW(actor.drawState, send); - RW(actor.isFlying, send); - - if (!send) - { - actorList->baseActors.push_back(actor); - } - } + RW(actor.movementFlags, send); + RW(actor.drawState, send); + RW(actor.isFlying, send); } diff --git a/components/openmw-mp/Packets/Actor/PacketActorAnimFlags.hpp b/components/openmw-mp/Packets/Actor/PacketActorAnimFlags.hpp index 6be12e9a9..42855954d 100644 --- a/components/openmw-mp/Packets/Actor/PacketActorAnimFlags.hpp +++ b/components/openmw-mp/Packets/Actor/PacketActorAnimFlags.hpp @@ -10,7 +10,7 @@ namespace mwmp public: PacketActorAnimFlags(RakNet::RakPeerInterface *peer); - virtual void Packet(RakNet::BitStream *bs, bool send); + virtual void Actor(BaseActor &actor, bool send); }; } diff --git a/components/openmw-mp/Packets/Actor/PacketActorAnimPlay.cpp b/components/openmw-mp/Packets/Actor/PacketActorAnimPlay.cpp index 197ec687a..3613b1cbf 100644 --- a/components/openmw-mp/Packets/Actor/PacketActorAnimPlay.cpp +++ b/components/openmw-mp/Packets/Actor/PacketActorAnimPlay.cpp @@ -9,43 +9,11 @@ PacketActorAnimPlay::PacketActorAnimPlay(RakNet::RakPeerInterface *peer) : Actor packetID = ID_ACTOR_ANIM_PLAY; } -void PacketActorAnimPlay::Packet(RakNet::BitStream *bs, bool send) +void PacketActorAnimPlay::Actor(BaseActor &actor, bool send) { - ActorPacket::Packet(bs, send); - if (send) - actorList->count = (unsigned int)(actorList->baseActors.size()); - else - actorList->baseActors.clear(); - - RW(actorList->count, send); - - if (actorList->count > maxActors) - { - actorList->isValid = false; - return; - } - - BaseActor actor; - - for (unsigned int i = 0; i < actorList->count; i++) - { - if (send) - { - actor = actorList->baseActors.at(i); - } - - RW(actor.refNumIndex, send); - RW(actor.mpNum, send); - - RW(actor.animation.groupname, send); - RW(actor.animation.mode, send); - RW(actor.animation.count, send); - RW(actor.animation.persist, send); - - if (!send) - { - actorList->baseActors.push_back(actor); - } - } + RW(actor.animation.groupname, send); + RW(actor.animation.mode, send); + RW(actor.animation.count, send); + RW(actor.animation.persist, send); } diff --git a/components/openmw-mp/Packets/Actor/PacketActorAnimPlay.hpp b/components/openmw-mp/Packets/Actor/PacketActorAnimPlay.hpp index 1fcc8b261..0bf818b58 100644 --- a/components/openmw-mp/Packets/Actor/PacketActorAnimPlay.hpp +++ b/components/openmw-mp/Packets/Actor/PacketActorAnimPlay.hpp @@ -10,7 +10,7 @@ namespace mwmp public: PacketActorAnimPlay(RakNet::RakPeerInterface *peer); - virtual void Packet(RakNet::BitStream *bs, bool send); + virtual void Actor(BaseActor &actor, bool send); }; } diff --git a/components/openmw-mp/Packets/Actor/PacketActorAttack.cpp b/components/openmw-mp/Packets/Actor/PacketActorAttack.cpp index e93bbe797..a0ec2676d 100644 --- a/components/openmw-mp/Packets/Actor/PacketActorAttack.cpp +++ b/components/openmw-mp/Packets/Actor/PacketActorAttack.cpp @@ -9,51 +9,18 @@ PacketActorAttack::PacketActorAttack(RakNet::RakPeerInterface *peer) : ActorPack packetID = ID_ACTOR_ATTACK; } -void PacketActorAttack::Packet(RakNet::BitStream *bs, bool send) +void PacketActorAttack::Actor(BaseActor &actor, bool send) { - ActorPacket::Packet(bs, send); - - if (send) - actorList->count = (unsigned int)(actorList->baseActors.size()); - else - actorList->baseActors.clear(); - - RW(actorList->count, send); - - if (actorList->count > maxActors) - { - actorList->isValid = false; - return; - } - - BaseActor actor; - - for (unsigned int i = 0; i < actorList->count; i++) - { - if (send) - { - actor = actorList->baseActors.at(i); - } - - RW(actor.refNumIndex, send); - RW(actor.mpNum, send); - - RW(actor.attack.target.refNumIndex, send); - RW(actor.attack.target.mpNum, send); - RW(actor.attack.target.guid, send); - - RW(actor.attack.spellId, send); - RW(actor.attack.type, send); - RW(actor.attack.success, send); - RW(actor.attack.damage, send); - - RW(actor.attack.pressed, send); - RW(actor.attack.knockdown, send); - RW(actor.attack.block, send); - - if (!send) - { - actorList->baseActors.push_back(actor); - } - } + RW(actor.attack.target.refNumIndex, send); + RW(actor.attack.target.mpNum, send); + RW(actor.attack.target.guid, send); + + RW(actor.attack.spellId, send); + RW(actor.attack.type, send); + RW(actor.attack.success, send); + RW(actor.attack.damage, send); + + RW(actor.attack.pressed, send); + RW(actor.attack.knockdown, send); + RW(actor.attack.block, send); } diff --git a/components/openmw-mp/Packets/Actor/PacketActorAttack.hpp b/components/openmw-mp/Packets/Actor/PacketActorAttack.hpp index 1dbcb9cea..d924da8df 100644 --- a/components/openmw-mp/Packets/Actor/PacketActorAttack.hpp +++ b/components/openmw-mp/Packets/Actor/PacketActorAttack.hpp @@ -10,7 +10,7 @@ namespace mwmp public: PacketActorAttack(RakNet::RakPeerInterface *peer); - virtual void Packet(RakNet::BitStream *bs, bool send); + virtual void Actor(BaseActor &actor, bool send); }; } diff --git a/components/openmw-mp/Packets/Actor/PacketActorAuthority.cpp b/components/openmw-mp/Packets/Actor/PacketActorAuthority.cpp index 0678751e5..a1886dc9c 100644 --- a/components/openmw-mp/Packets/Actor/PacketActorAuthority.cpp +++ b/components/openmw-mp/Packets/Actor/PacketActorAuthority.cpp @@ -10,5 +10,8 @@ PacketActorAuthority::PacketActorAuthority(RakNet::RakPeerInterface *peer) : Act void PacketActorAuthority::Packet(RakNet::BitStream *bs, bool send) { - ActorPacket::Packet(bs, send); + BasePacket::Packet(bs, send); + + RW(actorList->cell.mData, send, 1); + RW(actorList->cell.mName, send, 1); } diff --git a/components/openmw-mp/Packets/Actor/PacketActorCellChange.cpp b/components/openmw-mp/Packets/Actor/PacketActorCellChange.cpp index 077674334..394c181ed 100644 --- a/components/openmw-mp/Packets/Actor/PacketActorCellChange.cpp +++ b/components/openmw-mp/Packets/Actor/PacketActorCellChange.cpp @@ -9,40 +9,11 @@ PacketActorCellChange::PacketActorCellChange(RakNet::RakPeerInterface *peer) : A packetID = ID_ACTOR_CELL_CHANGE; } -void PacketActorCellChange::Packet(RakNet::BitStream *bs, bool send) +void PacketActorCellChange::Actor(BaseActor &actor, bool send) { - ActorPacket::Packet(bs, send); + RW(actor.cell.mData, send, 1); + RW(actor.cell.mName, send, 1); - if (send) - actorList->count = (unsigned int)(actorList->baseActors.size()); - else - actorList->baseActors.clear(); - - RW(actorList->count, send); - - if (actorList->count > maxActors) - { - actorList->isValid = false; - return; - } - - BaseActor actor; - - for (unsigned int i = 0; i < actorList->count; i++) - { - if (send) - actor = actorList->baseActors.at(i); - - RW(actor.refNumIndex, send); - RW(actor.mpNum, send); - - RW(actor.cell.mData, send, 1); - RW(actor.cell.mName, send, 1); - - RW(actor.position, send, 1); - RW(actor.direction, send, 1); - - if (!send) - actorList->baseActors.push_back(actor); - } + RW(actor.position, send, 1); + RW(actor.direction, send, 1); } diff --git a/components/openmw-mp/Packets/Actor/PacketActorCellChange.hpp b/components/openmw-mp/Packets/Actor/PacketActorCellChange.hpp index 6a2b05e79..cee4ecbda 100644 --- a/components/openmw-mp/Packets/Actor/PacketActorCellChange.hpp +++ b/components/openmw-mp/Packets/Actor/PacketActorCellChange.hpp @@ -10,7 +10,7 @@ namespace mwmp public: PacketActorCellChange(RakNet::RakPeerInterface *peer); - virtual void Packet(RakNet::BitStream *bs, bool send); + virtual void Actor(BaseActor &actor, bool send); }; } diff --git a/components/openmw-mp/Packets/Actor/PacketActorDeath.cpp b/components/openmw-mp/Packets/Actor/PacketActorDeath.cpp index 2cc10b672..b2b3d95a6 100644 --- a/components/openmw-mp/Packets/Actor/PacketActorDeath.cpp +++ b/components/openmw-mp/Packets/Actor/PacketActorDeath.cpp @@ -9,40 +9,7 @@ PacketActorDeath::PacketActorDeath(RakNet::RakPeerInterface *peer) : ActorPacket packetID = ID_ACTOR_DEATH; } -void PacketActorDeath::Packet(RakNet::BitStream *bs, bool send) +void PacketActorDeath::Actor(BaseActor &actor, bool send) { - ActorPacket::Packet(bs, send); - - if (send) - actorList->count = (unsigned int)(actorList->baseActors.size()); - else - actorList->baseActors.clear(); - - RW(actorList->count, send); - - if (actorList->count > maxActors) - { - actorList->isValid = false; - return; - } - - BaseActor actor; - - for (unsigned int i = 0; i < actorList->count; i++) - { - if (send) - { - actor = actorList->baseActors.at(i); - } - - RW(actor.refNumIndex, send); - RW(actor.mpNum, send); - // Placeholder to be filled in later - - if (!send) - { - actorList->baseActors.push_back(actor); - } - } } diff --git a/components/openmw-mp/Packets/Actor/PacketActorDeath.hpp b/components/openmw-mp/Packets/Actor/PacketActorDeath.hpp index 5aba35b6e..13ab4463a 100644 --- a/components/openmw-mp/Packets/Actor/PacketActorDeath.hpp +++ b/components/openmw-mp/Packets/Actor/PacketActorDeath.hpp @@ -10,7 +10,7 @@ namespace mwmp public: PacketActorDeath(RakNet::RakPeerInterface *peer); - virtual void Packet(RakNet::BitStream *bs, bool send); + virtual void Actor(BaseActor &actor, bool send); }; } diff --git a/components/openmw-mp/Packets/Actor/PacketActorEquipment.cpp b/components/openmw-mp/Packets/Actor/PacketActorEquipment.cpp index bfc5f61a6..513fd2833 100644 --- a/components/openmw-mp/Packets/Actor/PacketActorEquipment.cpp +++ b/components/openmw-mp/Packets/Actor/PacketActorEquipment.cpp @@ -9,45 +9,12 @@ PacketActorEquipment::PacketActorEquipment(RakNet::RakPeerInterface *peer) : Act packetID = ID_ACTOR_EQUIPMENT; } -void PacketActorEquipment::Packet(RakNet::BitStream *bs, bool send) +void PacketActorEquipment::Actor(BaseActor &actor, bool send) { - ActorPacket::Packet(bs, send); - - if (send) - actorList->count = (unsigned int)(actorList->baseActors.size()); - else - actorList->baseActors.clear(); - - RW(actorList->count, send); - - if (actorList->count > maxActors) - { - actorList->isValid = false; - return; - } - - BaseActor actor; - - for (unsigned int i = 0; i < actorList->count; i++) + for (int j = 0; j < 19; j++) { - if (send) - { - actor = actorList->baseActors.at(i); - } - - RW(actor.refNumIndex, send); - RW(actor.mpNum, send); - - for (int j = 0; j < 19; j++) - { - RW(actor.equipedItems[j].refId, send); - RW(actor.equipedItems[j].count, send); - RW(actor.equipedItems[j].charge, send); - } - - if (!send) - { - actorList->baseActors.push_back(actor); - } + RW(actor.equipedItems[j].refId, send); + RW(actor.equipedItems[j].count, send); + RW(actor.equipedItems[j].charge, send); } } diff --git a/components/openmw-mp/Packets/Actor/PacketActorEquipment.hpp b/components/openmw-mp/Packets/Actor/PacketActorEquipment.hpp index 264f5cd6a..8d8ed3946 100644 --- a/components/openmw-mp/Packets/Actor/PacketActorEquipment.hpp +++ b/components/openmw-mp/Packets/Actor/PacketActorEquipment.hpp @@ -10,7 +10,7 @@ namespace mwmp public: PacketActorEquipment(RakNet::RakPeerInterface *peer); - virtual void Packet(RakNet::BitStream *bs, bool send); + virtual void Actor(BaseActor &actor, bool send); }; } diff --git a/components/openmw-mp/Packets/Actor/PacketActorList.cpp b/components/openmw-mp/Packets/Actor/PacketActorList.cpp index ff2c1199e..f1cdba77b 100644 --- a/components/openmw-mp/Packets/Actor/PacketActorList.cpp +++ b/components/openmw-mp/Packets/Actor/PacketActorList.cpp @@ -10,31 +10,17 @@ PacketActorList::PacketActorList(RakNet::RakPeerInterface *peer) : ActorPacket(p void PacketActorList::Packet(RakNet::BitStream *bs, bool send) { - ActorPacket::Packet(bs, send); + if(!ActorPacket::PacketHeader(bs, send)) + return; RW(actorList->action, send); - if (send) - actorList->count = (unsigned int)(actorList->baseActors.size()); - else - actorList->baseActors.clear(); - - RW(actorList->count, send); - - if (actorList->count > maxActors) - { - actorList->isValid = false; - return; - } - BaseActor actor; for (unsigned int i = 0; i < actorList->count; i++) { if (send) - { actor = actorList->baseActors.at(i); - } RW(actor.refId, send); RW(actor.refNumIndex, send); @@ -47,8 +33,6 @@ void PacketActorList::Packet(RakNet::BitStream *bs, bool send) } if (!send) - { actorList->baseActors.push_back(actor); - } } } diff --git a/components/openmw-mp/Packets/Actor/PacketActorPosition.cpp b/components/openmw-mp/Packets/Actor/PacketActorPosition.cpp index ac2015326..53c6c8e8b 100644 --- a/components/openmw-mp/Packets/Actor/PacketActorPosition.cpp +++ b/components/openmw-mp/Packets/Actor/PacketActorPosition.cpp @@ -9,39 +9,10 @@ PacketActorPosition::PacketActorPosition(RakNet::RakPeerInterface *peer) : Actor packetID = ID_ACTOR_POSITION; } -void PacketActorPosition::Packet(RakNet::BitStream *bs, bool send) +void PacketActorPosition::Actor(BaseActor &actor, bool send) { - ActorPacket::Packet(bs, send); + RW(actor.position, send, 1); + RW(actor.direction, send, 1); - if (send) - actorList->count = (unsigned int)(actorList->baseActors.size()); - else - actorList->baseActors.clear(); - - RW(actorList->count, send); - - if (actorList->count > maxActors) - { - actorList->isValid = false; - return; - } - - BaseActor actor; - - for (unsigned int i = 0; i < actorList->count; i++) - { - if (send) - actor = actorList->baseActors.at(i); - - RW(actor.refNumIndex, send); - RW(actor.mpNum, send); - - RW(actor.position, send, 1); - RW(actor.direction, send, 1); - - actor.hasPositionData = true; - - if (!send) - actorList->baseActors.push_back(actor); - } + actor.hasPositionData = true; } diff --git a/components/openmw-mp/Packets/Actor/PacketActorPosition.hpp b/components/openmw-mp/Packets/Actor/PacketActorPosition.hpp index 3ea19fb3b..a0cee62f6 100644 --- a/components/openmw-mp/Packets/Actor/PacketActorPosition.hpp +++ b/components/openmw-mp/Packets/Actor/PacketActorPosition.hpp @@ -10,7 +10,7 @@ namespace mwmp public: PacketActorPosition(RakNet::RakPeerInterface *peer); - virtual void Packet(RakNet::BitStream *bs, bool send); + virtual void Actor(BaseActor &actor, bool send); }; } diff --git a/components/openmw-mp/Packets/Actor/PacketActorSpeech.cpp b/components/openmw-mp/Packets/Actor/PacketActorSpeech.cpp index 2e1b0c932..565097ccf 100644 --- a/components/openmw-mp/Packets/Actor/PacketActorSpeech.cpp +++ b/components/openmw-mp/Packets/Actor/PacketActorSpeech.cpp @@ -9,41 +9,8 @@ PacketActorSpeech::PacketActorSpeech(RakNet::RakPeerInterface *peer) : ActorPack packetID = ID_ACTOR_SPEECH; } -void PacketActorSpeech::Packet(RakNet::BitStream *bs, bool send) +void PacketActorSpeech::Actor(BaseActor &actor, bool send) { - ActorPacket::Packet(bs, send); - - if (send) - actorList->count = (unsigned int)(actorList->baseActors.size()); - else - actorList->baseActors.clear(); - - RW(actorList->count, send); - - if (actorList->count > maxActors) - { - actorList->isValid = false; - return; - } - - BaseActor actor; - - for (unsigned int i = 0; i < actorList->count; i++) - { - if (send) - { - actor = actorList->baseActors.at(i); - } - - RW(actor.refNumIndex, send); - RW(actor.mpNum, send); - - RW(actor.response, send); - RW(actor.sound, send); - - if (!send) - { - actorList->baseActors.push_back(actor); - } - } + RW(actor.response, send); + RW(actor.sound, send); } diff --git a/components/openmw-mp/Packets/Actor/PacketActorSpeech.hpp b/components/openmw-mp/Packets/Actor/PacketActorSpeech.hpp index 2d0b693e7..0c0b4f7f9 100644 --- a/components/openmw-mp/Packets/Actor/PacketActorSpeech.hpp +++ b/components/openmw-mp/Packets/Actor/PacketActorSpeech.hpp @@ -10,7 +10,7 @@ namespace mwmp public: PacketActorSpeech(RakNet::RakPeerInterface *peer); - virtual void Packet(RakNet::BitStream *bs, bool send); + virtual void Actor(BaseActor &actor, bool send); }; } diff --git a/components/openmw-mp/Packets/Actor/PacketActorStatsDynamic.cpp b/components/openmw-mp/Packets/Actor/PacketActorStatsDynamic.cpp index 2a02a4bf9..c970d49e0 100644 --- a/components/openmw-mp/Packets/Actor/PacketActorStatsDynamic.cpp +++ b/components/openmw-mp/Packets/Actor/PacketActorStatsDynamic.cpp @@ -10,44 +10,9 @@ PacketActorStatsDynamic::PacketActorStatsDynamic(RakNet::RakPeerInterface *peer) packetID = ID_ACTOR_STATS_DYNAMIC; } -void PacketActorStatsDynamic::Packet(RakNet::BitStream *bs, bool send) +void PacketActorStatsDynamic::Actor(BaseActor &actor, bool send) { - ActorPacket::Packet(bs, send); + RW(actor.creatureStats.mDynamic, send); - if (send) - actorList->count = (unsigned int)(actorList->baseActors.size()); - else - actorList->baseActors.clear(); - - RW(actorList->count, send); - - if (actorList->count > maxActors) - { - actorList->isValid = false; - return; - } - - BaseActor actor; - - for (unsigned int i = 0; i < actorList->count; i++) - { - if (send) - { - actor = actorList->baseActors.at(i); - } - - RW(actor.refNumIndex, send); - RW(actor.mpNum, send); - - RW(actor.creatureStats.mDynamic[0], send); // health - RW(actor.creatureStats.mDynamic[1], send); // magic - RW(actor.creatureStats.mDynamic[2], send); // fatigue - - actor.hasStatsDynamicData = true; - - if (!send) - { - actorList->baseActors.push_back(actor); - } - } + actor.hasStatsDynamicData = true; } diff --git a/components/openmw-mp/Packets/Actor/PacketActorStatsDynamic.hpp b/components/openmw-mp/Packets/Actor/PacketActorStatsDynamic.hpp index 87ac674b8..c5c26599a 100644 --- a/components/openmw-mp/Packets/Actor/PacketActorStatsDynamic.hpp +++ b/components/openmw-mp/Packets/Actor/PacketActorStatsDynamic.hpp @@ -10,7 +10,7 @@ namespace mwmp public: PacketActorStatsDynamic(RakNet::RakPeerInterface *peer); - virtual void Packet(RakNet::BitStream *bs, bool send); + virtual void Actor(BaseActor &actor, bool send); }; } diff --git a/components/openmw-mp/Packets/Actor/PacketActorTest.cpp b/components/openmw-mp/Packets/Actor/PacketActorTest.cpp index 9765df15a..9882f8d38 100644 --- a/components/openmw-mp/Packets/Actor/PacketActorTest.cpp +++ b/components/openmw-mp/Packets/Actor/PacketActorTest.cpp @@ -9,38 +9,7 @@ PacketActorTest::PacketActorTest(RakNet::RakPeerInterface *peer) : ActorPacket(p packetID = ID_ACTOR_TEST; } -void PacketActorTest::Packet(RakNet::BitStream *bs, bool send) +void PacketActorTest::Actor(BaseActor &actor, bool send) { - ActorPacket::Packet(bs, send); - if (send) - actorList->count = (unsigned int)(actorList->baseActors.size()); - else - actorList->baseActors.clear(); - - RW(actorList->count, send); - - if (actorList->count > maxActors) - { - actorList->isValid = false; - return; - } - - BaseActor actor; - - for (unsigned int i = 0; i < actorList->count; i++) - { - if (send) - { - actor = actorList->baseActors.at(i); - } - - RW(actor.refNumIndex, send); - RW(actor.mpNum, send); - - if (!send) - { - actorList->baseActors.push_back(actor); - } - } } diff --git a/components/openmw-mp/Packets/Actor/PacketActorTest.hpp b/components/openmw-mp/Packets/Actor/PacketActorTest.hpp index c8b16edc9..d53e2fecd 100644 --- a/components/openmw-mp/Packets/Actor/PacketActorTest.hpp +++ b/components/openmw-mp/Packets/Actor/PacketActorTest.hpp @@ -10,7 +10,7 @@ namespace mwmp public: PacketActorTest(RakNet::RakPeerInterface *peer); - virtual void Packet(RakNet::BitStream *bs, bool send); + virtual void Actor(BaseActor &actor, bool send); }; }