Skip to content

Commit

Permalink
Attempt to fix music replacement definitions again
Browse files Browse the repository at this point in the history
Store per-map music replacements in a TMap, and perform the replacements after parsing the MAPINFO
  • Loading branch information
Talon1024 authored and coelckers committed Sep 12, 2021
1 parent f675ade commit 2297c93
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion source/core/defparser.cpp
Expand Up @@ -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);
}

//===========================================================================
Expand Down
1 change: 1 addition & 0 deletions source/core/gamecontrol.cpp
Expand Up @@ -1057,6 +1057,7 @@ int RunGame()
gi->app_init();
StartScreen->Progress();
G_ParseMapInfo();
ReplaceMusics(true);
CreateStatusBar();
SetDefaultMenuColors();
M_Init();
Expand Down
20 changes: 20 additions & 0 deletions source/core/mapinfo.cpp
Expand Up @@ -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;
Expand All @@ -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.

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 2 additions & 0 deletions source/core/mapinfo.h
Expand Up @@ -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);
Expand Down

0 comments on commit 2297c93

Please sign in to comment.