mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-25 06:35:30 +00:00
Use a method to update an object's cell in the mechanics manager
This prevents destroying and recreating the object's character controller (and messing up the current animation) when moving between cells.
This commit is contained in:
parent
8d98f3649c
commit
fdabef65a1
@ -43,6 +43,9 @@ namespace MWBase
|
||||
virtual void remove (const MWWorld::Ptr& ptr) = 0;
|
||||
///< Deregister an object for management
|
||||
|
||||
virtual void updateCell(const MWWorld::Ptr &ptr) = 0;
|
||||
///< Moves an object to a new cell
|
||||
|
||||
virtual void drop (const MWWorld::CellStore *cellStore) = 0;
|
||||
///< Deregister all objects in the given cell.
|
||||
|
||||
|
@ -25,6 +25,17 @@ void Activators::removeActivator (const MWWorld::Ptr& ptr)
|
||||
mActivators.erase(iter);
|
||||
}
|
||||
|
||||
void Activators::updateActivatorCell(const MWWorld::Ptr &ptr)
|
||||
{
|
||||
PtrControllerMap::iterator iter = mActivators.find(ptr);
|
||||
if(iter != mActivators.end())
|
||||
{
|
||||
CharacterController ctrl = iter->second;
|
||||
mActivators.erase(iter);
|
||||
mActivators.insert(std::make_pair(ptr, ctrl));
|
||||
}
|
||||
}
|
||||
|
||||
void Activators::dropActivators (const MWWorld::Ptr::CellStore *cellStore)
|
||||
{
|
||||
PtrControllerMap::iterator iter = mActivators.begin();
|
||||
|
@ -28,6 +28,9 @@ namespace MWMechanics
|
||||
void removeActivator (const MWWorld::Ptr& ptr);
|
||||
///< Deregister an activator
|
||||
|
||||
void updateActivatorCell(const MWWorld::Ptr& ptr);
|
||||
///< Updates an activator with a new cell store
|
||||
|
||||
void dropActivators (const MWWorld::CellStore *cellStore);
|
||||
///< Deregister all activators in the given cell.
|
||||
|
||||
|
@ -179,6 +179,17 @@ namespace MWMechanics
|
||||
mActors.erase(iter);
|
||||
}
|
||||
|
||||
void Actors::updateActorCell(const MWWorld::Ptr &ptr)
|
||||
{
|
||||
PtrControllerMap::iterator iter = mActors.find(ptr);
|
||||
if(iter != mActors.end())
|
||||
{
|
||||
CharacterController ctrl = iter->second;
|
||||
mActors.erase(iter);
|
||||
mActors.insert(std::make_pair(ptr, ctrl));
|
||||
}
|
||||
}
|
||||
|
||||
void Actors::dropActors (const MWWorld::Ptr::CellStore *cellStore)
|
||||
{
|
||||
PtrControllerMap::iterator iter = mActors.begin();
|
||||
|
@ -53,6 +53,9 @@ namespace MWMechanics
|
||||
///
|
||||
/// \note Ignored, if \a ptr is not a registered actor.
|
||||
|
||||
void updateActorCell(const MWWorld::Ptr& ptr);
|
||||
///< Updates an actor with a new cell store
|
||||
|
||||
void dropActors (const MWWorld::CellStore *cellStore);
|
||||
///< Deregister all actors in the given cell.
|
||||
|
||||
|
@ -190,6 +190,15 @@ namespace MWMechanics
|
||||
mActors.removeActor(ptr);
|
||||
}
|
||||
|
||||
void MechanicsManager::updateCell(const MWWorld::Ptr &ptr)
|
||||
{
|
||||
if(ptr.getTypeName() == typeid(ESM::Activator).name())
|
||||
mActivators.updateActivatorCell(ptr);
|
||||
else
|
||||
mActors.updateActorCell(ptr);
|
||||
}
|
||||
|
||||
|
||||
void MechanicsManager::drop(const MWWorld::CellStore *cellStore)
|
||||
{
|
||||
if(!mWatched.isEmpty() && mWatched.getCell() == cellStore)
|
||||
|
@ -48,6 +48,9 @@ namespace MWMechanics
|
||||
virtual void remove (const MWWorld::Ptr& ptr);
|
||||
///< Deregister an object for management
|
||||
|
||||
virtual void updateCell(const MWWorld::Ptr &ptr);
|
||||
///< Moves an object to a new cell
|
||||
|
||||
virtual void drop(const MWWorld::CellStore *cellStore);
|
||||
///< Deregister all objects in the given cell.
|
||||
|
||||
|
@ -729,24 +729,14 @@ namespace MWWorld
|
||||
addContainerScripts(copy, &newCell);
|
||||
|
||||
mRendering->moveObjectToCell(copy, vec, currCell);
|
||||
MWBase::MechanicsManager *mechMgr = MWBase::Environment::get().getMechanicsManager();
|
||||
mechMgr->updateCell(copy);
|
||||
|
||||
if (MWWorld::Class::get(ptr).isActor())
|
||||
std::string script = MWWorld::Class::get(ptr).getScript(ptr);
|
||||
if(!script.empty())
|
||||
{
|
||||
MWBase::MechanicsManager *mechMgr =
|
||||
MWBase::Environment::get().getMechanicsManager();
|
||||
|
||||
mechMgr->remove(ptr);
|
||||
mechMgr->add(copy);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string script =
|
||||
MWWorld::Class::get(ptr).getScript(ptr);
|
||||
if (!script.empty())
|
||||
{
|
||||
mLocalScripts.remove(ptr);
|
||||
mLocalScripts.add(script, copy);
|
||||
}
|
||||
mLocalScripts.remove(ptr);
|
||||
mLocalScripts.add(script, copy);
|
||||
}
|
||||
}
|
||||
ptr.getRefData().setCount(0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user