forked from teamnwah/openmw-tes3coop
Use a deque fpr OpenAL's free sources
This commit is contained in:
parent
a3291ef360
commit
293f33914e
2 changed files with 26 additions and 25 deletions
|
@ -436,19 +436,22 @@ void OpenAL_Output::init(const std::string &devname)
|
|||
alcGetIntegerv(mDevice, ALC_STEREO_SOURCES, 1, &maxstereo);
|
||||
throwALCerror(mDevice);
|
||||
|
||||
mFreeSources.resize(std::min<ALCuint>(maxmono+maxstereo, 256));
|
||||
for(size_t i = 0;i < mFreeSources.size();i++)
|
||||
try
|
||||
{
|
||||
ALuint src;
|
||||
alGenSources(1, &src);
|
||||
if(alGetError() != AL_NO_ERROR)
|
||||
ALCuint maxtotal = std::min<ALCuint>(maxmono+maxstereo, 256);
|
||||
for(size_t i = 0;i < maxtotal;i++)
|
||||
{
|
||||
mFreeSources.resize(i);
|
||||
break;
|
||||
ALuint src = 0;
|
||||
alGenSources(1, &src);
|
||||
throwALerror();
|
||||
mFreeSources.push_back(src);
|
||||
}
|
||||
mFreeSources[i] = src;
|
||||
}
|
||||
if(mFreeSources.size() == 0)
|
||||
catch(std::exception &e)
|
||||
{
|
||||
std::cout <<"Error: "<<e.what()<<", trying to continue"<< std::endl;
|
||||
}
|
||||
if(mFreeSources.empty())
|
||||
fail("Could not allocate any sources");
|
||||
}
|
||||
|
||||
|
@ -456,10 +459,10 @@ void OpenAL_Output::deinit()
|
|||
{
|
||||
mStreamThread->removeAll();
|
||||
|
||||
if(!mFreeSources.empty())
|
||||
while(!mFreeSources.empty())
|
||||
{
|
||||
alDeleteSources(mFreeSources.size(), mFreeSources.data());
|
||||
mFreeSources.clear();
|
||||
alDeleteSources(1, &mFreeSources.front());
|
||||
mFreeSources.pop_front();
|
||||
}
|
||||
|
||||
mBufferRefs.clear();
|
||||
|
@ -584,8 +587,8 @@ SoundPtr OpenAL_Output::playSound(const std::string &fname, float volume, float
|
|||
|
||||
if(mFreeSources.empty())
|
||||
fail("No free sources");
|
||||
src = mFreeSources.back();
|
||||
mFreeSources.pop_back();
|
||||
src = mFreeSources.front();
|
||||
mFreeSources.pop_front();
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -633,8 +636,8 @@ SoundPtr OpenAL_Output::playSound3D(const std::string &fname, const float *pos,
|
|||
|
||||
if(mFreeSources.empty())
|
||||
fail("No free sources");
|
||||
src = mFreeSources.back();
|
||||
mFreeSources.pop_back();
|
||||
src = mFreeSources.front();
|
||||
mFreeSources.pop_front();
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -682,8 +685,8 @@ SoundPtr OpenAL_Output::streamSound(const std::string &fname, float volume, floa
|
|||
|
||||
if(mFreeSources.empty())
|
||||
fail("No free sources");
|
||||
src = mFreeSources.back();
|
||||
mFreeSources.pop_back();
|
||||
src = mFreeSources.front();
|
||||
mFreeSources.pop_front();
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -726,8 +729,8 @@ SoundPtr OpenAL_Output::streamSound3D(const std::string &fname, const float *pos
|
|||
|
||||
if(mFreeSources.empty())
|
||||
fail("No free sources");
|
||||
src = mFreeSources.back();
|
||||
mFreeSources.pop_back();
|
||||
src = mFreeSources.front();
|
||||
mFreeSources.pop_front();
|
||||
|
||||
try
|
||||
{
|
||||
|
|
|
@ -21,8 +21,9 @@ namespace MWSound
|
|||
ALCdevice *mDevice;
|
||||
ALCcontext *mContext;
|
||||
|
||||
typedef std::vector<ALuint> IDVec;
|
||||
IDVec mFreeSources;
|
||||
typedef std::deque<ALuint> IDDq;
|
||||
IDDq mFreeSources;
|
||||
IDDq mUnusedBuffers;
|
||||
|
||||
typedef std::map<std::string,ALuint> NameMap;
|
||||
NameMap mBufferCache;
|
||||
|
@ -30,9 +31,6 @@ namespace MWSound
|
|||
typedef std::map<ALuint,ALuint> IDRefMap;
|
||||
IDRefMap mBufferRefs;
|
||||
|
||||
typedef std::deque<ALuint> IDDq;
|
||||
IDDq mUnusedBuffers;
|
||||
|
||||
uint64_t mBufferCacheMemSize;
|
||||
|
||||
ALuint getBuffer(const std::string &fname);
|
||||
|
|
Loading…
Reference in a new issue