diff --git a/apps/openmw-mp/Cell.cpp b/apps/openmw-mp/Cell.cpp index 9781369fe..45d05cd3f 100644 --- a/apps/openmw-mp/Cell.cpp +++ b/apps/openmw-mp/Cell.cpp @@ -15,7 +15,7 @@ using namespace std; Cell::Cell(ESM::Cell cell) : cell(cell) { - cellActorList.count = 0; + } Cell::Iterator Cell::begin() const @@ -109,8 +109,6 @@ void Cell::readActorList(unsigned char packetID, const mwmp::BaseActorList *newA else cellActorList.baseActors.push_back(newActor); } - - cellActorList.count = cellActorList.baseActors.size(); } bool Cell::containsActor(int refNumIndex, int mpNum) @@ -155,8 +153,6 @@ void Cell::removeActors(const mwmp::BaseActorList &newActorList) if (!foundActor) it++; } - - cellActorList.count = cellActorList.baseActors.size(); } RakNet::RakNetGUID *Cell::getAuthority() diff --git a/apps/openmw-mp/processors/actor/ProcessorActorAI.hpp b/apps/openmw-mp/processors/actor/ProcessorActorAI.hpp index 1929f1693..a3a728095 100644 --- a/apps/openmw-mp/processors/actor/ProcessorActorAI.hpp +++ b/apps/openmw-mp/processors/actor/ProcessorActorAI.hpp @@ -16,7 +16,7 @@ namespace mwmp void Do(ActorPacket &packet, const std::shared_ptr &player, BaseActorList &actorList) override { // Send only to players who have the cell loaded - Cell *serverCell = CellController::get().getCell(&actorList.cell); + Cell *serverCell = CellController::get().getCell(actorList.cell); if (serverCell != nullptr && *serverCell->getAuthority() == actorList.guid) serverCell->sendToLoaded(&packet, &actorList); diff --git a/apps/openmw-mp/processors/actor/ProcessorActorAnimFlags.hpp b/apps/openmw-mp/processors/actor/ProcessorActorAnimFlags.hpp index 9c22c2426..048ae93dc 100644 --- a/apps/openmw-mp/processors/actor/ProcessorActorAnimFlags.hpp +++ b/apps/openmw-mp/processors/actor/ProcessorActorAnimFlags.hpp @@ -16,7 +16,7 @@ namespace mwmp void Do(ActorPacket &packet, const std::shared_ptr &player, BaseActorList &actorList) override { // Send only to players who have the cell loaded - Cell *serverCell = CellController::get().getCell(&actorList.cell); + Cell *serverCell = CellController::get().getCell(actorList.cell); if (serverCell != nullptr && *serverCell->getAuthority() == actorList.guid) serverCell->sendToLoaded(&packet, &actorList); diff --git a/apps/openmw-mp/processors/actor/ProcessorActorAnimPlay.hpp b/apps/openmw-mp/processors/actor/ProcessorActorAnimPlay.hpp index 233e86cb7..57a7d5f8f 100644 --- a/apps/openmw-mp/processors/actor/ProcessorActorAnimPlay.hpp +++ b/apps/openmw-mp/processors/actor/ProcessorActorAnimPlay.hpp @@ -16,7 +16,7 @@ namespace mwmp void Do(ActorPacket &packet, const std::shared_ptr &player, BaseActorList &actorList) override { // Send only to players who have the cell loaded - Cell *serverCell = CellController::get().getCell(&actorList.cell); + Cell *serverCell = CellController::get().getCell(actorList.cell); if (serverCell != nullptr && *serverCell->getAuthority() == actorList.guid) serverCell->sendToLoaded(&packet, &actorList); diff --git a/apps/openmw-mp/processors/actor/ProcessorActorAttack.hpp b/apps/openmw-mp/processors/actor/ProcessorActorAttack.hpp index ad2610fb1..6bfee16f3 100644 --- a/apps/openmw-mp/processors/actor/ProcessorActorAttack.hpp +++ b/apps/openmw-mp/processors/actor/ProcessorActorAttack.hpp @@ -16,7 +16,7 @@ namespace mwmp void Do(ActorPacket &packet, const std::shared_ptr &player, BaseActorList &actorList) override { // Send only to players who have the cell loaded - Cell *serverCell = CellController::get().getCell(&actorList.cell); + Cell *serverCell = CellController::get().getCell(actorList.cell); if (serverCell != nullptr && *serverCell->getAuthority() == actorList.guid) serverCell->sendToLoaded(&packet, &actorList); diff --git a/apps/openmw-mp/processors/actor/ProcessorActorCellChange.hpp b/apps/openmw-mp/processors/actor/ProcessorActorCellChange.hpp index d57004ef0..899dc059e 100644 --- a/apps/openmw-mp/processors/actor/ProcessorActorCellChange.hpp +++ b/apps/openmw-mp/processors/actor/ProcessorActorCellChange.hpp @@ -15,11 +15,11 @@ namespace mwmp void Do(ActorPacket &packet, const std::shared_ptr &player, BaseActorList &actorList) override { - Cell *serverCell = CellController::get().getCell(&actorList.cell); + Cell *serverCell = CellController::get().getCell(actorList.cell); if (serverCell != nullptr && *serverCell->getAuthority() == actorList.guid) { - serverCell->removeActors(&actorList); + serverCell->removeActors(actorList); std::vector> actors; diff --git a/apps/openmw-mp/processors/actor/ProcessorActorDeath.hpp b/apps/openmw-mp/processors/actor/ProcessorActorDeath.hpp index a5248e6a8..5c35f8652 100644 --- a/apps/openmw-mp/processors/actor/ProcessorActorDeath.hpp +++ b/apps/openmw-mp/processors/actor/ProcessorActorDeath.hpp @@ -16,7 +16,7 @@ namespace mwmp void Do(ActorPacket &packet, const std::shared_ptr &player, BaseActorList &actorList) override { // Send only to players who have the cell loaded - Cell *serverCell = CellController::get().getCell(&actorList.cell); + Cell *serverCell = CellController::get().getCell(actorList.cell); if (serverCell != nullptr && *serverCell->getAuthority() == actorList.guid) serverCell->sendToLoaded(&packet, &actorList); diff --git a/apps/openmw-mp/processors/actor/ProcessorActorPosition.hpp b/apps/openmw-mp/processors/actor/ProcessorActorPosition.hpp index 676e87877..752418647 100644 --- a/apps/openmw-mp/processors/actor/ProcessorActorPosition.hpp +++ b/apps/openmw-mp/processors/actor/ProcessorActorPosition.hpp @@ -16,7 +16,7 @@ namespace mwmp void Do(ActorPacket &packet, const std::shared_ptr &player, BaseActorList &actorList) override { // Send only to players who have the cell loaded - Cell *serverCell = CellController::get().getCell(&actorList.cell); + Cell *serverCell = CellController::get().getCell(actorList.cell); if (serverCell != nullptr && *serverCell->getAuthority() == actorList.guid) { diff --git a/apps/openmw-mp/processors/actor/ProcessorActorSpeech.hpp b/apps/openmw-mp/processors/actor/ProcessorActorSpeech.hpp index 2d878a798..3771bde92 100644 --- a/apps/openmw-mp/processors/actor/ProcessorActorSpeech.hpp +++ b/apps/openmw-mp/processors/actor/ProcessorActorSpeech.hpp @@ -16,7 +16,7 @@ namespace mwmp void Do(ActorPacket &packet, const std::shared_ptr &player, BaseActorList &actorList) override { // Send only to players who have the cell loaded - Cell *serverCell = CellController::get().getCell(&actorList.cell); + Cell *serverCell = CellController::get().getCell(actorList.cell); if (serverCell != nullptr && *serverCell->getAuthority() == actorList.guid) serverCell->sendToLoaded(&packet, &actorList); diff --git a/apps/openmw-mp/processors/actor/ProcessorActorStatsDynamic.hpp b/apps/openmw-mp/processors/actor/ProcessorActorStatsDynamic.hpp index b4ac19b06..2e39b911e 100644 --- a/apps/openmw-mp/processors/actor/ProcessorActorStatsDynamic.hpp +++ b/apps/openmw-mp/processors/actor/ProcessorActorStatsDynamic.hpp @@ -16,7 +16,7 @@ namespace mwmp void Do(ActorPacket &packet, const std::shared_ptr &player, BaseActorList &actorList) override { // Send only to players who have the cell loaded - Cell *serverCell = CellController::get().getCell(&actorList.cell); + Cell *serverCell = CellController::get().getCell(actorList.cell); if (serverCell != nullptr && *serverCell->getAuthority() == actorList.guid) { diff --git a/apps/openmw-mp/processors/world/ProcessorContainer.hpp b/apps/openmw-mp/processors/world/ProcessorContainer.hpp index e0fb8f2fc..fc5892eeb 100644 --- a/apps/openmw-mp/processors/world/ProcessorContainer.hpp +++ b/apps/openmw-mp/processors/world/ProcessorContainer.hpp @@ -23,9 +23,9 @@ namespace mwmp // Until we have a timestamp-based system, send packets pertaining to more // than one container (i.e. replies to server requests for container contents) // only to players who have the container's cell loaded - if (event.action == BaseEvent::SET && event.worldObjectCount > 1) + if (event.action == BaseEvent::SET && event.worldObjects.size() > 1) { - Cell *serverCell = CellController::get().getCell(&event.cell); + Cell *serverCell = CellController::get().getCell(event.cell); if (serverCell != nullptr) serverCell->sendToLoaded(&packet, &event); diff --git a/apps/openmw-mp/processors/world/ProcessorObjectPlace.hpp b/apps/openmw-mp/processors/world/ProcessorObjectPlace.hpp index 9f0d1dc42..1e95ab34e 100644 --- a/apps/openmw-mp/processors/world/ProcessorObjectPlace.hpp +++ b/apps/openmw-mp/processors/world/ProcessorObjectPlace.hpp @@ -18,10 +18,8 @@ namespace mwmp { LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received %s from %s", strPacketID.c_str(), player->npc.mName.c_str()); - for (unsigned int i = 0; i < event.worldObjectCount; i++) - { - event.worldObjects.at(i).mpNum = mwmp::Networking::getPtr()->incrementMpNum(); - } + for (auto & object : event.worldObjects) + object.mpNum = mwmp::Networking::getPtr()->incrementMpNum(); // Send this packet back to the original sender with the mpNum generation from above, // then send it to the other players diff --git a/apps/openmw-mp/processors/world/ProcessorObjectSpawn.hpp b/apps/openmw-mp/processors/world/ProcessorObjectSpawn.hpp index 3b906731a..a183edffb 100644 --- a/apps/openmw-mp/processors/world/ProcessorObjectSpawn.hpp +++ b/apps/openmw-mp/processors/world/ProcessorObjectSpawn.hpp @@ -18,10 +18,8 @@ namespace mwmp { LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received %s from %s", strPacketID.c_str(), player->npc.mName.c_str()); - for (unsigned int i = 0; i < event.worldObjectCount; i++) - { - event.worldObjects.at(i).mpNum = mwmp::Networking::getPtr()->incrementMpNum(); - } + for (auto & object : event.worldObjects) + object.mpNum = mwmp::Networking::getPtr()->incrementMpNum(); // Send this packet back to the original sender with the mpNum generation from above, // then send it to the other players diff --git a/components/openmw-mp/Base/BaseActor.hpp b/components/openmw-mp/Base/BaseActor.hpp index be922a65c..e7af6b689 100644 --- a/components/openmw-mp/Base/BaseActor.hpp +++ b/components/openmw-mp/Base/BaseActor.hpp @@ -59,8 +59,6 @@ namespace mwmp std::vector> baseActors; - unsigned int count; - ESM::Cell cell; unsigned char action; // 0 - Clear and set in entirety, 1 - Add item, 2 - Remove item, 3 - Request items diff --git a/components/openmw-mp/Base/BaseEvent.hpp b/components/openmw-mp/Base/BaseEvent.hpp index 6adb60b7a..38325c321 100644 --- a/components/openmw-mp/Base/BaseEvent.hpp +++ b/components/openmw-mp/Base/BaseEvent.hpp @@ -82,7 +82,6 @@ namespace mwmp RakNet::RakNetGUID guid; std::vector worldObjects; - unsigned int worldObjectCount; ESM::Cell cell; diff --git a/components/openmw-mp/Packets/Actor/ActorPacket.cpp b/components/openmw-mp/Packets/Actor/ActorPacket.cpp index 4692769a4..7dfd2bccf 100644 --- a/components/openmw-mp/Packets/Actor/ActorPacket.cpp +++ b/components/openmw-mp/Packets/Actor/ActorPacket.cpp @@ -25,23 +25,13 @@ void ActorPacket::Packet(RakNet::BitStream *bs, bool send) if (!PacketHeader(bs, send)) return; - BaseActor *actor; - - for (unsigned int i = 0; i < actorList->count; i++) + for(auto &actor : actorList->baseActors) { - if (send) - actor = actorList->baseActors.at(i).get(); - else - actor = new BaseActor(); - RW(actor->refNumIndex, send); RW(actor->mpNum, send); - Actor(*actor, send); - - if (!send) - actorList->baseActors.push_back(std::shared_ptr(actor)); } + } bool ActorPacket::PacketHeader(RakNet::BitStream *bs, bool send) @@ -51,14 +41,19 @@ bool ActorPacket::PacketHeader(RakNet::BitStream *bs, bool send) RW(actorList->cell.mData, send, true); RW(actorList->cell.mName, send, true); + uint32_t actorCount; if (send) - actorList->count = (unsigned int)(actorList->baseActors.size()); - else - actorList->baseActors.clear(); + actorCount = (uint32_t)(actorList->baseActors.size()); + + RW(actorCount, send); - RW(actorList->count, send); + if(!send) + { + actorList->baseActors.clear(); + actorList->baseActors.resize(actorCount, std::make_shared()); + } - if (actorList->count > maxActors) + if (actorCount > maxActors) { actorList->isValid = false; return false; diff --git a/components/openmw-mp/Packets/Actor/PacketActorList.cpp b/components/openmw-mp/Packets/Actor/PacketActorList.cpp index d5e4176cb..4ef034aab 100644 --- a/components/openmw-mp/Packets/Actor/PacketActorList.cpp +++ b/components/openmw-mp/Packets/Actor/PacketActorList.cpp @@ -15,15 +15,8 @@ void PacketActorList::Packet(RakNet::BitStream *bs, bool send) RW(actorList->action, send); - BaseActor *actor; - - for (unsigned int i = 0; i < actorList->count; i++) + for(auto &actor : actorList->baseActors) { - if (send) - actor = actorList->baseActors.at(i).get(); - else - actor = new BaseActor(); - RW(actor->refId, send); RW(actor->refNumIndex, send); RW(actor->mpNum, send); @@ -33,8 +26,5 @@ void PacketActorList::Packet(RakNet::BitStream *bs, bool send) actorList->isValid = false; return; } - - if (!send) - actorList->baseActors.push_back(std::shared_ptr(actor)); } } diff --git a/components/openmw-mp/Packets/World/WorldPacket.cpp b/components/openmw-mp/Packets/World/WorldPacket.cpp index da37dcd58..5b28e044e 100644 --- a/components/openmw-mp/Packets/World/WorldPacket.cpp +++ b/components/openmw-mp/Packets/World/WorldPacket.cpp @@ -36,14 +36,14 @@ bool WorldPacket::PacketHeader(RakNet::BitStream *bs, bool send) { BasePacket::Packet(bs, send); + uint32_t worldObjectCount; + if (send) - event->worldObjectCount = (unsigned int)(event->worldObjects.size()); - else - event->worldObjects.clear(); + worldObjectCount = (uint32_t) (event->worldObjects.size()); - RW(event->worldObjectCount, send); + RW(worldObjectCount, send); - if (event->worldObjectCount > maxObjects) + if (worldObjectCount > maxObjects) { event->isValid = false; return false; @@ -51,7 +51,8 @@ bool WorldPacket::PacketHeader(RakNet::BitStream *bs, bool send) if (!send) { - event->worldObjects.resize(event->worldObjectCount); + event->worldObjects.clear(); + event->worldObjects.resize(worldObjectCount); } if (hasCellData)