mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 21:53:51 +00:00
Return SoundPtr objects from playSound[3D]
Note that each Sound object currently contains "precious" resources even after the sound is stopped. The reference should be reliquished as soon as it's no longer needed (the SoundManager will make sure the sound continues to play until it's finished).
This commit is contained in:
parent
293f33914e
commit
be337ef7cc
3 changed files with 20 additions and 13 deletions
|
@ -5,9 +5,6 @@ namespace MWSound
|
|||
{
|
||||
class Sound
|
||||
{
|
||||
virtual void stop() = 0;
|
||||
virtual bool isPlaying() = 0;
|
||||
virtual void setVolume(float volume) = 0;
|
||||
virtual void update(const float *pos) = 0;
|
||||
|
||||
Sound& operator=(const Sound &rhs);
|
||||
|
@ -20,6 +17,10 @@ namespace MWSound
|
|||
float mMaxDistance;
|
||||
|
||||
public:
|
||||
virtual void stop() = 0;
|
||||
virtual bool isPlaying() = 0;
|
||||
virtual void setVolume(float volume) = 0;
|
||||
|
||||
Sound() : mVolume(1.0f)
|
||||
, mBaseVolume(1.0f)
|
||||
, mMinDistance(20.0f) /* 1 * min_range_scale */
|
||||
|
|
|
@ -185,7 +185,8 @@ namespace MWSound
|
|||
std::string filePath = std::string("Sound/")+filename;
|
||||
const ESM::Position &pos = ptr.getCellRef().pos;
|
||||
|
||||
SoundPtr sound = mOutput->playSound3D(filePath, pos.pos, basevol, 1.0f, 20.0f, 12750.0f, false);
|
||||
SoundPtr sound = mOutput->playSound3D(filePath, pos.pos, basevol, 1.0f,
|
||||
20.0f, 12750.0f, false);
|
||||
sound->mBaseVolume = basevol;
|
||||
|
||||
mActiveSounds[sound] = std::make_pair(ptr, std::string("_say_sound"));
|
||||
|
@ -202,15 +203,16 @@ namespace MWSound
|
|||
}
|
||||
|
||||
|
||||
void SoundManager::playSound(const std::string& soundId, float volume, float pitch, bool loop)
|
||||
SoundPtr SoundManager::playSound(const std::string& soundId, float volume, float pitch, bool loop)
|
||||
{
|
||||
SoundPtr sound;
|
||||
try
|
||||
{
|
||||
float basevol = 1.0f; /* TODO: volume settings */
|
||||
float min, max;
|
||||
std::string file = lookup(soundId, basevol, min, max);
|
||||
|
||||
SoundPtr sound = mOutput->playSound(file, volume*basevol, pitch, loop);
|
||||
sound = mOutput->playSound(file, volume*basevol, pitch, loop);
|
||||
sound->mVolume = volume;
|
||||
sound->mBaseVolume = basevol;
|
||||
sound->mMinDistance = min;
|
||||
|
@ -222,11 +224,14 @@ namespace MWSound
|
|||
{
|
||||
std::cout <<"Sound Error: "<<e.what()<< std::endl;
|
||||
}
|
||||
return sound;
|
||||
}
|
||||
|
||||
void SoundManager::playSound3D(MWWorld::Ptr ptr, const std::string& soundId,
|
||||
float volume, float pitch, bool loop, bool untracked)
|
||||
SoundPtr SoundManager::playSound3D(MWWorld::Ptr ptr, const std::string& soundId,
|
||||
float volume, float pitch, bool loop,
|
||||
bool untracked)
|
||||
{
|
||||
SoundPtr sound;
|
||||
try
|
||||
{
|
||||
// Look up the sound in the ESM data
|
||||
|
@ -235,7 +240,7 @@ namespace MWSound
|
|||
std::string file = lookup(soundId, basevol, min, max);
|
||||
const ESM::Position &pos = ptr.getCellRef().pos;
|
||||
|
||||
SoundPtr sound = mOutput->playSound3D(file, pos.pos, volume*basevol, pitch, min, max, loop);
|
||||
sound = mOutput->playSound3D(file, pos.pos, volume*basevol, pitch, min, max, loop);
|
||||
sound->mVolume = volume;
|
||||
sound->mBaseVolume = basevol;
|
||||
sound->mMinDistance = min;
|
||||
|
@ -248,6 +253,7 @@ namespace MWSound
|
|||
{
|
||||
std::cout <<"Sound Error: "<<e.what()<< std::endl;
|
||||
}
|
||||
return sound;
|
||||
}
|
||||
|
||||
void SoundManager::stopSound3D(MWWorld::Ptr ptr, const std::string& soundId)
|
||||
|
|
|
@ -87,12 +87,12 @@ namespace MWSound
|
|||
bool sayDone(MWWorld::Ptr reference) const;
|
||||
///< Is actor not speaking?
|
||||
|
||||
void playSound(const std::string& soundId, float volume, float pitch, bool loop=false);
|
||||
SoundPtr playSound(const std::string& soundId, float volume, float pitch, bool loop=false);
|
||||
///< Play a sound, independently of 3D-position
|
||||
|
||||
void playSound3D(MWWorld::Ptr reference, const std::string& soundId,
|
||||
float volume, float pitch, bool loop,
|
||||
bool untracked=false);
|
||||
SoundPtr playSound3D(MWWorld::Ptr reference, const std::string& soundId,
|
||||
float volume, float pitch, bool loop,
|
||||
bool untracked=false);
|
||||
///< Play a sound from an object
|
||||
|
||||
void stopSound3D(MWWorld::Ptr reference, const std::string& soundId);
|
||||
|
|
Loading…
Reference in a new issue