Add streamersafemusic cvar

Don't play music that is marked contentidunsafe in its MUSICDEF (if
it exists).
This commit is contained in:
Eidolon 2024-04-30 18:03:19 -05:00
parent 6a9fd1bf5f
commit ab854ab545
5 changed files with 23 additions and 2 deletions

View file

@ -318,6 +318,7 @@ void Captioning_OnChange(void);
consvar_t cv_closedcaptioning = Player("closedcaptioning", "Off").on_off().onchange(Captioning_OnChange);
consvar_t cv_continuousmusic = Player("continuousmusic", "On").on_off();
consvar_t cv_streamersafemusic = Player("streamersafemusic", "Off").on_off();
consvar_t cv_controlperkey = Player("controlperkey", "One").values({{1, "One"}, {2, "Several"}});
// actual general (maximum) sound & music volume, saved into the config

View file

@ -292,6 +292,9 @@ menuitem_t OPTIONS_Sound[] =
{IT_STRING | IT_CVAR, "Continuous Attack Music", "Keep music playing seamlessly when retrying in Attack modes.",
NULL, {.cvar = &cv_continuousmusic}, 0, 0},
{IT_STRING | IT_CVAR, "Streamer-Safe Music", "Only play music safe for video platforms.",
NULL, {.cvar = &cv_streamersafemusic}, 0, 0},
{IT_SPACE | IT_DYBIGSPACE, NULL, NULL,
NULL, {NULL}, 0, 0},

View file

@ -81,7 +81,12 @@ void TuneManager::tick()
{
if (load())
{
I_PlaySong(tune->loop);
musicdef_t* def = find_musicdef();
if (!cv_streamersafemusic.value || (def != nullptr && !def->contentidunsafe))
{
I_PlaySong(tune->loop);
}
I_FadeSongFromVolume(
tune->use_level_volume ? level_volume_ : 100,
0,
@ -151,7 +156,11 @@ void TuneManager::pause_unpause() const
}
else
{
I_ResumeSong();
musicdef_t* def = find_musicdef();
if (!cv_streamersafemusic.value || (def != nullptr && !def->contentidunsafe))
{
I_ResumeSong();
}
}
}
}
@ -168,6 +177,12 @@ bool TuneManager::load() const
return I_LoadSong(static_cast<char*>(W_CacheLumpNum(lumpnum, PU_MUSIC)), W_LumpLength(lumpnum));
}
musicdef_t* TuneManager::find_musicdef() const
{
uint8_t index = 0;
return S_FindMusicDef(current_song_.c_str(), &index);
}
void TuneManager::adjust_volume() const
{
UINT8 i;

View file

@ -121,6 +121,7 @@ private:
}
bool load() const;
musicdef_t* find_musicdef() const;
void adjust_volume() const;
bool resync();

View file

@ -43,6 +43,7 @@ extern consvar_t cv_gamedigimusic;
extern consvar_t cv_gamesounds;
extern consvar_t cv_bgaudio;
extern consvar_t cv_streamersafemusic;
typedef enum
{