1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-30 10:15:32 +00:00

[General] Use BaseActorLists in ActorPackets

This commit is contained in:
David Cernat 2017-04-09 16:32:44 +03:00
parent 1b714fbfa7
commit c52084a028
31 changed files with 346 additions and 265 deletions

View file

@ -5,7 +5,7 @@ using namespace mwmp;
ActorProcessor::processors_t ActorProcessor::processors; ActorProcessor::processors_t ActorProcessor::processors;
void ActorProcessor::Do(ActorPacket &packet, Player &player, BaseEvent &event) void ActorProcessor::Do(ActorPacket &packet, Player &player, BaseActorList &actorList)
{ {
packet.Send(true); packet.Send(true);
} }
@ -21,12 +21,12 @@ void ActorProcessor::AddProcessor(mwmp::ActorProcessor *processor) noexcept
processors.insert(processors_t::value_type(processor->GetPacketID(), processor)); processors.insert(processors_t::value_type(processor->GetPacketID(), processor));
} }
bool ActorProcessor::Process(RakNet::Packet &packet, BaseEvent &event) noexcept bool ActorProcessor::Process(RakNet::Packet &packet, BaseActorList &actorList) noexcept
{ {
// Clear our BaseEvent before loading new data in it // Clear our BaseActorList before loading new data in it
event.cell.blank(); actorList.cell.blank();
event.objectChanges.objects.clear(); actorList.baseActors.clear();
event.guid = packet.guid; actorList.guid = packet.guid;
for (auto &processor : processors) for (auto &processor : processors)
{ {
if (processor.first == packet.data[0]) if (processor.first == packet.data[0])
@ -34,12 +34,12 @@ bool ActorProcessor::Process(RakNet::Packet &packet, BaseEvent &event) noexcept
Player *player = Players::getPlayer(packet.guid); Player *player = Players::getPlayer(packet.guid);
ActorPacket *myPacket = Networking::get().getActorPacketController()->GetPacket(packet.data[0]); ActorPacket *myPacket = Networking::get().getActorPacketController()->GetPacket(packet.data[0]);
myPacket->setEvent(&event); myPacket->setActorList(&actorList);
if (!processor.second->avoidReading) if (!processor.second->avoidReading)
myPacket->Read(); myPacket->Read();
processor.second->Do(*myPacket, *player, event); processor.second->Do(*myPacket, *player, actorList);
return true; return true;
} }
} }

View file

@ -17,9 +17,9 @@ namespace mwmp
{ {
public: public:
virtual void Do(ActorPacket &packet, Player &player, BaseEvent &event); virtual void Do(ActorPacket &packet, Player &player, BaseActorList &actorList);
static bool Process(RakNet::Packet &packet, BaseEvent &event) noexcept; static bool Process(RakNet::Packet &packet, BaseActorList &actorList) noexcept;
static void AddProcessor(ActorProcessor *processor) noexcept; static void AddProcessor(ActorProcessor *processor) noexcept;
//typedef boost::unordered_map<unsigned char, boost::shared_ptr<ActorProcessor> > processors_t; //typedef boost::unordered_map<unsigned char, boost::shared_ptr<ActorProcessor> > processors_t;

View file

@ -51,7 +51,7 @@ Cell::TPlayers Cell::getPlayers() const
return players; return players;
} }
void Cell::sendToLoaded(mwmp::ActorPacket *actorPacket, mwmp::BaseEvent *baseEvent) const void Cell::sendToLoaded(mwmp::ActorPacket *actorPacket, mwmp::BaseActorList *baseActorList) const
{ {
if (players.empty()) if (players.empty())
return; return;
@ -66,9 +66,9 @@ void Cell::sendToLoaded(mwmp::ActorPacket *actorPacket, mwmp::BaseEvent *baseEve
for (auto pl : plList) for (auto pl : plList)
{ {
if (pl->guid == baseEvent->guid) continue; if (pl->guid == baseActorList->guid) continue;
actorPacket->setEvent(baseEvent); actorPacket->setActorList(baseActorList);
// Send the packet to this eligible guid // Send the packet to this eligible guid
actorPacket->Send(pl->guid); actorPacket->Send(pl->guid);

View file

@ -63,7 +63,7 @@ public:
void removePlayer(Player *player); void removePlayer(Player *player);
TPlayers getPlayers() const; TPlayers getPlayers() const;
void sendToLoaded(mwmp::ActorPacket *actorPacket, mwmp::BaseEvent *baseEvent) const; void sendToLoaded(mwmp::ActorPacket *actorPacket, mwmp::BaseActorList *baseActorList) const;
void sendToLoaded(mwmp::WorldPacket *worldPacket, mwmp::BaseEvent *baseEvent) const; void sendToLoaded(mwmp::WorldPacket *worldPacket, mwmp::BaseEvent *baseEvent) const;
std::string getDescription() const; std::string getDescription() const;

View file

@ -164,8 +164,8 @@ void Networking::processActorPacket(RakNet::Packet *packet)
if (!player->isHandshaked() || player->getLoadState() != Player::POSTLOADED) if (!player->isHandshaked() || player->getLoadState() != Player::POSTLOADED)
return; return;
if (!ActorProcessor::Process(*packet, baseEvent)) if (!ActorProcessor::Process(*packet, baseActorList))
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Unhandled WorldPacket with identifier %i has arrived", packet->data[0]); LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Unhandled ActorPacket with identifier %i has arrived", packet->data[0]);
} }
@ -311,6 +311,11 @@ WorldPacketController *Networking::getWorldPacketController() const
return worldPacketController; return worldPacketController;
} }
BaseActorList *Networking::getLastActorList()
{
return &baseActorList;
}
BaseEvent *Networking::getLastEvent() BaseEvent *Networking::getLastEvent()
{ {
return &baseEvent; return &baseEvent;

View file

@ -40,6 +40,7 @@ namespace mwmp
ActorPacketController *getActorPacketController() const; ActorPacketController *getActorPacketController() const;
WorldPacketController *getWorldPacketController() const; WorldPacketController *getWorldPacketController() const;
BaseActorList *getLastActorList();
BaseEvent *getLastEvent(); BaseEvent *getLastEvent();
int getCurrentMpNum(); int getCurrentMpNum();
@ -57,12 +58,15 @@ namespace mwmp
private: private:
std::string serverPassword; std::string serverPassword;
static Networking *sThis; static Networking *sThis;
BaseEvent baseEvent;
RakNet::RakPeerInterface *peer; RakNet::RakPeerInterface *peer;
RakNet::BitStream bsOut; RakNet::BitStream bsOut;
TPlayers *players; TPlayers *players;
MasterClient *mclient; MasterClient *mclient;
BaseActorList baseActorList;
BaseEvent baseEvent;
PlayerPacketController *playerPacketController; PlayerPacketController *playerPacketController;
ActorPacketController *actorPacketController; ActorPacketController *actorPacketController;
WorldPacketController *worldPacketController; WorldPacketController *worldPacketController;

View file

@ -9,7 +9,7 @@
using namespace mwmp; using namespace mwmp;
ActorList actorList; BaseActorList scriptActorList;
BaseActor tempActor; BaseActor tempActor;
void ActorFunctions::InitActorList(unsigned short pid) noexcept void ActorFunctions::InitActorList(unsigned short pid) noexcept
@ -17,12 +17,25 @@ void ActorFunctions::InitActorList(unsigned short pid) noexcept
Player *player; Player *player;
GET_PLAYER(pid, player, ); GET_PLAYER(pid, player, );
actorList.cell.blank(); scriptActorList.cell.blank();
actorList.baseActors.clear(); scriptActorList.baseActors.clear();
actorList.guid = player->guid; scriptActorList.guid = player->guid;
} }
unsigned int ActorFunctions::GetActorListSize() noexcept unsigned int ActorFunctions::GetActorListSize() noexcept
{ {
return mwmp::Networking::getPtr()->getLastEvent()->objectChanges.count; return mwmp::Networking::getPtr()->getLastEvent()->objectChanges.count;
} }
void ActorFunctions::SendActorList() noexcept
{
mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_LIST)->setActorList(&scriptActorList);
mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_LIST)->Send(scriptActorList.guid);
}
void ActorFunctions::SendActorAuthority() noexcept
{
mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_AUTHORITY)->setActorList(&scriptActorList);
mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_AUTHORITY)->Send(scriptActorList.guid);
}

