Use a ConstPtr in SoundManager

openmw-38
scrawl 9 years ago
parent a0fb31e3b1
commit 604b5d24e9

@ -87,7 +87,7 @@ namespace MWBase
///< Start playing music from the selected folder
/// \param name of the folder that contains the playlist
virtual void say(const MWWorld::Ptr &reference, const std::string& filename) = 0;
virtual void say(const MWWorld::ConstPtr &reference, const std::string& filename) = 0;
///< Make an actor say some text.
/// \param filename name of a sound file in "Sound/" in the data directory.
@ -95,13 +95,13 @@ namespace MWBase
///< Say some text, without an actor ref
/// \param filename name of a sound file in "Sound/" in the data directory.
virtual bool sayDone(const MWWorld::Ptr &reference=MWWorld::Ptr()) const = 0;
virtual bool sayDone(const MWWorld::ConstPtr &reference=MWWorld::ConstPtr()) const = 0;
///< Is actor not speaking?
virtual void stopSay(const MWWorld::Ptr &reference=MWWorld::Ptr()) = 0;
virtual void stopSay(const MWWorld::ConstPtr &reference=MWWorld::ConstPtr()) = 0;
///< Stop an actor speaking
virtual float getSaySoundLoudness(const MWWorld::Ptr& reference) const = 0;
virtual float getSaySoundLoudness(const MWWorld::ConstPtr& reference) const = 0;
///< Check the currently playing say sound for this actor
/// and get an average loudness value (scale [0,1]) at the current time position.
/// If the actor is not saying anything, returns 0.
@ -123,7 +123,7 @@ namespace MWBase
///< Play a sound, independently of 3D-position
///< @param offset Number of seconds into the sound to start playback.
virtual MWBase::SoundPtr playSound3D(const MWWorld::Ptr &reference, const std::string& soundId,
virtual MWBase::SoundPtr playSound3D(const MWWorld::ConstPtr &reference, const std::string& soundId,
float volume, float pitch, PlayType type=Play_TypeSfx,
PlayMode mode=Play_Normal, float offset=0) = 0;
///< Play a 3D sound attached to an MWWorld::Ptr. Will be updated automatically with the Ptr's position, unless Play_NoTrack is specified.
@ -136,10 +136,10 @@ namespace MWBase
virtual void stopSound(SoundPtr sound) = 0;
///< Stop the given sound from playing
virtual void stopSound3D(const MWWorld::Ptr &reference, const std::string& soundId) = 0;
virtual void stopSound3D(const MWWorld::ConstPtr &reference, const std::string& soundId) = 0;
///< Stop the given object from playing the given sound,
virtual void stopSound3D(const MWWorld::Ptr &reference) = 0;
virtual void stopSound3D(const MWWorld::ConstPtr &reference) = 0;
///< Stop the given object from playing all sounds.
virtual void stopSound(const MWWorld::CellStore *cell) = 0;
@ -148,13 +148,13 @@ namespace MWBase
virtual void stopSound(const std::string& soundId) = 0;
///< Stop a non-3d looping sound
virtual void fadeOutSound3D(const MWWorld::Ptr &reference, const std::string& soundId, float duration) = 0;
virtual void fadeOutSound3D(const MWWorld::ConstPtr &reference, const std::string& soundId, float duration) = 0;
///< Fade out given sound (that is already playing) of given object
///< @param reference Reference to object, whose sound is faded out
///< @param soundId ID of the sound to fade out.
///< @param duration Time until volume reaches 0.
virtual bool getSoundPlaying(const MWWorld::Ptr &reference, const std::string& soundId) const = 0;
virtual bool getSoundPlaying(const MWWorld::ConstPtr &reference, const std::string& soundId) const = 0;
///< Is the given sound currently playing on the given object?
/// If you want to check if sound played with playSound is playing, use empty Ptr
@ -168,7 +168,7 @@ namespace MWBase
virtual void setListenerPosDir(const osg::Vec3f &pos, const osg::Vec3f &dir, const osg::Vec3f &up, bool underwater) = 0;
virtual void updatePtr(const MWWorld::Ptr& old, const MWWorld::Ptr& updated) = 0;
virtual void updatePtr(const MWWorld::ConstPtr& old, const MWWorld::ConstPtr& updated) = 0;
virtual void clear() = 0;
};

