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 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) Pool::Pool(ALCdevice *device)
: device(device) : device(device)
, sources() , sources()
@@ -125,8 +135,17 @@ void Pool::update()
disconnectNotified = false; disconnectNotified = false;
else if (!disconnectNotified) 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); eventModule->push(msg);
disconnectNotified = true; disconnectNotified = true;
} }
} }
+2 -2
View File
@@ -129,8 +129,8 @@ function love.createhandlers()
localechanged = function () localechanged = function ()
if love.localechanged then return love.localechanged() end if love.localechanged then return love.localechanged() end
end, end,
audiodisconnected = function () audiodisconnected = function (sources)
if not love.audiodisconnected or not love.audiodisconnected() then if not love.audiodisconnected or not love.audiodisconnected(sources) then
love.audio.setOutputDevice() love.audio.setOutputDevice()
end end
end, end,