Merge branch 'tune-reset' into 'master'

Prevent non-dynamic tunes remapped by ACS from remaining remapped after map ends.

See merge request kart-krew-dev/ring-racers!24
This commit is contained in:
Eidolon 2025-10-15 21:28:49 -05:00
commit 6fa09928c8
7 changed files with 64 additions and 14 deletions

View file

@ -2409,6 +2409,8 @@ bool CallFunc_MusicStopAll(ACSVM::Thread *thread, const ACSVM::Word *argV, ACSVM
bool CallFunc_MusicRemap(ACSVM::Thread *thread, const ACSVM::Word *argV, ACSVM::Word argC) bool CallFunc_MusicRemap(ACSVM::Thread *thread, const ACSVM::Word *argV, ACSVM::Word argC)
{ {
ACSVM::MapScope *map = thread->scopeMap; ACSVM::MapScope *map = thread->scopeMap;
ACSVM::String *tuneStr = nullptr;
const char *tune = nullptr;
// 0: str tune - id for the tune to play // 0: str tune - id for the tune to play
// 1: str song - lump name for the song to map to // 1: str song - lump name for the song to map to
@ -2419,6 +2421,15 @@ bool CallFunc_MusicRemap(ACSVM::Thread *thread, const ACSVM::Word *argV, ACSVM::
return false; return false;
} }
tuneStr = map->getString(argV[0]);
tune = tuneStr->str;
// Do not allow ACS to remap Stereo Mode tunes.
if (strncmp("stere", tune, 5))
{
return false;
}
Music_Remap(map->getString(argV[0])->str, map->getString(argV[1])->str); Music_Remap(map->getString(argV[0])->str, map->getString(argV[1])->str);
return false; return false;

View file

@ -5215,6 +5215,9 @@ static void G_DoContinued(void)
// when something new is added. // when something new is added.
void G_EndGame(void) void G_EndGame(void)
{ {
// Clean up ACS music remaps.
Music_TuneReset();
// Handle voting // Handle voting
if (nextmap == NEXTMAP_VOTING) if (nextmap == NEXTMAP_VOTING)
{ {

View file

@ -481,6 +481,12 @@ static int lib_mMusicRemap(lua_State *L)
return LUA_ErrNoTune(L, tune_id); return LUA_ErrNoTune(L, tune_id);
} }
// Do not allow Lua to remap Stereo Mode tunes.
if (strncmp("stere", tune_id, 5))
{
return LUA_ErrStereo(L, tune_id);
}
Music_Remap(tune_id, music_name); Music_Remap(tune_id, music_name);
return 0; return 0;

View file

@ -117,6 +117,9 @@ void COM_Lua_f(void);
// Music: "No tune" error. // Music: "No tune" error.
#define LUA_ErrNoTune(L, tune) luaL_error(L, "tune \"%s\" does not exist", tune) #define LUA_ErrNoTune(L, tune) luaL_error(L, "tune \"%s\" does not exist", tune)
// Music: "Stereo Mode" error.
#define LUA_ErrStereo(L, tune) luaL_error(L, "tune \"%s\" cannot be remapped (stereo mode)", tune)
// Deprecation warnings // Deprecation warnings
// Shows once upon use. Then doesn't show again. // Shows once upon use. Then doesn't show again.
#define LUA_Deprecated(L,this_func,use_instead)\ #define LUA_Deprecated(L,this_func,use_instead)\

View file

@ -25,6 +25,7 @@ TuneManager g_tunes;
void Music_Init(void) void Music_Init(void)
{ {
// Many tunes below now have their default songs set in Music_TuneReset. Check there first for changing those.
{ {
Tune& tune = g_tunes.insert("level"); Tune& tune = g_tunes.insert("level");
@ -55,21 +56,21 @@ void Music_Init(void)
{ {
Tune& tune = g_tunes.insert("battle_overtime", g_tunes.find("level")); Tune& tune = g_tunes.insert("battle_overtime", g_tunes.find("level"));
tune.song = "shwdwn"; tune.song = ""; // Music_TuneReset
tune.priority = 11; tune.priority = 11;
} }
{ {
Tune& tune = g_tunes.insert("battle_overtime_stress", g_tunes.find("battle_overtime")); Tune& tune = g_tunes.insert("battle_overtime_stress", g_tunes.find("battle_overtime"));
tune.song = "shwdn2"; tune.song = ""; // Music_TuneReset
tune.priority = 10; tune.priority = 10;
} }
{ {
Tune& tune = g_tunes.insert("grow"); Tune& tune = g_tunes.insert("grow");
tune.song = "kgrow"; tune.song = ""; // Music_TuneReset
tune.priority = 20; tune.priority = 20;
tune.resume_fade_in = 200; tune.resume_fade_in = 200;
tune.use_level_volume = true; tune.use_level_volume = true;
@ -78,7 +79,7 @@ void Music_Init(void)
{ {
Tune& tune = g_tunes.insert("invinc"); Tune& tune = g_tunes.insert("invinc");
tune.song = "kinvnc"; tune.song = ""; // Music_TuneReset
tune.priority = 21; tune.priority = 21;
tune.use_level_volume = true; tune.use_level_volume = true;
} }
@ -86,7 +87,7 @@ void Music_Init(void)
{ {
Tune& tune = g_tunes.insert("finish_silence"); Tune& tune = g_tunes.insert("finish_silence");
tune.song = ""; tune.song = ""; // Music_TuneReset
tune.priority = 30; tune.priority = 30;
} }
@ -100,7 +101,7 @@ void Music_Init(void)
{ {
Tune& tune = g_tunes.insert("comeon"); Tune& tune = g_tunes.insert("comeon");
tune.song = "chalng"; tune.song = ""; // Music_TuneReset
tune.priority = 35; tune.priority = 35;
tune.loop = false; tune.loop = false;
} }
@ -116,7 +117,7 @@ void Music_Init(void)
{ {
Tune& tune = g_tunes.insert("vote"); Tune& tune = g_tunes.insert("vote");
tune.song = "vote"; tune.song = ""; // Music_TuneReset
tune.priority = 50; tune.priority = 50;
tune.credit = true; tune.credit = true;
} }
@ -124,14 +125,14 @@ void Music_Init(void)
{ {
Tune& tune = g_tunes.insert("vote_suspense"); Tune& tune = g_tunes.insert("vote_suspense");
tune.song = "voteea"; tune.song = ""; // Music_TuneReset
tune.priority = 51; tune.priority = 51;
} }
{ {
Tune& tune = g_tunes.insert("vote_end"); Tune& tune = g_tunes.insert("vote_end");
tune.song = "voteeb"; tune.song = ""; // Music_TuneReset
tune.priority = 52; tune.priority = 52;
tune.loop = false; tune.loop = false;
} }
@ -139,14 +140,14 @@ void Music_Init(void)
{ {
Tune& tune = g_tunes.insert("wait"); Tune& tune = g_tunes.insert("wait");
tune.song = "WAIT2J"; tune.song = ""; // Music_TuneReset
tune.priority = 60; tune.priority = 60;
} }
{ {
Tune& tune = g_tunes.insert("title"); Tune& tune = g_tunes.insert("title");
tune.song = "_title"; tune.song = ""; // Music_TuneReset
tune.priority = 100; tune.priority = 100;
tune.resist = true; tune.resist = true;
} }
@ -167,7 +168,7 @@ void Music_Init(void)
{ {
Tune& tune = g_tunes.insert("credits_silence"); Tune& tune = g_tunes.insert("credits_silence");
tune.song = ""; tune.song = ""; // Music_TuneReset
tune.priority = 100; tune.priority = 100;
} }
@ -175,7 +176,7 @@ void Music_Init(void)
Tune& tune = g_tunes.insert("credits"); Tune& tune = g_tunes.insert("credits");
tune.priority = 101; tune.priority = 101;
tune.song = "_creds"; tune.song = ""; // Music_TuneReset
tune.credit = true; tune.credit = true;
} }
@ -213,10 +214,12 @@ void Music_Init(void)
{ {
Tune& tune = g_tunes.insert("lawyer"); Tune& tune = g_tunes.insert("lawyer");
tune.song = "lawyer"; tune.song = ""; // Music_TuneReset
tune.priority = 35; tune.priority = 35;
tune.loop = false; tune.loop = false;
} }
Music_TuneReset();
} }
@ -522,3 +525,21 @@ void Music_ResetLevelVolume(void)
{ {
g_tunes.level_volume(100, true); g_tunes.level_volume(100, true);
} }
void Music_TuneReset(void)
{
Music_Remap("battle_overtime", "shwdwn");
Music_Remap("battle_overtime_stress", "shwdn2");
Music_Remap("grow", "kgrow");
Music_Remap("invinc", "kinvnc");
Music_Remap("finish_silence", "");
Music_Remap("comeon", "chalng");
Music_Remap("vote", "vote");
Music_Remap("vote_suspense", "voteea");
Music_Remap("vote_end", "voteeb");
Music_Remap("wait", "WAIT2J");
Music_Remap("title", "_title");
Music_Remap("credits_silence", "");
Music_Remap("credits", "_creds");
Music_Remap("lawyer", "lawyer");
}

View file

@ -207,6 +207,10 @@ void Music_Tick(void);
// the music plays again when re-enabled. // the music plays again when re-enabled.
void Music_Flip(void); void Music_Flip(void);
// Resets all non-dynamic tunes to default values.
// Keeps ACS music remapping from playing havoc after a map.
void Music_TuneReset(void);
#ifdef __cplusplus #ifdef __cplusplus
} // extern "C" } // extern "C"

View file

@ -9100,6 +9100,8 @@ void P_PostLoadLevel(void)
marathonmode = static_cast<marathonmode_t>(marathonmode & ~MA_INIT); marathonmode = static_cast<marathonmode_t>(marathonmode & ~MA_INIT);
} }
Music_TuneReset(); // Placed before ACS scripts to allow remaps to occur on level start.
ACS_RunLevelStartScripts(); ACS_RunLevelStartScripts();
LUA_HookInt(gamemap, HOOK(MapLoad)); LUA_HookInt(gamemap, HOOK(MapLoad));