diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index 86adfb71a0..8757c93fde 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -7,9 +7,12 @@ #include "../mwworld/ptr.hpp" #include "../mwworld/actiontalk.hpp" +#include "../mwworld/environment.hpp" #include "../mwrender/cellimp.hpp" +#include "../mwmechanics/mechanicsmanager.hpp" + namespace MWClass { void Creature::insertObj (const MWWorld::Ptr& ptr, MWRender::CellRenderImp& cellRender, @@ -28,6 +31,16 @@ namespace MWClass } } + void Creature::enable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const + { + environment.mMechanicsManager->addActor (ptr); + } + + void Creature::disable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const + { + environment.mMechanicsManager->removeActor (ptr); + } + std::string Creature::getName (const MWWorld::Ptr& ptr) const { ESMS::LiveCellRef *ref = diff --git a/apps/openmw/mwclass/creature.hpp b/apps/openmw/mwclass/creature.hpp index 18771491ee..ec354a0158 100644 --- a/apps/openmw/mwclass/creature.hpp +++ b/apps/openmw/mwclass/creature.hpp @@ -13,6 +13,12 @@ namespace MWClass MWWorld::Environment& environment) const; ///< Add reference into a cell for rendering + virtual void enable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const; + ///< Enable reference; only does the non-rendering part + + virtual void disable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const; + ///< Enable reference; only does the non-rendering part + virtual std::string getName (const MWWorld::Ptr& ptr) const; ///< \return name (the one that is to be presented to the user; not the internal one); /// can return an empty string. diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 09b589c67f..1aae8928d4 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -12,6 +12,8 @@ #include "../mwrender/cellimp.hpp" +#include "../mwmechanics/mechanicsmanager.hpp" + namespace MWClass { void Npc::insertObj (const MWWorld::Ptr& ptr, MWRender::CellRenderImp& cellRender, @@ -43,6 +45,16 @@ namespace MWClass ref->mData.setHandle (cellRender.insertEnd (ref->mData.isEnabled())); } + void Npc::enable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const + { + environment.mMechanicsManager->addActor (ptr); + } + + void Npc::disable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const + { + environment.mMechanicsManager->removeActor (ptr); + } + std::string Npc::getName (const MWWorld::Ptr& ptr) const { ESMS::LiveCellRef *ref = diff --git a/apps/openmw/mwclass/npc.hpp b/apps/openmw/mwclass/npc.hpp index af00ff1981..1bbf427def 100644 --- a/apps/openmw/mwclass/npc.hpp +++ b/apps/openmw/mwclass/npc.hpp @@ -13,6 +13,12 @@ namespace MWClass MWWorld::Environment& environment) const; ///< Add reference into a cell for rendering + virtual void enable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const; + ///< Enable reference; only does the non-rendering part + + virtual void disable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const; + ///< Enable reference; only does the non-rendering part + virtual std::string getName (const MWWorld::Ptr& ptr) const; ///< \return name (the one that is to be presented to the user; not the internal one); /// can return an empty string. diff --git a/apps/openmw/mwrender/cellimp.cpp b/apps/openmw/mwrender/cellimp.cpp index 0b5e7c9518..d1e1ec8f93 100644 --- a/apps/openmw/mwrender/cellimp.cpp +++ b/apps/openmw/mwrender/cellimp.cpp @@ -20,7 +20,11 @@ void insertCellRefList (CellRenderImp& cellRender, MWWorld::Environment& environ it != cellRefList.list.end(); it++) { if (it->mData.getCount()) - class_.insertObj (MWWorld::Ptr (&*it, &cell), cellRender, environment); + { + MWWorld::Ptr ptr (&*it, &cell); + class_.insertObj (ptr, cellRender, environment); + class_.enable (ptr, environment); + } } } } diff --git a/apps/openmw/mwworld/class.cpp b/apps/openmw/mwworld/class.cpp index b7498dcdd4..386ba650e8 100644 --- a/apps/openmw/mwworld/class.cpp +++ b/apps/openmw/mwworld/class.cpp @@ -20,6 +20,16 @@ namespace MWWorld } + void Class::enable (const Ptr& ptr, MWWorld::Environment& environment) const + { + + } + + void Class::disable (const Ptr& ptr, MWWorld::Environment& environment) const + { + + } + MWMechanics::CreatureStats& Class::getCreatureStats (const Ptr& ptr) const { throw std::runtime_error ("class does not have creature stats"); diff --git a/apps/openmw/mwworld/class.hpp b/apps/openmw/mwworld/class.hpp index 83269957ab..d230605dae 100644 --- a/apps/openmw/mwworld/class.hpp +++ b/apps/openmw/mwworld/class.hpp @@ -46,6 +46,16 @@ namespace MWWorld MWWorld::Environment& environment) const; ///< Add reference into a cell for rendering (default implementation: don't render anything). + virtual void enable (const Ptr& ptr, MWWorld::Environment& environment) const; + ///< Enable reference; only does the non-rendering part (default implementation: ignore) + /// \attention This is not the same as the script instruction with the same name. References + /// should only be enabled while in an active cell. + + virtual void disable (const Ptr& ptr, MWWorld::Environment& environment) const; + ///< Enable reference; only does the non-rendering part (default implementation: ignore) + /// \attention This is not the same as the script instruction with the same name. References + /// should only be enabled while in an active cell. + virtual std::string getName (const Ptr& ptr) const = 0; ///< \return name (the one that is to be presented to the user; not the internal one); /// can return an empty string. diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 620751f612..5744779da7 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -15,6 +15,7 @@ #include "ptr.hpp" #include "environment.hpp" +#include "class.hpp" namespace { @@ -374,12 +375,8 @@ namespace MWWorld { 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); - } + if (mActiveCells.find (reference.getCell())!=mActiveCells.end()) + Class::get (reference).enable (reference, mEnvironment); } } } @@ -394,12 +391,8 @@ namespace MWWorld { 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); - } + if (mActiveCells.find (reference.getCell())!=mActiveCells.end()) + Class::get (reference).disable (reference, mEnvironment); } } } @@ -626,12 +619,8 @@ namespace MWWorld render->deleteObject (ptr.getRefData().getHandle()); ptr.getRefData().setHandle (""); - if (mActiveCells.find (ptr.getCell())!=mActiveCells.end() && - (ptr.getType()==typeid (ESMS::LiveCellRef) || - ptr.getType()==typeid (ESMS::LiveCellRef))) - { - mEnvironment.mMechanicsManager->removeActor (ptr); - } + if (mActiveCells.find (ptr.getCell())!=mActiveCells.end()) + Class::get (ptr).disable (ptr, mEnvironment); } } }