From 63480a0012548e5653f06f9cb1cea420018571c2 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sun, 26 Jul 2020 17:58:59 +0200 Subject: [PATCH] [Client] Use DetourNavigator for local actors, working around c1ebd9474bdafb7c252428c83927802eac09b269 --- apps/openmw/mwmp/CellController.cpp | 26 ++++++++++++++----- .../actor/ProcessorActorAuthority.hpp | 6 +++++ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwmp/CellController.cpp b/apps/openmw/mwmp/CellController.cpp index e55cf808a..a1f3e68e0 100644 --- a/apps/openmw/mwmp/CellController.cpp +++ b/apps/openmw/mwmp/CellController.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -31,12 +32,14 @@ CellController::~CellController() void CellController::updateLocal(bool forceUpdate) { + MWBase::World* world = MWBase::Environment::get().getWorld(); + // Loop through Cells, deleting inactive ones and updating LocalActors in active ones for (auto it = cellsInitialized.begin(); it != cellsInitialized.end();) { mwmp::Cell *mpCell = it->second; - if (!MWBase::Environment::get().getWorld()->isCellActive(*mpCell->getCellStore()->getCell())) + if (!world->isCellActive(*mpCell->getCellStore()->getCell())) { mpCell->uninitializeLocalActors(); mpCell->uninitializeDedicatedActors(); @@ -50,19 +53,28 @@ void CellController::updateLocal(bool forceUpdate) } } - // Loop through Cells and initialize new LocalActors for eligible ones + // If there are cellsInitialized remaining, loop through them and initialize new LocalActors for eligible ones + // // // Note: This cannot be combined with the above loop because initializing LocalActors in a Cell before they are // deleted from their previous one can make their records stay deleted - for (auto &cell : cellsInitialized) + if (cellsInitialized.size() > 0) { - mwmp::Cell *mpCell = cell.second; - if (mpCell->shouldInitializeActors == true) + for (auto& cell : cellsInitialized) { - mpCell->shouldInitializeActors = false; - mpCell->initializeLocalActors(); + mwmp::Cell* mpCell = cell.second; + if (mpCell->shouldInitializeActors == true) + { + mpCell->shouldInitializeActors = false; + mpCell->initializeLocalActors(); + } } } + // Otherwise, disable the DetourNavigator for advanced pathfinding for the time being + else + { + world->getNavigator()->setUpdatesEnabled(false); + } } void CellController::updateDedicated(float dt) diff --git a/apps/openmw/mwmp/processors/actor/ProcessorActorAuthority.hpp b/apps/openmw/mwmp/processors/actor/ProcessorActorAuthority.hpp index e454084c8..2ac91d2c0 100644 --- a/apps/openmw/mwmp/processors/actor/ProcessorActorAuthority.hpp +++ b/apps/openmw/mwmp/processors/actor/ProcessorActorAuthority.hpp @@ -3,6 +3,7 @@ #include "../ActorProcessor.hpp" +#include #include "apps/openmw/mwmp/Main.hpp" #include "apps/openmw/mwmp/CellController.hpp" @@ -34,6 +35,11 @@ namespace mwmp cell->uninitializeDedicatedActors(); cell->initializeLocalActors(); cell->updateLocal(true); + + // Enable updates for DetourNavigator for advanced pathfinding + MWBase::World* world = MWBase::Environment::get().getWorld(); + world->getNavigator()->setUpdatesEnabled(true); + world->getNavigator()->update(world->getPlayerPtr().getRefData().getPosition().asVec3()); } else {