From f9565d4049b52e6ad171747dfb55221810fdc27d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20Kera=CC=88nen?= Date: Sat, 24 Nov 2018 20:35:41 +0200 Subject: [PATCH] Fixed|Music: Defined external music file ignored The way Hexen loads the MAPINFO and SNDINFO lumps was causing custom music definitions to be ignored. The MAPINFO translator (that generates corresponding DEDs) was adding music definitions that would be used even when custom music was loaded. Now these generated definitions are only present when parsing custom MAPINFO data. (Non-custom map infos are expected to have a music definition available matching the map ID.) In Hexen, SNDINFO is applied by default so that if a matching music definition is available (by ID), the map info is changed to use that music (that may be a custom music definition). IssueID #2082 --- .../apps/plugins/common/include/g_common.h | 2 +- .../apps/plugins/common/src/game/g_game.cpp | 6 +-- .../apps/plugins/common/src/world/p_sound.cpp | 15 +++++-- .../importidtech1/src/mapinfotranslator.cpp | 42 ++++++++++++------- 4 files changed, 43 insertions(+), 22 deletions(-) diff --git a/doomsday/apps/plugins/common/include/g_common.h b/doomsday/apps/plugins/common/include/g_common.h index 118df9849b..872b62bf1a 100644 --- a/doomsday/apps/plugins/common/include/g_common.h +++ b/doomsday/apps/plugins/common/include/g_common.h @@ -96,7 +96,7 @@ de::String G_EpisodeTitle(de::String episodeId); * * @todo: Should use WorldSystem::mapInfoForMapUri() instead. */ -de::Record const &G_MapInfoForMapUri(de::Uri const &mapUri); +de::Record &G_MapInfoForMapUri(de::Uri const &mapUri); /** * @param mapUri Identifier of the map to lookup the author of. diff --git a/doomsday/apps/plugins/common/src/game/g_game.cpp b/doomsday/apps/plugins/common/src/game/g_game.cpp index e4d9b3066b..1ae5db908f 100644 --- a/doomsday/apps/plugins/common/src/game/g_game.cpp +++ b/doomsday/apps/plugins/common/src/game/g_game.cpp @@ -2088,15 +2088,15 @@ de::Uri G_ComposeMapUri(uint episode, uint map) return de::Uri("Maps", mapId); } -Record const &G_MapInfoForMapUri(de::Uri const &mapUri) +Record &G_MapInfoForMapUri(de::Uri const &mapUri) { // Is there a MapInfo definition for the given URI? - if (Record const *def = Defs().mapInfos.tryFind("id", mapUri.compose())) + if (Record *def = Defs().mapInfos.tryFind("id", mapUri.compose())) { return *def; } // Is there is a default definition (for all maps)? - if (Record const *def = Defs().mapInfos.tryFind("id", de::Uri("Maps", Path("*")).compose())) + if (Record *def = Defs().mapInfos.tryFind("id", de::Uri("Maps", Path("*")).compose())) { return *def; } diff --git a/doomsday/apps/plugins/common/src/world/p_sound.cpp b/doomsday/apps/plugins/common/src/world/p_sound.cpp index 442dd8aa64..0ba4299f50 100644 --- a/doomsday/apps/plugins/common/src/world/p_sound.cpp +++ b/doomsday/apps/plugins/common/src/world/p_sound.cpp @@ -115,10 +115,19 @@ void SndInfoParser(ddstring_s const *path) if(mapNumber > 0) { - Record const &mapInfo = G_MapInfoForMapUri(G_ComposeMapUri(0, mapNumber - 1)); - if(Record *music = Defs().musics.tryFind("id", mapInfo.gets("music"))) + Record &mapInfo = G_MapInfoForMapUri(G_ComposeMapUri(0, mapNumber - 1)); + if (const Record *music = Defs().musics.tryFind("id", Str_Text(lumpName))) { - music->set("lumpName", Str_Text(lumpName)); + // There is a music definition with this ID, let's use that. + mapInfo.set("music", Str_Text(lumpName)); + } + else + { + // Modify the map's currently used music to override the music lump. + if (Record *music = Defs().musics.tryFind("id", mapInfo.gets("music"))) + { + music->set("lumpName", Str_Text(lumpName)); + } } } continue; diff --git a/doomsday/apps/plugins/importidtech1/src/mapinfotranslator.cpp b/doomsday/apps/plugins/importidtech1/src/mapinfotranslator.cpp index b2319d6568..9bb6eebfc9 100644 --- a/doomsday/apps/plugins/importidtech1/src/mapinfotranslator.cpp +++ b/doomsday/apps/plugins/importidtech1/src/mapinfotranslator.cpp @@ -1415,35 +1415,47 @@ DENG2_PIMPL_NOREF(MapInfoTranslator) for(auto const pair : defs.mapInfos) { MapInfo const &info = pair.second; - if(custom != info.getb("custom")) continue; + + const bool isCustomMapInfo = info.getb("custom"); + + if(custom != isCustomMapInfo) continue; de::Uri mapUri(info.gets("id"), RC_NULL); - if(mapUri.path().isEmpty()) continue; + if (mapUri.path().isEmpty()) continue; - String const mapId = toMapId(mapUri); + const String mapId = toMapId(mapUri); + const String musicLumpName = info.gets("music"); + bool addedMusicDef = false; - String const musicId = mapId + "_music"; - os << "\n\nMusic {" - << "\n ID = \"" + musicId + "\";"; - String const musicLumpName = info.gets("music"); - if(!musicLumpName.isEmpty()) + if (isCustomMapInfo && (!musicLumpName.isEmpty() || info.geti("cdTrack"))) { - os << "\n Lump = \"" + musicLumpName + "\";"; + addedMusicDef = true; + + // Add a music def for this custom music. + os << "\n\nMusic {" + << "\n ID = \"" + mapId + "\";"; // music ID == map ID + if (!musicLumpName.isEmpty()) + { + os << "\n Lump = \"" + musicLumpName + "\";"; + } + os << "\n CD Track = " << info.geti("cdTrack") << ";" + << "\n}"; } - os << "\n CD Track = " + String::number(info.geti("cdTrack")) + ";" - << "\n}"; - bool const doubleSky = info.getb("doubleSky"); + const bool doubleSky = info.getb("doubleSky"); os << "\n\nMap Info {" << "\n ID = \"" + mapId + "\";" << "\n Title = \"" + info.gets("title") + "\";"; - if(!info.getb("custom")) + if (!isCustomMapInfo) { os << "\n Author = \"" + String(Str_Text(gameInfo.author)) + "\";"; } - os << "\n Fade Table = \"" + info.gets("fadeTable") + "\";" - << "\n Music = \"" + musicId + "\";"; + os << "\n Fade Table = \"" + info.gets("fadeTable") + "\";"; + if (addedMusicDef) + { + os << "\n Music = \"" + mapId + "\";"; + } de::Uri titleImageUri(info.gets("titleImage"), RC_NULL); if(!titleImageUri.path().isEmpty()) {