Enable support for up to 6 SFX channels (#355)

I'm somewhat confused as to why this wasn't enabled to begin with, since all the necessary code is here.

Closes #306, and fixes the issue with realizations being cut off by other sounds.

Co-authored-by: oldmud0 <oldmud0@users.noreply.github.com>
This commit is contained in:
in1tiate 2020-12-28 00:54:08 -06:00 committed by GitHub
parent b159ca35df
commit 39a8ab8ab2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 15 deletions

View File

@ -16,8 +16,7 @@ public:
void clear();
void loop_clear();
void play(QString p_sfx, QString p_char = "", QString shout = "",
int channel = -1);
void play(QString p_sfx, QString p_char = "", QString shout = "");
void stop(int channel = -1);
void set_volume(qreal p_volume);
void set_looping(bool toggle, int channel = -1);

View File

@ -24,16 +24,16 @@ void AOSfxPlayer::loop_clear()
set_volume_internal(m_volume);
}
void AOSfxPlayer::play(QString p_sfx, QString p_char, QString shout,
int channel)
void AOSfxPlayer::play(QString p_sfx, QString p_char, QString shout)
{
if (channel == -1) {
if (BASS_ChannelIsActive(m_stream_list[channel]) == BASS_ACTIVE_PLAYING)
m_channel = (m_channel + 1) % m_channelmax;
channel = m_channel;
for (int i = 0; i < m_channelmax; ++i) {
if (BASS_ChannelIsActive(m_stream_list[i]) == BASS_ACTIVE_PLAYING)
m_channel = (i + 1) % m_channelmax;
else {
m_channel = i;
break;
}
}
BASS_ChannelStop(m_stream_list[channel]);
QString misc_path = "";
QString char_path = "";
@ -45,7 +45,8 @@ void AOSfxPlayer::play(QString p_sfx, QString p_char, QString shout,
shout + "/" + p_sfx);
theme_path = ao_app->get_sfx_suffix(ao_app->get_theme_path(p_sfx));
if (!file_exists(theme_path))
theme_path = ao_app->get_sfx_suffix(ao_app->get_default_theme_path(p_sfx));
theme_path =
ao_app->get_sfx_suffix(ao_app->get_default_theme_path(p_sfx));
}
if (p_char != "")
char_path =
@ -57,17 +58,17 @@ void AOSfxPlayer::play(QString p_sfx, QString p_char, QString shout,
f_path = char_path;
else if (file_exists(misc_path))
f_path = misc_path;
else if (shout != "" && file_exists(theme_path)) //only check here for shouts
else if (shout != "" && file_exists(theme_path)) // only check here for shouts
f_path = theme_path;
else
f_path = sound_path;
if (f_path.endsWith(".opus"))
m_stream_list[channel] = BASS_OPUS_StreamCreateFile(
m_stream_list[m_channel] = BASS_OPUS_StreamCreateFile(
FALSE, f_path.utf16(), 0, 0,
BASS_STREAM_AUTOFREE | BASS_UNICODE | BASS_ASYNCFILE);
else
m_stream_list[channel] = BASS_StreamCreateFile(
m_stream_list[m_channel] = BASS_StreamCreateFile(
FALSE, f_path.utf16(), 0, 0,
BASS_STREAM_AUTOFREE | BASS_UNICODE | BASS_ASYNCFILE);
@ -81,7 +82,7 @@ void AOSfxPlayer::play(QString p_sfx, QString p_char, QString shout,
}
BASS_ChannelPlay(m_stream_list[m_channel], false);
BASS_ChannelSetSync(m_stream_list[channel], BASS_SYNC_DEV_FAIL, 0,
BASS_ChannelSetSync(m_stream_list[m_channel], BASS_SYNC_DEV_FAIL, 0,
ao_app->BASSreset, 0);
}