From 5bd224489878dcf33e685499048c04d846233677 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Thu, 16 Aug 2018 03:50:41 +0300 Subject: [PATCH] [Client] Uninitialize DedicatedActors instantly in some situations When LocalActors briefly become DedicatedActors as the result of a server script, the DedicatedActors are immediately uninitialized to avoid bugs like them jumping in place or rotating slightly. Additionally, the playing of animations and sounds received in packets for DedicatedActors is no longer done during their next update, but is instead done instantly when the packets are received. --- apps/openmw/mwmp/Cell.cpp | 22 ++++++++++++++++++++++ apps/openmw/mwmp/Cell.hpp | 1 + apps/openmw/mwmp/DedicatedActor.cpp | 2 -- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwmp/Cell.cpp b/apps/openmw/mwmp/Cell.cpp index 6b3813f3e..fb5ac74f5 100644 --- a/apps/openmw/mwmp/Cell.cpp +++ b/apps/openmw/mwmp/Cell.cpp @@ -171,6 +171,7 @@ void Cell::readAnimPlay(ActorList& actorList) actor->animation.mode = baseActor.animation.mode; actor->animation.count = baseActor.animation.count; actor->animation.persist = baseActor.animation.persist; + actor->playAnimation(); } } } @@ -229,6 +230,9 @@ void Cell::readEquipment(ActorList& actorList) actor->setEquipment(); } } + + if (hasLocalAuthority()) + uninitializeDedicatedActors(actorList); } void Cell::readSpeech(ActorList& actorList) @@ -243,8 +247,12 @@ void Cell::readSpeech(ActorList& actorList) { DedicatedActor *actor = dedicatedActors[mapIndex]; actor->sound = baseActor.sound; + actor->playSound(); } } + + if (hasLocalAuthority()) + uninitializeDedicatedActors(actorList); } void Cell::readAi(ActorList& actorList) @@ -268,6 +276,9 @@ void Cell::readAi(ActorList& actorList) actor->setAi(); } } + + if (hasLocalAuthority()) + uninitializeDedicatedActors(actorList); } void Cell::readAttack(ActorList& actorList) @@ -454,6 +465,17 @@ void Cell::uninitializeLocalActors() localActors.clear(); } +void Cell::uninitializeDedicatedActors(ActorList& actorList) +{ + for (const auto &baseActor : actorList.baseActors) + { + std::string mapIndex = Main::get().getCellController()->generateMapIndex(baseActor); + Main::get().getCellController()->removeDedicatedActorRecord(mapIndex); + delete dedicatedActors.at(mapIndex); + dedicatedActors.erase(mapIndex); + } +} + void Cell::uninitializeDedicatedActors() { for (const auto &actor : dedicatedActors) diff --git a/apps/openmw/mwmp/Cell.hpp b/apps/openmw/mwmp/Cell.hpp index ab81c9030..f367b9728 100644 --- a/apps/openmw/mwmp/Cell.hpp +++ b/apps/openmw/mwmp/Cell.hpp @@ -35,6 +35,7 @@ namespace mwmp void initializeDedicatedActors(ActorList& actorList); void uninitializeLocalActors(); + void uninitializeDedicatedActors(ActorList& actorList); void uninitializeDedicatedActors(); virtual LocalActor *getLocalActor(std::string actorIndex); diff --git a/apps/openmw/mwmp/DedicatedActor.cpp b/apps/openmw/mwmp/DedicatedActor.cpp index 0e4565eef..fe26a4b84 100644 --- a/apps/openmw/mwmp/DedicatedActor.cpp +++ b/apps/openmw/mwmp/DedicatedActor.cpp @@ -61,8 +61,6 @@ void DedicatedActor::update(float dt) setAnimFlags(); } - playAnimation(); - playSound(); setStatsDynamic(); }