Create and start using WorldEvent class

pull/78/head
David Cernat 8 years ago
parent a42d5f2429
commit b2845cd17c

@ -18,6 +18,7 @@
#include "../mwstate/statemanagerimp.hpp"
#include <components/openmw-mp/Log.hpp>
#include <components/openmw-mp/Version.hpp>
#include <components/openmw-mp/Base/WorldEvent.hpp>
#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)

@ -48,6 +48,8 @@ namespace mwmp
bool isConnected();
WorldEvent *createWorldEvent();
private:
bool connected;
RakNet::RakPeerInterface *peer;

@ -17,6 +17,7 @@
#include <components/sceneutil/positionattitudetransform.hpp>
#include <components/openmw-mp/Base/WorldEvent.hpp>
#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);

@ -0,0 +1,26 @@
#ifndef OPENMW_WORLDEVENT_HPP
#define OPENMW_WORLDEVENT_HPP
#include <RakNetTypes.h>
namespace mwmp
{
class WorldEvent
{
public:
WorldEvent(RakNet::RakNetGUID guid) : guid(guid)
{
}
WorldEvent()
{
}
RakNet::RakNetGUID guid;
};
}
#endif //OPENMW_WORLDEVENT_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()
{

@ -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);
}

@ -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);
};
}

@ -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)

@ -5,7 +5,7 @@
#include <RakNetTypes.h>
#include <BitStream.h>
#include <PacketPriority.h>
#include <components/openmw-mp/Base/BasePlayer.hpp>
#include <components/openmw-mp/Base/WorldEvent.hpp>
#include <components/openmw-mp/Packets/BasePacket.hpp>
@ -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;
};
}

Loading…
Cancel
Save