View file

@ -4,7 +4,10 @@
#define ACTORAPI \ #define ACTORAPI \
{"InitActorList", ActorFunctions::InitActorList},\ {"InitActorList", ActorFunctions::InitActorList},\
\ \
{"GetActorListSize", ActorFunctions::GetActorListSize} {"GetActorListSize", ActorFunctions::GetActorListSize},\
\
{"SendActorList", ActorFunctions::SendActorList},\
{"SendActorAuthority", ActorFunctions::SendActorAuthority}\
class ActorFunctions class ActorFunctions
{ {
@ -13,6 +16,9 @@ public:
static void InitActorList(unsigned short pid) noexcept; static void InitActorList(unsigned short pid) noexcept;
static unsigned int GetActorListSize() noexcept; static unsigned int GetActorListSize() noexcept;
static void SendActorList() noexcept;
static void SendActorAuthority() noexcept;
}; };

View file

@ -271,18 +271,6 @@ void WorldFunctions::AddContainerItem() noexcept
tempWorldObject.containerChanges.items.push_back(containerItem); tempWorldObject.containerChanges.items.push_back(containerItem);
} }
void WorldFunctions::SendActorList() noexcept
{
mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_LIST)->setEvent(&scriptEvent);
mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_LIST)->Send(scriptEvent.guid);
}
void WorldFunctions::SendActorAuthority() noexcept
{
mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_AUTHORITY)->setEvent(&scriptEvent);
mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_AUTHORITY)->Send(scriptEvent.guid);
}
void WorldFunctions::SendObjectDelete() noexcept void WorldFunctions::SendObjectDelete() noexcept
{ {
mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_DELETE)->setEvent(&scriptEvent); mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_DELETE)->setEvent(&scriptEvent);

View file

@ -51,8 +51,6 @@
{"AddWorldObject", WorldFunctions::AddWorldObject},\ {"AddWorldObject", WorldFunctions::AddWorldObject},\
{"AddContainerItem", WorldFunctions::AddContainerItem},\ {"AddContainerItem", WorldFunctions::AddContainerItem},\
\ \
{"SendActorList", WorldFunctions::SendActorList},\
{"SendActorAuthority", WorldFunctions::SendActorAuthority},\
{"SendObjectDelete", WorldFunctions::SendObjectDelete},\ {"SendObjectDelete", WorldFunctions::SendObjectDelete},\
{"SendObjectPlace", WorldFunctions::SendObjectPlace},\ {"SendObjectPlace", WorldFunctions::SendObjectPlace},\
{"SendObjectScale", WorldFunctions::SendObjectScale},\ {"SendObjectScale", WorldFunctions::SendObjectScale},\
@ -118,8 +116,6 @@ public:
static void AddWorldObject() noexcept; static void AddWorldObject() noexcept;
static void AddContainerItem() noexcept; static void AddContainerItem() noexcept;
static void SendActorList() noexcept;
static void SendActorAuthority() noexcept;
static void SendObjectDelete() noexcept; static void SendObjectDelete() noexcept;
static void SendObjectPlace() noexcept; static void SendObjectPlace() noexcept;
static void SendObjectScale() noexcept; static void SendObjectScale() noexcept;

