[Client] Send and read ActorCellChange packets

0.6.1
David Cernat 8 years ago
parent f4c3a28141
commit 871d8c8308

@ -33,6 +33,7 @@ void ActorList::reset()
speechActors.clear();
statsDynamicActors.clear();
attackActors.clear();
cellChangeActors.clear();
guid = mwmp::Main::get().getNetworking()->getLocalPlayer()->guid;
}
@ -76,6 +77,11 @@ void ActorList::addAttackActor(LocalActor localActor)
attackActors.push_back(localActor);
}
void ActorList::addCellChangeActor(LocalActor localActor)
{
cellChangeActors.push_back(localActor);
}
void ActorList::sendPositionActors()
{
if (positionActors.size() > 0)
@ -136,6 +142,16 @@ void ActorList::sendAttackActors()
}
}
void ActorList::sendCellChangeActors()
{
if (cellChangeActors.size() > 0)
{
baseActors = cellChangeActors;
Main::get().getNetworking()->getActorPacket(ID_ACTOR_CELL_CHANGE)->setActorList(this);
Main::get().getNetworking()->getActorPacket(ID_ACTOR_CELL_CHANGE)->Send();
}
}
// TODO: Finish this
void ActorList::editActorsInCell(MWWorld::CellStore* cellStore)
{

@ -27,6 +27,7 @@ namespace mwmp
void addSpeechActor(LocalActor localActor);
void addStatsDynamicActor(LocalActor localActor);
void addAttackActor(LocalActor localActor);
void addCellChangeActor(LocalActor localActor);
void sendPositionActors();
void sendAnimFlagsActors();
@ -34,6 +35,7 @@ namespace mwmp
void sendSpeechActors();
void sendStatsDynamicActors();
void sendAttackActors();
void sendCellChangeActors();
void editActorsInCell(MWWorld::CellStore* cellStore);
@ -48,6 +50,7 @@ namespace mwmp
std::vector<BaseActor> speechActors;
std::vector<BaseActor> statsDynamicActors;
std::vector<BaseActor> attackActors;
std::vector<BaseActor> cellChangeActors;
};
}

