[Client] Add ActorProcessor

pull/176/merge
Koncord 8 years ago
parent 29f9453554
commit 7ec897a829

@ -96,8 +96,9 @@ add_openmw_dir (mwbase
inputmanager windowmanager statemanager
)
add_openmw_dir (mwmp Main Networking LocalPlayer DedicatedPlayer LocalActor DedicatedActor ActorList WorldEvent Cell CellController MechanicsHelper GUIChat GUILogin
GUIController PlayerMarkerCollection GUIDialogList WorldController PlayerProcessor WorldProcessor ProcessorInitializer)
add_openmw_dir (mwmp Main Networking LocalPlayer DedicatedPlayer LocalActor DedicatedActor ActorList WorldEvent Cell
CellController MechanicsHelper GUIChat GUILogin GUIController PlayerMarkerCollection GUIDialogList WorldController
PlayerProcessor WorldProcessor ActorProcessor ProcessorInitializer)
# Main executable

@ -0,0 +1,60 @@
//
// Created by koncord on 18.04.17.
//
#include <boost/foreach.hpp>
#include "ActorProcessor.hpp"
#include "Networking.hpp"
#include "Main.hpp"
using namespace mwmp;
ActorProcessor::processors_t ActorProcessor::processors;
RakNet::RakNetGUID ActorProcessor::guid;
RakNet::SystemAddress ActorProcessor::serverAddr;
bool ActorProcessor::request;
bool ActorProcessor::Process(RakNet::Packet &packet, ActorList &actorList)
{
RakNet::BitStream bsIn(&packet.data[1], packet.length, false);
bsIn.Read(guid);
ActorPacket *myPacket = Main::get().getNetworking()->getActorPacket(packet.data[0]);
myPacket->setActorList(&actorList);
myPacket->SetReadStream(&bsIn);
BOOST_FOREACH(processors_t::value_type &processor, processors)
{
if(processor.first == packet.data[0])
{
request = packet.length == myPacket->headerSize();
if(!request && !processor.second->avoidReading)
{
myPacket->Read();
}
processor.second->Do(*myPacket, actorList);
return true;
}
}
return false;
}
void ActorProcessor::AddProcessor(mwmp::ActorProcessor *processor)
{
BOOST_FOREACH(processors_t::value_type &p, processors)
{
if(processor->packetID == p.first)
throw std::logic_error("processor " + p.second->strPacketID + " already registered. Check " +
processor->className + " and " + p.second->className);
}
processors.insert(processors_t::value_type(processor->GetPacketID(), boost::shared_ptr<ActorProcessor>(processor)));
}
LocalPlayer *ActorProcessor::getLocalPlayer()
{
return Main::get().getLocalPlayer();
}

@ -0,0 +1,52 @@
//
// Created by koncord on 18.04.17.
//
#ifndef OPENMW_ACTORPROCESSOR_HPP
#define OPENMW_ACTORPROCESSOR_HPP
#include <boost/unordered_map.hpp>
#include <boost/shared_ptr.hpp>
#include <components/openmw-mp/Log.hpp>
#include <components/openmw-mp/NetworkMessages.hpp>
#include <components/openmw-mp/Base/BasePacketProcessor.hpp>
#include <components/openmw-mp/Packets/Actor/ActorPacket.hpp>
#include "WorldEvent.hpp"
#include "LocalPlayer.hpp"
#include "DedicatedPlayer.hpp"
#include "ActorList.hpp"
namespace mwmp
{
class ActorProcessor : public BasePacketProcessor
{
public:
virtual void Do(ActorPacket &packet, ActorList &actorList) = 0;
static bool Process(RakNet::Packet &packet, ActorList &actorList);
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;
protected:
inline bool isRequest()
{
return request;
}
LocalPlayer *getLocalPlayer();
protected:
static RakNet::RakNetGUID guid;
static RakNet::SystemAddress serverAddr;
private:
static processors_t processors;
static bool request;
};
}
#endif //OPENMW_ACTORPROCESSOR_HPP
Loading…
Cancel
Save