View file

@ -13,7 +13,7 @@ namespace mwmp
BPP_INIT(ID_ACTOR_AUTHORITY) BPP_INIT(ID_ACTOR_AUTHORITY)
} }
void Do(ActorPacket &packet, Player &player, BaseEvent &event) override void Do(ActorPacket &packet, Player &player, BaseActorList &actorList) override
{ {
packet.Send(true); packet.Send(true);
} }

View file

@ -13,15 +13,15 @@ namespace mwmp
BPP_INIT(ID_ACTOR_FRAME) BPP_INIT(ID_ACTOR_FRAME)
} }
void Do(ActorPacket &packet, Player &player, BaseEvent &event) override void Do(ActorPacket &packet, Player &player, BaseActorList &actorList) override
{ {
// Send only to players who have the cell loaded // Send only to players who have the cell loaded
Cell *serverCell = CellController::get()->getCell(&event.cell); Cell *serverCell = CellController::get()->getCell(&actorList.cell);
if (serverCell != nullptr) if (serverCell != nullptr)
serverCell->sendToLoaded(&packet, &event); serverCell->sendToLoaded(&packet, &actorList);
Script::Call<Script::CallbackIdentity("OnActorFrame")>(player.getId(), event.cell.getDescription().c_str()); Script::Call<Script::CallbackIdentity("OnActorFrame")>(player.getId(), actorList.cell.getDescription().c_str());
} }
}; };
} }

View file

@ -13,17 +13,17 @@ namespace mwmp
BPP_INIT(ID_ACTOR_LIST) BPP_INIT(ID_ACTOR_LIST)
} }
void Do(ActorPacket &packet, Player &player, BaseEvent &event) override void Do(ActorPacket &packet, Player &player, BaseActorList &actorList) override
{ {
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received %s from %s", strPacketID.c_str(), player.npc.mName.c_str()); LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received %s from %s", strPacketID.c_str(), player.npc.mName.c_str());
// Send only to players who have the cell loaded // Send only to players who have the cell loaded
Cell *serverCell = CellController::get()->getCell(&event.cell); Cell *serverCell = CellController::get()->getCell(&actorList.cell);
if (serverCell != nullptr) if (serverCell != nullptr)
serverCell->sendToLoaded(&packet, &event); serverCell->sendToLoaded(&packet, &actorList);
Script::Call<Script::CallbackIdentity("OnActorList")>(player.getId(), event.cell.getDescription().c_str()); Script::Call<Script::CallbackIdentity("OnActorList")>(player.getId(), actorList.cell.getDescription().c_str());
} }
}; };
} }

View file

@ -96,7 +96,7 @@ add_openmw_dir (mwbase
inputmanager windowmanager statemanager inputmanager windowmanager statemanager
) )
add_openmw_dir (mwmp Main Networking LocalPlayer DedicatedPlayer LocalActor DedicatedActor WorldEvent Cell CellController GUIChat GUILogin GUIController PlayerMarkerCollection GUIDialogList) add_openmw_dir (mwmp Main Networking LocalPlayer DedicatedPlayer LocalActor DedicatedActor ActorList WorldEvent Cell CellController GUIChat GUILogin GUIController PlayerMarkerCollection GUIDialogList)
# Main executable # Main executable

View file

@ -0,0 +1,109 @@
#include "ActorList.hpp"
#include "Main.hpp"
#include "Networking.hpp"
#include "LocalPlayer.hpp"
#include <components/openmw-mp/Log.hpp>
using namespace mwmp;
using namespace std;
ActorList::ActorList()
{
}
ActorList::~ActorList()
{
}
Networking *ActorList::getNetworking()
{
return mwmp::Main::get().getNetworking();
}
void ActorList::reset()
{
cell.blank();
baseActors.clear();
guid = mwmp::Main::get().getNetworking()->getLocalPlayer()->guid;
}
void ActorList::addActor(BaseActor baseActor)
{
baseActors.push_back(baseActor);
}
void ActorList::addActor(LocalActor localActor)
{
baseActors.push_back(localActor);
}
// TODO: Finish this
void ActorList::editActors(MWWorld::CellStore* cellStore)
{
BaseActor actor;
for (unsigned int i = 0; i < count; i++)
{
actor = baseActors.at(i);
LOG_APPEND(Log::LOG_VERBOSE, "- cellRef: %s, %i, %i", actor.refId.c_str(), actor.refNumIndex, actor.mpNum);
return;
MWWorld::Ptr ptrFound = cellStore->searchExact(actor.refId, actor.refNumIndex, actor.mpNum);
if (ptrFound)
{
LOG_APPEND(Log::LOG_VERBOSE, "-- Found %s, %i, %i", ptrFound.getCellRef().getRefId().c_str(),
ptrFound.getCellRef().getRefNum(), ptrFound.getCellRef().getMpNum());
}
else
{
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "-- Could not find %s, %i, %i", ptrFound.getCellRef().getRefId().c_str(),
ptrFound.getCellRef().getRefNum(), ptrFound.getCellRef().getMpNum());
}
}
}
void ActorList::sendActors(MWWorld::CellStore* cellStore)
{
reset();
cell = *cellStore->getCell();
action = BaseActorList::SET;
MWWorld::CellRefList<ESM::NPC> *npcList = cellStore->getNpcs();
for (typename MWWorld::CellRefList<ESM::NPC>::List::iterator listIter(npcList->mList.begin());
listIter != npcList->mList.end(); ++listIter)
{
MWWorld::Ptr ptr(&*listIter, 0);
BaseActor actor;
actor.refId = ptr.getCellRef().getRefId();
actor.refNumIndex = ptr.getCellRef().getRefNum().mIndex;
actor.mpNum = ptr.getCellRef().getMpNum();
addActor(actor);
}
MWWorld::CellRefList<ESM::Creature> *creatureList = cellStore->getCreatures();
for (typename MWWorld::CellRefList<ESM::Creature>::List::iterator listIter(creatureList->mList.begin());
listIter != creatureList->mList.end(); ++listIter)
{
MWWorld::Ptr ptr(&*listIter, 0);
BaseActor actor;
actor.refId = ptr.getCellRef().getRefId();
actor.refNumIndex = ptr.getCellRef().getRefNum().mIndex;
actor.mpNum = ptr.getCellRef().getMpNum();
addActor(actor);
}
mwmp::Main::get().getNetworking()->getActorPacket(ID_ACTOR_LIST)->setActorList(this);
mwmp::Main::get().getNetworking()->getActorPacket(ID_ACTOR_LIST)->Send();
}

