mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-03-03 15:19:42 +00:00
Add and implement methods to update tracked sounds on an object
This commit is contained in:
parent
979ae89aab
commit
5563f583ff
3 changed files with 33 additions and 4 deletions
|
@ -95,6 +95,7 @@ public:
|
||||||
void Play(float volume, float pitch);
|
void Play(float volume, float pitch);
|
||||||
virtual void Stop();
|
virtual void Stop();
|
||||||
virtual bool isPlaying();
|
virtual bool isPlaying();
|
||||||
|
virtual void Update(MWWorld::Ptr ptr);
|
||||||
};
|
};
|
||||||
|
|
||||||
class OpenAL_Sound : public Sound
|
class OpenAL_Sound : public Sound
|
||||||
|
@ -108,6 +109,7 @@ public:
|
||||||
|
|
||||||
virtual void Stop();
|
virtual void Stop();
|
||||||
virtual bool isPlaying();
|
virtual bool isPlaying();
|
||||||
|
virtual void Update(MWWorld::Ptr ptr);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -231,6 +233,15 @@ bool OpenAL_SoundStream::isPlaying()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OpenAL_SoundStream::Update(MWWorld::Ptr ptr)
|
||||||
|
{
|
||||||
|
const float *pos = ptr.getCellRef().pos.pos;
|
||||||
|
alSource3f(Source, AL_POSITION, pos[0], pos[2], -pos[1]);
|
||||||
|
alSource3f(Source, AL_DIRECTION, 0.0f, 0.0f, 0.0f);
|
||||||
|
alSource3f(Source, AL_VELOCITY, 0.0f, 0.0f, 0.0f);
|
||||||
|
throwALerror();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
OpenAL_Sound::OpenAL_Sound(ALuint src, ALuint buf)
|
OpenAL_Sound::OpenAL_Sound(ALuint src, ALuint buf)
|
||||||
: Source(src), Buffer(buf)
|
: Source(src), Buffer(buf)
|
||||||
|
@ -259,6 +270,15 @@ bool OpenAL_Sound::isPlaying()
|
||||||
return state==AL_PLAYING;
|
return state==AL_PLAYING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OpenAL_Sound::Update(MWWorld::Ptr ptr)
|
||||||
|
{
|
||||||
|
const float *pos = ptr.getCellRef().pos.pos;
|
||||||
|
alSource3f(Source, AL_POSITION, pos[0], pos[2], -pos[1]);
|
||||||
|
alSource3f(Source, AL_DIRECTION, 0.0f, 0.0f, 0.0f);
|
||||||
|
alSource3f(Source, AL_VELOCITY, 0.0f, 0.0f, 0.0f);
|
||||||
|
throwALerror();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool OpenAL_Output::Initialize(const std::string &devname)
|
bool OpenAL_Output::Initialize(const std::string &devname)
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,12 +3,15 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "../mwworld/ptr.hpp"
|
||||||
|
|
||||||
namespace MWSound
|
namespace MWSound
|
||||||
{
|
{
|
||||||
class Sound
|
class Sound
|
||||||
{
|
{
|
||||||
virtual void Stop() = 0;
|
virtual void Stop() = 0;
|
||||||
virtual bool isPlaying() = 0;
|
virtual bool isPlaying() = 0;
|
||||||
|
virtual void Update(MWWorld::Ptr ptr) = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~Sound() { }
|
virtual ~Sound() { }
|
||||||
|
|
|
@ -353,15 +353,21 @@ namespace MWSound
|
||||||
|
|
||||||
bool SoundManager::getSoundPlaying(MWWorld::Ptr ptr, const std::string& soundId) const
|
bool SoundManager::getSoundPlaying(MWWorld::Ptr ptr, const std::string& soundId) const
|
||||||
{
|
{
|
||||||
// Mark all sounds as playing, otherwise the scripts will just
|
|
||||||
// keep trying to play them every frame.
|
|
||||||
|
|
||||||
return isPlaying(ptr, soundId);
|
return isPlaying(ptr, soundId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundManager::updateObject(MWWorld::Ptr ptr)
|
void SoundManager::updateObject(MWWorld::Ptr ptr)
|
||||||
{
|
{
|
||||||
// FIXME: Update tracked sounds that are using this ptr
|
SoundMap::iterator snditer = ActiveSounds.find(ptr);
|
||||||
|
if(snditer == ActiveSounds.end())
|
||||||
|
return;
|
||||||
|
|
||||||
|
IDMap::iterator iditer = snditer->second.begin();
|
||||||
|
while(iditer != snditer->second.end())
|
||||||
|
{
|
||||||
|
iditer->second->Update(ptr);
|
||||||
|
iditer++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundManager::updateRegionSound(float duration)
|
void SoundManager::updateRegionSound(float duration)
|
||||||
|
|
Loading…
Reference in a new issue