From 9659b4a95e1d4bb40560046b288173ec54f07ab2 Mon Sep 17 00:00:00 2001 From: greye Date: Thu, 21 Feb 2013 23:56:34 +0400 Subject: [PATCH] update NpcAnimation inventory reference on cell change --- apps/openmw/mwrender/actors.cpp | 4 ++- apps/openmw/mwrender/npcanimation.cpp | 52 +++++++++++++-------------- apps/openmw/mwrender/npcanimation.hpp | 8 ++++- 3 files changed, 36 insertions(+), 28 deletions(-) diff --git a/apps/openmw/mwrender/actors.cpp b/apps/openmw/mwrender/actors.cpp index 92f5cbe28..e886f3a09 100644 --- a/apps/openmw/mwrender/actors.cpp +++ b/apps/openmw/mwrender/actors.cpp @@ -163,7 +163,9 @@ void Actors::updateObjectCell(const MWWorld::Ptr &ptr) { /// \note Update key (Ptr's are compared only with refdata so mCell /// on key is outdated), maybe redundant - Animation *anim = iter->second; + NpcAnimation *anim = static_cast(iter->second); + anim->updateParts(MWWorld::Class::get(ptr).getInventoryStore(ptr)); + mAllActors.erase(iter); mAllActors[ptr] = anim; } diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index d33bdda91..6f6c9e740 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -48,21 +48,21 @@ NpcAnimation::~NpcAnimation() NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, Ogre::SceneNode* node, MWWorld::InventoryStore& inv, int visibilityFlags) : Animation(), mStateID(-1), - mInv(inv), + mInv(&inv), mTimeToChange(0), mVisibilityFlags(visibilityFlags), - mRobe(mInv.end()), - mHelmet(mInv.end()), - mShirt(mInv.end()), - mCuirass(mInv.end()), - mGreaves(mInv.end()), - mPauldronL(mInv.end()), - mPauldronR(mInv.end()), - mBoots(mInv.end()), - mPants(mInv.end()), - mGloveL(mInv.end()), - mGloveR(mInv.end()), - mSkirtIter(mInv.end()) + mRobe(mInv->end()), + mHelmet(mInv->end()), + mShirt(mInv->end()), + mCuirass(mInv->end()), + mGreaves(mInv->end()), + mPauldronL(mInv->end()), + mPauldronR(mInv->end()), + mBoots(mInv->end()), + mPants(mInv->end()), + mGloveL(mInv->end()), + mGloveR(mInv->end()), + mSkirtIter(mInv->end()) { mNpc = ptr.get()->mBase; @@ -160,7 +160,7 @@ void NpcAnimation::updateParts() }; for(size_t i = 0;i < sizeof(slotlist)/sizeof(slotlist[0]);i++) { - MWWorld::ContainerStoreIterator iter = mInv.getSlot(slotlist[i].slot); + MWWorld::ContainerStoreIterator iter = mInv->getSlot(slotlist[i].slot); if(*slotlist[i].iter != iter) { *slotlist[i].iter = iter; @@ -171,7 +171,7 @@ void NpcAnimation::updateParts() if(apparelChanged) { - if(mRobe != mInv.end()) + if(mRobe != mInv->end()) { MWWorld::Ptr ptr = *mRobe; @@ -191,7 +191,7 @@ void NpcAnimation::updateParts() reserveIndividualPart(ESM::PRT_RPauldron, MWWorld::InventoryStore::Slot_Robe, 5); reserveIndividualPart(ESM::PRT_LPauldron, MWWorld::InventoryStore::Slot_Robe, 5); } - if(mSkirtIter != mInv.end()) + if(mSkirtIter != mInv->end()) { MWWorld::Ptr ptr = *mSkirtIter; @@ -203,39 +203,39 @@ void NpcAnimation::updateParts() reserveIndividualPart(ESM::PRT_LLeg, MWWorld::InventoryStore::Slot_Skirt, 4); } - if(mHelmet != mInv.end()) + if(mHelmet != mInv->end()) { removeIndividualPart(ESM::PRT_Hair); const ESM::Armor *armor = (mHelmet->get())->mBase; std::vector parts = armor->mParts.mParts; addPartGroup(MWWorld::InventoryStore::Slot_Helmet, 3, parts); } - if(mCuirass != mInv.end()) + if(mCuirass != mInv->end()) { const ESM::Armor *armor = (mCuirass->get())->mBase; std::vector parts = armor->mParts.mParts; addPartGroup(MWWorld::InventoryStore::Slot_Cuirass, 3, parts); } - if(mGreaves != mInv.end()) + if(mGreaves != mInv->end()) { const ESM::Armor *armor = (mGreaves->get())->mBase; std::vector parts = armor->mParts.mParts; addPartGroup(MWWorld::InventoryStore::Slot_Greaves, 3, parts); } - if(mPauldronL != mInv.end()) + if(mPauldronL != mInv->end()) { const ESM::Armor *armor = (mPauldronL->get())->mBase; std::vector parts = armor->mParts.mParts; addPartGroup(MWWorld::InventoryStore::Slot_LeftPauldron, 3, parts); } - if(mPauldronR != mInv.end()) + if(mPauldronR != mInv->end()) { const ESM::Armor *armor = (mPauldronR->get())->mBase; std::vector parts = armor->mParts.mParts; addPartGroup(MWWorld::InventoryStore::Slot_RightPauldron, 3, parts); } - if(mBoots != mInv.end()) + if(mBoots != mInv->end()) { if(mBoots->getTypeName() == typeid(ESM::Clothing).name()) { @@ -250,7 +250,7 @@ void NpcAnimation::updateParts() addPartGroup(MWWorld::InventoryStore::Slot_Boots, 3, parts); } } - if(mGloveL != mInv.end()) + if(mGloveL != mInv->end()) { if(mGloveL->getTypeName() == typeid(ESM::Clothing).name()) { @@ -265,7 +265,7 @@ void NpcAnimation::updateParts() addPartGroup(MWWorld::InventoryStore::Slot_LeftGauntlet, 3, parts); } } - if(mGloveR != mInv.end()) + if(mGloveR != mInv->end()) { if(mGloveR->getTypeName() == typeid(ESM::Clothing).name()) { @@ -282,13 +282,13 @@ void NpcAnimation::updateParts() } - if(mShirt != mInv.end()) + if(mShirt != mInv->end()) { const ESM::Clothing *clothes = (mShirt->get())->mBase; std::vector parts = clothes->mParts.mParts; addPartGroup(MWWorld::InventoryStore::Slot_Shirt, 2, parts); } - if(mPants != mInv.end()) + if(mPants != mInv->end()) { const ESM::Clothing *clothes = (mPants->get())->mBase; std::vector parts = clothes->mParts.mParts; diff --git a/apps/openmw/mwrender/npcanimation.hpp b/apps/openmw/mwrender/npcanimation.hpp index ca76dcc22..fd1a96aa3 100644 --- a/apps/openmw/mwrender/npcanimation.hpp +++ b/apps/openmw/mwrender/npcanimation.hpp @@ -17,7 +17,7 @@ namespace MWRender{ class NpcAnimation: public Animation{ private: - MWWorld::InventoryStore& mInv; + MWWorld::InventoryStore *mInv; int mStateID; int mPartslots[27]; //Each part slot is taken by clothing, armor, or is empty @@ -78,7 +78,13 @@ public: virtual ~NpcAnimation(); NifOgre::EntityList insertBoundedPart(const std::string &mesh, int group, const std::string &bonename); virtual void runAnimation(float timepassed); + void updateParts(); + void updateParts(MWWorld::InventoryStore &inventory) { + mInv = &inventory; + updateParts(); + } + void removeEntities(NifOgre::EntityList &entities); void removeIndividualPart(int type); void reserveIndividualPart(int type, int group, int priority);