View file

@ -0,0 +1,34 @@
#ifndef OPENMW_ACTORLIST_HPP
#define OPENMW_ACTORLIST_HPP
#include <components/openmw-mp/Base/BaseActor.hpp>
#include "../mwworld/cellstore.hpp"
#include <RakNetTypes.h>
#include "LocalActor.hpp"
namespace mwmp
{
class Networking;
class ActorList : public BaseActorList
{
public:
ActorList();
virtual ~ActorList();
void reset();
void addActor(BaseActor baseActor);
void addActor(LocalActor localActor);
void editActors(MWWorld::CellStore* cellStore);
void sendActors(MWWorld::CellStore* cellStore);
private:
Networking *getNetworking();
};
}
#endif //OPENMW_ACTORLIST_HPP

View file

@ -27,9 +27,10 @@ void Cell::updateLocal()
{ {
if (localActors.empty()) return; if (localActors.empty()) return;
WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent(); ActorList *actorList = mwmp::Main::get().getNetworking()->getActorList();
worldEvent->reset(); actorList->reset();
worldEvent->cell = *store->getCell();
actorList->cell = *store->getCell();
for (std::map<std::string, LocalActor *>::iterator it = localActors.begin(); it != localActors.end();) for (std::map<std::string, LocalActor *>::iterator it = localActors.begin(); it != localActors.end();)
{ {
@ -46,47 +47,17 @@ void Cell::updateLocal()
{ {
//LOG_APPEND(Log::LOG_VERBOSE, "- Updating LocalActor %s", it->first.c_str()); //LOG_APPEND(Log::LOG_VERBOSE, "- Updating LocalActor %s", it->first.c_str());
actor->update(); actor->update();
MWWorld::Ptr ptr = actor->getPtr();
WorldObject worldObject;
worldObject.refId = ptr.getCellRef().getRefId();
worldObject.refNumIndex = ptr.getCellRef().getRefNum().mIndex;
worldObject.mpNum = ptr.getCellRef().getMpNum();
worldObject.pos = actor->position;
worldObject.drawState = actor->drawState;
worldObject.headPitch = actor->headPitch;
worldObject.headYaw = actor->headYaw;
worldObject.hasAnimation = actor->hasAnimation;
worldObject.hasAnimStates = actor->hasAnimStates;
worldObject.hasMovement = actor->hasMovement;
if (actor->hasAnimation)
{
worldObject.animation = actor->animation;
}
if (actor->hasAnimStates)
{
worldObject.animStates = actor->animStates;
}
if (actor->hasMovement)
{
worldObject.movement = actor->movement;
}
actorList->addActor(*actor);
actor->hasAnimation = false; actor->hasAnimation = false;
actor->hasAnimStates = false; actor->hasAnimStates = false;
actor->hasMovement = false; actor->hasMovement = false;
worldEvent->addObject(worldObject);
++it; ++it;
} }
} }
Main::get().getNetworking()->getActorPacket(ID_ACTOR_FRAME)->setEvent(worldEvent); Main::get().getNetworking()->getActorPacket(ID_ACTOR_FRAME)->setActorList(actorList);
Main::get().getNetworking()->getActorPacket(ID_ACTOR_FRAME)->Send(); Main::get().getNetworking()->getActorPacket(ID_ACTOR_FRAME)->Send();
} }
@ -102,24 +73,24 @@ void Cell::updateDedicated(float dt)
} }
} }
void Cell::readCellFrame(WorldEvent& worldEvent) void Cell::readCellFrame(ActorList& actorList)
{ {
WorldObject worldObject; BaseActor baseActor;
for (unsigned int i = 0; i < worldEvent.objectChanges.count; i++) for (unsigned int i = 0; i < actorList.count; i++)
{ {
worldObject = worldEvent.objectChanges.objects.at(i); baseActor = actorList.baseActors.at(i);
std::string mapIndex = Main::get().getCellController()->generateMapIndex(worldObject); std::string mapIndex = Main::get().getCellController()->generateMapIndex(baseActor);
// If this key doesn't exist, create it // If this key doesn't exist, create it
if (dedicatedActors.count(mapIndex) == 0) if (dedicatedActors.count(mapIndex) == 0)
{ {
MWWorld::Ptr ptrFound = store->searchExact(worldObject.refId, worldObject.refNumIndex, worldObject.mpNum); MWWorld::Ptr ptrFound = store->searchExact(baseActor.refId, baseActor.refNumIndex, baseActor.mpNum);
if (!ptrFound) return; if (!ptrFound) return;
DedicatedActor *actor = new DedicatedActor(); DedicatedActor *actor = new DedicatedActor();
actor->cell = worldEvent.cell; actor->cell = actorList.cell;
actor->setPtr(ptrFound); actor->setPtr(ptrFound);
dedicatedActors[mapIndex] = actor; dedicatedActors[mapIndex] = actor;
@ -132,29 +103,29 @@ void Cell::readCellFrame(WorldEvent& worldEvent)
if (dedicatedActors.count(mapIndex) > 0) if (dedicatedActors.count(mapIndex) > 0)
{ {
DedicatedActor *actor = dedicatedActors[mapIndex]; DedicatedActor *actor = dedicatedActors[mapIndex];
actor->position = worldObject.pos; actor->position = baseActor.pos;
actor->drawState = worldObject.drawState; actor->drawState = baseActor.drawState;
actor->headPitch = worldObject.headPitch; actor->headPitch = baseActor.headPitch;
actor->headYaw = worldObject.headYaw; actor->headYaw = baseActor.headYaw;
actor->hasAnimation = worldObject.hasAnimation; actor->hasAnimation = baseActor.hasAnimation;
actor->hasAnimStates = worldObject.hasAnimStates; actor->hasAnimStates = baseActor.hasAnimStates;
actor->hasMovement = worldObject.hasMovement; actor->hasMovement = baseActor.hasMovement;
if (actor->hasAnimation) if (actor->hasAnimation)
{ {
actor->animation = worldObject.animation; actor->animation = baseActor.animation;
} }
if (actor->hasAnimStates) if (actor->hasAnimStates)
{ {
actor->animStates = worldObject.animStates; actor->animStates = baseActor.animStates;
} }
if (actor->hasMovement) if (actor->hasMovement)
{ {
actor->movement = worldObject.movement; actor->movement = baseActor.movement;
} }
} }
} }

View file

@ -1,7 +1,7 @@
#ifndef OPENMW_CELL_HPP #ifndef OPENMW_CELL_HPP
#define OPENMW_CELL_HPP #define OPENMW_CELL_HPP
#include "WorldEvent.hpp" #include "ActorList.hpp"
#include "LocalActor.hpp" #include "LocalActor.hpp"
#include "DedicatedActor.hpp" #include "DedicatedActor.hpp"
#include "../mwworld/cellstore.hpp" #include "../mwworld/cellstore.hpp"
@ -18,7 +18,7 @@ namespace mwmp
void updateLocal(); void updateLocal();
void updateDedicated(float dt); void updateDedicated(float dt);
void readCellFrame(mwmp::WorldEvent& worldEvent); void readCellFrame(mwmp::ActorList& actorList);
void initializeLocalActors(); void initializeLocalActors();
void uninitializeLocalActors(); void uninitializeLocalActors();

View file

@ -89,16 +89,16 @@ void CellController::initializeLocalActors(const ESM::Cell& cell)
} }
} }
void CellController::readCellFrame(WorldEvent& worldEvent) void CellController::readCellFrame(ActorList& actorList)
{ {
std::string mapIndex = worldEvent.cell.getDescription(); std::string mapIndex = actorList.cell.getDescription();
initializeCell(worldEvent.cell); initializeCell(actorList.cell);
// If this now exists, send it the data // If this now exists, send it the data
if (cellsActive.count(mapIndex) > 0) if (cellsActive.count(mapIndex) > 0)
{ {
cellsActive[mapIndex]->readCellFrame(worldEvent); cellsActive[mapIndex]->readCellFrame(actorList);
} }
} }
@ -161,12 +161,12 @@ std::string CellController::generateMapIndex(MWWorld::Ptr ptr)
return mapIndex; return mapIndex;
} }
std::string CellController::generateMapIndex(WorldObject object) std::string CellController::generateMapIndex(BaseActor baseActor)
{ {
std::string mapIndex = ""; std::string mapIndex = "";
mapIndex += object.refId; mapIndex += baseActor.refId;
mapIndex += "-" + Utils::toString(object.refNumIndex); mapIndex += "-" + Utils::toString(baseActor.refNumIndex);
mapIndex += "-" + Utils::toString(object.mpNum); mapIndex += "-" + Utils::toString(baseActor.mpNum);
return mapIndex; return mapIndex;
} }

