Fix NPC part attachment

This commit is contained in:
Chris Robinson 2013-02-22 10:15:29 -08:00
parent 3eaf937a1f
commit ecbf1568a1
2 changed files with 20 additions and 14 deletions

View file

@ -133,10 +133,10 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, Ogre::SceneNode* node, MWWor
if(mNpc->mModel.length() > 0) if(mNpc->mModel.length() > 0)
insertSkeletonSource("meshes\\"+Misc::StringUtils::lowerCase(mNpc->mModel)); insertSkeletonSource("meshes\\"+Misc::StringUtils::lowerCase(mNpc->mModel));
updateParts(); updateParts(true);
} }
void NpcAnimation::updateParts() void NpcAnimation::updateParts(bool forceupdate)
{ {
static const struct { static const struct {
int numRemoveParts; // Max: 1 int numRemoveParts; // Max: 1
@ -212,11 +212,21 @@ void NpcAnimation::updateParts()
}; };
static const size_t slotlistsize = sizeof(slotlist)/sizeof(slotlist[0]); static const size_t slotlistsize = sizeof(slotlist)/sizeof(slotlist[0]);
for(size_t i = 0;!forceupdate && i < slotlistsize;i++)
{
MWWorld::ContainerStoreIterator iter = mInv.getSlot(slotlist[i].slot);
if(this->*slotlist[i].part != iter)
{
forceupdate = true;
break;
}
}
if(!forceupdate)
return;
for(size_t i = 0;i < slotlistsize;i++) for(size_t i = 0;i < slotlistsize;i++)
{ {
MWWorld::ContainerStoreIterator iter = mInv.getSlot(slotlist[i].slot); MWWorld::ContainerStoreIterator iter = mInv.getSlot(slotlist[i].slot);
if(this->*slotlist[i].part == iter)
continue;
this->*slotlist[i].part = iter; this->*slotlist[i].part = iter;
removePartGroup(slotlist[i].slot); removePartGroup(slotlist[i].slot);
@ -332,12 +342,12 @@ NifOgre::EntityList NpcAnimation::insertBoundedPart(const std::string &mesh, int
Ogre::Vector3 NpcAnimation::runAnimation(float timepassed) Ogre::Vector3 NpcAnimation::runAnimation(float timepassed)
{ {
if(mTimeToChange > .2) if(mTimeToChange <= 0.0f)
{ {
mTimeToChange = 0; mTimeToChange = 0.2f;
updateParts(); updateParts();
} }
mTimeToChange += timepassed; mTimeToChange -= timepassed;
Ogre::Vector3 ret = Animation::runAnimation(timepassed); Ogre::Vector3 ret = Animation::runAnimation(timepassed);
const Ogre::SkeletonInstance *skelsrc = mEntityList.mSkelBase->getSkeleton(); const Ogre::SkeletonInstance *skelsrc = mEntityList.mSkelBase->getSkeleton();
@ -441,9 +451,4 @@ void NpcAnimation::addPartGroup(int group, int priority, const std::vector<ESM::
} }
} }
void NpcAnimation::forceUpdate ()
{
updateParts();
}
} }

View file

@ -57,7 +57,7 @@ private:
int mPartPriorities[sPartListSize]; int mPartPriorities[sPartListSize];
NifOgre::EntityList insertBoundedPart(const std::string &mesh, int group, const std::string &bonename); NifOgre::EntityList insertBoundedPart(const std::string &mesh, int group, const std::string &bonename);
void updateParts(); void updateParts(bool forceupdate = false);
void removeEntities(NifOgre::EntityList &entities); void removeEntities(NifOgre::EntityList &entities);
void removeIndividualPart(int type); void removeIndividualPart(int type);
void reserveIndividualPart(int type, int group, int priority); void reserveIndividualPart(int type, int group, int priority);
@ -73,7 +73,8 @@ public:
virtual Ogre::Vector3 runAnimation(float timepassed); virtual Ogre::Vector3 runAnimation(float timepassed);
void forceUpdate(); void forceUpdate()
{ updateParts(true); }
}; };
} }