1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-16 18:19:55 +00:00

[Client] Make DedicatedActors transition into LocalActors when eligible

This commit is contained in:
David Cernat 2017-05-05 07:37:09 +03:00
parent 06f3c07116
commit 60cf623455
4 changed files with 41 additions and 14 deletions

View file

@ -243,28 +243,47 @@ void Cell::readCellChange(ActorList& actorList)
if (dedicatedActors.count(mapIndex) > 0)
{
DedicatedActor *actor = dedicatedActors[mapIndex];
actor->cell = baseActor.cell;
actor->position = baseActor.position;
DedicatedActor *dedicatedActor = dedicatedActors[mapIndex];
dedicatedActor->cell = baseActor.cell;
dedicatedActor->position = baseActor.position;
dedicatedActor->direction = baseActor.direction;
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Server says DedicatedActor %s moved to %s", mapIndex.c_str(), actor->cell.getDescription().c_str());
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Server says DedicatedActor %s moved to %s", mapIndex.c_str(), dedicatedActor->cell.getDescription().c_str());
MWWorld::CellStore *newStore = cellController->getCellStore(actor->cell);
actor->setCell(newStore);
MWWorld::CellStore *newStore = cellController->getCellStore(dedicatedActor->cell);
dedicatedActor->setCell(newStore);
// If the cell this actor has moved to is active and not under our authority, move them to it
if (cellController->isInitializedCell(actor->cell))
if (cellController->isActiveWorldCell(dedicatedActor->cell) && !cellController->hasLocalAuthority(dedicatedActor->cell))
{
LOG_APPEND(Log::LOG_INFO, "- Moving DedicatedActor %s to our active cell %s", mapIndex.c_str(), actor->cell.getDescription().c_str());
Cell *newCell = cellController->getCell(actor->cell);
newCell->dedicatedActors[mapIndex] = actor;
LOG_APPEND(Log::LOG_INFO, "- Moving DedicatedActor %s to our active cell %s", mapIndex.c_str(), dedicatedActor->cell.getDescription().c_str());
Cell *newCell = cellController->getCell(dedicatedActor->cell);
newCell->dedicatedActors[mapIndex] = dedicatedActor;
cellController->setDedicatedActorRecord(mapIndex, newCell->getDescription());
}
else
{
LOG_APPEND(Log::LOG_INFO, "- Deleting DedicatedActor %s which is no longer in an active cell", mapIndex.c_str(), getDescription().c_str());
if (cellController->hasLocalAuthority(dedicatedActor->cell))
{
LOG_APPEND(Log::LOG_INFO, "- Creating new LocalActor based on %s in %s", mapIndex.c_str(), dedicatedActor->cell.getDescription().c_str());
Cell *newCell = cellController->getCell(dedicatedActor->cell);
LocalActor *localActor = new LocalActor();
localActor->cell = dedicatedActor->cell;
localActor->setPtr(dedicatedActor->getPtr());
localActor->position = dedicatedActor->position;
localActor->direction = dedicatedActor->direction;
localActor->movementFlags = dedicatedActor->movementFlags;
localActor->drawState = dedicatedActor->drawState;
localActor->isFlying = dedicatedActor->isFlying;
localActor->creatureStats = dedicatedActor->creatureStats;
newCell->localActors[mapIndex] = localActor;
cellController->setLocalActorRecord(mapIndex, newCell->getDescription());
}
LOG_APPEND(Log::LOG_INFO, "- Deleting DedicatedActor %s which is no longer needed", mapIndex.c_str(), getDescription().c_str());
cellController->removeDedicatedActorRecord(mapIndex);
delete actor;
delete dedicatedActor;
}
dedicatedActors.erase(mapIndex);

View file

@ -55,6 +55,7 @@ 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]);
setMovementSettings();
hasChangedCell = true;
}
@ -79,15 +80,20 @@ void DedicatedActor::move(float dt)
else
{
setPosition();
setMovementSettings();
hasChangedCell = false;
}
setMovementSettings();
world->rotateObject(ptr, position.rot[0], position.rot[1], position.rot[2]);
}
void DedicatedActor::setMovementSettings()
{
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]);
}
void DedicatedActor::setPosition()

View file

@ -17,6 +17,7 @@ namespace mwmp
void update(float dt);
void move(float dt);
void setCell(MWWorld::CellStore *cellStore);
void setMovementSettings();
void setPosition();
void setAnimFlags();
void playAnimation();

View file

@ -44,6 +44,7 @@ void PacketActorCellChange::Packet(RakNet::BitStream *bs, bool send)
RW(actor.cell.mName, send);
RW(actor.position, send);
RW(actor.direction, send);
if (!send)
{