@ -392,7 +392,7 @@ namespace MWSound
}
void SoundManager::say(const MWWorld::Ptr &ptr, const std::string &filename)
void SoundManager::say(const MWWorld::ConstPtr &ptr, const std::string &filename)
{
if(!mOutput->isInitialized())
return;
@ -429,7 +429,7 @@ namespace MWSound
}
}
float SoundManager::getSaySoundLoudness(const MWWorld::Ptr &ptr) const
float SoundManager::getSaySoundLoudness(const MWWorld::ConstPtr &ptr) const
{
SaySoundMap::const_iterator snditer = mActiveSaySounds.find(ptr);
if(snditer != mActiveSaySounds.end())
@ -456,17 +456,17 @@ namespace MWSound
DecoderPtr decoder = loadVoice(voicefile, &loudness);
if(!loudness->isReady())
mPendingSaySounds[MWWorld::Ptr()] = std::make_pair(decoder, loudness);
mPendingSaySounds[MWWorld::ConstPtr()] = std::make_pair(decoder, loudness);
else
{
SaySoundMap::iterator oldIt = mActiveSaySounds.find(MWWorld::Ptr());
SaySoundMap::iterator oldIt = mActiveSaySounds.find(MWWorld::ConstPtr());
if (oldIt != mActiveSaySounds.end())
{
mOutput->finishStream(oldIt->second.first);
mActiveSaySounds.erase(oldIt);
}
mActiveSaySounds.insert(std::make_pair(MWWorld::Ptr(),
mActiveSaySounds.insert(std::make_pair(MWWorld::ConstPtr(),
std::make_pair(playVoice(decoder, osg::Vec3f(), true), loudness)));
}
}
@ -476,7 +476,7 @@ namespace MWSound
}
}
bool SoundManager::sayDone(const MWWorld::Ptr &ptr) const
bool SoundManager::sayDone(const MWWorld::ConstPtr &ptr) const
{
SaySoundMap::const_iterator snditer = mActiveSaySounds.find(ptr);
if(snditer != mActiveSaySounds.end())
@ -488,7 +488,7 @@ namespace MWSound
return mPendingSaySounds.find(ptr) == mPendingSaySounds.end();
}
void SoundManager::stopSay(const MWWorld::Ptr &ptr)
void SoundManager::stopSay(const MWWorld::ConstPtr &ptr)
{
SaySoundMap::iterator snditer = mActiveSaySounds.find(ptr);
if(snditer != mActiveSaySounds.end())
@ -552,7 +552,7 @@ namespace MWSound
if(iter != mUnusedBuffers.end())
mUnusedBuffers.erase(iter);
}
mActiveSounds[MWWorld::Ptr()].push_back(std::make_pair(sound, sfx));
mActiveSounds[MWWorld::ConstPtr()].push_back(std::make_pair(sound, sfx));
}
catch(std::exception&)
{
@ -562,7 +562,7 @@ namespace MWSound
return sound;
}
MWBase::SoundPtr SoundManager::playSound3D(const MWWorld::Ptr &ptr, const std::string& soundId,
MWBase::SoundPtr SoundManager::playSound3D(const MWWorld::ConstPtr &ptr, const std::string& soundId,
float volume, float pitch, PlayType type, PlayMode mode, float offset)
{
MWBase::SoundPtr sound;
@ -627,7 +627,7 @@ namespace MWSound
if(iter != mUnusedBuffers.end())
mUnusedBuffers.erase(iter);
}
mActiveSounds[MWWorld::Ptr()].push_back(std::make_pair(sound, sfx));
mActiveSounds[MWWorld::ConstPtr()].push_back(std::make_pair(sound, sfx));
}
catch(std::exception &)
{
@ -643,7 +643,7 @@ namespace MWSound
mOutput->finishSound(sound);
}
void SoundManager::stopSound3D(const MWWorld::Ptr &ptr, const std::string& soundId)
void SoundManager::stopSound3D(const MWWorld::ConstPtr &ptr, const std::string& soundId)
{
SoundMap::iterator snditer = mActiveSounds.find(ptr);
if(snditer != mActiveSounds.end())
@ -658,7 +658,7 @@ namespace MWSound
}
}
void SoundManager::stopSound3D(const MWWorld::Ptr &ptr)
void SoundManager::stopSound3D(const MWWorld::ConstPtr &ptr)
{
SoundMap::iterator snditer = mActiveSounds.find(ptr);
if(snditer != mActiveSounds.end())
@ -674,7 +674,7 @@ namespace MWSound
SoundMap::iterator snditer = mActiveSounds.begin();
while(snditer != mActiveSounds.end())
{
if(snditer->first != MWWorld::Ptr() &&
if(snditer->first != MWWorld::ConstPtr() &&
snditer->first != MWMechanics::getPlayer() &&
snditer->first.getCell() == cell)
{
@ -687,7 +687,7 @@ namespace MWSound
SaySoundMap::iterator sayiter = mActiveSaySounds.begin();
while(sayiter != mActiveSaySounds.end())
{
if(sayiter->first != MWWorld::Ptr() &&
if(sayiter->first != MWWorld::ConstPtr() &&
sayiter->first != MWMechanics::getPlayer() &&
sayiter->first.getCell() == cell)
{
@ -699,7 +699,7 @@ namespace MWSound
void SoundManager::stopSound(const std::string& soundId)
{
SoundMap::iterator snditer = mActiveSounds.find(MWWorld::Ptr());
SoundMap::iterator snditer = mActiveSounds.find(MWWorld::ConstPtr());
if(snditer != mActiveSounds.end())
{
Sound_Buffer *sfx = loadSound(Misc::StringUtils::lowerCase(soundId));
@ -712,7 +712,7 @@ namespace MWSound
}
}
void SoundManager::fadeOutSound3D(const MWWorld::Ptr &ptr,
void SoundManager::fadeOutSound3D(const MWWorld::ConstPtr &ptr,
const std::string& soundId, float duration)
{
SoundMap::iterator snditer = mActiveSounds.find(ptr);
@ -728,7 +728,7 @@ namespace MWSound
}
}
bool SoundManager::getSoundPlaying(const MWWorld::Ptr &ptr, const std::string& soundId) const
bool SoundManager::getSoundPlaying(const MWWorld::ConstPtr &ptr, const std::string& soundId) const
{
SoundMap::const_iterator snditer = mActiveSounds.find(ptr);
if(snditer != mActiveSounds.end())
@ -773,7 +773,7 @@ namespace MWSound
static std::string regionName = "";
static float sTimePassed = 0.0;
MWBase::World *world = MWBase::Environment::get().getWorld();
const MWWorld::Ptr player = world->getPlayerPtr();
const MWWorld::ConstPtr player = world->getPlayerPtr();
const ESM::Cell *cell = player.getCell()->getCell();
sTimePassed += duration;
@ -864,7 +864,7 @@ namespace MWSound
SoundBufferRefPairList::iterator sndidx = snditer->second.begin();
while(sndidx != snditer->second.end())
{
MWWorld::Ptr ptr = snditer->first;
MWWorld::ConstPtr ptr = snditer->first;
MWBase::SoundPtr sound = sndidx->first;
if(!ptr.isEmpty() && sound->getIs3D())
{
@ -912,7 +912,7 @@ namespace MWSound
decoder->rewind();
MWBase::SoundStreamPtr sound;
MWWorld::Ptr ptr = penditer->first;
MWWorld::ConstPtr ptr = penditer->first;
SaySoundMap::iterator old = mActiveSaySounds.find(ptr);
if (old != mActiveSaySounds.end())
@ -921,7 +921,7 @@ namespace MWSound
mActiveSaySounds.erase(old);
}
if(ptr == MWWorld::Ptr())
if(ptr == MWWorld::ConstPtr())
sound = playVoice(decoder, osg::Vec3f(), true);
else
{
@ -944,7 +944,7 @@ namespace MWSound
SaySoundMap::iterator sayiter = mActiveSaySounds.begin();
while(sayiter != mActiveSaySounds.end())
{
MWWorld::Ptr ptr = sayiter->first;
MWWorld::ConstPtr ptr = sayiter->first;
MWBase::SoundStreamPtr sound = sayiter->second.first;
if(!ptr.isEmpty() && sound->getIs3D())
{
@ -1068,7 +1068,7 @@ namespace MWSound
mListenerUnderwater = underwater;
}
void SoundManager::updatePtr(const MWWorld::Ptr &old, const MWWorld::Ptr &updated)
void SoundManager::updatePtr(const MWWorld::ConstPtr &old, const MWWorld::ConstPtr &updated)
{
SoundMap::iterator snditer = mActiveSounds.find(old);
if(snditer != mActiveSounds.end())

@ -81,15 +81,15 @@ namespace MWSound
typedef std::pair<MWBase::SoundPtr,Sound_Buffer*> SoundBufferRefPair;
typedef std::vector<SoundBufferRefPair> SoundBufferRefPairList;
typedef std::map<MWWorld::Ptr,SoundBufferRefPairList> SoundMap;
typedef std::map<MWWorld::ConstPtr,SoundBufferRefPairList> SoundMap;
SoundMap mActiveSounds;
typedef std::pair<MWBase::SoundStreamPtr,Sound_Loudness*> SoundLoudnessPair;
typedef std::map<MWWorld::Ptr,SoundLoudnessPair> SaySoundMap;
typedef std::map<MWWorld::ConstPtr,SoundLoudnessPair> SaySoundMap;
SaySoundMap mActiveSaySounds;
typedef std::pair<DecoderPtr,Sound_Loudness*> DecoderLoudnessPair;
typedef std::map<MWWorld::Ptr,DecoderLoudnessPair> SayDecoderMap;
typedef std::map<MWWorld::ConstPtr,DecoderLoudnessPair> SayDecoderMap;
SayDecoderMap mPendingSaySounds;
typedef std::vector<MWBase::SoundStreamPtr> TrackList;
@ -154,7 +154,7 @@ namespace MWSound
///< Start playing music from the selected folder
/// \param name of the folder that contains the playlist
virtual void say(const MWWorld::Ptr &reference, const std::string& filename);
virtual void say(const MWWorld::ConstPtr &reference, const std::string& filename);
///< Make an actor say some text.
/// \param filename name of a sound file in "Sound/" in the data directory.
@ -162,13 +162,13 @@ namespace MWSound
///< Say some text, without an actor ref
/// \param filename name of a sound file in "Sound/" in the data directory.
virtual bool sayDone(const MWWorld::Ptr &reference=MWWorld::Ptr()) const;
virtual bool sayDone(const MWWorld::ConstPtr &reference=MWWorld::ConstPtr()) const;
///< Is actor not speaking?
virtual void stopSay(const MWWorld::Ptr &reference=MWWorld::Ptr());
virtual void stopSay(const MWWorld::ConstPtr &reference=MWWorld::ConstPtr());
///< Stop an actor speaking
virtual float getSaySoundLoudness(const MWWorld::Ptr& reference) const;
virtual float getSaySoundLoudness(const MWWorld::ConstPtr& reference) const;
///< Check the currently playing say sound for this actor
/// and get an average loudness value (scale [0,1]) at the current time position.
/// If the actor is not saying anything, returns 0.
@ -188,7 +188,7 @@ namespace MWSound
///< Play a sound, independently of 3D-position
///< @param offset Number of seconds into the sound to start playback.
virtual MWBase::SoundPtr playSound3D(const MWWorld::Ptr &reference, const std::string& soundId,
virtual MWBase::SoundPtr playSound3D(const MWWorld::ConstPtr &reference, const std::string& soundId,
float volume, float pitch, PlayType type=Play_TypeSfx,
PlayMode mode=Play_Normal, float offset=0);
///< Play a 3D sound attached to an MWWorld::Ptr. Will be updated automatically with the Ptr's position, unless Play_NoTrack is specified.
@ -203,10 +203,10 @@ namespace MWSound
///< Stop the given sound from playing
/// @note no-op if \a sound is null
virtual void stopSound3D(const MWWorld::Ptr &reference, const std::string& soundId);
virtual void stopSound3D(const MWWorld::ConstPtr &reference, const std::string& soundId);
///< Stop the given object from playing the given sound,
virtual void stopSound3D(const MWWorld::Ptr &reference);
virtual void stopSound3D(const MWWorld::ConstPtr &reference);
///< Stop the given object from playing all sounds.
virtual void stopSound(const MWWorld::CellStore *cell);
@ -215,13 +215,13 @@ namespace MWSound
virtual void stopSound(const std::string& soundId);
///< Stop a non-3d looping sound
virtual void fadeOutSound3D(const MWWorld::Ptr &reference, const std::string& soundId, float duration);
virtual void fadeOutSound3D(const MWWorld::ConstPtr &reference, const std::string& soundId, float duration);
///< Fade out given sound (that is already playing) of given object
///< @param reference Reference to object, whose sound is faded out
///< @param soundId ID of the sound to fade out.
///< @param duration Time until volume reaches 0.
virtual bool getSoundPlaying(const MWWorld::Ptr &reference, const std::string& soundId) const;
virtual bool getSoundPlaying(const MWWorld::ConstPtr &reference, const std::string& soundId) const;
///< Is the given sound currently playing on the given object?
virtual void pauseSounds(int types=Play_TypeMask);
@ -234,7 +234,7 @@ namespace MWSound
virtual void setListenerPosDir(const osg::Vec3f &pos, const osg::Vec3f &dir, const osg::Vec3f &up, bool underwater);
virtual void updatePtr (const MWWorld::Ptr& old, const MWWorld::Ptr& updated);
virtual void updatePtr (const MWWorld::ConstPtr& old, const MWWorld::ConstPtr& updated);
virtual void clear();
};

Loading…
Cancel
Save