Pass all stopped sources on love.audiodisconnected callback.

The behavior of sources re-played during these times is inconsistent.
Streaming sources will desync while static sources stop completely.
This commit is contained in:
Miku AuahDark
2022-05-07 10:50:10 +08:00
parent 2cc93af436
commit b2a6abdc0a
2 changed files with 22 additions and 3 deletions
+20 -1
View File
@@ -30,6 +30,16 @@ namespace audio
namespace openal
{
static Variant::SharedTable *putSourcesAsSharedTable(std::vector<audio::Source *> &sources)
{
Variant::SharedTable *table = new Variant::SharedTable();
for (int i = 0; i < sources.size(); i++)
table->pairs.emplace_back((double) (i + 1), Variant(&Source::type, sources[i]));
return table;
}
Pool::Pool(ALCdevice *device)
: device(device)
, sources()
@@ -125,8 +135,17 @@ void Pool::update()
disconnectNotified = false;
else if (!disconnectNotified)
{
StrongRef<event::Message> msg(new event::Message("audiodisconnected"), Acquire::NORETAIN);
// Get all sources in this Pool then stop it
// since they're all internally stopped.
std::vector<audio::Source *> sources = getPlayingSources();
Source::stop(sources);
std::vector<Variant> vargs;
vargs.emplace_back(putSourcesAsSharedTable(sources));
StrongRef<event::Message> msg(new event::Message("audiodisconnected", vargs), Acquire::NORETAIN);
eventModule->push(msg);
disconnectNotified = true;
}
}
+2 -2
View File
@@ -129,8 +129,8 @@ function love.createhandlers()
localechanged = function ()
if love.localechanged then return love.localechanged() end
end,
audiodisconnected = function ()
if not love.audiodisconnected or not love.audiodisconnected() then
audiodisconnected = function (sources)
if not love.audiodisconnected or not love.audiodisconnected(sources) then
love.audio.setOutputDevice()
end
end,