View file

@ -2,7 +2,7 @@
#define OPENMW_CELLCONTROLLER_HPP #define OPENMW_CELLCONTROLLER_HPP
#include "Cell.hpp" #include "Cell.hpp"
#include "WorldEvent.hpp" #include "ActorList.hpp"
#include "LocalActor.hpp" #include "LocalActor.hpp"
#include "DedicatedActor.hpp" #include "DedicatedActor.hpp"
#include "../mwworld/cellstore.hpp" #include "../mwworld/cellstore.hpp"
@ -21,7 +21,7 @@ namespace mwmp
void initializeCell(const ESM::Cell& cell); void initializeCell(const ESM::Cell& cell);
void initializeLocalActors(const ESM::Cell& cell); void initializeLocalActors(const ESM::Cell& cell);
void readCellFrame(mwmp::WorldEvent& worldEvent); void readCellFrame(mwmp::ActorList& actorList);
void setLocalActorRecord(std::string actorIndex, std::string cellIndex); void setLocalActorRecord(std::string actorIndex, std::string cellIndex);
void removeLocalActorRecord(std::string actorIndex); void removeLocalActorRecord(std::string actorIndex);
@ -34,7 +34,7 @@ namespace mwmp
virtual DedicatedActor *getDedicatedActor(MWWorld::Ptr ptr); virtual DedicatedActor *getDedicatedActor(MWWorld::Ptr ptr);
std::string generateMapIndex(MWWorld::Ptr ptr); std::string generateMapIndex(MWWorld::Ptr ptr);
std::string generateMapIndex(mwmp::WorldObject object); std::string generateMapIndex(mwmp::BaseActor baseActor);
int getCellSize() const; int getCellSize() const;
virtual MWWorld::CellStore *getCell(const ESM::Cell& cell); virtual MWWorld::CellStore *getCell(const ESM::Cell& cell);

