diff --git a/apps/openmw-mp/ProcessorInitializer.cpp b/apps/openmw-mp/ProcessorInitializer.cpp index 4c56ed362..427625a70 100644 --- a/apps/openmw-mp/ProcessorInitializer.cpp +++ b/apps/openmw-mp/ProcessorInitializer.cpp @@ -27,6 +27,7 @@ #include "ActorProcessor.hpp" #include "processors/actor/ProcessorActorList.hpp" #include "processors/actor/ProcessorActorAuthority.hpp" +#include "processors/actor/ProcessorActorPosition.hpp" #include "processors/actor/ProcessorActorTest.hpp" #include "WorldProcessor.hpp" #include "processors/world/ProcessorContainer.hpp" @@ -73,6 +74,7 @@ void ProcessorInitializer() ActorProcessor::AddProcessor(new ProcessorActorList()); ActorProcessor::AddProcessor(new ProcessorActorAuthority()); + ActorProcessor::AddProcessor(new ProcessorActorPosition()); ActorProcessor::AddProcessor(new ProcessorActorTest()); WorldProcessor::AddProcessor(new ProcessorContainer()); diff --git a/apps/openmw-mp/processors/actor/ProcessorActorPosition.hpp b/apps/openmw-mp/processors/actor/ProcessorActorPosition.hpp new file mode 100644 index 000000000..9e3c8732b --- /dev/null +++ b/apps/openmw-mp/processors/actor/ProcessorActorPosition.hpp @@ -0,0 +1,29 @@ +#ifndef OPENMW_PROCESSORACTORPOSITION_HPP +#define OPENMW_PROCESSORACTORPOSITION_HPP + +#include "apps/openmw-mp/ActorProcessor.hpp" + +namespace mwmp +{ + class ProcessorActorPosition : public ActorProcessor + { + public: + ProcessorActorPosition() + { + BPP_INIT(ID_ACTOR_POSITION) + } + + void Do(ActorPacket &packet, Player &player, BaseActorList &actorList) override + { + // Send only to players who have the cell loaded + Cell *serverCell = CellController::get()->getCell(&actorList.cell); + + if (serverCell != nullptr) + serverCell->sendToLoaded(&packet, &actorList); + + //Script::Call(player.getId(), actorList.cell.getDescription().c_str()); + } + }; +} + +#endif //OPENMW_PROCESSORACTORPOSITION_HPP diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 6976a86cc..2da12cfa3 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -167,7 +167,8 @@ add_component_dir (openmw-mp Packets/Player/PacketGUIBoxes Packets/Player/PacketTime - Packets/Actor/PacketActorList Packets/Actor/PacketActorAuthority Packets/Actor/PacketActorTest + Packets/Actor/PacketActorList Packets/Actor/PacketActorAuthority Packets/Actor/PacketActorPosition + Packets/Actor/PacketActorTest Packets/World/PacketObjectDelete Packets/World/PacketObjectPlace Packets/World/PacketObjectScale Packets/World/PacketObjectLock Packets/World/PacketObjectUnlock Packets/World/PacketObjectMove diff --git a/components/openmw-mp/Controllers/ActorPacketController.cpp b/components/openmw-mp/Controllers/ActorPacketController.cpp index e94a5ff55..dacbe7792 100644 --- a/components/openmw-mp/Controllers/ActorPacketController.cpp +++ b/components/openmw-mp/Controllers/ActorPacketController.cpp @@ -4,6 +4,7 @@ #include "../Packets/Actor/PacketActorList.hpp" #include "../Packets/Actor/PacketActorAuthority.hpp" +#include "../Packets/Actor/PacketActorPosition.hpp" #include "../Packets/Actor/PacketActorTest.hpp" #include "ActorPacketController.hpp" @@ -20,6 +21,7 @@ mwmp::ActorPacketController::ActorPacketController(RakNet::RakPeerInterface *pee { AddPacket(&packets, peer); AddPacket(&packets, peer); + AddPacket(&packets, peer); AddPacket(&packets, peer); } diff --git a/components/openmw-mp/NetworkMessages.hpp b/components/openmw-mp/NetworkMessages.hpp index 91e98398f..ea91294d8 100644 --- a/components/openmw-mp/NetworkMessages.hpp +++ b/components/openmw-mp/NetworkMessages.hpp @@ -41,6 +41,7 @@ enum GameMessages ID_ACTOR_LIST, ID_ACTOR_AUTHORITY, + ID_ACTOR_POSITION, ID_ACTOR_TEST, ID_OBJECT_PLACE, diff --git a/components/openmw-mp/Packets/Actor/PacketActorPosition.cpp b/components/openmw-mp/Packets/Actor/PacketActorPosition.cpp new file mode 100644 index 000000000..2f7ec17fa --- /dev/null +++ b/components/openmw-mp/Packets/Actor/PacketActorPosition.cpp @@ -0,0 +1,47 @@ +#include +#include +#include "PacketActorPosition.hpp" + +using namespace mwmp; + +PacketActorPosition::PacketActorPosition(RakNet::RakPeerInterface *peer) : ActorPacket(peer) +{ + packetID = ID_ACTOR_POSITION; +} + +void PacketActorPosition::Packet(RakNet::BitStream *bs, bool send) +{ + ActorPacket::Packet(bs, send); + + if (!send) + actorList->baseActors.clear(); + else + actorList->count = (unsigned int)(actorList->baseActors.size()); + + RW(actorList->count, send); + + RW(actorList->cell.mData.mFlags, send); + RW(actorList->cell.mData.mX, send); + RW(actorList->cell.mData.mY, send); + RW(actorList->cell.mName, send); + + 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); + RW(actor.mpNum, send); + RW(actor.position, send); + + if (!send) + { + actorList->baseActors.push_back(actor); + } + } +} diff --git a/components/openmw-mp/Packets/Actor/PacketActorPosition.hpp b/components/openmw-mp/Packets/Actor/PacketActorPosition.hpp new file mode 100644 index 000000000..3ea19fb3b --- /dev/null +++ b/components/openmw-mp/Packets/Actor/PacketActorPosition.hpp @@ -0,0 +1,17 @@ +#ifndef OPENMW_PACKETACTORPOSITION_HPP +#define OPENMW_PACKETACTORPOSITION_HPP + +#include + +namespace mwmp +{ + class PacketActorPosition : public ActorPacket + { + public: + PacketActorPosition(RakNet::RakPeerInterface *peer); + + virtual void Packet(RakNet::BitStream *bs, bool send); + }; +} + +#endif //OPENMW_PACKETACTORPOSITION_HPP