forked from mirror/openmw-tes3mp
Create and start using WorldEvent class
This commit is contained in:
parent
a42d5f2429
commit
b2845cd17c
9 changed files with 58 additions and 22 deletions
|
@ -18,6 +18,7 @@
|
||||||
#include "../mwstate/statemanagerimp.hpp"
|
#include "../mwstate/statemanagerimp.hpp"
|
||||||
#include <components/openmw-mp/Log.hpp>
|
#include <components/openmw-mp/Log.hpp>
|
||||||
#include <components/openmw-mp/Version.hpp>
|
#include <components/openmw-mp/Version.hpp>
|
||||||
|
#include <components/openmw-mp/Base/WorldEvent.hpp>
|
||||||
#include "DedicatedPlayer.hpp"
|
#include "DedicatedPlayer.hpp"
|
||||||
#include "Main.hpp"
|
#include "Main.hpp"
|
||||||
|
|
||||||
|
@ -635,6 +636,11 @@ LocalPlayer *Networking::getLocalPlayer()
|
||||||
return mwmp::Main::get().getLocalPlayer();
|
return mwmp::Main::get().getLocalPlayer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WorldEvent *Networking::createWorldEvent()
|
||||||
|
{
|
||||||
|
return new WorldEvent(getLocalPlayer()->guid);
|
||||||
|
}
|
||||||
|
|
||||||
bool Networking::isDedicatedPlayer(const MWWorld::Ptr &ptr)
|
bool Networking::isDedicatedPlayer(const MWWorld::Ptr &ptr)
|
||||||
{
|
{
|
||||||
if (ptr.mRef == 0)
|
if (ptr.mRef == 0)
|
||||||
|
|
|
@ -48,6 +48,8 @@ namespace mwmp
|
||||||
|
|
||||||
bool isConnected();
|
bool isConnected();
|
||||||
|
|
||||||
|
WorldEvent *createWorldEvent();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool connected;
|
bool connected;
|
||||||
RakNet::RakPeerInterface *peer;
|
RakNet::RakPeerInterface *peer;
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
#include <components/sceneutil/positionattitudetransform.hpp>
|
#include <components/sceneutil/positionattitudetransform.hpp>
|
||||||
|
|
||||||
|
#include <components/openmw-mp/Base/WorldEvent.hpp>
|
||||||
#include "../mwmp/Main.hpp"
|
#include "../mwmp/Main.hpp"
|
||||||
|
|
||||||
#include "../mwbase/environment.hpp"
|
#include "../mwbase/environment.hpp"
|
||||||
|
@ -1105,7 +1106,8 @@ namespace MWWorld
|
||||||
&& mWorldScene->getActiveCells().find(ptr.getCell()) != mWorldScene->getActiveCells().end()
|
&& mWorldScene->getActiveCells().find(ptr.getCell()) != mWorldScene->getActiveCells().end()
|
||||||
&& ptr.getRefData().isEnabled())
|
&& 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);
|
mWorldScene->removeObjectFromScene (ptr);
|
||||||
mLocalScripts.remove (ptr);
|
mLocalScripts.remove (ptr);
|
||||||
|
|
26
components/openmw-mp/Base/WorldEvent.hpp
Normal file
26
components/openmw-mp/Base/WorldEvent.hpp
Normal file
|
@ -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 Send(BasePlayer *player, RakNet::AddressOrGUID destination);
|
||||||
virtual void Read(BasePlayer *player);
|
virtual void Read(BasePlayer *player);
|
||||||
|
|
||||||
virtual void RequestData(RakNet::RakNetGUID player);
|
virtual void RequestData(RakNet::RakNetGUID guid);
|
||||||
|
|
||||||
static size_t headerSize()
|
static size_t headerSize()
|
||||||
{
|
{
|
||||||
|
|
|
@ -8,7 +8,7 @@ PacketObjectRemoval::PacketObjectRemoval(RakNet::RakPeerInterface *peer) : World
|
||||||
packetID = ID_WORLD_OBJECT_REMOVAL;
|
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:
|
public:
|
||||||
PacketObjectRemoval(RakNet::RakPeerInterface *peer);
|
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;
|
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;
|
this->bs = bs;
|
||||||
|
|
||||||
if (send)
|
if (send)
|
||||||
{
|
{
|
||||||
bs->Write(packetID);
|
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();
|
bsSend->ResetWritePointer();
|
||||||
Packet(bsSend, player, true);
|
Packet(bsSend, event, true);
|
||||||
peer->Send(bsSend, priority, reliability, 0, destination, false);
|
peer->Send(bsSend, priority, reliability, 0, destination, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldPacket::Send(BasePlayer *player, bool toOther)
|
void WorldPacket::Send(WorldEvent *event, bool toOther)
|
||||||
{
|
{
|
||||||
bsSend->ResetWritePointer();
|
bsSend->ResetWritePointer();
|
||||||
Packet(bsSend, player, true);
|
Packet(bsSend, event, true);
|
||||||
peer->Send(bsSend, priority, reliability, 0, player->guid, toOther);
|
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)
|
void WorldPacket::RequestData(RakNet::RakNetGUID guid)
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
#include <RakNetTypes.h>
|
#include <RakNetTypes.h>
|
||||||
#include <BitStream.h>
|
#include <BitStream.h>
|
||||||
#include <PacketPriority.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>
|
#include <components/openmw-mp/Packets/BasePacket.hpp>
|
||||||
|
|
||||||
|
@ -19,13 +19,13 @@ namespace mwmp
|
||||||
|
|
||||||
~WorldPacket();
|
~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(WorldEvent *event, bool toOtherPlayers = true);
|
||||||
virtual void Send(BasePlayer *player, RakNet::AddressOrGUID destination);
|
virtual void Send(WorldEvent *event, RakNet::AddressOrGUID destination);
|
||||||
virtual void Read(BasePlayer *player);
|
virtual void Read(WorldEvent *event);
|
||||||
|
|
||||||
virtual void RequestData(RakNet::RakNetGUID player);
|
virtual void RequestData(RakNet::RakNetGUID guid);
|
||||||
|
|
||||||
static size_t headerSize()
|
static size_t headerSize()
|
||||||
{
|
{
|
||||||
|
@ -38,7 +38,7 @@ namespace mwmp
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
BasePlayer *player;
|
WorldEvent *event;
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue