forked from mirror/openmw-tes3mp
Started implementing sound time tracking so we can have NPCs' mouths move as they talk.
This commit is contained in:
parent
beba58268c
commit
b897080156
3 changed files with 48 additions and 3 deletions
|
@ -100,6 +100,9 @@ namespace MWBase
|
|||
|
||||
virtual void stopSay(const MWWorld::Ptr &reference=MWWorld::Ptr()) = 0;
|
||||
///< Stop an actor speaking
|
||||
|
||||
virtual float getSoundPlayingTime(const MWWorld::Ptr &reference=MWWorld::Ptr()) = 0;
|
||||
///< Get the amount of time this sound has been playing.
|
||||
|
||||
virtual SoundPtr playTrack(const MWSound::DecoderPtr& decoder, PlayType type) = 0;
|
||||
///< Play a 2D audio track, using a custom decoder
|
||||
|
|
|
@ -244,6 +244,7 @@ namespace MWSound
|
|||
MWBase::SoundPtr sound = mOutput->playSound3D(filePath, objpos, 1.0f, basevol, 1.0f,
|
||||
20.0f, 1500.0f, Play_Normal|Play_TypeVoice, 0);
|
||||
mActiveSounds[sound] = std::make_pair(ptr, std::string("_say_sound"));
|
||||
mSoundPlayTime[sound] = std::make_pair(ptr, 0);
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
|
@ -261,7 +262,9 @@ namespace MWSound
|
|||
std::string filePath = "Sound/"+filename;
|
||||
|
||||
MWBase::SoundPtr sound = mOutput->playSound(filePath, 1.0f, basevol, 1.0f, Play_Normal|Play_TypeVoice, 0);
|
||||
mActiveSounds[sound] = std::make_pair(MWWorld::Ptr(), std::string("_say_sound"));
|
||||
MWWorld::Ptr ptr = MWWorld::Ptr();
|
||||
mActiveSounds[sound] = std::make_pair(ptr, std::string("_say_sound"));
|
||||
mSoundPlayTime[sound] = std::make_pair(ptr, 0);
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
|
@ -288,6 +291,18 @@ namespace MWSound
|
|||
++snditer;
|
||||
}
|
||||
}
|
||||
|
||||
float SoundManager::getSoundPlayingTime(const MWWorld::Ptr &ptr)
|
||||
{
|
||||
typedef SoundPlayingTimeMap::iterator iter_type;
|
||||
for(iter_type iterator = mSoundPlayTime.begin(); iterator != mSoundPlayTime.end(); iterator++)
|
||||
{
|
||||
if (iterator->second.first == ptr)
|
||||
return iterator->second.second;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
MWBase::SoundPtr SoundManager::playTrack(const DecoderPtr& decoder, PlayType type)
|
||||
|
@ -602,8 +617,12 @@ namespace MWSound
|
|||
while(snditer != mActiveSounds.end())
|
||||
{
|
||||
if(!snditer->first->isPlaying())
|
||||
mActiveSounds.erase(snditer++);
|
||||
else
|
||||
{
|
||||
mActiveSounds.erase(snditer);
|
||||
mSoundPlayTime.erase(snditer->first);
|
||||
snditer++;
|
||||
}
|
||||
else
|
||||
{
|
||||
const MWWorld::Ptr &ptr = snditer->second.first;
|
||||
if(!ptr.isEmpty())
|
||||
|
@ -626,6 +645,22 @@ namespace MWSound
|
|||
++snditer;
|
||||
}
|
||||
}
|
||||
|
||||
// Update the total playing time for all sounds.
|
||||
// This is primarily used for detecting amplitude for NPC mouth animation.
|
||||
|
||||
typedef SoundPlayingTimeMap::iterator it_type;
|
||||
for(it_type iterator = mSoundPlayTime.begin(); iterator != mSoundPlayTime.end(); iterator++)
|
||||
{
|
||||
iterator->second.second += duration;
|
||||
}
|
||||
|
||||
std::cout << mSoundPlayTime.size() << " sounds currently playing." << std::endl;
|
||||
typedef SoundPlayingTimeMap::iterator it_ty;
|
||||
for(it_ty iterator = mSoundPlayTime.begin(); iterator != mSoundPlayTime.end(); iterator++)
|
||||
{
|
||||
std::cout << iterator->first->getPlayType() << ": " << iterator->second.second << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void SoundManager::update(float duration)
|
||||
|
|
|
@ -43,6 +43,10 @@ namespace MWSound
|
|||
typedef std::pair<MWWorld::Ptr,std::string> PtrIDPair;
|
||||
typedef std::map<MWBase::SoundPtr,PtrIDPair> SoundMap;
|
||||
SoundMap mActiveSounds;
|
||||
|
||||
typedef std::pair<MWWorld::Ptr, float> PtrFloatPair;
|
||||
typedef std::map<MWBase::SoundPtr, PtrFloatPair> SoundPlayingTimeMap;
|
||||
SoundPlayingTimeMap mSoundPlayTime;
|
||||
|
||||
MWBase::SoundPtr mUnderwaterSound;
|
||||
|
||||
|
@ -104,6 +108,9 @@ namespace MWSound
|
|||
|
||||
virtual void stopSay(const MWWorld::Ptr &reference=MWWorld::Ptr());
|
||||
///< Stop an actor speaking
|
||||
|
||||
virtual float getSoundPlayingTime(const MWWorld::Ptr &reference=MWWorld::Ptr());
|
||||
///< Get the amount of time this sound has been playing.
|
||||
|
||||
virtual MWBase::SoundPtr playTrack(const DecoderPtr& decoder, PlayType type);
|
||||
///< Play a 2D audio track, using a custom decoder
|
||||
|
|
Loading…
Reference in a new issue