From 038757b91a73b490545236360b6c6b3f305b36a7 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sat, 21 Jul 2018 19:27:36 +0300 Subject: [PATCH] [General] Temporarily revert to original rotation animation sync I originally added rotation animation sync as part of commit 068a45be8799b36bf47086767245fe86eb473af5. Unfortunately, it meant the PlayerPosition packets were now twice as large as they had been before, which was less than ideal for such a frequently sent packet, which is why Koncord switched to a more optimized approach in commits 5f30dfd5db19da0faf12fc09fae34968e61ec4d4 and d67db1a9bdbda521ccc57aa4fa386e040197fc09. Recently, there have since been some rotation animation problems in OpenMW, which have broken the way Koncord's approach looks. My original approach still looks somewhat okay, so I'm switching back to it until we can figure out how to reuse it under the current circumstances. --- apps/openmw/mwmechanics/character.cpp | 4 +++ apps/openmw/mwmp/DedicatedPlayer.cpp | 12 ++++++--- apps/openmw/mwmp/LocalPlayer.cpp | 2 +- .../Packets/Player/PacketPlayerPosition.cpp | 25 ++----------------- 4 files changed, 16 insertions(+), 27 deletions(-) diff --git a/apps/openmw/mwmechanics/character.cpp b/apps/openmw/mwmechanics/character.cpp index 56a145522..f0fbbadf6 100644 --- a/apps/openmw/mwmechanics/character.cpp +++ b/apps/openmw/mwmechanics/character.cpp @@ -1871,6 +1871,10 @@ void CharacterController::update(float duration) MWMechanics::Movement &movementSettings = cls.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)) { diff --git a/apps/openmw/mwmp/DedicatedPlayer.cpp b/apps/openmw/mwmp/DedicatedPlayer.cpp index 2e26c586b..89c34bcb2 100644 --- a/apps/openmw/mwmp/DedicatedPlayer.cpp +++ b/apps/openmw/mwmp/DedicatedPlayer.cpp @@ -133,14 +133,20 @@ void DedicatedPlayer::move(float dt) else world->moveObject(ptr, position.pos[0], position.pos[1], position.pos[2]); - float oldZ = ptr.getRefData().getPosition().rot[2]; - world->rotateObject(ptr, position.rot[0], 0, oldZ); + world->rotateObject(ptr, position.rot[0], 0, 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]; - MWMechanics::zTurn(ptr, position.rot[2], osg::DegreesToRadians(1.0)); + // Make sure the values are valid, or we'll get an infinite error loop + if (!isnan(direction.rot[0]) && !isnan(direction.rot[1]) && !isnan(direction.rot[2])) + { + move->mRotation[0] = direction.rot[0]; + move->mRotation[1] = direction.rot[1]; + move->mRotation[2] = direction.rot[2]; + } } void DedicatedPlayer::setBaseInfo() diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index 5a4714019..2925b2ad2 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -383,7 +383,7 @@ void LocalPlayer::updatePosition(bool forceUpdate) position = ptrPlayer.getRefData().getPosition(); bool posIsChanging = (direction.pos[0] != 0 || direction.pos[1] != 0 || - position.rot[0] != oldRot[0] || position.rot[2] != oldRot[1]); + direction.rot[0] != 0 || direction.rot[1] != 0 || direction.rot[2] != 0); // Animations can change a player's position without actually creating directional movement, // so update positions accordingly diff --git a/components/openmw-mp/Packets/Player/PacketPlayerPosition.cpp b/components/openmw-mp/Packets/Player/PacketPlayerPosition.cpp index 9dc55b41a..cc2e63496 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerPosition.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerPosition.cpp @@ -19,27 +19,6 @@ void PacketPlayerPosition::Packet(RakNet::BitStream *bs, bool send) { PlayerPacket::Packet(bs, send); - float rot[2]; - unsigned char dir; - if (send) - { - rot[0] = player->position.rot[0] * 0.1f; - rot[1] = player->position.rot[2] * 0.1f; - - dir = (player->direction.pos[0] >= 0 ? (unsigned char)(player->direction.pos[0]) : (unsigned char) 0x3) << 2; // pack direction - dir += (player->direction.pos[1] >= 0 ? (unsigned char)(player->direction.pos[1]) : (unsigned char) 0x3); - } - RW(rot[0], send, true); - RW(rot[1], send, true); - - RW(player->position.pos, send, true); - RW(dir, send); - - if (!send) - { - player->position.rot[0] = rot[0] / 0.1f; - player->position.rot[2] = rot[1] / 0.1f; - player->direction.pos[0] = (dir >> 2) == 0x3 ? -1 : dir >> 2; // unpack direction - player->direction.pos[1] = (dir & 0x3) == 0x3 ? -1 : dir & 0x3; - } + RW(player->position, send, 1); + RW(player->direction, send, 1); }