diff --git a/apps/openmw/mwmechanics/mechanicsmanager.cpp b/apps/openmw/mwmechanics/mechanicsmanager.cpp index 4287c6a64..ad40d2e0c 100644 --- a/apps/openmw/mwmechanics/mechanicsmanager.cpp +++ b/apps/openmw/mwmechanics/mechanicsmanager.cpp @@ -45,6 +45,11 @@ namespace MWMechanics mActors.insert (ptr); } + void MechanicsManager::removeActor (const MWWorld::Ptr& ptr) + { + mActors.erase (ptr); + } + void MechanicsManager::dropActors (const MWWorld::Ptr::CellStore *cellStore) { std::set::iterator iter = mActors.begin(); diff --git a/apps/openmw/mwmechanics/mechanicsmanager.hpp b/apps/openmw/mwmechanics/mechanicsmanager.hpp index 0a46a8f26..e0c44b93e 100644 --- a/apps/openmw/mwmechanics/mechanicsmanager.hpp +++ b/apps/openmw/mwmechanics/mechanicsmanager.hpp @@ -31,7 +31,10 @@ namespace MWMechanics void addActor (const MWWorld::Ptr& ptr); ///< Register an actor for stats management - + + void removeActor (const MWWorld::Ptr& ptr); + ///< Deregister an actor for stats management + void dropActors (const MWWorld::Ptr::CellStore *cellStore); ///< Deregister all actors in the given cell. }; diff --git a/apps/openmw/mwworld/ptr.hpp b/apps/openmw/mwworld/ptr.hpp index 778a66b67..0c4e76f22 100644 --- a/apps/openmw/mwworld/ptr.hpp +++ b/apps/openmw/mwworld/ptr.hpp @@ -37,6 +37,12 @@ namespace MWWorld return mPtr.empty(); } + const std::type_info& getType() + { + assert (!mPtr.empty()); + return mPtr.type(); + } + template Ptr (ESMS::LiveCellRef *liveCellRef, CellStore *cell) { diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index a3f82417c..e450cc513 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -275,6 +275,13 @@ namespace MWWorld if (MWRender::CellRender *render = searchRender (reference.getCell())) { render->enable (reference.getRefData().getHandle()); + + if (mActiveCells.find (reference.getCell())!=mActiveCells.end() && + (reference.getType()==typeid (ESMS::LiveCellRef) || + reference.getType()==typeid (ESMS::LiveCellRef))) + { + mEnvironment.mMechanicsManager->addActor (reference); + } } } } @@ -288,6 +295,13 @@ namespace MWWorld if (MWRender::CellRender *render = searchRender (reference.getCell())) { render->disable (reference.getRefData().getHandle()); + + if (mActiveCells.find (reference.getCell())!=mActiveCells.end() && + (reference.getType()==typeid (ESMS::LiveCellRef) || + reference.getType()==typeid (ESMS::LiveCellRef))) + { + mEnvironment.mMechanicsManager->removeActor (reference); + } } } } @@ -456,16 +470,22 @@ namespace MWWorld cell->creatures.list.begin()); iter!=cell->creatures.list.end(); ++iter) { - Ptr ptr (&*iter, cell); - mEnvironment.mMechanicsManager->addActor (ptr); + if (iter->mData.isEnabled()) + { + Ptr ptr (&*iter, cell); + mEnvironment.mMechanicsManager->addActor (ptr); + } } for (ESMS::CellRefList::List::iterator iter ( cell->npcs.list.begin()); iter!=cell->npcs.list.end(); ++iter) { - Ptr ptr (&*iter, cell); - mEnvironment.mMechanicsManager->addActor (ptr); + if (iter->mData.isEnabled()) + { + Ptr ptr (&*iter, cell); + mEnvironment.mMechanicsManager->addActor (ptr); + } } // Sky system