From b2845cd17ccb0c06e3eb2e6d1f023a356741473f Mon Sep 17 00:00:00 2001 From: David Cernat Date: Thu, 20 Oct 2016 14:28:19 +0300 Subject: [PATCH] Create and start using WorldEvent class --- apps/openmw/mwmp/Networking.cpp | 6 +++++ apps/openmw/mwmp/Networking.hpp | 2 ++ apps/openmw/mwworld/worldimp.cpp | 4 ++- components/openmw-mp/Base/WorldEvent.hpp | 26 +++++++++++++++++++ .../openmw-mp/Packets/Player/PlayerPacket.hpp | 2 +- .../Packets/World/PacketObjectRemoval.cpp | 4 +-- .../Packets/World/PacketObjectRemoval.hpp | 2 +- .../openmw-mp/Packets/World/WorldPacket.cpp | 20 +++++++------- .../openmw-mp/Packets/World/WorldPacket.hpp | 14 +++++----- 9 files changed, 58 insertions(+), 22 deletions(-) create mode 100644 components/openmw-mp/Base/WorldEvent.hpp diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index 46e9ab7c0..1fbcc8f14 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -18,6 +18,7 @@ #include "../mwstate/statemanagerimp.hpp" #include #include +#include #include "DedicatedPlayer.hpp" #include "Main.hpp" @@ -635,6 +636,11 @@ LocalPlayer *Networking::getLocalPlayer() return mwmp::Main::get().getLocalPlayer(); } +WorldEvent *Networking::createWorldEvent() +{ + return new WorldEvent(getLocalPlayer()->guid); +} + bool Networking::isDedicatedPlayer(const MWWorld::Ptr &ptr) { if (ptr.mRef == 0) diff --git a/apps/openmw/mwmp/Networking.hpp b/apps/openmw/mwmp/Networking.hpp index fff9703b2..9acfaf96c 100644 --- a/apps/openmw/mwmp/Networking.hpp +++ b/apps/openmw/mwmp/Networking.hpp @@ -48,6 +48,8 @@ namespace mwmp bool isConnected(); + WorldEvent *createWorldEvent(); + private: bool connected; RakNet::RakPeerInterface *peer; diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 267e88dfc..872471ebb 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -17,6 +17,7 @@ #include +#include #include "../mwmp/Main.hpp" #include "../mwbase/environment.hpp" @@ -1105,7 +1106,8 @@ namespace MWWorld && mWorldScene->getActiveCells().find(ptr.getCell()) != mWorldScene->getActiveCells().end() && ptr.getRefData().isEnabled()) { - mwmp::Main::get().getNetworking()->GetWorldPacket(ID_WORLD_OBJECT_REMOVAL)->Send(mwmp::Main::get().getLocalPlayer()); + mwmp::WorldEvent *event = mwmp::Main::get().getNetworking()->createWorldEvent(); + mwmp::Main::get().getNetworking()->GetWorldPacket(ID_WORLD_OBJECT_REMOVAL)->Send(event); mWorldScene->removeObjectFromScene (ptr); mLocalScripts.remove (ptr); diff --git a/components/openmw-mp/Base/WorldEvent.hpp b/components/openmw-mp/Base/WorldEvent.hpp new file mode 100644 index 000000000..e70427b4c --- /dev/null +++ b/components/openmw-mp/Base/WorldEvent.hpp @@ -0,0 +1,26 @@ +#ifndef OPENMW_WORLDEVENT_HPP +#define OPENMW_WORLDEVENT_HPP + +#include + +namespace mwmp +{ + class WorldEvent + { + public: + + WorldEvent(RakNet::RakNetGUID guid) : guid(guid) + { + + } + + WorldEvent() + { + + } + + RakNet::RakNetGUID guid; + }; +} + +#endif //OPENMW_WORLDEVENT_HPP diff --git a/components/openmw-mp/Packets/Player/PlayerPacket.hpp b/components/openmw-mp/Packets/Player/PlayerPacket.hpp index 54c085db9..8d4953183 100644 --- a/components/openmw-mp/Packets/Player/PlayerPacket.hpp +++ b/components/openmw-mp/Packets/Player/PlayerPacket.hpp @@ -25,7 +25,7 @@ namespace mwmp virtual void Send(BasePlayer *player, RakNet::AddressOrGUID destination); virtual void Read(BasePlayer *player); - virtual void RequestData(RakNet::RakNetGUID player); + virtual void RequestData(RakNet::RakNetGUID guid); static size_t headerSize() { diff --git a/components/openmw-mp/Packets/World/PacketObjectRemoval.cpp b/components/openmw-mp/Packets/World/PacketObjectRemoval.cpp index a13dc548b..2c4e02297 100644 --- a/components/openmw-mp/Packets/World/PacketObjectRemoval.cpp +++ b/components/openmw-mp/Packets/World/PacketObjectRemoval.cpp @@ -8,7 +8,7 @@ PacketObjectRemoval::PacketObjectRemoval(RakNet::RakPeerInterface *peer) : World packetID = ID_WORLD_OBJECT_REMOVAL; } -void PacketObjectRemoval::Packet(RakNet::BitStream *bs, BasePlayer *player, bool send) +void PacketObjectRemoval::Packet(RakNet::BitStream *bs, WorldEvent *event, bool send) { - WorldPacket::Packet(bs, player, send); + WorldPacket::Packet(bs, event, send); } diff --git a/components/openmw-mp/Packets/World/PacketObjectRemoval.hpp b/components/openmw-mp/Packets/World/PacketObjectRemoval.hpp index 2469dee37..1046ad0e0 100644 --- a/components/openmw-mp/Packets/World/PacketObjectRemoval.hpp +++ b/components/openmw-mp/Packets/World/PacketObjectRemoval.hpp @@ -10,7 +10,7 @@ namespace mwmp public: PacketObjectRemoval(RakNet::RakPeerInterface *peer); - virtual void Packet(RakNet::BitStream *bs, BasePlayer *player, bool send); + virtual void Packet(RakNet::BitStream *bs, WorldEvent *event, bool send); }; } diff --git a/components/openmw-mp/Packets/World/WorldPacket.cpp b/components/openmw-mp/Packets/World/WorldPacket.cpp index 7bc634d83..543c6c5d6 100644 --- a/components/openmw-mp/Packets/World/WorldPacket.cpp +++ b/components/openmw-mp/Packets/World/WorldPacket.cpp @@ -5,15 +5,15 @@ using namespace mwmp; -void WorldPacket::Packet(RakNet::BitStream *bs, BasePlayer *player, bool send) +void WorldPacket::Packet(RakNet::BitStream *bs, WorldEvent *event, bool send) { - this->player = player; + this->event = event; this->bs = bs; if (send) { bs->Write(packetID); - bs->Write(player->guid); + bs->Write(event->guid); } } @@ -30,23 +30,23 @@ WorldPacket::~WorldPacket() } -void WorldPacket::Send(BasePlayer *player, RakNet::AddressOrGUID destination) +void WorldPacket::Send(WorldEvent *event, RakNet::AddressOrGUID destination) { bsSend->ResetWritePointer(); - Packet(bsSend, player, true); + Packet(bsSend, event, true); peer->Send(bsSend, priority, reliability, 0, destination, false); } -void WorldPacket::Send(BasePlayer *player, bool toOther) +void WorldPacket::Send(WorldEvent *event, bool toOther) { bsSend->ResetWritePointer(); - Packet(bsSend, player, true); - peer->Send(bsSend, priority, reliability, 0, player->guid, toOther); + Packet(bsSend, event, true); + peer->Send(bsSend, priority, reliability, 0, event->guid, toOther); } -void WorldPacket::Read(BasePlayer *player) +void WorldPacket::Read(WorldEvent *event) { - Packet(bsRead, player, false); + Packet(bsRead, event, false); } void WorldPacket::RequestData(RakNet::RakNetGUID guid) diff --git a/components/openmw-mp/Packets/World/WorldPacket.hpp b/components/openmw-mp/Packets/World/WorldPacket.hpp index 9dc0fe8f8..8ad187870 100644 --- a/components/openmw-mp/Packets/World/WorldPacket.hpp +++ b/components/openmw-mp/Packets/World/WorldPacket.hpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include @@ -19,13 +19,13 @@ namespace mwmp ~WorldPacket(); - virtual void Packet(RakNet::BitStream *bs, BasePlayer *player, bool send); + virtual void Packet(RakNet::BitStream *bs, WorldEvent *event, bool send); - virtual void Send(BasePlayer *player, bool toOtherPlayers = true); - virtual void Send(BasePlayer *player, RakNet::AddressOrGUID destination); - virtual void Read(BasePlayer *player); + virtual void Send(WorldEvent *event, bool toOtherPlayers = true); + virtual void Send(WorldEvent *event, RakNet::AddressOrGUID destination); + virtual void Read(WorldEvent *event); - virtual void RequestData(RakNet::RakNetGUID player); + virtual void RequestData(RakNet::RakNetGUID guid); static size_t headerSize() { @@ -38,7 +38,7 @@ namespace mwmp } protected: - BasePlayer *player; + WorldEvent *event; }; }