@ -6,7 +6,6 @@
#include "Cell.hpp"
#include "Main.hpp"
#include "Networking.hpp"
#include "LocalPlayer.hpp"
#include "CellController.hpp"
#include "MechanicsHelper.hpp"
@ -38,12 +37,20 @@ void Cell::updateLocal(bool forceUpdate)
{
LocalActor *actor = it->second;
// TODO:: Make sure this condition actually works
if (actor->getPtr().getCell() != store)
MWWorld::CellStore *newStore = actor->getPtr().getCell();
if (newStore != store)
{
actor->updateCell();
LOG_APPEND(Log::LOG_INFO, "- Removing LocalActor %s which is no longer in this cell", it->first.c_str());
Main::get().getCellController()->removeLocalActorRecord(it->first);
// If the cell this actor has moved to is active, initialize them in it
if (Main::get().getCellController()->isActiveCell(*newStore->getCell()))
Main::get().getCellController()->getCell(*newStore->getCell())->initializeLocalActor(actor->getPtr());
localActors.erase(it++);
}
else
@ -61,6 +68,7 @@ void Cell::updateLocal(bool forceUpdate)
actorList->sendSpeechActors();
actorList->sendStatsDynamicActors();
actorList->sendAttackActors();
actorList->sendCellChangeActors();
}
void Cell::updateDedicated(float dt)
@ -97,8 +105,6 @@ void Cell::readPositions(ActorList& actorList)
void Cell::readAnimFlags(ActorList& actorList)
{
initializeDedicatedActors(actorList);
BaseActor baseActor;
for (unsigned int i = 0; i < actorList.count; i++)
@ -118,8 +124,6 @@ void Cell::readAnimFlags(ActorList& actorList)
void Cell::readAnimPlay(ActorList& actorList)
{
initializeDedicatedActors(actorList);
BaseActor baseActor;
for (unsigned int i = 0; i < actorList.count; i++)
@ -140,8 +144,6 @@ void Cell::readAnimPlay(ActorList& actorList)
void Cell::readStatsDynamic(ActorList& actorList)
{
initializeDedicatedActors(actorList);
BaseActor baseActor;
for (unsigned int i = 0; i < actorList.count; i++)
@ -159,8 +161,6 @@ void Cell::readStatsDynamic(ActorList& actorList)
void Cell::readSpeech(ActorList& actorList)
{
initializeDedicatedActors(actorList);
BaseActor baseActor;
for (unsigned int i = 0; i < actorList.count; i++)
@ -179,8 +179,6 @@ void Cell::readSpeech(ActorList& actorList)
void Cell::readAttack(ActorList& actorList)
{
initializeDedicatedActors(actorList);
BaseActor baseActor;
for (unsigned int i = 0; i < actorList.count; i++)
@ -197,9 +195,56 @@ void Cell::readAttack(ActorList& actorList)
}
}
void Cell::readCellChange(ActorList& actorList)
{
initializeDedicatedActors(actorList);
BaseActor baseActor;
for (unsigned int i = 0; i < actorList.count; i++)
{
baseActor = actorList.baseActors.at(i);
std::string mapIndex = Main::get().getCellController()->generateMapIndex(baseActor);
if (dedicatedActors.count(mapIndex) > 0)
{
DedicatedActor *actor = dedicatedActors[mapIndex];
actor->cell = baseActor.cell;
actor->position = baseActor.position;
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Server says DedicatedActor %s, %i, %i moved to %s",
actor->refId.c_str(), actor->refNumIndex, actor->mpNum, actor->cell.getDescription().c_str());
MWWorld::CellStore *newStore = Main::get().getCellController()->getCellStore(actor->cell);
actor->setCell(newStore);
Main::get().getCellController()->removeDedicatedActorRecord(mapIndex);
// If the cell this actor has moved to is active, initialize them in it
if (Main::get().getCellController()->isActiveCell(actor->cell))
Main::get().getCellController()->getCell(actor->cell)->initializeDedicatedActor(actor->getPtr());
dedicatedActors.erase(mapIndex);
}
}
}
void Cell::initializeLocalActor(const MWWorld::Ptr& ptr)
{
LocalActor *actor = new LocalActor();
actor->cell = *store->getCell();
actor->setPtr(ptr);
std::string mapIndex = Main::get().getCellController()->generateMapIndex(ptr);
localActors[mapIndex] = actor;
Main::get().getCellController()->setLocalActorRecord(mapIndex, getDescription());
LOG_APPEND(Log::LOG_INFO, "- Initialized LocalActor %s", mapIndex.c_str());
}
void Cell::initializeLocalActors()
{
ESM::Cell esmCell = *store->getCell();
MWWorld::CellRefList<ESM::NPC> *npcList = store->getNpcs();
for (typename MWWorld::CellRefList<ESM::NPC>::List::iterator listIter(npcList->mList.begin());
@ -207,17 +252,22 @@ void Cell::initializeLocalActors()
{
MWWorld::Ptr ptr(&*listIter, store);
LocalActor *actor = new LocalActor();
actor->cell = esmCell;
actor->setPtr(ptr);
initializeLocalActor(ptr);
}
}
void Cell::initializeDedicatedActor(const MWWorld::Ptr& ptr)
{
DedicatedActor *actor = new DedicatedActor();
actor->cell = *store->getCell();
actor->setPtr(ptr);
std::string mapIndex = Main::get().getCellController()->generateMapIndex(ptr);
localActors[mapIndex] = actor;
std::string mapIndex = Main::get().getCellController()->generateMapIndex(ptr);
dedicatedActors[mapIndex] = actor;
Main::get().getCellController()->setLocalActorRecord(mapIndex, getDescription());
Main::get().getCellController()->setDedicatedActorRecord(mapIndex, getDescription());
LOG_APPEND(Log::LOG_INFO, "- Initialized LocalActor %s", mapIndex.c_str());
}
LOG_APPEND(Log::LOG_INFO, "- Initialized DedicatedActor %s", mapIndex.c_str());
}
void Cell::initializeDedicatedActors(ActorList& actorList)
@ -236,14 +286,7 @@ void Cell::initializeDedicatedActors(ActorList& actorList)
if (!ptrFound) return;
DedicatedActor *actor = new DedicatedActor();
actor->cell = actorList.cell;
actor->setPtr(ptrFound);
dedicatedActors[mapIndex] = actor;
Main::get().getCellController()->setDedicatedActorRecord(mapIndex, getDescription());
LOG_APPEND(Log::LOG_INFO, "- Initialized DedicatedActor %s", mapIndex.c_str());
initializeDedicatedActor(ptrFound);
}
}
}

