Fixes #1887: Equipped items do not emit sounds

Added getSound() method to MWClass class and implementation
into Light class.

Also added additional bool parameter responsible for enabling/disabling
of playing items sounds into NpcAnimation class constructor.

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

@ -297,4 +297,9 @@ namespace MWClass
state2.mTime = dynamic_cast<LightCustomData&> (*ptr.getRefData().getCustomData()).mTime;
}
const std::string& Light::getSound(const MWWorld::Ptr& ptr) const
{
return ptr.get<ESM::Light>()->mBase->mSound;
}
}

@ -82,6 +82,8 @@ namespace MWClass
virtual void writeAdditionalState (const MWWorld::Ptr& ptr, ESM::ObjectState& state)
const;
///< Write additional state from \a ptr into \a state.
virtual const std::string& getSound(const MWWorld::Ptr& ptr) const;
};
}

@ -85,7 +85,7 @@ namespace MWRender
mNode = renderRoot->createChildSceneNode();
mAnimation = new NpcAnimation(mCharacter, mNode,
0, true, (renderHeadOnly() ? NpcAnimation::VM_HeadOnly : NpcAnimation::VM_Normal));
0, true, true, (renderHeadOnly() ? NpcAnimation::VM_HeadOnly : NpcAnimation::VM_Normal));
Ogre::Vector3 scale = mNode->getScale();
mCamera->setPosition(mPosition * scale);
@ -118,7 +118,7 @@ namespace MWRender
assert(mAnimation);
delete mAnimation;
mAnimation = new NpcAnimation(mCharacter, mNode,
0, true, (renderHeadOnly() ? NpcAnimation::VM_HeadOnly : NpcAnimation::VM_Normal));
0, true, true, (renderHeadOnly() ? NpcAnimation::VM_HeadOnly : NpcAnimation::VM_Normal));
float scale=1.f;
mCharacter.getClass().adjustScale(mCharacter, scale);

@ -177,7 +177,7 @@ NpcAnimation::~NpcAnimation()
}
NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, Ogre::SceneNode* node, int visibilityFlags, bool disableListener, ViewMode viewMode)
NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, Ogre::SceneNode* node, int visibilityFlags, bool disableListener, bool disableSounds, ViewMode viewMode)
: Animation(ptr, node),
mVisibilityFlags(visibilityFlags),
mListenerDisabled(disableListener),
@ -186,7 +186,8 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, Ogre::SceneNode* node, int v
mShowCarriedLeft(true),
mFirstPersonOffset(0.f, 0.f, 0.f),
mAlpha(1.f),
mNpcType(Type_Normal)
mNpcType(Type_Normal),
mSoundsDisabled(disableSounds)
{
mNpc = mPtr.get<ESM::NPC>()->mBase;
@ -625,7 +626,7 @@ void NpcAnimation::removeIndividualPart(ESM::PartReferenceType type)
mPartslots[type] = -1;
mObjectParts[type].setNull();
if (!mSoundIds[type].empty())
if (!mSoundIds[type].empty() && !mSoundsDisabled)
{
MWBase::Environment::get().getSoundManager()->stopSound3D(mPtr, mSoundIds[type]);
mSoundIds[type].clear();
@ -659,20 +660,22 @@ bool NpcAnimation::addOrReplaceIndividualPart(ESM::PartReferenceType type, int g
removeIndividualPart(type);
mPartslots[type] = group;
mPartPriorities[type] = priority;
mObjectParts[type] = insertBoundedPart(mesh, group, sPartList.at(type), enchantedGlow, glowColor);
if (!mSoundsDisabled)
{
MWWorld::InventoryStore& inv = mPtr.getClass().getInventoryStore(mPtr);
MWWorld::ContainerStoreIterator csi = inv.getSlot(group < 0 ? MWWorld::InventoryStore::Slot_Helmet : group);
if (csi != inv.end() && csi->getTypeName() == typeid(ESM::Light).name())
if (csi != inv.end())
{
mSoundIds[type] = csi->get<ESM::Light>()->mBase->mSound;
}
mObjectParts[type] = insertBoundedPart(mesh, group, sPartList.at(type), enchantedGlow, glowColor);
if (!mSoundIds[type].empty() && mPtr.getClass().getCreatureStats(mPtr).getDrawState() == MWMechanics::DrawState_Nothing)
mSoundIds[type] = csi->getClass().getSound(*csi);
if (!mSoundIds[type].empty())
{
MWBase::Environment::get().getSoundManager()->playSound3D(mPtr, mSoundIds[type], 1.0f, 1.0f, MWBase::SoundManager::Play_TypeSfx,
MWBase::SoundManager::Play_Loop);
}
}
}
if(mObjectParts[type]->mSkelBase)
{
Ogre::SkeletonInstance *skel = mObjectParts[type]->mSkelBase->getSkeleton();

@ -98,6 +98,7 @@ private:
Ogre::SharedPtr<WeaponAnimationTime> mWeaponAnimationTime;
float mAlpha;
bool mSoundsDisabled;
void updateNpcBase();
@ -124,10 +125,11 @@ public:
* one listener at a time, so you shouldn't do this if creating several NpcAnimations
* for the same Ptr, eg preview dolls for the player.
* Those need to be manually rendered anyway.
* @param disableSounds Same as \a disableListener but for playing items sounds
* @param viewMode
*/
NpcAnimation(const MWWorld::Ptr& ptr, Ogre::SceneNode* node, int visibilityFlags, bool disableListener = false,
ViewMode viewMode=VM_Normal);
bool disableSounds = false, ViewMode viewMode=VM_Normal);
virtual ~NpcAnimation();
virtual void enableHeadAnimation(bool enable);

@ -420,4 +420,9 @@ namespace MWWorld
{
throw std::runtime_error("this is not a door");
}
const std::string& Class::getSound(const MWWorld::Ptr&) const
{
return std::string();
}
}

@ -336,6 +336,9 @@ namespace MWWorld
virtual void respawn (const MWWorld::Ptr& ptr) const {}
virtual void restock (const MWWorld::Ptr& ptr) const {}
/// Returns sound id
virtual const std::string& getSound(const MWWorld::Ptr& ptr) const;
};
}

Loading…
Cancel
Save