View file

@ -837,37 +837,37 @@ void Networking::processActorPacket(RakNet::Packet *packet)
ActorPacket *myPacket = actorPacketController.GetPacket(packet->data[0]); ActorPacket *myPacket = actorPacketController.GetPacket(packet->data[0]);
myPacket->setEvent(&worldEvent); myPacket->setActorList(&actorList);
myPacket->Packet(&bsIn, false); myPacket->Packet(&bsIn, false);
switch (packet->data[0]) switch (packet->data[0])
{ {
case ID_ACTOR_LIST: case ID_ACTOR_LIST:
{ {
MWWorld::CellStore *ptrCellStore = Main::get().getCellController()->getCell(worldEvent.cell); MWWorld::CellStore *ptrCellStore = Main::get().getCellController()->getCell(actorList.cell);
if (!ptrCellStore) return; if (!ptrCellStore) return;
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Received ID_ACTOR_LIST about %s", worldEvent.cell.getDescription().c_str()); LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Received ID_ACTOR_LIST about %s", actorList.cell.getDescription().c_str());
LOG_APPEND(Log::LOG_VERBOSE, "- action: %i", worldEvent.action); LOG_APPEND(Log::LOG_VERBOSE, "- action: %i", actorList.action);
// If we've received a request for information, comply with it // If we've received a request for information, comply with it
if (worldEvent.action == mwmp::BaseEvent::REQUEST) if (actorList.action == mwmp::BaseActorList::REQUEST)
worldEvent.sendActors(ptrCellStore); actorList.sendActors(ptrCellStore);
break; break;
} }
case ID_ACTOR_AUTHORITY: case ID_ACTOR_AUTHORITY:
{ {
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Received ID_ACTOR_AUTHORITY about %s", worldEvent.cell.getDescription().c_str()); LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Received ID_ACTOR_AUTHORITY about %s", actorList.cell.getDescription().c_str());
//Main::get().getCellController()->initializeLocalActors(worldEvent.cell); //Main::get().getCellController()->initializeLocalActors(actorList.cell);
break; break;
} }
case ID_ACTOR_FRAME: case ID_ACTOR_FRAME:
{ {
//Main::get().getCellController()->readCellFrame(worldEvent); //Main::get().getCellController()->readCellFrame(actorList);
break; break;
} }
@ -1105,6 +1105,11 @@ LocalPlayer *Networking::getLocalPlayer()
return mwmp::Main::get().getLocalPlayer(); return mwmp::Main::get().getLocalPlayer();
} }
ActorList *Networking::getActorList()
{
return &actorList;
}
WorldEvent *Networking::getWorldEvent() WorldEvent *Networking::getWorldEvent()
{ {
return &worldEvent; return &worldEvent;

View file

@ -9,6 +9,7 @@
#include <BitStream.h> #include <BitStream.h>
#include <string> #include <string>
#include "ActorList.hpp"
#include "WorldEvent.hpp" #include "WorldEvent.hpp"
#include <components/openmw-mp/NetworkMessages.hpp> #include <components/openmw-mp/NetworkMessages.hpp>
@ -44,8 +45,9 @@ namespace mwmp
bool isConnected(); bool isConnected();
WorldEvent *getWorldEvent();
LocalPlayer *getLocalPlayer(); LocalPlayer *getLocalPlayer();
ActorList *getActorList();
WorldEvent *getWorldEvent();
private: private:
bool connected; bool connected;
@ -57,6 +59,7 @@ namespace mwmp
ActorPacketController actorPacketController; ActorPacketController actorPacketController;
WorldPacketController worldPacketController; WorldPacketController worldPacketController;
ActorList actorList;
WorldEvent worldEvent; WorldEvent worldEvent;
void processPlayerPacket(RakNet::Packet *packet); void processPlayerPacket(RakNet::Packet *packet);

View file

@ -47,33 +47,6 @@ void WorldEvent::addObject(WorldObject worldObject)
objectChanges.objects.push_back(worldObject); objectChanges.objects.push_back(worldObject);
} }
void WorldEvent::editActors(MWWorld::CellStore* cellStore)
{
WorldObject worldObject;
for (unsigned int i = 0; i < objectChanges.count; i++)
{
worldObject = objectChanges.objects.at(i);
LOG_APPEND(Log::LOG_VERBOSE, "- cellRef: %s, %i, %i", worldObject.refId.c_str(), worldObject.refNumIndex, worldObject.mpNum);
return;
MWWorld::Ptr ptrFound = cellStore->searchExact(worldObject.refId, worldObject.refNumIndex, worldObject.mpNum);
if (ptrFound)
{
LOG_APPEND(Log::LOG_VERBOSE, "-- Found %s, %i, %i", ptrFound.getCellRef().getRefId().c_str(),
ptrFound.getCellRef().getRefNum(), ptrFound.getCellRef().getMpNum());
}
else
{
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "-- Could not find %s, %i, %i", ptrFound.getCellRef().getRefId().c_str(),
ptrFound.getCellRef().getRefNum(), ptrFound.getCellRef().getMpNum());
}
}
}
void WorldEvent::editContainers(MWWorld::CellStore* cellStore) void WorldEvent::editContainers(MWWorld::CellStore* cellStore)
{ {
WorldObject worldObject; WorldObject worldObject;
@ -476,46 +449,6 @@ void WorldEvent::playVideo()
} }
} }
void WorldEvent::sendActors(MWWorld::CellStore* cellStore)
{
reset();
cell = *cellStore->getCell();
action = BaseEvent::SET;
MWWorld::CellRefList<ESM::NPC> *npcList = cellStore->getNpcs();
for (typename MWWorld::CellRefList<ESM::NPC>::List::iterator listIter(npcList->mList.begin());
listIter != npcList->mList.end(); ++listIter)
{
MWWorld::Ptr ptr(&*listIter, 0);
mwmp::WorldObject worldObject;
worldObject.refId = ptr.getCellRef().getRefId();
worldObject.refNumIndex = ptr.getCellRef().getRefNum().mIndex;
worldObject.mpNum = ptr.getCellRef().getMpNum();
addObject(worldObject);
}
MWWorld::CellRefList<ESM::Creature> *creatureList = cellStore->getCreatures();
for (typename MWWorld::CellRefList<ESM::Creature>::List::iterator listIter(creatureList->mList.begin());
listIter != creatureList->mList.end(); ++listIter)
{
MWWorld::Ptr ptr(&*listIter, 0);
mwmp::WorldObject worldObject;
worldObject.refId = ptr.getCellRef().getRefId();
worldObject.refNumIndex = ptr.getCellRef().getRefNum().mIndex;
worldObject.mpNum = ptr.getCellRef().getMpNum();
addObject(worldObject);
}
mwmp::Main::get().getNetworking()->getActorPacket(ID_ACTOR_LIST)->setEvent(this);
mwmp::Main::get().getNetworking()->getActorPacket(ID_ACTOR_LIST)->Send();
}
void WorldEvent::sendContainers(MWWorld::CellStore* cellStore) void WorldEvent::sendContainers(MWWorld::CellStore* cellStore)
{ {
reset(); reset();

View file

@ -18,7 +18,6 @@ namespace mwmp
void reset(); void reset();
void addObject(WorldObject worldObject); void addObject(WorldObject worldObject);
void editActors(MWWorld::CellStore* cellStore);
void editContainers(MWWorld::CellStore* cellStore); void editContainers(MWWorld::CellStore* cellStore);
void placeObjects(MWWorld::CellStore* cellStore); void placeObjects(MWWorld::CellStore* cellStore);
@ -39,7 +38,6 @@ namespace mwmp
void playMusic(); void playMusic();
void playVideo(); void playVideo();
void sendActors(MWWorld::CellStore* cellStore);
void sendContainers(MWWorld::CellStore* cellStore); void sendContainers(MWWorld::CellStore* cellStore);
void sendObjectPlace(MWWorld::Ptr ptr); void sendObjectPlace(MWWorld::Ptr ptr);

View file

@ -16,6 +16,12 @@ namespace mwmp
} }
std::string refId;
int refNumIndex;
int mpNum;
ESM::Position pos;
char drawState; char drawState;
bool isFlying; bool isFlying;
@ -35,21 +41,31 @@ namespace mwmp
bool hasMovement; bool hasMovement;
}; };
class ActorList class BaseActorList
{ {
public: public:
ActorList() BaseActorList()
{ {
} }
enum ACTOR_ACTION
{
SET = 0,
ADD = 1,
REMOVE = 2,
REQUEST = 3
};
RakNet::RakNetGUID guid; RakNet::RakNetGUID guid;
std::vector<BaseActor> baseActors; std::vector<BaseActor> baseActors;
unsigned int count; unsigned int count;
ESM::Cell cell; ESM::Cell cell;
unsigned char action; // 0 - Clear and set in entirety, 1 - Add item, 2 - Remove item, 3 - Request items
}; };
} }

