forked from teamnwah/openmw-tes3coop
[Client] Retool LocalActors and DedicatedActors for ActorPosition packet
This commit is contained in:
parent
cbd2af972d
commit
d14102716d
11 changed files with 107 additions and 82 deletions
|
@ -27,6 +27,7 @@ void ActorList::reset()
|
|||
{
|
||||
cell.blank();
|
||||
baseActors.clear();
|
||||
positionActors.clear();
|
||||
guid = mwmp::Main::get().getNetworking()->getLocalPlayer()->guid;
|
||||
}
|
||||
|
||||
|
@ -40,8 +41,20 @@ void ActorList::addActor(LocalActor localActor)
|
|||
baseActors.push_back(localActor);
|
||||
}
|
||||
|
||||
void ActorList::addPositionActor(LocalActor localActor)
|
||||
{
|
||||
positionActors.push_back(localActor);
|
||||
}
|
||||
|
||||
void ActorList::sendPositionActors()
|
||||
{
|
||||
baseActors = positionActors;
|
||||
Main::get().getNetworking()->getActorPacket(ID_ACTOR_POSITION)->setActorList(this);
|
||||
Main::get().getNetworking()->getActorPacket(ID_ACTOR_POSITION)->Send();
|
||||
}
|
||||
|
||||
// TODO: Finish this
|
||||
void ActorList::editActors(MWWorld::CellStore* cellStore)
|
||||
void ActorList::editActorsInCell(MWWorld::CellStore* cellStore)
|
||||
{
|
||||
BaseActor actor;
|
||||
|
||||
|
@ -68,7 +81,7 @@ void ActorList::editActors(MWWorld::CellStore* cellStore)
|
|||
}
|
||||
}
|
||||
|
||||
void ActorList::sendActors(MWWorld::CellStore* cellStore)
|
||||
void ActorList::sendActorsInCell(MWWorld::CellStore* cellStore)
|
||||
{
|
||||
reset();
|
||||
cell = *cellStore->getCell();
|
||||
|
|
|
@ -21,13 +21,18 @@ namespace mwmp
|
|||
void addActor(BaseActor baseActor);
|
||||
void addActor(LocalActor localActor);
|
||||
|
||||
void editActors(MWWorld::CellStore* cellStore);
|
||||
void addPositionActor(LocalActor localActor);
|
||||
|
||||
void sendActors(MWWorld::CellStore* cellStore);
|
||||
void sendPositionActors();
|
||||
|
||||
void editActorsInCell(MWWorld::CellStore* cellStore);
|
||||
|
||||
void sendActorsInCell(MWWorld::CellStore* cellStore);
|
||||
|
||||
private:
|
||||
Networking *getNetworking();
|
||||
|
||||
std::vector<BaseActor> positionActors;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ mwmp::Cell::~Cell()
|
|||
|
||||
}
|
||||
|
||||
void Cell::updateLocal()
|
||||
void Cell::updateLocal(bool forceUpdate)
|
||||
{
|
||||
if (localActors.empty()) return;
|
||||
|
||||
|
@ -45,20 +45,12 @@ void Cell::updateLocal()
|
|||
}
|
||||
else
|
||||
{
|
||||
//LOG_APPEND(Log::LOG_VERBOSE, "- Updating LocalActor %s", it->first.c_str());
|
||||
actor->update();
|
||||
|
||||
actorList->addActor(*actor);
|
||||
actor->hasAnimation = false;
|
||||
actor->hasAnimStates = false;
|
||||
actor->hasMovement = false;
|
||||
|
||||
actor->update(forceUpdate);
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
Main::get().getNetworking()->getActorPacket(ID_ACTOR_TEST)->setActorList(actorList);
|
||||
Main::get().getNetworking()->getActorPacket(ID_ACTOR_TEST)->Send();
|
||||
actorList->sendPositionActors();
|
||||
}
|
||||
|
||||
void Cell::updateDedicated(float dt)
|
||||
|
@ -73,8 +65,10 @@ void Cell::updateDedicated(float dt)
|
|||
}
|
||||
}
|
||||
|
||||
void Cell::readCellFrame(ActorList& actorList)
|
||||
void Cell::readPositions(ActorList& actorList)
|
||||
{
|
||||
initializeDedicatedActors(actorList);
|
||||
|
||||
BaseActor baseActor;
|
||||
|
||||
for (unsigned int i = 0; i < actorList.count; i++)
|
||||
|
@ -82,51 +76,11 @@ void Cell::readCellFrame(ActorList& actorList)
|
|||
baseActor = actorList.baseActors.at(i);
|
||||
std::string mapIndex = Main::get().getCellController()->generateMapIndex(baseActor);
|
||||
|
||||
// If this key doesn't exist, create it
|
||||
if (dedicatedActors.count(mapIndex) == 0)
|
||||
{
|
||||
MWWorld::Ptr ptrFound = store->searchExact(baseActor.refId, baseActor.refNumIndex, baseActor.mpNum);
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
// If this now exists, set its details
|
||||
if (dedicatedActors.count(mapIndex) > 0)
|
||||
{
|
||||
DedicatedActor *actor = dedicatedActors[mapIndex];
|
||||
actor->position = baseActor.position;
|
||||
actor->drawState = baseActor.drawState;
|
||||
|
||||
actor->headPitch = baseActor.headPitch;
|
||||
actor->headYaw = baseActor.headYaw;
|
||||
|
||||
actor->hasAnimation = baseActor.hasAnimation;
|
||||
actor->hasAnimStates = baseActor.hasAnimStates;
|
||||
actor->hasMovement = baseActor.hasMovement;
|
||||
|
||||
if (actor->hasAnimation)
|
||||
{
|
||||
actor->animation = baseActor.animation;
|
||||
}
|
||||
|
||||
if (actor->hasAnimStates)
|
||||
{
|
||||
actor->animStates = baseActor.animStates;
|
||||
}
|
||||
|
||||
if (actor->hasMovement)
|
||||
{
|
||||
actor->movement = baseActor.movement;
|
||||
}
|
||||
actor->direction = baseActor.direction;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -155,6 +109,34 @@ void Cell::initializeLocalActors()
|
|||
}
|
||||
}
|
||||
|
||||
void Cell::initializeDedicatedActors(ActorList& 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 this key doesn't exist, create it
|
||||
if (dedicatedActors.count(mapIndex) == 0)
|
||||
{
|
||||
MWWorld::Ptr ptrFound = store->searchExact(baseActor.refId, baseActor.refNumIndex, baseActor.mpNum);
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Cell::uninitializeLocalActors()
|
||||
{
|
||||
for (std::map<std::string, LocalActor *>::iterator it = localActors.begin(); it != localActors.end(); ++it)
|
||||
|
|
|
@ -15,12 +15,14 @@ namespace mwmp
|
|||
Cell(MWWorld::CellStore* cellStore);
|
||||
~Cell();
|
||||
|
||||
void updateLocal();
|
||||
void updateLocal(bool forceUpdate);
|
||||
void updateDedicated(float dt);
|
||||
|
||||
void readCellFrame(mwmp::ActorList& actorList);
|
||||
void readPositions(ActorList& actorList);
|
||||
|
||||
void initializeLocalActors();
|
||||
void initializeDedicatedActors(ActorList& actorList);
|
||||
|
||||
void uninitializeLocalActors();
|
||||
void uninitializeDedicatedActors();
|
||||
|
||||
|
@ -32,8 +34,8 @@ namespace mwmp
|
|||
|
||||
private:
|
||||
MWWorld::CellStore* store;
|
||||
std::map<std::string, mwmp::LocalActor *> localActors;
|
||||
std::map<std::string, mwmp::DedicatedActor *> dedicatedActors;
|
||||
std::map<std::string, LocalActor *> localActors;
|
||||
std::map<std::string, DedicatedActor *> dedicatedActors;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ mwmp::CellController::~CellController()
|
|||
|
||||
}
|
||||
|
||||
void CellController::updateLocal()
|
||||
void CellController::updateLocal(bool forceUpdate)
|
||||
{
|
||||
for (std::map<std::string, mwmp::Cell *>::iterator it = cellsActive.begin(); it != cellsActive.end();)
|
||||
{
|
||||
|
@ -43,7 +43,7 @@ void CellController::updateLocal()
|
|||
else
|
||||
{
|
||||
//LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Updating mwmp::Cell %s", mpCell->getDescription().c_str());
|
||||
mpCell->updateLocal();
|
||||
mpCell->updateLocal(forceUpdate);
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ void CellController::initializeLocalActors(const ESM::Cell& cell)
|
|||
}
|
||||
}
|
||||
|
||||
void CellController::readCellFrame(ActorList& actorList)
|
||||
void CellController::readPositions(ActorList& actorList)
|
||||
{
|
||||
std::string mapIndex = actorList.cell.getDescription();
|
||||
|
||||
|
@ -98,7 +98,7 @@ void CellController::readCellFrame(ActorList& actorList)
|
|||
// If this now exists, send it the data
|
||||
if (cellsActive.count(mapIndex) > 0)
|
||||
{
|
||||
cellsActive[mapIndex]->readCellFrame(actorList);
|
||||
cellsActive[mapIndex]->readPositions(actorList);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,12 +16,12 @@ namespace mwmp
|
|||
CellController();
|
||||
~CellController();
|
||||
|
||||
void updateLocal();
|
||||
void updateLocal(bool forceUpdate);
|
||||
void updateDedicated(float dt);
|
||||
|
||||
void initializeCell(const ESM::Cell& cell);
|
||||
void initializeLocalActors(const ESM::Cell& cell);
|
||||
void readCellFrame(mwmp::ActorList& actorList);
|
||||
void readPositions(mwmp::ActorList& actorList);
|
||||
|
||||
void setLocalActorRecord(std::string actorIndex, std::string cellIndex);
|
||||
void removeLocalActorRecord(std::string actorIndex);
|
||||
|
|
|
@ -26,8 +26,8 @@ DedicatedActor::~DedicatedActor()
|
|||
void DedicatedActor::update(float dt)
|
||||
{
|
||||
move(dt);
|
||||
setDrawState();
|
||||
setAnimation();
|
||||
//setDrawState();
|
||||
//setAnimation();
|
||||
}
|
||||
|
||||
void DedicatedActor::move(float dt)
|
||||
|
@ -36,6 +36,11 @@ void DedicatedActor::move(float dt)
|
|||
|
||||
world->moveObject(ptr, position.pos[0], position.pos[1], position.pos[2]);
|
||||
|
||||
MWMechanics::Movement *move = &ptr.getClass().getMovementSettings(ptr);
|
||||
move->mPosition[0] = direction.pos[0];
|
||||
move->mPosition[1] = direction.pos[1];
|
||||
move->mPosition[2] = direction.pos[2];
|
||||
|
||||
world->rotateObject(ptr, position.rot[0], position.rot[1], position.rot[2]);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,17 +8,16 @@
|
|||
#include "../mwworld/worldimp.hpp"
|
||||
|
||||
#include "LocalActor.hpp"
|
||||
#include "Main.hpp"
|
||||
#include "Networking.hpp"
|
||||
#include "ActorList.hpp"
|
||||
|
||||
using namespace mwmp;
|
||||
using namespace std;
|
||||
|
||||
LocalActor::LocalActor()
|
||||
{
|
||||
headPitch = -1;
|
||||
headYaw = -1;
|
||||
hasAnimation = false;
|
||||
hasAnimStates = false;
|
||||
hasMovement = false;
|
||||
posWasChanged = false;
|
||||
}
|
||||
|
||||
LocalActor::~LocalActor()
|
||||
|
@ -26,15 +25,26 @@ LocalActor::~LocalActor()
|
|||
|
||||
}
|
||||
|
||||
void LocalActor::update()
|
||||
void LocalActor::update(bool forceUpdate)
|
||||
{
|
||||
updatePosition();
|
||||
updatePosition(forceUpdate);
|
||||
updateDrawState();
|
||||
}
|
||||
|
||||
void LocalActor::updatePosition()
|
||||
void LocalActor::updatePosition(bool forceUpdate)
|
||||
{
|
||||
position = ptr.getRefData().getPosition();
|
||||
bool posIsChanging = (direction.pos[0] != 0 || direction.pos[1] != 0 || direction.pos[2] != 0 ||
|
||||
direction.rot[0] != 0 || direction.rot[1] != 0 || direction.rot[2] != 0);
|
||||
|
||||
if (posIsChanging || posWasChanged)
|
||||
{
|
||||
posWasChanged = posIsChanging;
|
||||
|
||||
position = ptr.getRefData().getPosition();
|
||||
|
||||
ActorList *actorList = mwmp::Main::get().getNetworking()->getActorList();
|
||||
actorList->addPositionActor(*this);
|
||||
}
|
||||
}
|
||||
|
||||
void LocalActor::updateDrawState()
|
||||
|
|
|
@ -13,9 +13,9 @@ namespace mwmp
|
|||
LocalActor();
|
||||
virtual ~LocalActor();
|
||||
|
||||
void update();
|
||||
void update(bool forceUpdate);
|
||||
|
||||
void updatePosition();
|
||||
void updatePosition(bool forceUpdate);
|
||||
void updateDrawState();
|
||||
|
||||
MWWorld::Ptr getPtr();
|
||||
|
@ -23,6 +23,8 @@ namespace mwmp
|
|||
|
||||
private:
|
||||
MWWorld::Ptr ptr;
|
||||
|
||||
bool posWasChanged;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -211,7 +211,7 @@ void Main::updateWorld(float dt) const
|
|||
else
|
||||
{
|
||||
mLocalPlayer->update();
|
||||
mCellController->updateLocal();
|
||||
mCellController->updateLocal(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -853,7 +853,7 @@ void Networking::processActorPacket(RakNet::Packet *packet)
|
|||
|
||||
// If we've received a request for information, comply with it
|
||||
if (actorList.action == mwmp::BaseActorList::REQUEST)
|
||||
actorList.sendActors(ptrCellStore);
|
||||
actorList.sendActorsInCell(ptrCellStore);
|
||||
|
||||
break;
|
||||
}
|
||||
|
@ -865,6 +865,12 @@ void Networking::processActorPacket(RakNet::Packet *packet)
|
|||
|
||||
break;
|
||||
}
|
||||
case ID_ACTOR_POSITION:
|
||||
{
|
||||
//Main::get().getCellController()->readPositions(actorList);
|
||||
|
||||
break;
|
||||
}
|
||||
case ID_ACTOR_TEST:
|
||||
{
|
||||
//Main::get().getCellController()->readCellFrame(actorList);
|
||||
|
|
Loading…
Reference in a new issue