mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-10-25 11:26:37 +00:00 
			
		
		
		
	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>
This commit is contained in:
		
							parent
							
								
									b44ba84a80
								
							
						
					
					
						commit
						e1663de7cf
					
				
					 7 changed files with 38 additions and 18 deletions
				
			
		|  | @ -297,4 +297,9 @@ namespace MWClass | ||||||
| 
 | 
 | ||||||
|         state2.mTime = dynamic_cast<LightCustomData&> (*ptr.getRefData().getCustomData()).mTime; |         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) |             virtual void writeAdditionalState (const MWWorld::Ptr& ptr, ESM::ObjectState& state) | ||||||
|                 const; |                 const; | ||||||
|             ///< Write additional state from \a ptr into \a state.
 |             ///< 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(); |         mNode = renderRoot->createChildSceneNode(); | ||||||
| 
 | 
 | ||||||
|         mAnimation = new NpcAnimation(mCharacter, mNode, |         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(); |         Ogre::Vector3 scale = mNode->getScale(); | ||||||
|         mCamera->setPosition(mPosition * scale); |         mCamera->setPosition(mPosition * scale); | ||||||
|  | @ -118,7 +118,7 @@ namespace MWRender | ||||||
|         assert(mAnimation); |         assert(mAnimation); | ||||||
|         delete mAnimation; |         delete mAnimation; | ||||||
|         mAnimation = new NpcAnimation(mCharacter, mNode, |         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; |         float scale=1.f; | ||||||
|         mCharacter.getClass().adjustScale(mCharacter, scale); |         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), |   : Animation(ptr, node), | ||||||
|     mVisibilityFlags(visibilityFlags), |     mVisibilityFlags(visibilityFlags), | ||||||
|     mListenerDisabled(disableListener), |     mListenerDisabled(disableListener), | ||||||
|  | @ -186,7 +186,8 @@ 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), | ||||||
|  |     mSoundsDisabled(disableSounds) | ||||||
| { | { | ||||||
|     mNpc = mPtr.get<ESM::NPC>()->mBase; |     mNpc = mPtr.get<ESM::NPC>()->mBase; | ||||||
| 
 | 
 | ||||||
|  | @ -625,7 +626,7 @@ void NpcAnimation::removeIndividualPart(ESM::PartReferenceType type) | ||||||
|     mPartslots[type] = -1; |     mPartslots[type] = -1; | ||||||
| 
 | 
 | ||||||
|     mObjectParts[type].setNull(); |     mObjectParts[type].setNull(); | ||||||
|     if (!mSoundIds[type].empty()) |     if (!mSoundIds[type].empty() && !mSoundsDisabled) | ||||||
|     { |     { | ||||||
|         MWBase::Environment::get().getSoundManager()->stopSound3D(mPtr, mSoundIds[type]); |         MWBase::Environment::get().getSoundManager()->stopSound3D(mPtr, mSoundIds[type]); | ||||||
|         mSoundIds[type].clear(); |         mSoundIds[type].clear(); | ||||||
|  | @ -659,20 +660,22 @@ bool NpcAnimation::addOrReplaceIndividualPart(ESM::PartReferenceType type, int g | ||||||
|     removeIndividualPart(type); |     removeIndividualPart(type); | ||||||
|     mPartslots[type] = group; |     mPartslots[type] = group; | ||||||
|     mPartPriorities[type] = priority; |     mPartPriorities[type] = priority; | ||||||
|  |     mObjectParts[type] = insertBoundedPart(mesh, group, sPartList.at(type), enchantedGlow, glowColor); | ||||||
| 
 | 
 | ||||||
|  |     if (!mSoundsDisabled) | ||||||
|  |     { | ||||||
|         MWWorld::InventoryStore& inv = mPtr.getClass().getInventoryStore(mPtr); |         MWWorld::InventoryStore& inv = mPtr.getClass().getInventoryStore(mPtr); | ||||||
|         MWWorld::ContainerStoreIterator csi = inv.getSlot(group < 0 ? MWWorld::InventoryStore::Slot_Helmet : group); |         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; |             mSoundIds[type] = csi->getClass().getSound(*csi); | ||||||
|     } |             if (!mSoundIds[type].empty()) | ||||||
|     mObjectParts[type] = insertBoundedPart(mesh, group, sPartList.at(type), enchantedGlow, glowColor); |  | ||||||
|     if (!mSoundIds[type].empty() &&  mPtr.getClass().getCreatureStats(mPtr).getDrawState() == MWMechanics::DrawState_Nothing) |  | ||||||
|             { |             { | ||||||
|                 MWBase::Environment::get().getSoundManager()->playSound3D(mPtr, mSoundIds[type], 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]->mSkelBase) |     if(mObjectParts[type]->mSkelBase) | ||||||
|     { |     { | ||||||
|         Ogre::SkeletonInstance *skel = mObjectParts[type]->mSkelBase->getSkeleton(); |         Ogre::SkeletonInstance *skel = mObjectParts[type]->mSkelBase->getSkeleton(); | ||||||
|  |  | ||||||
|  | @ -98,6 +98,7 @@ private: | ||||||
|     Ogre::SharedPtr<WeaponAnimationTime> mWeaponAnimationTime; |     Ogre::SharedPtr<WeaponAnimationTime> mWeaponAnimationTime; | ||||||
| 
 | 
 | ||||||
|     float mAlpha; |     float mAlpha; | ||||||
|  |     bool mSoundsDisabled; | ||||||
| 
 | 
 | ||||||
|     void updateNpcBase(); |     void updateNpcBase(); | ||||||
| 
 | 
 | ||||||
|  | @ -124,10 +125,11 @@ public: | ||||||
|      *                         one listener at a time, so you shouldn't do this if creating several NpcAnimations |      *                         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. |      *                         for the same Ptr, eg preview dolls for the player. | ||||||
|      *                         Those need to be manually rendered anyway. |      *                         Those need to be manually rendered anyway. | ||||||
|  |      * @param disableSounds    Same as \a disableListener but for playing items sounds | ||||||
|      * @param viewMode |      * @param viewMode | ||||||
|      */ |      */ | ||||||
|     NpcAnimation(const MWWorld::Ptr& ptr, Ogre::SceneNode* node, int visibilityFlags, bool disableListener = false, |     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 ~NpcAnimation(); | ||||||
| 
 | 
 | ||||||
|     virtual void enableHeadAnimation(bool enable); |     virtual void enableHeadAnimation(bool enable); | ||||||
|  |  | ||||||
|  | @ -420,4 +420,9 @@ namespace MWWorld | ||||||
|     { |     { | ||||||
|         throw std::runtime_error("this is not a door"); |         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 respawn (const MWWorld::Ptr& ptr) const {} | ||||||
| 
 | 
 | ||||||
|             virtual void restock (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…
	
		Reference in a new issue