forked from mirror/openmw-tes3mp
Make the PlayMode and PlayType enums scoped
Also shorten them by putting them in the MWSound namespace
This commit is contained in:
parent
0c1ad7c74e
commit
780e82480d
17 changed files with 157 additions and 146 deletions
|
@ -18,6 +18,37 @@ namespace MWSound
|
|||
class Stream;
|
||||
struct Sound_Decoder;
|
||||
typedef std::shared_ptr<Sound_Decoder> DecoderPtr;
|
||||
|
||||
/* These must all fit together */
|
||||
enum class PlayMode {
|
||||
Normal = 0, /* non-looping, affected by environment */
|
||||
Loop = 1<<0, /* Sound will continually loop until explicitly stopped */
|
||||
NoEnv = 1<<1, /* Do not apply environment effects (eg, underwater filters) */
|
||||
RemoveAtDistance = 1<<2, /* (3D only) If the listener gets further than 2000 units away
|
||||
* from the sound source, the sound is removed.
|
||||
* This is weird stuff but apparently how vanilla works for sounds
|
||||
* played by the PlayLoopSound family of script functions. Perhaps
|
||||
* we can make this cut off a more subtle fade later, but have to
|
||||
* be careful to not change the overall volume of areas by too
|
||||
* much. */
|
||||
NoPlayerLocal = 1<<3, /* (3D only) Don't play the sound local to the listener even if the
|
||||
* player is making it. */
|
||||
LoopNoEnv = Loop | NoEnv,
|
||||
LoopRemoveAtDistance = Loop | RemoveAtDistance
|
||||
};
|
||||
enum class Type {
|
||||
Sfx = 1<<4, /* Normal SFX sound */
|
||||
Voice = 1<<5, /* Voice sound */
|
||||
Foot = 1<<6, /* Footstep sound */
|
||||
Music = 1<<7, /* Music track */
|
||||
Movie = 1<<8, /* Movie audio track */
|
||||
Mask = Sfx | Voice | Foot | Music | Movie
|
||||
};
|
||||
// Used for creating a type mask for SoundManager::pauseSounds and resumeSounds
|
||||
inline int operator~(Type a) { return ~static_cast<int>(a); }
|
||||
inline int operator&(Type a, Type b) { return static_cast<int>(a) & static_cast<int>(b); }
|
||||
inline int operator&(int a, Type b) { return a & static_cast<int>(b); }
|
||||
inline int operator|(Type a, Type b) { return static_cast<int>(a) | static_cast<int>(b); }
|
||||
}
|
||||
|
||||
namespace MWBase
|
||||
|
@ -28,44 +59,18 @@ namespace MWBase
|
|||
/// \brief Interface for sound manager (implemented in MWSound)
|
||||
class SoundManager
|
||||
{
|
||||
public:
|
||||
/* These must all fit together */
|
||||
enum PlayMode {
|
||||
Play_Normal = 0, /* non-looping, affected by environment */
|
||||
Play_Loop = 1<<0, /* Sound will continually loop until explicitly stopped */
|
||||
Play_NoEnv = 1<<1, /* Do not apply environment effects (eg, underwater filters) */
|
||||
Play_RemoveAtDistance = 1<<2, /* (3D only) If the listener gets further than 2000 units away
|
||||
from the sound source, the sound is removed.
|
||||
This is weird stuff but apparently how vanilla works for sounds
|
||||
played by the PlayLoopSound family of script functions. Perhaps we
|
||||
can make this cut off a more subtle fade later, but have to
|
||||
be careful to not change the overall volume of areas by too much. */
|
||||
Play_NoPlayerLocal = 1<<3, /* (3D only) Don't play the sound local to the listener even if the
|
||||
player is making it. */
|
||||
Play_LoopNoEnv = Play_Loop | Play_NoEnv,
|
||||
Play_LoopRemoveAtDistance = Play_Loop | Play_RemoveAtDistance
|
||||
};
|
||||
enum PlayType {
|
||||
Play_TypeSfx = 1<<4, /* Normal SFX sound */
|
||||
Play_TypeVoice = 1<<5, /* Voice sound */
|
||||
Play_TypeFoot = 1<<6, /* Footstep sound */
|
||||
Play_TypeMusic = 1<<7, /* Music track */
|
||||
Play_TypeMovie = 1<<8, /* Movie audio track */
|
||||
Play_TypeMask = Play_TypeSfx|Play_TypeVoice|Play_TypeFoot|Play_TypeMusic|Play_TypeMovie
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
SoundManager (const SoundManager&);
|
||||
///< not implemented
|
||||
|
||||
SoundManager& operator= (const SoundManager&);
|
||||
///< not implemented
|
||||
|
||||
protected:
|
||||
using PlayMode = MWSound::PlayMode;
|
||||
using Type = MWSound::Type;
|
||||
|
||||
public:
|
||||
|
||||
SoundManager() {}
|
||||
|
||||
virtual ~SoundManager() {}
|
||||
|
||||
virtual void processChangedSettings(const std::set< std::pair<std::string, std::string> >& settings) = 0;
|
||||
|
@ -106,7 +111,7 @@ namespace MWBase
|
|||
/// and get an average loudness value (scale [0,1]) at the current time position.
|
||||
/// If the actor is not saying anything, returns 0.
|
||||
|
||||
virtual SoundStream *playTrack(const MWSound::DecoderPtr& decoder, PlayType type) = 0;
|
||||
virtual SoundStream *playTrack(const MWSound::DecoderPtr& decoder, Type type) = 0;
|
||||
///< Play a 2D audio track, using a custom decoder. The caller is expected to call
|
||||
/// stopTrack with the returned handle when done.
|
||||
|
||||
|
@ -119,20 +124,20 @@ namespace MWBase
|
|||
/// decoder's read method.
|
||||
|
||||
virtual Sound *playSound(const std::string& soundId, float volume, float pitch,
|
||||
PlayType type=Play_TypeSfx, PlayMode mode=Play_Normal,
|
||||
Type type=Type::Sfx, PlayMode mode=PlayMode::Normal,
|
||||
float offset=0) = 0;
|
||||
///< Play a sound, independently of 3D-position
|
||||
///< @param offset Number of seconds into the sound to start playback.
|
||||
|
||||
virtual Sound *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;
|
||||
float volume, float pitch, Type type=Type::Sfx,
|
||||
PlayMode mode=PlayMode::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.
|
||||
///< @param offset Number of seconds into the sound to start playback.
|
||||
|
||||
virtual Sound *playSound3D(const osg::Vec3f& initialPos, const std::string& soundId,
|
||||
float volume, float pitch, PlayType type=Play_TypeSfx,
|
||||
PlayMode mode=Play_Normal, float offset=0) = 0;
|
||||
float volume, float pitch, Type type=Type::Sfx,
|
||||
PlayMode mode=PlayMode::Normal, float offset=0) = 0;
|
||||
///< Play a 3D sound at \a initialPos. If the sound should be moving, it must be updated using Sound::setPosition.
|
||||
|
||||
virtual void stopSound(Sound *sound) = 0;
|
||||
|
@ -160,10 +165,10 @@ namespace MWBase
|
|||
///< 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
|
||||
|
||||
virtual void pauseSounds(int types=Play_TypeMask) = 0;
|
||||
virtual void pauseSounds(int types=static_cast<int>(Type::Mask)) = 0;
|
||||
///< Pauses all currently playing sounds, including music.
|
||||
|
||||
virtual void resumeSounds(int types=Play_TypeMask) = 0;
|
||||
virtual void resumeSounds(int types=static_cast<int>(Type::Mask)) = 0;
|
||||
///< Resumes all previously paused sounds.
|
||||
|
||||
virtual void update(float duration) = 0;
|
||||
|
|
|
@ -169,9 +169,7 @@ namespace MWClass
|
|||
if(isTrapped)
|
||||
{
|
||||
ptr.getCellRef().setTrap("");
|
||||
MWBase::Environment::get().getSoundManager()->playSound3D(ptr,
|
||||
"Disarm Trap", 1.0f, 1.0f, MWBase::SoundManager::Play_TypeSfx,
|
||||
MWBase::SoundManager::Play_Normal);
|
||||
MWBase::Environment::get().getSoundManager()->playSound3D(ptr, "Disarm Trap", 1.0f, 1.0f);
|
||||
isTrapped = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -163,9 +163,7 @@ namespace MWClass
|
|||
if(isTrapped)
|
||||
{
|
||||
ptr.getCellRef().setTrap("");
|
||||
MWBase::Environment::get().getSoundManager()->playSound3D(ptr,
|
||||
"Disarm Trap", 1.0f, 1.0f, MWBase::SoundManager::Play_TypeSfx,
|
||||
MWBase::SoundManager::Play_Normal);
|
||||
MWBase::Environment::get().getSoundManager()->playSound3D(ptr, "Disarm Trap", 1.0f, 1.0f);
|
||||
isTrapped = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,8 +49,8 @@ namespace MWClass
|
|||
|
||||
if (!ref->mBase->mSound.empty() && !(ref->mBase->mData.mFlags & ESM::Light::OffDefault))
|
||||
MWBase::Environment::get().getSoundManager()->playSound3D(ptr, ref->mBase->mSound, 1.0, 1.0,
|
||||
MWBase::SoundManager::Play_TypeSfx,
|
||||
MWBase::SoundManager::Play_Loop);
|
||||
MWSound::Type::Sfx,
|
||||
MWSound::PlayMode::Loop);
|
||||
}
|
||||
|
||||
bool Light::useAnim() const
|
||||
|
|
|
@ -1848,7 +1848,8 @@ namespace MWGui
|
|||
|
||||
if (mVideoWidget->hasAudioStream())
|
||||
MWBase::Environment::get().getSoundManager()->pauseSounds(
|
||||
MWBase::SoundManager::Play_TypeMask&(~MWBase::SoundManager::Play_TypeMovie));
|
||||
~MWSound::Type::Movie & MWSound::Type::Mask
|
||||
);
|
||||
osg::Timer frameTimer;
|
||||
while (mVideoWidget->update() && !MWBase::Environment::get().getStateManager()->hasQuitRequest())
|
||||
{
|
||||
|
@ -2035,7 +2036,7 @@ namespace MWGui
|
|||
|
||||
void WindowManager::playSound(const std::string& soundId, float volume, float pitch)
|
||||
{
|
||||
MWBase::Environment::get().getSoundManager()->playSound(soundId, volume, pitch, MWBase::SoundManager::Play_TypeSfx, MWBase::SoundManager::Play_NoEnv);
|
||||
MWBase::Environment::get().getSoundManager()->playSound(soundId, volume, pitch, MWSound::Type::Sfx, MWSound::PlayMode::NoEnv);
|
||||
}
|
||||
|
||||
void WindowManager::setConsoleSelectedObject(const MWWorld::Ptr &object)
|
||||
|
|
|
@ -991,7 +991,7 @@ namespace MWMechanics
|
|||
// ...But, only the player makes a sound.
|
||||
if(isPlayer)
|
||||
MWBase::Environment::get().getSoundManager()->playSound("torch out",
|
||||
1.0, 1.0, MWBase::SoundManager::Play_TypeSfx, MWBase::SoundManager::Play_NoEnv);
|
||||
1.0, 1.0, MWSound::Type::Sfx, MWSound::PlayMode::NoEnv);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -843,8 +843,8 @@ void CharacterController::handleTextKey(const std::string &groupname, const std:
|
|||
{
|
||||
// Don't make foot sounds local for the player, it makes sense to keep them
|
||||
// positioned on the ground.
|
||||
sndMgr->playSound3D(mPtr, sound, volume, pitch, MWBase::SoundManager::Play_TypeFoot,
|
||||
MWBase::SoundManager::Play_NoPlayerLocal);
|
||||
sndMgr->playSound3D(mPtr, sound, volume, pitch, MWSound::Type::Foot,
|
||||
MWSound::PlayMode::NoPlayerLocal);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1177,8 +1177,8 @@ bool CharacterController::updateWeaponState()
|
|||
&& mWeaponType == WeapType_None)
|
||||
{
|
||||
if(!sndMgr->getSoundPlaying(mPtr, "WolfRun"))
|
||||
sndMgr->playSound3D(mPtr, "WolfRun", 1.0f, 1.0f, MWBase::SoundManager::Play_TypeSfx,
|
||||
MWBase::SoundManager::Play_Loop);
|
||||
sndMgr->playSound3D(mPtr, "WolfRun", 1.0f, 1.0f, MWSound::Type::Sfx,
|
||||
MWSound::PlayMode::Loop);
|
||||
}
|
||||
else
|
||||
sndMgr->stopSound3D(mPtr, "WolfRun");
|
||||
|
@ -1309,9 +1309,8 @@ bool CharacterController::updateWeaponState()
|
|||
if(!resultMessage.empty())
|
||||
MWBase::Environment::get().getWindowManager()->messageBox(resultMessage);
|
||||
if(!resultSound.empty())
|
||||
MWBase::Environment::get().getSoundManager()->playSound3D(target,
|
||||
resultSound, 1.0f, 1.0f, MWBase::SoundManager::Play_TypeSfx,
|
||||
MWBase::SoundManager::Play_Normal);
|
||||
MWBase::Environment::get().getSoundManager()->playSound3D(target, resultSound,
|
||||
1.0f, 1.0f);
|
||||
}
|
||||
else if (ammunition)
|
||||
{
|
||||
|
|
|
@ -770,8 +770,9 @@ bool NpcAnimation::addOrReplaceIndividualPart(ESM::PartReferenceType type, int g
|
|||
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);
|
||||
MWBase::Environment::get().getSoundManager()->playSound3D(mPtr, mSoundIds[type],
|
||||
1.0f, 1.0f, MWSound::Type::Sfx, MWSound::PlayMode::Loop
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ namespace MWScript
|
|||
std::string sound = runtime.getStringLiteral (runtime[0].mInteger);
|
||||
runtime.pop();
|
||||
|
||||
MWBase::Environment::get().getSoundManager()->playSound(sound, 1.0, 1.0, MWBase::SoundManager::Play_TypeSfx, MWBase::SoundManager::Play_NoEnv);
|
||||
MWBase::Environment::get().getSoundManager()->playSound(sound, 1.0, 1.0, MWSound::Type::Sfx, MWSound::PlayMode::NoEnv);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -101,7 +101,7 @@ namespace MWScript
|
|||
Interpreter::Type_Float pitch = runtime[0].mFloat;
|
||||
runtime.pop();
|
||||
|
||||
MWBase::Environment::get().getSoundManager()->playSound(sound, volume, pitch, MWBase::SoundManager::Play_TypeSfx, MWBase::SoundManager::Play_NoEnv);
|
||||
MWBase::Environment::get().getSoundManager()->playSound(sound, volume, pitch, MWSound::Type::Sfx, MWSound::PlayMode::NoEnv);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -122,9 +122,9 @@ namespace MWScript
|
|||
runtime.pop();
|
||||
|
||||
MWBase::Environment::get().getSoundManager()->playSound3D(ptr, sound, 1.0, 1.0,
|
||||
MWBase::SoundManager::Play_TypeSfx,
|
||||
mLoop ? MWBase::SoundManager::Play_LoopRemoveAtDistance
|
||||
: MWBase::SoundManager::Play_Normal);
|
||||
MWSound::Type::Sfx,
|
||||
mLoop ? MWSound::PlayMode::LoopRemoveAtDistance
|
||||
: MWSound::PlayMode::Normal);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -151,9 +151,9 @@ namespace MWScript
|
|||
runtime.pop();
|
||||
|
||||
MWBase::Environment::get().getSoundManager()->playSound3D(ptr, sound, volume, pitch,
|
||||
MWBase::SoundManager::Play_TypeSfx,
|
||||
mLoop ? MWBase::SoundManager::Play_LoopRemoveAtDistance
|
||||
: MWBase::SoundManager::Play_Normal);
|
||||
MWSound::Type::Sfx,
|
||||
mLoop ? MWSound::PlayMode::LoopRemoveAtDistance
|
||||
: MWSound::PlayMode::Normal);
|
||||
|
||||
}
|
||||
};
|
||||
|
|
|
@ -162,7 +162,7 @@ namespace MWSound
|
|||
decoder->setupFormat();
|
||||
|
||||
MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager();
|
||||
MWBase::SoundStream *sound = sndMgr->playTrack(decoder->mDecoderBridge, MWBase::SoundManager::Play_TypeMovie);
|
||||
MWBase::SoundStream *sound = sndMgr->playTrack(decoder->mDecoderBridge, MWSound::Type::Movie);
|
||||
if (!sound)
|
||||
{
|
||||
decoder.reset();
|
||||
|
|
|
@ -1403,21 +1403,23 @@ void OpenAL_Output::updateListener(const osg::Vec3f &pos, const osg::Vec3f &atdi
|
|||
void OpenAL_Output::pauseSounds(int types)
|
||||
{
|
||||
std::vector<ALuint> sources;
|
||||
SoundVec::const_iterator sound = mActiveSounds.begin();
|
||||
for(;sound != mActiveSounds.end();++sound)
|
||||
{
|
||||
if(*sound && (*sound)->mHandle && ((*sound)->getPlayType()&types))
|
||||
sources.push_back(GET_PTRID((*sound)->mHandle));
|
||||
}
|
||||
StreamVec::const_iterator stream = mActiveStreams.begin();
|
||||
for(;stream != mActiveStreams.end();++stream)
|
||||
{
|
||||
if(*stream && (*stream)->mHandle && ((*stream)->getPlayType()&types))
|
||||
std::for_each(mActiveSounds.cbegin(), mActiveSounds.cend(),
|
||||
[types,&sources](const SoundVec::value_type &sound) -> void
|
||||
{
|
||||
OpenAL_SoundStream *strm = reinterpret_cast<OpenAL_SoundStream*>((*stream)->mHandle);
|
||||
sources.push_back(strm->mSource);
|
||||
if(sound && sound->mHandle && (types&sound->getPlayType()))
|
||||
sources.push_back(GET_PTRID(sound->mHandle));
|
||||
}
|
||||
}
|
||||
);
|
||||
std::for_each(mActiveStreams.cbegin(), mActiveStreams.cend(),
|
||||
[types,&sources](const StreamVec::value_type &stream) -> void
|
||||
{
|
||||
if(stream && stream->mHandle && (types&stream->getPlayType()))
|
||||
{
|
||||
OpenAL_SoundStream *strm = reinterpret_cast<OpenAL_SoundStream*>(stream->mHandle);
|
||||
sources.push_back(strm->mSource);
|
||||
}
|
||||
}
|
||||
);
|
||||
if(!sources.empty())
|
||||
{
|
||||
alSourcePausev(sources.size(), sources.data());
|
||||
|
@ -1428,21 +1430,23 @@ void OpenAL_Output::pauseSounds(int types)
|
|||
void OpenAL_Output::resumeSounds(int types)
|
||||
{
|
||||
std::vector<ALuint> sources;
|
||||
SoundVec::const_iterator sound = mActiveSounds.begin();
|
||||
for(;sound != mActiveSounds.end();++sound)
|
||||
{
|
||||
if(*sound && (*sound)->mHandle && ((*sound)->getPlayType()&types))
|
||||
sources.push_back(GET_PTRID((*sound)->mHandle));
|
||||
}
|
||||
StreamVec::const_iterator stream = mActiveStreams.begin();
|
||||
for(;stream != mActiveStreams.end();++stream)
|
||||
{
|
||||
if(*stream && (*stream)->mHandle && ((*stream)->getPlayType()&types))
|
||||
std::for_each(mActiveSounds.cbegin(), mActiveSounds.cend(),
|
||||
[types,&sources](const SoundVec::value_type &sound) -> void
|
||||
{
|
||||
OpenAL_SoundStream *strm = reinterpret_cast<OpenAL_SoundStream*>((*stream)->mHandle);
|
||||
sources.push_back(strm->mSource);
|
||||
if(sound && sound->mHandle && (types&sound->getPlayType()))
|
||||
sources.push_back(GET_PTRID(sound->mHandle));
|
||||
}
|
||||
}
|
||||
);
|
||||
std::for_each(mActiveStreams.cbegin(), mActiveStreams.cend(),
|
||||
[types,&sources](const StreamVec::value_type &stream) -> void
|
||||
{
|
||||
if(stream && stream->mHandle && (types&stream->getPlayType()))
|
||||
{
|
||||
OpenAL_SoundStream *strm = reinterpret_cast<OpenAL_SoundStream*>(stream->mHandle);
|
||||
sources.push_back(strm->mSource);
|
||||
}
|
||||
}
|
||||
);
|
||||
if(!sources.empty())
|
||||
{
|
||||
alSourcePlayv(sources.size(), sources.data());
|
||||
|
|
|
@ -7,6 +7,10 @@
|
|||
|
||||
namespace MWSound
|
||||
{
|
||||
// For testing individual PlayMode flags
|
||||
inline int operator&(int a, PlayMode b) { return a & static_cast<int>(b); }
|
||||
inline int operator&(PlayMode a, PlayMode b) { return static_cast<int>(a) & static_cast<int>(b); }
|
||||
|
||||
class SoundBase {
|
||||
SoundBase& operator=(const SoundBase&) = delete;
|
||||
SoundBase(const SoundBase&) = delete;
|
||||
|
@ -48,11 +52,11 @@ namespace MWSound
|
|||
float getMinDistance() const { return mMinDistance; }
|
||||
float getMaxDistance() const { return mMaxDistance; }
|
||||
|
||||
MWBase::SoundManager::PlayType getPlayType() const
|
||||
{ return (MWBase::SoundManager::PlayType)(mFlags&MWBase::SoundManager::Play_TypeMask); }
|
||||
bool getUseEnv() const { return !(mFlags&MWBase::SoundManager::Play_NoEnv); }
|
||||
bool getIsLooping() const { return mFlags&MWBase::SoundManager::Play_Loop; }
|
||||
bool getDistanceCull() const { return mFlags&MWBase::SoundManager::Play_RemoveAtDistance; }
|
||||
MWSound::Type getPlayType() const
|
||||
{ return static_cast<MWSound::Type>(mFlags&MWSound::Type::Mask); }
|
||||
bool getUseEnv() const { return !(mFlags&MWSound::PlayMode::NoEnv); }
|
||||
bool getIsLooping() const { return mFlags&MWSound::PlayMode::Loop; }
|
||||
bool getDistanceCull() const { return mFlags&MWSound::PlayMode::RemoveAtDistance; }
|
||||
bool getIs3D() const { return mFlags&Play_3D; }
|
||||
|
||||
void init(const osg::Vec3f& pos, float vol, float basevol, float pitch, float mindist, float maxdist, int flags)
|
||||
|
|
|
@ -35,6 +35,9 @@
|
|||
|
||||
namespace MWSound
|
||||
{
|
||||
// For combining PlayMode and Type flags
|
||||
inline int operator|(PlayMode a, Type b) { return static_cast<int>(a) | static_cast<int>(b); }
|
||||
|
||||
SoundManager::SoundManager(const VFS::Manager* vfs, const std::map<std::string, std::string>& fallbackMap, bool useSound)
|
||||
: mVFS(vfs)
|
||||
, mFallback(fallbackMap)
|
||||
|
@ -299,17 +302,17 @@ namespace MWSound
|
|||
static float maxDistance = std::max(fAudioVoiceDefaultMaxDistance * fAudioMaxDistanceMult, minDistance);
|
||||
|
||||
bool played;
|
||||
float basevol = volumeFromType(Play_TypeVoice);
|
||||
float basevol = volumeFromType(Type::Voice);
|
||||
Stream *sound = getStreamRef();
|
||||
if(playlocal)
|
||||
{
|
||||
sound->init(1.0f, basevol, 1.0f, Play_NoEnv|Play_TypeVoice|Play_2D);
|
||||
sound->init(1.0f, basevol, 1.0f, PlayMode::NoEnv|Type::Voice|Play_2D);
|
||||
played = mOutput->streamSound(decoder, sound);
|
||||
}
|
||||
else
|
||||
{
|
||||
sound->init(pos, 1.0f, basevol, 1.0f, minDistance, maxDistance,
|
||||
Play_Normal|Play_TypeVoice|Play_3D);
|
||||
PlayMode::Normal|Type::Voice|Play_3D);
|
||||
played = mOutput->streamSound3D(decoder, sound, true);
|
||||
}
|
||||
if(!played)
|
||||
|
@ -321,26 +324,25 @@ namespace MWSound
|
|||
}
|
||||
|
||||
// Gets the combined volume settings for the given sound type
|
||||
float SoundManager::volumeFromType(PlayType type) const
|
||||
float SoundManager::volumeFromType(Type type) const
|
||||
{
|
||||
float volume = mMasterVolume;
|
||||
switch(type)
|
||||
{
|
||||
case Play_TypeSfx:
|
||||
case Type::Sfx:
|
||||
volume *= mSFXVolume;
|
||||
break;
|
||||
case Play_TypeVoice:
|
||||
case Type::Voice:
|
||||
volume *= mVoiceVolume;
|
||||
break;
|
||||
case Play_TypeFoot:
|
||||
case Type::Foot:
|
||||
volume *= mFootstepsVolume;
|
||||
break;
|
||||
case Play_TypeMusic:
|
||||
case Type::Music:
|
||||
volume *= mMusicVolume;
|
||||
break;
|
||||
case Play_TypeMask:
|
||||
break;
|
||||
default:
|
||||
case Type::Movie:
|
||||
case Type::Mask:
|
||||
break;
|
||||
}
|
||||
return volume;
|
||||
|
@ -369,8 +371,8 @@ namespace MWSound
|
|||
decoder->open(filename);
|
||||
|
||||
mMusic = getStreamRef();
|
||||
mMusic->init(1.0f, volumeFromType(Play_TypeMusic), 1.0f,
|
||||
Play_NoEnv|Play_TypeMusic|Play_2D);
|
||||
mMusic->init(1.0f, volumeFromType(Type::Music), 1.0f,
|
||||
PlayMode::NoEnv|Type::Music|Play_2D);
|
||||
mOutput->streamSound(decoder, mMusic);
|
||||
}
|
||||
|
||||
|
@ -527,13 +529,13 @@ namespace MWSound
|
|||
}
|
||||
|
||||
|
||||
Stream *SoundManager::playTrack(const DecoderPtr& decoder, PlayType type)
|
||||
Stream *SoundManager::playTrack(const DecoderPtr& decoder, Type type)
|
||||
{
|
||||
if(!mOutput->isInitialized())
|
||||
return nullptr;
|
||||
|
||||
Stream *track = getStreamRef();
|
||||
track->init(1.0f, volumeFromType(type), 1.0f, Play_NoEnv|type|Play_2D);
|
||||
track->init(1.0f, volumeFromType(type), 1.0f, PlayMode::NoEnv|type|Play_2D);
|
||||
if(!mOutput->streamSound(decoder, track))
|
||||
{
|
||||
mUnusedStreams.push_back(track);
|
||||
|
@ -561,7 +563,7 @@ namespace MWSound
|
|||
}
|
||||
|
||||
|
||||
Sound *SoundManager::playSound(const std::string& soundId, float volume, float pitch, PlayType type, PlayMode mode, float offset)
|
||||
Sound *SoundManager::playSound(const std::string& soundId, float volume, float pitch, Type type, PlayMode mode, float offset)
|
||||
{
|
||||
if(!mOutput->isInitialized())
|
||||
return nullptr;
|
||||
|
@ -588,7 +590,7 @@ namespace MWSound
|
|||
}
|
||||
|
||||
Sound *SoundManager::playSound3D(const MWWorld::ConstPtr &ptr, const std::string& soundId,
|
||||
float volume, float pitch, PlayType type, PlayMode mode,
|
||||
float volume, float pitch, Type type, PlayMode mode,
|
||||
float offset)
|
||||
{
|
||||
if(!mOutput->isInitialized())
|
||||
|
@ -599,7 +601,7 @@ namespace MWSound
|
|||
if(!sfx) return nullptr;
|
||||
|
||||
const osg::Vec3f objpos(ptr.getRefData().getPosition().asVec3());
|
||||
if((mode&Play_RemoveAtDistance) && (mListenerPos-objpos).length2() > 2000*2000)
|
||||
if((mode&PlayMode::RemoveAtDistance) && (mListenerPos-objpos).length2() > 2000*2000)
|
||||
return nullptr;
|
||||
|
||||
// Only one copy of given sound can be played at time on ptr, so stop previous copy
|
||||
|
@ -607,7 +609,7 @@ namespace MWSound
|
|||
|
||||
bool played;
|
||||
Sound *sound = getSoundRef();
|
||||
if(!(mode&Play_NoPlayerLocal) && ptr == MWMechanics::getPlayer())
|
||||
if(!(mode&PlayMode::NoPlayerLocal) && ptr == MWMechanics::getPlayer())
|
||||
{
|
||||
sound->init(volume * sfx->mVolume, volumeFromType(type), pitch, mode|type|Play_2D);
|
||||
played = mOutput->playSound(sound, sfx->mHandle, offset);
|
||||
|
@ -635,7 +637,7 @@ namespace MWSound
|
|||
}
|
||||
|
||||
Sound *SoundManager::playSound3D(const osg::Vec3f& initialPos, const std::string& soundId,
|
||||
float volume, float pitch, PlayType type, PlayMode mode,
|
||||
float volume, float pitch, Type type, PlayMode mode,
|
||||
float offset)
|
||||
{
|
||||
if(!mOutput->isInitialized())
|
||||
|
@ -772,7 +774,7 @@ namespace MWSound
|
|||
{
|
||||
if(mOutput->isInitialized())
|
||||
{
|
||||
types &= Play_TypeMask;
|
||||
types = types & Type::Mask;
|
||||
mOutput->pauseSounds(types);
|
||||
mPausedSoundTypes |= types;
|
||||
}
|
||||
|
@ -782,7 +784,7 @@ namespace MWSound
|
|||
{
|
||||
if(mOutput->isInitialized())
|
||||
{
|
||||
types &= types&Play_TypeMask&mPausedSoundTypes;
|
||||
types = types & Type::Mask & mPausedSoundTypes;
|
||||
mOutput->resumeSounds(types);
|
||||
mPausedSoundTypes &= ~types;
|
||||
}
|
||||
|
@ -932,7 +934,7 @@ namespace MWSound
|
|||
if(soundIdChanged)
|
||||
{
|
||||
mOutput->finishSound(mNearWaterSound);
|
||||
mNearWaterSound = playSound(soundId, volume, 1.0f, Play_TypeSfx, Play_Loop);
|
||||
mNearWaterSound = playSound(soundId, volume, 1.0f, Type::Sfx, PlayMode::Loop);
|
||||
}
|
||||
else if (sfx)
|
||||
mNearWaterSound->setVolume(volume * sfx->mVolume);
|
||||
|
@ -941,7 +943,7 @@ namespace MWSound
|
|||
else if (volume > 0.0f)
|
||||
{
|
||||
LastCell = curcell;
|
||||
mNearWaterSound = playSound(soundId, volume, 1.0f, Play_TypeSfx, Play_Loop);
|
||||
mNearWaterSound = playSound(soundId, volume, 1.0f, Type::Sfx, PlayMode::Loop);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1084,7 +1086,7 @@ namespace MWSound
|
|||
{
|
||||
// Play underwater sound (after updating sounds)
|
||||
if(!mUnderwaterSound)
|
||||
mUnderwaterSound = playSound("Underwater", 1.0f, 1.0f, Play_TypeSfx, Play_LoopNoEnv);
|
||||
mUnderwaterSound = playSound("Underwater", 1.0f, 1.0f, Type::Sfx, PlayMode::LoopNoEnv);
|
||||
}
|
||||
mOutput->finishUpdate();
|
||||
}
|
||||
|
|
|
@ -135,7 +135,7 @@ namespace MWSound
|
|||
|
||||
std::string mNextMusic;
|
||||
|
||||
float volumeFromType(PlayType type) const;
|
||||
float volumeFromType(Type type) const;
|
||||
|
||||
SoundManager(const SoundManager &rhs);
|
||||
SoundManager& operator=(const SoundManager &rhs);
|
||||
|
@ -186,7 +186,7 @@ namespace MWSound
|
|||
/// and get an average loudness value (scale [0,1]) at the current time position.
|
||||
/// If the actor is not saying anything, returns 0.
|
||||
|
||||
virtual Stream *playTrack(const DecoderPtr& decoder, PlayType type);
|
||||
virtual Stream *playTrack(const DecoderPtr& decoder, Type type);
|
||||
///< Play a 2D audio track, using a custom decoder
|
||||
|
||||
virtual void stopTrack(Stream *stream);
|
||||
|
@ -197,18 +197,18 @@ namespace MWSound
|
|||
/// returned by \ref playTrack). Only intended to be called by the track
|
||||
/// decoder's read method.
|
||||
|
||||
virtual Sound *playSound(const std::string& soundId, float volume, float pitch, PlayType type=Play_TypeSfx, PlayMode mode=Play_Normal, float offset=0);
|
||||
virtual Sound *playSound(const std::string& soundId, float volume, float pitch, Type type=Type::Sfx, PlayMode mode=PlayMode::Normal, float offset=0);
|
||||
///< Play a sound, independently of 3D-position
|
||||
///< @param offset Number of seconds into the sound to start playback.
|
||||
|
||||
virtual Sound *playSound3D(const MWWorld::ConstPtr &reference, const std::string& soundId,
|
||||
float volume, float pitch, PlayType type=Play_TypeSfx,
|
||||
PlayMode mode=Play_Normal, float offset=0);
|
||||
float volume, float pitch, Type type=Type::Sfx,
|
||||
PlayMode mode=PlayMode::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.
|
||||
///< @param offset Number of seconds into the sound to start playback.
|
||||
|
||||
virtual Sound *playSound3D(const osg::Vec3f& initialPos, const std::string& soundId,
|
||||
float volume, float pitch, PlayType type, PlayMode mode, float offset=0);
|
||||
float volume, float pitch, Type type, PlayMode mode, float offset=0);
|
||||
///< Play a 3D sound at \a initialPos. If the sound should be moving, it must be updated using Sound::setPosition.
|
||||
///< @param offset Number of seconds into the sound to start playback.
|
||||
|
||||
|
@ -237,10 +237,10 @@ namespace MWSound
|
|||
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);
|
||||
virtual void pauseSounds(int types);
|
||||
///< Pauses all currently playing sounds, including music.
|
||||
|
||||
virtual void resumeSounds(int types=Play_TypeMask);
|
||||
virtual void resumeSounds(int types);
|
||||
///< Resumes all previously paused sounds.
|
||||
|
||||
virtual void update(float duration);
|
||||
|
|
|
@ -27,18 +27,18 @@ void MWWorld::Action::execute (const Ptr& actor, bool noSound)
|
|||
{
|
||||
if(!mSoundId.empty() && !noSound)
|
||||
{
|
||||
MWBase::SoundManager::PlayMode envType = MWBase::SoundManager::Play_Normal;
|
||||
MWSound::PlayMode envType = MWSound::PlayMode::Normal;
|
||||
|
||||
// Action sounds should not have a distortion in GUI mode
|
||||
// example: take an item or drink a potion underwater
|
||||
if (actor == MWMechanics::getPlayer() && MWBase::Environment::get().getWindowManager()->isGuiMode())
|
||||
{
|
||||
envType = MWBase::SoundManager::Play_NoEnv;
|
||||
envType = MWSound::PlayMode::NoEnv;
|
||||
}
|
||||
|
||||
if(mKeepSound && actor == MWMechanics::getPlayer())
|
||||
MWBase::Environment::get().getSoundManager()->playSound(mSoundId, 1.0, 1.0,
|
||||
MWBase::SoundManager::Play_TypeSfx, envType, mSoundOffset
|
||||
MWSound::Type::Sfx, envType, mSoundOffset
|
||||
);
|
||||
else
|
||||
{
|
||||
|
@ -46,13 +46,11 @@ void MWWorld::Action::execute (const Ptr& actor, bool noSound)
|
|||
if(mKeepSound)
|
||||
MWBase::Environment::get().getSoundManager()->playSound3D(
|
||||
(local ? actor : mTarget).getRefData().getPosition().asVec3(),
|
||||
mSoundId, 1.0, 1.0, MWBase::SoundManager::Play_TypeSfx,
|
||||
envType, mSoundOffset
|
||||
mSoundId, 1.0, 1.0, MWSound::Type::Sfx, envType, mSoundOffset
|
||||
);
|
||||
else
|
||||
MWBase::Environment::get().getSoundManager()->playSound3D(local ? actor : mTarget,
|
||||
mSoundId, 1.0, 1.0, MWBase::SoundManager::Play_TypeSfx,
|
||||
envType, mSoundOffset
|
||||
mSoundId, 1.0, 1.0, MWSound::Type::Sfx, envType, mSoundOffset
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -283,7 +283,8 @@ namespace MWWorld
|
|||
MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager();
|
||||
for (size_t it = 0; it != state.mSoundIds.size(); it++)
|
||||
{
|
||||
MWBase::Sound *sound = sndMgr->playSound3D(pos, state.mSoundIds.at(it), 1.0f, 1.0f, MWBase::SoundManager::Play_TypeSfx, MWBase::SoundManager::Play_Loop);
|
||||
MWBase::Sound *sound = sndMgr->playSound3D(pos, state.mSoundIds.at(it), 1.0f, 1.0f,
|
||||
MWSound::Type::Sfx, MWSound::PlayMode::Loop);
|
||||
if (sound)
|
||||
state.mSounds.push_back(sound);
|
||||
}
|
||||
|
@ -377,10 +378,9 @@ namespace MWWorld
|
|||
MWBase::Environment::get().getWorld()->explodeSpell(pos, it->mEffects, caster, result.mHitObject,
|
||||
ESM::RT_Target, it->mSpellId, it->mSourceName);
|
||||
|
||||
MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager();
|
||||
for (size_t soundIter = 0; soundIter != it->mSounds.size(); soundIter++)
|
||||
{
|
||||
MWBase::Environment::get().getSoundManager()->stopSound(it->mSounds.at(soundIter));
|
||||
}
|
||||
sndMgr->stopSound(it->mSounds.at(soundIter));
|
||||
|
||||
mParent->removeChild(it->mNode);
|
||||
|
||||
|
@ -581,11 +581,10 @@ namespace MWWorld
|
|||
createModel(state, model, osg::Vec3f(esm.mPosition), osg::Quat(esm.mOrientation), true, true, lightDiffuseColor, texture);
|
||||
|
||||
MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager();
|
||||
|
||||
for (size_t soundIter = 0; soundIter != state.mSoundIds.size(); soundIter++)
|
||||
{
|
||||
MWBase::Sound *sound = sndMgr->playSound3D(esm.mPosition, state.mSoundIds.at(soundIter), 1.0f, 1.0f,
|
||||
MWBase::SoundManager::Play_TypeSfx, MWBase::SoundManager::Play_Loop);
|
||||
MWSound::Type::Sfx, MWSound::PlayMode::Loop);
|
||||
if (sound)
|
||||
state.mSounds.push_back(sound);
|
||||
}
|
||||
|
|
|
@ -731,8 +731,10 @@ void WeatherManager::update(float duration, bool paused)
|
|||
{
|
||||
stopSounds();
|
||||
if (!mResult.mAmbientLoopSoundID.empty())
|
||||
mAmbientSound = MWBase::Environment::get().getSoundManager()->playSound(mResult.mAmbientLoopSoundID, mResult.mAmbientSoundVolume, 1.0, MWBase::SoundManager::Play_TypeSfx, MWBase::SoundManager::Play_Loop);
|
||||
|
||||
mAmbientSound = MWBase::Environment::get().getSoundManager()->playSound(
|
||||
mResult.mAmbientLoopSoundID, mResult.mAmbientSoundVolume, 1.0,
|
||||
MWSound::Type::Sfx, MWSound::PlayMode::Loop
|
||||
);
|
||||
mPlayingSoundID = mResult.mAmbientLoopSoundID;
|
||||
}
|
||||
else if (mAmbientSound)
|
||||
|
|
Loading…
Reference in a new issue