Unstable 0.1300.0.4

This commit is contained in:
Markus Isberg
2021-03-30 15:51:49 +03:00
parent 58c50a235d
commit 862221635c
108 changed files with 907 additions and 378 deletions
@@ -105,7 +105,7 @@ namespace Barotrauma.Sounds
int alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to set buffer data for non-streamed audio! " + Al.GetErrorString(alError));
throw new Exception("Failed to set regular buffer data for non-streamed audio! " + Al.GetErrorString(alError));
}
MuffleBuffer(floatBuffer, SampleRate, reader.Channels);
@@ -118,7 +118,7 @@ namespace Barotrauma.Sounds
alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to set buffer data for non-streamed audio! " + Al.GetErrorString(alError));
throw new Exception("Failed to set muffled buffer data for non-streamed audio! " + Al.GetErrorString(alError));
}
reader.Dispose(); reader = null;
@@ -34,6 +34,7 @@ namespace Barotrauma.Sounds
{
bufferPool.ForEach(b => Al.DeleteBuffer(b));
bufferPool.Clear();
BuffersGenerated = 0;
}
public bool RequestAlBuffers()
@@ -81,10 +82,37 @@ namespace Barotrauma.Sounds
if (otherSound.IsPlaying()) { continue; }
if (otherSound.Buffers == null) { continue; }
if (otherSound.Buffers.AlBuffer == 0) { continue; }
// Dispose all channels that are holding
// a reference to these buffers, otherwise
// an INVALID_OPERATION error will be thrown
// when attempting to set the buffer data later.
// Having the sources not play is not enough,
// as OpenAL assumes that you may want to call
// alSourcePlay without reassigning the buffer.
otherSound.Owner.KillChannels(otherSound);
AlBuffer = otherSound.Buffers.AlBuffer;
AlMuffledBuffer = otherSound.Buffers.AlMuffledBuffer;
otherSound.Buffers.AlBuffer = 0;
otherSound.Buffers.AlMuffledBuffer = 0;
// For performance reasons, sift the current sound to
// the end of the loadedSounds list, that way it'll
// be less likely to have its buffers stolen, which
// means less reuploads for frequently played sounds.
sound.Owner.MoveSoundToPosition(sound, sound.Owner.LoadedSoundCount-1);
if (!Al.IsBuffer(AlBuffer))
{
throw new Exception(sound.Filename + " has an invalid buffer!");
}
if (!Al.IsBuffer(AlMuffledBuffer))
{
throw new Exception(sound.Filename + " has an invalid muffled buffer!");
}
return true;
}
@@ -491,8 +491,10 @@ namespace Barotrauma.Sounds
mutex = new object();
}
#if !DEBUG
try
{
#endif
if (mutex != null) { Monitor.Enter(mutex); }
if (sound.Owner.CountPlayingInstances(sound) < sound.MaxSimultaneousInstances)
{
@@ -515,15 +517,6 @@ namespace Barotrauma.Sounds
Sound.FillBuffers();
}
if (!Al.IsBuffer(sound.Buffers.AlBuffer))
{
throw new Exception(sound.Filename + " has an invalid buffer!");
}
if (!Al.IsBuffer(sound.Buffers.AlMuffledBuffer))
{
throw new Exception(sound.Filename + " has an invalid muffled buffer!");
}
uint alBuffer = sound.Owner.GetCategoryMuffle(category) || muffled ? Sound.Buffers.AlMuffledBuffer : Sound.Buffers.AlBuffer;
Al.Sourcei(sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex), Al.Buffer, (int)alBuffer);
alError = Al.GetError();
@@ -587,6 +580,7 @@ namespace Barotrauma.Sounds
this.Near = near;
this.Far = far;
this.Category = category;
#if !DEBUG
}
catch
{
@@ -594,8 +588,11 @@ namespace Barotrauma.Sounds
}
finally
{
#endif
if (mutex != null) { Monitor.Exit(mutex); }
#if !DEBUG
}
#endif
Sound.Owner.Update();
}
@@ -514,6 +514,18 @@ namespace Barotrauma.Sounds
}
}
public void MoveSoundToPosition(Sound sound, int pos)
{
lock (loadedSounds)
{
int index = loadedSounds.IndexOf(sound);
if (index >= 0)
{
loadedSounds.SiftElement(index, pos);
}
}
}
public void SetCategoryGainMultiplier(string category, float gain, int index=0)
{
if (Disabled) { return; }