From 4b4025ed0fb87113700dd1208657350a58fde5e1 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 30 Nov 2013 10:50:02 +0100 Subject: [PATCH] Keep the player's CharacterController when changing cells. Fixes several glitches. --- apps/openmw/mwmechanics/actors.cpp | 4 ++-- apps/openmw/mwmechanics/actors.hpp | 4 ++-- apps/openmw/mwmechanics/mechanicsmanagerimp.cpp | 5 +---- apps/openmw/mwworld/scene.cpp | 8 ++++---- apps/openmw/mwworld/worldimp.cpp | 2 +- 5 files changed, 10 insertions(+), 13 deletions(-) diff --git a/apps/openmw/mwmechanics/actors.cpp b/apps/openmw/mwmechanics/actors.cpp index 161c8dcfe..22a641b34 100644 --- a/apps/openmw/mwmechanics/actors.cpp +++ b/apps/openmw/mwmechanics/actors.cpp @@ -516,12 +516,12 @@ namespace MWMechanics } } - void Actors::dropActors (const MWWorld::Ptr::CellStore *cellStore) + void Actors::dropActors (const MWWorld::Ptr::CellStore *cellStore, const MWWorld::Ptr& ignore) { PtrControllerMap::iterator iter = mActors.begin(); while(iter != mActors.end()) { - if(iter->first.getCell()==cellStore) + if(iter->first.getCell()==cellStore && iter->first != ignore) { delete iter->second; mActors.erase(iter++); diff --git a/apps/openmw/mwmechanics/actors.hpp b/apps/openmw/mwmechanics/actors.hpp index b733c966b..6afdefdbd 100644 --- a/apps/openmw/mwmechanics/actors.hpp +++ b/apps/openmw/mwmechanics/actors.hpp @@ -68,8 +68,8 @@ namespace MWMechanics void updateActor(const MWWorld::Ptr &old, const MWWorld::Ptr& ptr); ///< Updates an actor with a new Ptr - void dropActors (const MWWorld::CellStore *cellStore); - ///< Deregister all actors in the given cell. + void dropActors (const MWWorld::CellStore *cellStore, const MWWorld::Ptr& ignore); + ///< Deregister all actors (except for \a ignore) in the given cell. void update (float duration, bool paused); ///< Update actor stats and store desired velocity vectors in \a movement diff --git a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp index ff13841a2..1316baaeb 100644 --- a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp +++ b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp @@ -200,10 +200,7 @@ namespace MWMechanics void MechanicsManager::drop(const MWWorld::CellStore *cellStore) { - if(!mWatched.isEmpty() && mWatched.getCell() == cellStore) - mWatched = MWWorld::Ptr(); - - mActors.dropActors(cellStore); + mActors.dropActors(cellStore, mWatched); mObjects.dropObjects(cellStore); } diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 254ad98cf..25ce038f3 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -111,7 +111,9 @@ namespace MWWorld mRendering.removeCell(*iter); MWBase::Environment::get().getWorld()->getLocalScripts().clearCell (*iter); + MWBase::Environment::get().getMechanicsManager()->drop (*iter); + MWBase::Environment::get().getSoundManager()->stopSound (*iter); mActiveCells.erase(*iter); } @@ -164,6 +166,7 @@ namespace MWWorld void Scene::playerCellChange(MWWorld::CellStore *cell, const ESM::Position& pos, bool adjustPlayerPos) { MWBase::World *world = MWBase::Environment::get().getWorld(); + MWWorld::Ptr old = world->getPlayer().getPlayer(); world->getPlayer().setCell(cell); MWWorld::Ptr player = world->getPlayer().getPlayer(); @@ -183,7 +186,7 @@ namespace MWWorld MWBase::MechanicsManager *mechMgr = MWBase::Environment::get().getMechanicsManager(); - mechMgr->add(player); + mechMgr->updateCell(old, player); mechMgr->watchActor(player); MWBase::Environment::get().getWindowManager()->changeCell(mCurrentCell); @@ -205,9 +208,6 @@ namespace MWWorld Loading::Listener* loadingListener = MWBase::Environment::get().getWindowManager()->getLoadingScreen(); Loading::ScopedLoad load(loadingListener); - // remove active - MWBase::Environment::get().getMechanicsManager()->remove(MWBase::Environment::get().getWorld()->getPlayer().getPlayer()); - std::string loadingExteriorText = "#{sLoadingMessage3}"; loadingListener->setLabel(loadingExteriorText); diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 1247ae6e6..525c811af 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -889,7 +889,7 @@ namespace MWWorld int cellY = newCell.mCell->getGridY(); mWorldScene->changeCell(cellX, cellY, pos, false); } - addContainerScripts (ptr, &newCell); + addContainerScripts (getPlayer().getPlayer(), &newCell); } else {