View file

@ -24,4 +24,4 @@ namespace mwmp
}; };
} }
#endif //OPENMW_WORLDPACKETCONTROLLER_HPP #endif //OPENMW_ACTORPACKETCONTROLLER_HPP

View file

@ -18,8 +18,8 @@ ActorPacket::~ActorPacket()
} }
void ActorPacket::setEvent(BaseEvent *event) void ActorPacket::setActorList(BaseActorList *actorList)
{ {
this->event = event; this->actorList = actorList;
guid = event->guid; guid = actorList->guid;
} }

View file

@ -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/BaseEvent.hpp> #include <components/openmw-mp/Base/BaseActor.hpp>
#include <components/openmw-mp/Packets/BasePacket.hpp> #include <components/openmw-mp/Packets/BasePacket.hpp>
@ -19,10 +19,10 @@ namespace mwmp
~ActorPacket(); ~ActorPacket();
void setEvent(BaseEvent *event); void setActorList(BaseActorList *actorList);
protected: protected:
BaseEvent *event; BaseActorList *actorList;
}; };
} }

View file

@ -13,33 +13,33 @@ void PacketActorAuthority::Packet(RakNet::BitStream *bs, bool send)
ActorPacket::Packet(bs, send); ActorPacket::Packet(bs, send);
if (!send) if (!send)
event->objectChanges.objects.clear(); actorList->baseActors.clear();
else else
event->objectChanges.count = (unsigned int)(event->objectChanges.objects.size()); actorList->count = (unsigned int)(actorList->baseActors.size());
RW(event->objectChanges.count, send); RW(actorList->count, send);
RW(event->cell.mData.mFlags, send); RW(actorList->cell.mData.mFlags, send);
RW(event->cell.mData.mX, send); RW(actorList->cell.mData.mX, send);
RW(event->cell.mData.mY, send); RW(actorList->cell.mData.mY, send);
RW(event->cell.mName, send); RW(actorList->cell.mName, send);
WorldObject worldObject; BaseActor actor;
for (unsigned int i = 0; i < event->objectChanges.count; i++) for (unsigned int i = 0; i < actorList->count; i++)
{ {
if (send) if (send)
{ {
worldObject = event->objectChanges.objects.at(i); actor = actorList->baseActors.at(i);
} }
RW(worldObject.refId, send); RW(actor.refId, send);
RW(worldObject.refNumIndex, send); RW(actor.refNumIndex, send);
RW(worldObject.mpNum, send); RW(actor.mpNum, send);
if (!send) if (!send)
{ {
event->objectChanges.objects.push_back(worldObject); actorList->baseActors.push_back(actor);
} }
} }
} }

