Issue #1887: Equipped items do not emit sounds

Use separate arrays for sound ids and object parts.
Restored getting inventoryStore via getInventoryStore()
call (removed mInv introduced in previous commit).

Signed-off-by: Lukasz Gromanowski <lgromanowski@gmail.com>
deque
Lukasz Gromanowski 10 years ago
parent 1a0c3dc6cf
commit b44ba84a80

@ -173,7 +173,7 @@ const NpcAnimation::PartBoneMap NpcAnimation::sPartList = createPartListMap();
NpcAnimation::~NpcAnimation() NpcAnimation::~NpcAnimation()
{ {
if (!mListenerDisabled) if (!mListenerDisabled)
mInv.setListener(NULL, mPtr); mPtr.getClass().getInventoryStore(mPtr).setListener(NULL, mPtr);
} }
@ -186,8 +186,7 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, Ogre::SceneNode* node, int v
mShowCarriedLeft(true), mShowCarriedLeft(true),
mFirstPersonOffset(0.f, 0.f, 0.f), mFirstPersonOffset(0.f, 0.f, 0.f),
mAlpha(1.f), mAlpha(1.f),
mNpcType(Type_Normal), mNpcType(Type_Normal)
mInv(ptr.getClass().getInventoryStore(ptr))
{ {
mNpc = mPtr.get<ESM::NPC>()->mBase; mNpc = mPtr.get<ESM::NPC>()->mBase;
@ -201,7 +200,7 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, Ogre::SceneNode* node, int v
} }
if (!disableListener) if (!disableListener)
mInv.setListener(this, mPtr); mPtr.getClass().getInventoryStore(mPtr).setListener(this, mPtr);
updateNpcBase(); updateNpcBase();
} }
@ -334,13 +333,14 @@ void NpcAnimation::updateParts()
}; };
static const size_t slotlistsize = sizeof(slotlist)/sizeof(slotlist[0]); static const size_t slotlistsize = sizeof(slotlist)/sizeof(slotlist[0]);
MWWorld::InventoryStore& inv = mPtr.getClass().getInventoryStore(mPtr);
for(size_t i = 0;i < slotlistsize && mViewMode != VM_HeadOnly;i++) for(size_t i = 0;i < slotlistsize && mViewMode != VM_HeadOnly;i++)
{ {
MWWorld::ContainerStoreIterator store = mInv.getSlot(slotlist[i].mSlot); MWWorld::ContainerStoreIterator store = inv.getSlot(slotlist[i].mSlot);
removePartGroup(slotlist[i].mSlot); removePartGroup(slotlist[i].mSlot);
if(store == mInv.end()) if(store == inv.end())
continue; continue;
if(slotlist[i].mSlot == MWWorld::InventoryStore::Slot_Helmet) if(slotlist[i].mSlot == MWWorld::InventoryStore::Slot_Helmet)
@ -393,14 +393,14 @@ void NpcAnimation::updateParts()
if(mPartPriorities[ESM::PRT_Shield] < 1) if(mPartPriorities[ESM::PRT_Shield] < 1)
{ {
MWWorld::ContainerStoreIterator store = mInv.getSlot(MWWorld::InventoryStore::Slot_CarriedLeft); MWWorld::ContainerStoreIterator store = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedLeft);
MWWorld::Ptr part; MWWorld::Ptr part;
if(store != mInv.end() && (part=*store).getTypeName() == typeid(ESM::Light).name()) if(store != inv.end() && (part=*store).getTypeName() == typeid(ESM::Light).name())
{ {
const ESM::Light *light = part.get<ESM::Light>()->mBase; const ESM::Light *light = part.get<ESM::Light>()->mBase;
addOrReplaceIndividualPart(ESM::PRT_Shield, MWWorld::InventoryStore::Slot_CarriedLeft, addOrReplaceIndividualPart(ESM::PRT_Shield, MWWorld::InventoryStore::Slot_CarriedLeft,
1, "meshes\\"+light->mModel); 1, "meshes\\"+light->mModel);
addExtraLight(mInsert->getCreator(), mObjectParts[ESM::PRT_Shield].first, light); addExtraLight(mInsert->getCreator(), mObjectParts[ESM::PRT_Shield], light);
} }
} }
@ -604,13 +604,13 @@ Ogre::Vector3 NpcAnimation::runAnimation(float timepassed)
for(size_t i = 0;i < ESM::PRT_Count;i++) for(size_t i = 0;i < ESM::PRT_Count;i++)
{ {
if (mObjectParts[i].first.isNull()) if (mObjectParts[i].isNull())
continue; continue;
std::vector<Ogre::Controller<Ogre::Real> >::iterator ctrl(mObjectParts[i].first->mControllers.begin()); std::vector<Ogre::Controller<Ogre::Real> >::iterator ctrl(mObjectParts[i]->mControllers.begin());
for(;ctrl != mObjectParts[i].first->mControllers.end();++ctrl) for(;ctrl != mObjectParts[i]->mControllers.end();++ctrl)
ctrl->update(); ctrl->update();
Ogre::Entity *ent = mObjectParts[i].first->mSkelBase; Ogre::Entity *ent = mObjectParts[i]->mSkelBase;
if(!ent) continue; if(!ent) continue;
updateSkeletonInstance(baseinst, ent->getSkeleton()); updateSkeletonInstance(baseinst, ent->getSkeleton());
ent->getAllAnimationStates()->_notifyDirty(); ent->getAllAnimationStates()->_notifyDirty();
@ -624,11 +624,11 @@ void NpcAnimation::removeIndividualPart(ESM::PartReferenceType type)
mPartPriorities[type] = 0; mPartPriorities[type] = 0;
mPartslots[type] = -1; mPartslots[type] = -1;
mObjectParts[type].first.setNull(); mObjectParts[type].setNull();
if (!mObjectParts[type].second.empty()) if (!mSoundIds[type].empty())
{ {
MWBase::Environment::get().getSoundManager()->stopSound3D(mPtr, mObjectParts[type].second); MWBase::Environment::get().getSoundManager()->stopSound3D(mPtr, mSoundIds[type]);
mObjectParts[type].second.clear(); mSoundIds[type].clear();
} }
} }
@ -660,25 +660,25 @@ bool NpcAnimation::addOrReplaceIndividualPart(ESM::PartReferenceType type, int g
mPartslots[type] = group; mPartslots[type] = group;
mPartPriorities[type] = priority; mPartPriorities[type] = priority;
std::string soundId; MWWorld::InventoryStore& inv = mPtr.getClass().getInventoryStore(mPtr);
MWWorld::ContainerStoreIterator csi = mInv.getSlot(group < 0 ? MWWorld::InventoryStore::Slot_Helmet : group); MWWorld::ContainerStoreIterator csi = inv.getSlot(group < 0 ? MWWorld::InventoryStore::Slot_Helmet : group);
if (csi != mInv.end() && csi->getTypeName() == typeid(ESM::Light).name()) if (csi != inv.end() && csi->getTypeName() == typeid(ESM::Light).name())
{ {
soundId = csi->get<ESM::Light>()->mBase->mSound; mSoundIds[type] = csi->get<ESM::Light>()->mBase->mSound;
} }
mObjectParts[type] = std::make_pair(insertBoundedPart(mesh, group, sPartList.at(type), enchantedGlow, glowColor), soundId); mObjectParts[type] = insertBoundedPart(mesh, group, sPartList.at(type), enchantedGlow, glowColor);
if (!soundId.empty() && mPtr.getClass().getCreatureStats(mPtr).getDrawState() == MWMechanics::DrawState_Nothing) if (!mSoundIds[type].empty() && mPtr.getClass().getCreatureStats(mPtr).getDrawState() == MWMechanics::DrawState_Nothing)
{ {
MWBase::Environment::get().getSoundManager()->playSound3D(mPtr, soundId, 1.0f, 1.0f, MWBase::SoundManager::Play_TypeSfx, MWBase::Environment::get().getSoundManager()->playSound3D(mPtr, mSoundIds[type], 1.0f, 1.0f, MWBase::SoundManager::Play_TypeSfx,
MWBase::SoundManager::Play_Loop); MWBase::SoundManager::Play_Loop);
} }
if(mObjectParts[type].first->mSkelBase) if(mObjectParts[type]->mSkelBase)
{ {
Ogre::SkeletonInstance *skel = mObjectParts[type].first->mSkelBase->getSkeleton(); Ogre::SkeletonInstance *skel = mObjectParts[type]->mSkelBase->getSkeleton();
if(mObjectParts[type].first->mSkelBase->isParentTagPoint()) if(mObjectParts[type]->mSkelBase->isParentTagPoint())
{ {
Ogre::Node *root = mObjectParts[type].first->mSkelBase->getParentNode(); Ogre::Node *root = mObjectParts[type]->mSkelBase->getParentNode();
if(skel->hasBone("BoneOffset")) if(skel->hasBone("BoneOffset"))
{ {
Ogre::Bone *offset = skel->getBone("BoneOffset"); Ogre::Bone *offset = skel->getBone("BoneOffset");
@ -697,8 +697,8 @@ bool NpcAnimation::addOrReplaceIndividualPart(ESM::PartReferenceType type, int g
updateSkeletonInstance(mSkelBase->getSkeleton(), skel); updateSkeletonInstance(mSkelBase->getSkeleton(), skel);
} }
std::vector<Ogre::Controller<Ogre::Real> >::iterator ctrl(mObjectParts[type].first->mControllers.begin()); std::vector<Ogre::Controller<Ogre::Real> >::iterator ctrl(mObjectParts[type]->mControllers.begin());
for(;ctrl != mObjectParts[type].first->mControllers.end();++ctrl) for(;ctrl != mObjectParts[type]->mControllers.end();++ctrl)
{ {
if(ctrl->getSource().isNull()) if(ctrl->getSource().isNull())
{ {
@ -707,7 +707,7 @@ bool NpcAnimation::addOrReplaceIndividualPart(ESM::PartReferenceType type, int g
if (type == ESM::PRT_Head) if (type == ESM::PRT_Head)
{ {
ctrl->setSource(mHeadAnimationTime); ctrl->setSource(mHeadAnimationTime);
const NifOgre::TextKeyMap& keys = mObjectParts[type].first->mTextKeys; const NifOgre::TextKeyMap& keys = mObjectParts[type]->mTextKeys;
for (NifOgre::TextKeyMap::const_iterator it = keys.begin(); it != keys.end(); ++it) for (NifOgre::TextKeyMap::const_iterator it = keys.begin(); it != keys.end(); ++it)
{ {
if (Misc::StringUtils::ciEqual(it->second, "talk: start")) if (Misc::StringUtils::ciEqual(it->second, "talk: start"))
@ -777,8 +777,9 @@ void NpcAnimation::showWeapons(bool showWeapon)
mShowWeapons = showWeapon; mShowWeapons = showWeapon;
if(showWeapon) if(showWeapon)
{ {
MWWorld::ContainerStoreIterator weapon = mInv.getSlot(MWWorld::InventoryStore::Slot_CarriedRight); MWWorld::InventoryStore& inv = mPtr.getClass().getInventoryStore(mPtr);
if(weapon != mInv.end()) MWWorld::ContainerStoreIterator weapon = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedRight);
if(weapon != inv.end())
{ {
Ogre::Vector3 glowColor = getEnchantmentColor(*weapon); Ogre::Vector3 glowColor = getEnchantmentColor(*weapon);
std::string mesh = weapon->getClass().getModel(*weapon); std::string mesh = weapon->getClass().getModel(*weapon);
@ -789,8 +790,8 @@ void NpcAnimation::showWeapons(bool showWeapon)
if (weapon->getTypeName() == typeid(ESM::Weapon).name() && if (weapon->getTypeName() == typeid(ESM::Weapon).name() &&
weapon->get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::MarksmanCrossbow) weapon->get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::MarksmanCrossbow)
{ {
MWWorld::ContainerStoreIterator ammo = mInv.getSlot(MWWorld::InventoryStore::Slot_Ammunition); MWWorld::ContainerStoreIterator ammo = inv.getSlot(MWWorld::InventoryStore::Slot_Ammunition);
if (ammo != mInv.end() && ammo->get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::Bolt) if (ammo != inv.end() && ammo->get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::Bolt)
attachArrow(); attachArrow();
else else
mAmmunition.setNull(); mAmmunition.setNull();
@ -809,9 +810,9 @@ void NpcAnimation::showWeapons(bool showWeapon)
void NpcAnimation::showCarriedLeft(bool show) void NpcAnimation::showCarriedLeft(bool show)
{ {
mShowCarriedLeft = show; mShowCarriedLeft = show;
MWWorld::InventoryStore& inv = mPtr.getClass().getInventoryStore(mPtr);
MWWorld::ContainerStoreIterator iter = mInv.getSlot(MWWorld::InventoryStore::Slot_CarriedLeft); MWWorld::ContainerStoreIterator iter = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedLeft);
if(show && iter != mInv.end()) if(show && iter != inv.end())
{ {
Ogre::Vector3 glowColor = getEnchantmentColor(*iter); Ogre::Vector3 glowColor = getEnchantmentColor(*iter);
std::string mesh = iter->getClass().getModel(*iter); std::string mesh = iter->getClass().getModel(*iter);
@ -819,7 +820,7 @@ void NpcAnimation::showCarriedLeft(bool show)
mesh, !iter->getClass().getEnchantment(*iter).empty(), &glowColor)) mesh, !iter->getClass().getEnchantment(*iter).empty(), &glowColor))
{ {
if (iter->getTypeName() == typeid(ESM::Light).name()) if (iter->getTypeName() == typeid(ESM::Light).name())
addExtraLight(mInsert->getCreator(), mObjectParts[ESM::PRT_Shield].first, iter->get<ESM::Light>()->mBase); addExtraLight(mInsert->getCreator(), mObjectParts[ESM::PRT_Shield], iter->get<ESM::Light>()->mBase);
} }
} }
else else
@ -882,14 +883,14 @@ void NpcAnimation::setAlpha(float alpha)
for (int i=0; i<ESM::PRT_Count; ++i) for (int i=0; i<ESM::PRT_Count; ++i)
{ {
if (mObjectParts[i].first.isNull()) if (mObjectParts[i].isNull())
continue; continue;
for (unsigned int j=0; j<mObjectParts[i].first->mEntities.size(); ++j) for (unsigned int j=0; j<mObjectParts[i]->mEntities.size(); ++j)
{ {
Ogre::Entity* ent = mObjectParts[i].first->mEntities[j]; Ogre::Entity* ent = mObjectParts[i]->mEntities[j];
if (ent != mObjectParts[i].first->mSkelBase) if (ent != mObjectParts[i]->mSkelBase)
applyAlpha(alpha, ent, mObjectParts[i].first); applyAlpha(alpha, ent, mObjectParts[i]);
} }
} }
} }
@ -904,9 +905,9 @@ void NpcAnimation::preRender(Ogre::Camera *camera)
Animation::preRender(camera); Animation::preRender(camera);
for (int i=0; i<ESM::PRT_Count; ++i) for (int i=0; i<ESM::PRT_Count; ++i)
{ {
if (mObjectParts[i].first.isNull()) if (mObjectParts[i].isNull())
continue; continue;
mObjectParts[i].first->rotateBillboardNodes(camera); mObjectParts[i]->rotateBillboardNodes(camera);
} }
} }

@ -69,7 +69,8 @@ private:
bool mListenerDisabled; bool mListenerDisabled;
// Bounded Parts // Bounded Parts
std::pair<NifOgre::ObjectScenePtr, std::string /* sound id */> mObjectParts[ESM::PRT_Count]; NifOgre::ObjectScenePtr mObjectParts[ESM::PRT_Count];
std::string mSoundIds[ESM::PRT_Count];
const ESM::NPC *mNpc; const ESM::NPC *mNpc;
std::string mHeadModel; std::string mHeadModel;
@ -97,7 +98,6 @@ private:
Ogre::SharedPtr<WeaponAnimationTime> mWeaponAnimationTime; Ogre::SharedPtr<WeaponAnimationTime> mWeaponAnimationTime;
float mAlpha; float mAlpha;
MWWorld::InventoryStore& mInv;
void updateNpcBase(); void updateNpcBase();
@ -147,7 +147,7 @@ public:
virtual void releaseArrow(); virtual void releaseArrow();
// WeaponAnimation // WeaponAnimation
virtual NifOgre::ObjectScenePtr getWeapon() { return mObjectParts[ESM::PRT_Weapon].first; } virtual NifOgre::ObjectScenePtr getWeapon() { return mObjectParts[ESM::PRT_Weapon]; }
virtual void showWeapon(bool show) { showWeapons(show); } virtual void showWeapon(bool show) { showWeapons(show); }
virtual void configureAddedObject(NifOgre::ObjectScenePtr object, MWWorld::Ptr ptr, int slot); virtual void configureAddedObject(NifOgre::ObjectScenePtr object, MWWorld::Ptr ptr, int slot);

Loading…
Cancel
Save