[Client] Simplify Processors

pull/176/merge
Koncord 8 years ago
parent cc2250815d
commit 67aba35d37

@ -98,7 +98,7 @@ add_openmw_dir (mwbase
add_openmw_dir (mwmp Main Networking LocalPlayer DedicatedPlayer LocalActor DedicatedActor ActorList WorldEvent Cell add_openmw_dir (mwmp Main Networking LocalPlayer DedicatedPlayer LocalActor DedicatedActor ActorList WorldEvent Cell
CellController MechanicsHelper GUIChat GUILogin GUIController PlayerMarkerCollection GUIDialogList WorldController CellController MechanicsHelper GUIChat GUILogin GUIController PlayerMarkerCollection GUIDialogList WorldController
PlayerProcessor WorldProcessor ActorProcessor ProcessorInitializer) BaseClientPacketProcessor PlayerProcessor WorldProcessor ActorProcessor ProcessorInitializer)
# Main executable # Main executable

@ -10,9 +10,6 @@
using namespace mwmp; using namespace mwmp;
ActorProcessor::processors_t ActorProcessor::processors; ActorProcessor::processors_t ActorProcessor::processors;
RakNet::RakNetGUID ActorProcessor::guid;
RakNet::SystemAddress ActorProcessor::serverAddr;
bool ActorProcessor::request;
bool ActorProcessor::Process(RakNet::Packet &packet, ActorList &actorList) bool ActorProcessor::Process(RakNet::Packet &packet, ActorList &actorList)
{ {
@ -28,6 +25,7 @@ bool ActorProcessor::Process(RakNet::Packet &packet, ActorList &actorList)
{ {
if(processor.first == packet.data[0]) if(processor.first == packet.data[0])
{ {
myGuid = Main::get().getLocalPlayer()->guid;
request = packet.length == myPacket->headerSize(); request = packet.length == myPacket->headerSize();
if(!request && !processor.second->avoidReading) if(!request && !processor.second->avoidReading)
@ -52,9 +50,4 @@ void ActorProcessor::AddProcessor(mwmp::ActorProcessor *processor)
processor->className + " and " + p.second->className); processor->className + " and " + p.second->className);
} }
processors.insert(processors_t::value_type(processor->GetPacketID(), boost::shared_ptr<ActorProcessor>(processor))); processors.insert(processors_t::value_type(processor->GetPacketID(), boost::shared_ptr<ActorProcessor>(processor)));
} }
LocalPlayer *ActorProcessor::getLocalPlayer()
{
return Main::get().getLocalPlayer();
}

@ -10,41 +10,25 @@
#include <components/openmw-mp/Log.hpp> #include <components/openmw-mp/Log.hpp>
#include <components/openmw-mp/NetworkMessages.hpp> #include <components/openmw-mp/NetworkMessages.hpp>
#include <components/openmw-mp/Base/BasePacketProcessor.hpp>
#include <components/openmw-mp/Packets/Actor/ActorPacket.hpp> #include <components/openmw-mp/Packets/Actor/ActorPacket.hpp>
#include "WorldEvent.hpp" #include "WorldEvent.hpp"
#include "LocalPlayer.hpp"
#include "DedicatedPlayer.hpp"
#include "ActorList.hpp" #include "ActorList.hpp"
#include "BaseClientPacketProcessor.hpp"
namespace mwmp namespace mwmp
{ {
class ActorProcessor : public BasePacketProcessor class ActorProcessor : public BaseClientPacketProcessor
{ {
public: public:
virtual void Do(ActorPacket &packet, ActorList &actorList) = 0; virtual void Do(ActorPacket &packet, ActorList &actorList) = 0;
static bool Process(RakNet::Packet &packet, ActorList &actorList); static bool Process(RakNet::Packet &packet, ActorList &actorList);
static void AddProcessor(ActorProcessor *processor); static void AddProcessor(ActorProcessor *processor);
static void SetServerAddr(RakNet::SystemAddress addr)
{
serverAddr = addr;
}
typedef boost::unordered_map<unsigned char, boost::shared_ptr<ActorProcessor> > processors_t; typedef boost::unordered_map<unsigned char, boost::shared_ptr<ActorProcessor> > processors_t;
protected:
inline bool isRequest()
{
return request;
}
LocalPlayer *getLocalPlayer();
protected:
static RakNet::RakNetGUID guid;
static RakNet::SystemAddress serverAddr;
private: private:
static processors_t processors; static processors_t processors;
static bool request;
}; };
} }

@ -0,0 +1,18 @@
//
// Created by koncord on 18.04.17.
//
#include "BaseClientPacketProcessor.hpp"
#include "Main.hpp"
using namespace mwmp;
RakNet::RakNetGUID BaseClientPacketProcessor::guid;
RakNet::RakNetGUID BaseClientPacketProcessor::myGuid;
RakNet::SystemAddress BaseClientPacketProcessor::serverAddr;
bool BaseClientPacketProcessor::request;
LocalPlayer *BaseClientPacketProcessor::getLocalPlayer()
{
return Main::get().getLocalPlayer();
}

@ -0,0 +1,43 @@
//
// Created by koncord on 18.04.17.
//
#ifndef OPENMW_BASECLIENTPACKETPROCESSOR_HPP
#define OPENMW_BASECLIENTPACKETPROCESSOR_HPP
#include <components/openmw-mp/Base/BasePacketProcessor.hpp>
#include "LocalPlayer.hpp"
#include "DedicatedPlayer.hpp"
namespace mwmp
{
class BaseClientPacketProcessor : public BasePacketProcessor
{
public:
static void SetServerAddr(RakNet::SystemAddress addr)
{
serverAddr = addr;
}
protected:
inline bool isRequest()
{
return request;
}
inline bool isLocal()
{
return guid == myGuid;
}
LocalPlayer *getLocalPlayer();
protected:
static RakNet::RakNetGUID guid, myGuid;
static RakNet::SystemAddress serverAddr;
static bool request;
};
}
#endif //OPENMW_BASECLIENTPACKETPROCESSOR_HPP

@ -153,9 +153,7 @@ void Networking::connect(const std::string &ip, unsigned short port, std::vector
case ID_CONNECTION_REQUEST_ACCEPTED: case ID_CONNECTION_REQUEST_ACCEPTED:
{ {
serverAddr = packet->systemAddress; serverAddr = packet->systemAddress;
PlayerProcessor::SetServerAddr(packet->systemAddress); BaseClientPacketProcessor::SetServerAddr(packet->systemAddress);
WorldProcessor::SetServerAddr(packet->systemAddress);
ActorProcessor::SetServerAddr(packet->systemAddress);
connected = true; connected = true;
queue = false; queue = false;

@ -12,10 +12,6 @@
using namespace mwmp; using namespace mwmp;
PlayerProcessor::processors_t PlayerProcessor::processors; PlayerProcessor::processors_t PlayerProcessor::processors;
RakNet::RakNetGUID PlayerProcessor::myGuid;
RakNet::RakNetGUID PlayerProcessor::guid;
RakNet::SystemAddress PlayerProcessor::serverAddr;
bool PlayerProcessor::request;
void PlayerProcessor::AddProcessor(PlayerProcessor *processor) void PlayerProcessor::AddProcessor(PlayerProcessor *processor)
{ {
@ -66,8 +62,3 @@ bool PlayerProcessor::Process(RakNet::Packet &packet)
} }
return false; return false;
} }
LocalPlayer *PlayerProcessor::getLocalPlayer()
{
return Main::get().getLocalPlayer();
}

@ -10,46 +10,25 @@
#include <components/openmw-mp/Log.hpp> #include <components/openmw-mp/Log.hpp>
#include <components/openmw-mp/NetworkMessages.hpp> #include <components/openmw-mp/NetworkMessages.hpp>
#include <components/openmw-mp/Base/BasePacketProcessor.hpp>
#include <components/openmw-mp/Packets/Player/PlayerPacket.hpp> #include <components/openmw-mp/Packets/Player/PlayerPacket.hpp>
#include "LocalPlayer.hpp" #include "LocalPlayer.hpp"
#include "DedicatedPlayer.hpp" #include "DedicatedPlayer.hpp"
#include "BaseClientPacketProcessor.hpp"
namespace mwmp namespace mwmp
{ {
class PlayerProcessor : public BasePacketProcessor class PlayerProcessor : public BaseClientPacketProcessor
{ {
public: public:
virtual void Do(PlayerPacket &packet, BasePlayer *player) = 0; virtual void Do(PlayerPacket &packet, BasePlayer *player) = 0;
static bool Process(RakNet::Packet &packet); static bool Process(RakNet::Packet &packet);
static void AddProcessor(PlayerProcessor *processor); static void AddProcessor(PlayerProcessor *processor);
static void SetServerAddr(RakNet::SystemAddress addr)
{
serverAddr = addr;
}
typedef boost::unordered_map<unsigned char, boost::shared_ptr<PlayerProcessor> > processors_t; typedef boost::unordered_map<unsigned char, boost::shared_ptr<PlayerProcessor> > processors_t;
//typedef std::unordered_map<unsigned char, std::unique_ptr<PlayerProcessor> > processors_t; //typedef std::unordered_map<unsigned char, std::unique_ptr<PlayerProcessor> > processors_t;
private: private:
static processors_t processors; static processors_t processors;
static bool request;
protected:
inline bool isRequest()
{
return request;
}
inline bool isLocal()
{
return guid == myGuid;
}
LocalPlayer *getLocalPlayer();
protected:
static RakNet::RakNetGUID myGuid;
static RakNet::RakNetGUID guid;
static RakNet::SystemAddress serverAddr;
}; };
} }

@ -10,9 +10,6 @@
using namespace mwmp; using namespace mwmp;
WorldProcessor::processors_t WorldProcessor::processors; WorldProcessor::processors_t WorldProcessor::processors;
RakNet::RakNetGUID WorldProcessor::guid;
RakNet::SystemAddress WorldProcessor::serverAddr;
bool WorldProcessor::request;
bool WorldProcessor::Process(RakNet::Packet &packet, WorldEvent &event) bool WorldProcessor::Process(RakNet::Packet &packet, WorldEvent &event)
{ {
@ -28,6 +25,7 @@ bool WorldProcessor::Process(RakNet::Packet &packet, WorldEvent &event)
{ {
if(processor.first == packet.data[0]) if(processor.first == packet.data[0])
{ {
myGuid = Main::get().getLocalPlayer()->guid;
request = packet.length == myPacket->headerSize(); request = packet.length == myPacket->headerSize();
if(!request && !processor.second->avoidReading) if(!request && !processor.second->avoidReading)
@ -52,9 +50,4 @@ void WorldProcessor::AddProcessor(mwmp::WorldProcessor *processor)
processor->className + " and " + p.second->className); processor->className + " and " + p.second->className);
} }
processors.insert(processors_t::value_type(processor->GetPacketID(), boost::shared_ptr<WorldProcessor>(processor))); processors.insert(processors_t::value_type(processor->GetPacketID(), boost::shared_ptr<WorldProcessor>(processor)));
} }
LocalPlayer *WorldProcessor::getLocalPlayer()
{
return Main::get().getLocalPlayer();
}

@ -10,40 +10,26 @@
#include <components/openmw-mp/Log.hpp> #include <components/openmw-mp/Log.hpp>
#include <components/openmw-mp/NetworkMessages.hpp> #include <components/openmw-mp/NetworkMessages.hpp>
#include <components/openmw-mp/Base/BasePacketProcessor.hpp>
#include <components/openmw-mp/Packets/World/WorldPacket.hpp> #include <components/openmw-mp/Packets/World/WorldPacket.hpp>
#include "WorldEvent.hpp" #include "WorldEvent.hpp"
#include "LocalPlayer.hpp" #include "LocalPlayer.hpp"
#include "DedicatedPlayer.hpp" #include "DedicatedPlayer.hpp"
#include "BaseClientPacketProcessor.hpp"
namespace mwmp namespace mwmp
{ {
class WorldProcessor : public BasePacketProcessor class WorldProcessor : public BaseClientPacketProcessor
{ {
public: public:
virtual void Do(WorldPacket &packet, WorldEvent &event) = 0; virtual void Do(WorldPacket &packet, WorldEvent &event) = 0;
static bool Process(RakNet::Packet &packet, WorldEvent &event); static bool Process(RakNet::Packet &packet, WorldEvent &event);
static void AddProcessor(WorldProcessor *processor); static void AddProcessor(WorldProcessor *processor);
static void SetServerAddr(RakNet::SystemAddress addr)
{
serverAddr = addr;
}
typedef boost::unordered_map<unsigned char, boost::shared_ptr<WorldProcessor> > processors_t; typedef boost::unordered_map<unsigned char, boost::shared_ptr<WorldProcessor> > processors_t;
protected:
inline bool isRequest()
{
return request;
}
LocalPlayer *getLocalPlayer();
protected:
static RakNet::RakNetGUID guid;
static RakNet::SystemAddress serverAddr;
private: private:
static processors_t processors; static processors_t processors;
static bool request;
}; };
} }

Loading…
Cancel
Save