View file

@ -14,65 +14,65 @@ void PacketActorFrame::Packet(RakNet::BitStream *bs, bool send)
ActorPacket::Packet(bs, send); ActorPacket::Packet(bs, send);
if (!send) if (!send)
event->objectChanges.objects.clear(); actorList->baseActors.clear();
else else
event->objectChanges.count = (unsigned int)(event->objectChanges.objects.size()); actorList->count = (unsigned int)(actorList->baseActors.size());
RW(event->objectChanges.count, send); RW(actorList->count, send);
RW(event->cell.mData.mFlags, send); RW(actorList->cell.mData.mFlags, send);
RW(event->cell.mData.mX, send); RW(actorList->cell.mData.mX, send);
RW(event->cell.mData.mY, send); RW(actorList->cell.mData.mY, send);
RW(event->cell.mName, send); RW(actorList->cell.mName, send);
WorldObject worldObject; BaseActor actor;
for (unsigned int i = 0; i < event->objectChanges.count; i++) for (unsigned int i = 0; i < actorList->count; i++)
{ {
if (send) if (send)
{ {
worldObject = event->objectChanges.objects.at(i); actor = actorList->baseActors.at(i);
} }
RW(worldObject.refId, send); RW(actor.refId, send);
RW(worldObject.refNumIndex, send); RW(actor.refNumIndex, send);
RW(worldObject.mpNum, send); RW(actor.mpNum, send);
RW(worldObject.pos, send); RW(actor.pos, send);
RW(worldObject.drawState, send); RW(actor.drawState, send);
RW(worldObject.headPitch, send); RW(actor.headPitch, send);
RW(worldObject.headYaw, send); RW(actor.headYaw, send);
RW(worldObject.hasAnimation, send); RW(actor.hasAnimation, send);
RW(worldObject.hasAnimStates, send); RW(actor.hasAnimStates, send);
RW(worldObject.hasMovement, send); RW(actor.hasMovement, send);
if (worldObject.hasAnimation) if (actor.hasAnimation)
{ {
RW(worldObject.animation.groupname, send); RW(actor.animation.groupname, send);
RW(worldObject.animation.mode, send); RW(actor.animation.mode, send);
RW(worldObject.animation.count, send); RW(actor.animation.count, send);
RW(worldObject.animation.persist, send); RW(actor.animation.persist, send);
} }
if (worldObject.hasAnimStates) if (actor.hasAnimStates)
{ {
RW(worldObject.animStates.idlestate, send); RW(actor.animStates.idlestate, send);
RW(worldObject.animStates.movestate, send); RW(actor.animStates.movestate, send);
RW(worldObject.animStates.jumpstate, send); RW(actor.animStates.jumpstate, send);
RW(worldObject.animStates.forcestateupdate, send); RW(actor.animStates.forcestateupdate, send);
} }
if (worldObject.hasMovement) if (actor.hasMovement)
{ {
RW(worldObject.movement.x, send); RW(actor.movement.x, send);
RW(worldObject.movement.y, send); RW(actor.movement.y, send);
RW(worldObject.movement.y, send); RW(actor.movement.y, send);
} }
if (!send) if (!send)
{ {
event->objectChanges.objects.push_back(worldObject); actorList->baseActors.push_back(actor);
} }
} }
} }

View file

@ -12,40 +12,40 @@ void PacketActorList::Packet(RakNet::BitStream *bs, bool send)
{ {
ActorPacket::Packet(bs, send); ActorPacket::Packet(bs, send);
RW(event->action, send); RW(actorList->action, send);
if (send) if (send)
{ {
event->objectChanges.count = (unsigned int)(event->objectChanges.objects.size()); actorList->count = (unsigned int)(actorList->baseActors.size());
} }
else else
{ {
event->objectChanges.objects.clear(); actorList->baseActors.clear();
} }
RW(event->objectChanges.count, send); RW(actorList->count, send);
RW(event->cell.mData.mFlags, send); RW(actorList->cell.mData.mFlags, send);
RW(event->cell.mData.mX, send); RW(actorList->cell.mData.mX, send);
RW(event->cell.mData.mY, send); RW(actorList->cell.mData.mY, send);
RW(event->cell.mName, send); RW(actorList->cell.mName, send);
WorldObject worldObject; BaseActor actor;
for (unsigned int i = 0; i < event->objectChanges.count; i++) for (unsigned int i = 0; i < actorList->count; i++)
{ {
if (send) if (send)
{ {
worldObject = event->objectChanges.objects.at(i); actor = actorList->baseActors.at(i);
} }
RW(worldObject.refId, send); RW(actor.refId, send);
RW(worldObject.refNumIndex, send); RW(actor.refNumIndex, send);
RW(worldObject.mpNum, send); RW(actor.mpNum, send);
if (!send) if (!send)
{ {
event->objectChanges.objects.push_back(worldObject); actorList->baseActors.push_back(actor);
} }
} }
} }