From 068a45be8799b36bf47086767245fe86eb473af5 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Tue, 30 May 2017 12:08:58 +0300 Subject: [PATCH] [General] Synchronize player & NPC rotation animations --- apps/openmw/mwmechanics/character.cpp | 29 ++++++++++++++----- apps/openmw/mwmp/DedicatedActor.cpp | 3 ++ apps/openmw/mwmp/DedicatedPlayer.cpp | 6 +++- apps/openmw/mwmp/LocalPlayer.cpp | 10 ++----- .../Packets/Actor/PacketActorCellChange.cpp | 2 +- .../Packets/Actor/PacketActorPosition.cpp | 2 +- .../Packets/Player/PacketPlayerPosition.cpp | 2 +- 7 files changed, 34 insertions(+), 20 deletions(-) diff --git a/apps/openmw/mwmechanics/character.cpp b/apps/openmw/mwmechanics/character.cpp index 98622d12a..949eeb3f0 100644 --- a/apps/openmw/mwmechanics/character.cpp +++ b/apps/openmw/mwmechanics/character.cpp @@ -1685,17 +1685,30 @@ void CharacterController::update(float duration) Start of tes3mp addition Character movement setting rotations get reset here, so we have to assign movement - settings to a relevant LocalActor now + settings to the LocalPlayer or a LocalActor now */ - if (mwmp::Main::get().getCellController()->isLocalActor(mPtr)) + if (MWBase::Environment::get().getWorld()->getPlayerPtr() == mPtr) + { + mwmp::LocalPlayer *localPlayer = mwmp::Main::get().getLocalPlayer(); + MWMechanics::Movement &movementSettings = mPtr.getClass().getMovementSettings(mPtr); + localPlayer->direction.pos[0] = movementSettings.mPosition[0]; + localPlayer->direction.pos[1] = movementSettings.mPosition[1]; + localPlayer->direction.pos[2] = movementSettings.mPosition[2]; + localPlayer->direction.rot[0] = movementSettings.mRotation[0]; + localPlayer->direction.rot[1] = movementSettings.mRotation[1]; + localPlayer->direction.rot[2] = movementSettings.mRotation[2]; + } + + else if (mwmp::Main::get().getCellController()->isLocalActor(mPtr)) { mwmp::LocalActor *localActor = mwmp::Main::get().getCellController()->getLocalActor(mPtr); - localActor->direction.pos[0] = cls.getMovementSettings(mPtr).mPosition[0]; - localActor->direction.pos[1] = cls.getMovementSettings(mPtr).mPosition[1]; - localActor->direction.pos[2] = cls.getMovementSettings(mPtr).mPosition[2]; - localActor->direction.rot[0] = cls.getMovementSettings(mPtr).mRotation[0]; - localActor->direction.rot[1] = cls.getMovementSettings(mPtr).mRotation[1]; - localActor->direction.rot[2] = cls.getMovementSettings(mPtr).mRotation[2]; + MWMechanics::Movement &movementSettings = mPtr.getClass().getMovementSettings(mPtr); + localActor->direction.pos[0] = movementSettings.mPosition[0]; + localActor->direction.pos[1] = movementSettings.mPosition[1]; + localActor->direction.pos[2] = movementSettings.mPosition[2]; + localActor->direction.rot[0] = movementSettings.mRotation[0]; + localActor->direction.rot[1] = movementSettings.mRotation[1]; + localActor->direction.rot[2] = movementSettings.mRotation[2]; } /* End of tes3mp addition diff --git a/apps/openmw/mwmp/DedicatedActor.cpp b/apps/openmw/mwmp/DedicatedActor.cpp index 6f8a59f5d..fa0709190 100644 --- a/apps/openmw/mwmp/DedicatedActor.cpp +++ b/apps/openmw/mwmp/DedicatedActor.cpp @@ -104,6 +104,9 @@ void DedicatedActor::setMovementSettings() move->mPosition[0] = direction.pos[0]; move->mPosition[1] = direction.pos[1]; move->mPosition[2] = direction.pos[2]; + move->mRotation[0] = direction.rot[0]; + move->mRotation[1] = direction.rot[1]; + move->mRotation[2] = direction.rot[2]; } void DedicatedActor::setPosition() diff --git a/apps/openmw/mwmp/DedicatedPlayer.cpp b/apps/openmw/mwmp/DedicatedPlayer.cpp index f7eee2076..ab30052eb 100644 --- a/apps/openmw/mwmp/DedicatedPlayer.cpp +++ b/apps/openmw/mwmp/DedicatedPlayer.cpp @@ -117,12 +117,16 @@ void DedicatedPlayer::move(float dt) world->moveObject(ptr, position.pos[0], position.pos[1], position.pos[2]); } + world->rotateObject(ptr, position.rot[0], position.rot[1], position.rot[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]; + move->mRotation[0] = direction.rot[0]; + move->mRotation[1] = direction.rot[1]; + move->mRotation[2] = direction.rot[2]; - world->rotateObject(ptr, position.rot[0], position.rot[1], position.rot[2]); } void DedicatedPlayer::setAnimFlags() diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index 40b05991c..bd1dcae96 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -324,10 +324,8 @@ void LocalPlayer::updatePosition(bool forceUpdate) static bool isJumping = false; static bool sentJumpEnd = true; - const MWMechanics::Movement &move = player.getClass().getMovementSettings(player); - - bool posIsChanging = (move.mPosition[0] != 0 || move.mPosition[1] != 0 || move.mPosition[2] != 0 || - move.mRotation[0] != 0 || move.mRotation[1] != 0 || move.mRotation[2] != 0); + 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 (forceUpdate || posIsChanging || posWasChanged) { @@ -340,10 +338,6 @@ void LocalPlayer::updatePosition(bool forceUpdate) position = player.getRefData().getPosition(); - direction.pos[0] = move.mPosition[0]; - direction.pos[1] = move.mPosition[1]; - direction.pos[2] = move.mPosition[2]; - getNetworking()->getPlayerPacket(ID_PLAYER_POSITION)->setPlayer(this); getNetworking()->getPlayerPacket(ID_PLAYER_POSITION)->Send(); } diff --git a/components/openmw-mp/Packets/Actor/PacketActorCellChange.cpp b/components/openmw-mp/Packets/Actor/PacketActorCellChange.cpp index 2d187ca6f..02d9bd234 100644 --- a/components/openmw-mp/Packets/Actor/PacketActorCellChange.cpp +++ b/components/openmw-mp/Packets/Actor/PacketActorCellChange.cpp @@ -36,7 +36,7 @@ void PacketActorCellChange::Packet(RakNet::BitStream *bs, bool send) RW(actor.cell.mName, send, 1); RW(actor.position, send, 1); - RW(actor.direction.pos, send, 1); + RW(actor.direction, send, 1); if (!send) { diff --git a/components/openmw-mp/Packets/Actor/PacketActorPosition.cpp b/components/openmw-mp/Packets/Actor/PacketActorPosition.cpp index 04b29ad7f..e6f6cfa20 100644 --- a/components/openmw-mp/Packets/Actor/PacketActorPosition.cpp +++ b/components/openmw-mp/Packets/Actor/PacketActorPosition.cpp @@ -31,7 +31,7 @@ void PacketActorPosition::Packet(RakNet::BitStream *bs, bool send) RW(actor.mpNum, send); RW(actor.position, send, 1); - RW(actor.direction.pos, send, 1); + RW(actor.direction, send, 1); actor.hasPositionData = true; diff --git a/components/openmw-mp/Packets/Player/PacketPlayerPosition.cpp b/components/openmw-mp/Packets/Player/PacketPlayerPosition.cpp index c9c3b0769..cc2e63496 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerPosition.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerPosition.cpp @@ -20,5 +20,5 @@ void PacketPlayerPosition::Packet(RakNet::BitStream *bs, bool send) PlayerPacket::Packet(bs, send); RW(player->position, send, 1); - RW(player->direction.pos, send, 1); + RW(player->direction, send, 1); }