mirror of
https://github.com/TES3MP/TES3MP.git
synced 2025-09-28 07:32:00 -04:00
[Client] Retool LocalActors and DedicatedActors for ActorPosition packet
This commit is contained in:
parent
cbd2af972d
commit
d14102716d
@ -27,6 +27,7 @@ void ActorList::reset()
|
|||||||
{
|
{
|
||||||
cell.blank();
|
cell.blank();
|
||||||
baseActors.clear();
|
baseActors.clear();
|
||||||
|
positionActors.clear();
|
||||||
guid = mwmp::Main::get().getNetworking()->getLocalPlayer()->guid;
|
guid = mwmp::Main::get().getNetworking()->getLocalPlayer()->guid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,8 +41,20 @@ void ActorList::addActor(LocalActor localActor)
|
|||||||
baseActors.push_back(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
|
// TODO: Finish this
|
||||||
void ActorList::editActors(MWWorld::CellStore* cellStore)
|
void ActorList::editActorsInCell(MWWorld::CellStore* cellStore)
|
||||||
{
|
{
|
||||||
BaseActor actor;
|
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();
|
reset();
|
||||||
cell = *cellStore->getCell();
|
cell = *cellStore->getCell();
|
||||||
|
@ -21,13 +21,18 @@ namespace mwmp
|
|||||||
void addActor(BaseActor baseActor);
|
void addActor(BaseActor baseActor);
|
||||||
void addActor(LocalActor localActor);
|
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:
|
private:
|
||||||
Networking *getNetworking();
|
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;
|
if (localActors.empty()) return;
|
||||||
|
|
||||||
@ -45,20 +45,12 @@ void Cell::updateLocal()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//LOG_APPEND(Log::LOG_VERBOSE, "- Updating LocalActor %s", it->first.c_str());
|
actor->update(forceUpdate);
|
||||||
actor->update();
|
|
||||||
|
|
||||||
actorList->addActor(*actor);
|
|
||||||
actor->hasAnimation = false;
|
|
||||||
actor->hasAnimStates = false;
|
|
||||||
actor->hasMovement = false;
|
|
||||||
|
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Main::get().getNetworking()->getActorPacket(ID_ACTOR_TEST)->setActorList(actorList);
|
actorList->sendPositionActors();
|
||||||
Main::get().getNetworking()->getActorPacket(ID_ACTOR_TEST)->Send();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cell::updateDedicated(float dt)
|
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;
|
BaseActor baseActor;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < actorList.count; i++)
|
for (unsigned int i = 0; i < actorList.count; i++)
|
||||||
@ -82,51 +76,11 @@ void Cell::readCellFrame(ActorList& actorList)
|
|||||||
baseActor = actorList.baseActors.at(i);
|
baseActor = actorList.baseActors.at(i);
|
||||||
std::string mapIndex = Main::get().getCellController()->generateMapIndex(baseActor);
|
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)
|
if (dedicatedActors.count(mapIndex) > 0)
|
||||||
{
|
{
|
||||||
DedicatedActor *actor = dedicatedActors[mapIndex];
|
DedicatedActor *actor = dedicatedActors[mapIndex];
|
||||||
actor->position = baseActor.position;
|
actor->position = baseActor.position;
|
||||||
actor->drawState = baseActor.drawState;
|
actor->direction = baseActor.direction;
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -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()
|
void Cell::uninitializeLocalActors()
|
||||||
{
|
{
|
||||||
for (std::map<std::string, LocalActor *>::iterator it = localActors.begin(); it != localActors.end(); ++it)
|
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(MWWorld::CellStore* cellStore);
|
||||||
~Cell();
|
~Cell();
|
||||||
|
|
||||||
void updateLocal();
|
void updateLocal(bool forceUpdate);
|
||||||
void updateDedicated(float dt);
|
void updateDedicated(float dt);
|
||||||
|
|
||||||
void readCellFrame(mwmp::ActorList& actorList);
|
void readPositions(ActorList& actorList);
|
||||||
|
|
||||||
void initializeLocalActors();
|
void initializeLocalActors();
|
||||||
|
void initializeDedicatedActors(ActorList& actorList);
|
||||||
|
|
||||||
void uninitializeLocalActors();
|
void uninitializeLocalActors();
|
||||||
void uninitializeDedicatedActors();
|
void uninitializeDedicatedActors();
|
||||||
|
|
||||||
@ -32,8 +34,8 @@ namespace mwmp
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
MWWorld::CellStore* store;
|
MWWorld::CellStore* store;
|
||||||
std::map<std::string, mwmp::LocalActor *> localActors;
|
std::map<std::string, LocalActor *> localActors;
|
||||||
std::map<std::string, mwmp::DedicatedActor *> dedicatedActors;
|
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();)
|
for (std::map<std::string, mwmp::Cell *>::iterator it = cellsActive.begin(); it != cellsActive.end();)
|
||||||
{
|
{
|
||||||
@ -43,7 +43,7 @@ void CellController::updateLocal()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
//LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Updating mwmp::Cell %s", mpCell->getDescription().c_str());
|
//LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Updating mwmp::Cell %s", mpCell->getDescription().c_str());
|
||||||
mpCell->updateLocal();
|
mpCell->updateLocal(forceUpdate);
|
||||||
++it;
|
++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();
|
std::string mapIndex = actorList.cell.getDescription();
|
||||||
|
|
||||||
@ -98,7 +98,7 @@ void CellController::readCellFrame(ActorList& actorList)
|
|||||||
// 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(actorList);
|
cellsActive[mapIndex]->readPositions(actorList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,12 +16,12 @@ namespace mwmp
|
|||||||
CellController();
|
CellController();
|
||||||
~CellController();
|
~CellController();
|
||||||
|
|
||||||
void updateLocal();
|
void updateLocal(bool forceUpdate);
|
||||||
void updateDedicated(float dt);
|
void updateDedicated(float dt);
|
||||||
|
|
||||||
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::ActorList& actorList);
|
void readPositions(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);
|
||||||
|
@ -26,8 +26,8 @@ DedicatedActor::~DedicatedActor()
|
|||||||
void DedicatedActor::update(float dt)
|
void DedicatedActor::update(float dt)
|
||||||
{
|
{
|
||||||
move(dt);
|
move(dt);
|
||||||
setDrawState();
|
//setDrawState();
|
||||||
setAnimation();
|
//setAnimation();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DedicatedActor::move(float dt)
|
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]);
|
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]);
|
world->rotateObject(ptr, position.rot[0], position.rot[1], position.rot[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,17 +8,16 @@
|
|||||||
#include "../mwworld/worldimp.hpp"
|
#include "../mwworld/worldimp.hpp"
|
||||||
|
|
||||||
#include "LocalActor.hpp"
|
#include "LocalActor.hpp"
|
||||||
|
#include "Main.hpp"
|
||||||
|
#include "Networking.hpp"
|
||||||
|
#include "ActorList.hpp"
|
||||||
|
|
||||||
using namespace mwmp;
|
using namespace mwmp;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
LocalActor::LocalActor()
|
LocalActor::LocalActor()
|
||||||
{
|
{
|
||||||
headPitch = -1;
|
posWasChanged = false;
|
||||||
headYaw = -1;
|
|
||||||
hasAnimation = false;
|
|
||||||
hasAnimStates = false;
|
|
||||||
hasMovement = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LocalActor::~LocalActor()
|
LocalActor::~LocalActor()
|
||||||
@ -26,15 +25,26 @@ LocalActor::~LocalActor()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalActor::update()
|
void LocalActor::update(bool forceUpdate)
|
||||||
{
|
{
|
||||||
updatePosition();
|
updatePosition(forceUpdate);
|
||||||
updateDrawState();
|
updateDrawState();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalActor::updatePosition()
|
void LocalActor::updatePosition(bool forceUpdate)
|
||||||
{
|
{
|
||||||
|
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();
|
position = ptr.getRefData().getPosition();
|
||||||
|
|
||||||
|
ActorList *actorList = mwmp::Main::get().getNetworking()->getActorList();
|
||||||
|
actorList->addPositionActor(*this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalActor::updateDrawState()
|
void LocalActor::updateDrawState()
|
||||||
|
@ -13,9 +13,9 @@ namespace mwmp
|
|||||||
LocalActor();
|
LocalActor();
|
||||||
virtual ~LocalActor();
|
virtual ~LocalActor();
|
||||||
|
|
||||||
void update();
|
void update(bool forceUpdate);
|
||||||
|
|
||||||
void updatePosition();
|
void updatePosition(bool forceUpdate);
|
||||||
void updateDrawState();
|
void updateDrawState();
|
||||||
|
|
||||||
MWWorld::Ptr getPtr();
|
MWWorld::Ptr getPtr();
|
||||||
@ -23,6 +23,8 @@ namespace mwmp
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
MWWorld::Ptr ptr;
|
MWWorld::Ptr ptr;
|
||||||
|
|
||||||
|
bool posWasChanged;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -211,7 +211,7 @@ void Main::updateWorld(float dt) const
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
mLocalPlayer->update();
|
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 we've received a request for information, comply with it
|
||||||
if (actorList.action == mwmp::BaseActorList::REQUEST)
|
if (actorList.action == mwmp::BaseActorList::REQUEST)
|
||||||
actorList.sendActors(ptrCellStore);
|
actorList.sendActorsInCell(ptrCellStore);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -865,6 +865,12 @@ void Networking::processActorPacket(RakNet::Packet *packet)
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case ID_ACTOR_POSITION:
|
||||||
|
{
|
||||||
|
//Main::get().getCellController()->readPositions(actorList);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
case ID_ACTOR_TEST:
|
case ID_ACTOR_TEST:
|
||||||
{
|
{
|
||||||
//Main::get().getCellController()->readCellFrame(actorList);
|
//Main::get().getCellController()->readCellFrame(actorList);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user