@ -1,5 +1,5 @@
#ifndef OPENMW_CELL_HPP
#define OPENMW_CELL_HPP
#ifndef OPENMW_MPCELL_HPP
#define OPENMW_MPCELL_HPP
#include "ActorList.hpp"
#include "LocalActor.hpp"
@ -24,8 +24,12 @@ namespace mwmp
void readStatsDynamic(ActorList& actorList);
void readSpeech(ActorList& actorList);
void readAttack(ActorList& actorList);
void readCellChange(ActorList& actorList);
void initializeLocalActor(const MWWorld::Ptr& ptr);
void initializeLocalActors();
void initializeDedicatedActor(const MWWorld::Ptr& ptr);
void initializeDedicatedActors(ActorList& actorList);
void uninitializeLocalActors();
@ -44,4 +48,4 @@ namespace mwmp
};
}
#endif //OPENMW_CELL_HPP
#endif //OPENMW_MPCELL_HPP

@ -167,6 +167,19 @@ void CellController::readAttack(ActorList& actorList)
}
}
void CellController::readCellChange(ActorList& actorList)
{
std::string mapIndex = actorList.cell.getDescription();
initializeCell(actorList.cell);
// If this now exists, send it the data
if (cellsActive.count(mapIndex) > 0)
{
cellsActive[mapIndex]->readCellChange(actorList);
}
}
void CellController::setLocalActorRecord(std::string actorIndex, std::string cellIndex)
{
localActorsToCells[actorIndex] = cellIndex;

@ -28,6 +28,7 @@ namespace mwmp
void readStatsDynamic(mwmp::ActorList& actorList);
void readSpeech(mwmp::ActorList& actorList);
void readAttack(mwmp::ActorList& actorList);
void readCellChange(mwmp::ActorList& actorList);
void setLocalActorRecord(std::string actorIndex, std::string cellIndex);
void removeLocalActorRecord(std::string actorIndex);

@ -10,10 +10,13 @@
#include "../mwrender/animation.hpp"
#include "../mwworld/cellstore.hpp"
#include "../mwworld/class.hpp"
#include "../mwworld/worldimp.hpp"
#include "DedicatedActor.hpp"
#include "Main.hpp"
#include "CellController.hpp"
using namespace mwmp;
using namespace std;
@ -44,6 +47,13 @@ void DedicatedActor::update(float dt)
setStatsDynamic();
}
void DedicatedActor::setCell(MWWorld::CellStore *cellStore)
{
MWBase::World *world = MWBase::Environment::get().getWorld();
ptr = world->moveObject(ptr, cellStore, position.pos[0], position.pos[1], position.pos[2]);
}
void DedicatedActor::move(float dt)
{
MWBase::World *world = MWBase::Environment::get().getWorld();

@ -15,6 +15,7 @@ namespace mwmp
virtual ~DedicatedActor();
void update(float dt);
void setCell(MWWorld::CellStore *cellStore);
void move(float dt);
void setAnimFlags();
void playAnimation();

@ -54,6 +54,18 @@ void LocalActor::update(bool forceUpdate)
updateAttack();
}
void LocalActor::updateCell()
{
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Sending ID_ACTOR_CELL_CHANGE about %s, %i, %i to server",
refId.c_str(), refNumIndex, mpNum);
LOG_APPEND(Log::LOG_INFO, "- Moved from %s to %s", cell.getDescription().c_str(), ptr.getCell()->getCell()->getDescription().c_str());
cell = *ptr.getCell()->getCell();
mwmp::Main::get().getNetworking()->getActorList()->addCellChangeActor(*this);
}
void LocalActor::updatePosition(bool forceUpdate)
{
bool posIsChanging = (direction.pos[0] != 0 || direction.pos[1] != 0 || direction.pos[2] != 0 ||

@ -16,6 +16,7 @@ namespace mwmp
void update(bool forceUpdate);
void updateCell();
void updatePosition(bool forceUpdate);
void updateAnimFlags(bool forceUpdate);
void updateAnimPlay();

@ -22,7 +22,7 @@ namespace mwmp
virtual void Do(ActorPacket &packet, ActorList &actorList)
{
//Main::get().getCellController()->readCellChange(actorList);
}
};
}

Loading…
Cancel
Save