Attempt to fix music replacement definitions again

Store per-map music replacements in a TMap, and perform the replacements after parsing the MAPINFO
This commit is contained in:
Kevin Caccamo 2021-09-05 14:35:10 -04:00 committed by Christoph Oelckers
parent f675adebbd
commit 2297c9351a
4 changed files with 24 additions and 1 deletions

View file

@ -815,7 +815,7 @@ void parseMusic(FScanner& sc, FScriptPosition& pos)
if (sc.Compare("id")) sc.GetString(id);
else if (sc.Compare("file")) sc.GetString(file);
}
SetMusicForMap(id, file, true);
SetMusicReplacement(id, file);
}
//===========================================================================

View file

@ -1057,6 +1057,7 @@ int RunGame()
gi->app_init();
StartScreen->Progress();
G_ParseMapInfo();
ReplaceMusics(true);
CreateStatusBar();
SetDefaultMenuColors();
M_Init();

View file

@ -40,6 +40,7 @@
#include "printf.h"
#include "gamecontrol.h"
#include "raze_sound.h"
#include "zstring.h"
FString gSkillNames[MAXSKILLS];
int gDefaultVolume = 0, gDefaultSkill = 1;
@ -48,6 +49,7 @@ GlobalCutscenes globalCutscenes;
TArray<ClusterDef> clusters;
TArray<VolumeRecord> volumes;
TArray<TPointer<MapRecord>> mapList; // must be allocated as pointers because it can whack the currentlLevel pointer if this was a flat array.
static TMap<FString, FString> musicReplacements;
MapRecord *currentLevel; // level that is currently played.
MapRecord* lastLevel; // Same here, for the last level.
@ -157,6 +159,23 @@ MapRecord* FindNextSecretMap(MapRecord* thismap)
return next? next : FindNextMap(thismap);
}
void SetMusicReplacement(const char *mapname, const char *music)
{
musicReplacements[mapname] = music;
}
void ReplaceMusics(bool namehack)
{
TMap<FString, FString>::Iterator it(musicReplacements);
TMap<FString, FString>::Pair* pair;
while (it.NextPair(pair))
{
FString mapname = pair->Key;
FString music = pair->Value;
SetMusicForMap(mapname, music, namehack);
}
musicReplacements.Clear();
}
bool SetMusicForMap(const char* mapname, const char* music, bool namehack)
{
@ -192,6 +211,7 @@ bool SetMusicForMap(const char* mapname, const char* music, bool namehack)
index->music = music;
return true;
}
DPrintf(DMSG_WARNING, "Could not replace %s music with %s\n", mapname, music);
return false;
}

View file

@ -209,6 +209,8 @@ struct SummaryInfo
extern GlobalCutscenes globalCutscenes;
extern MapRecord *currentLevel;
void SetMusicReplacement(const char *mapname, const char *music);
void ReplaceMusics(bool namehack = false);
bool SetMusicForMap(const char* mapname, const char* music, bool namehack = false);
MapRecord *FindMapByName(const char *nm);