Skip to content

Commit

Permalink
Fixed|Music: Defined external music file ignored
Browse files Browse the repository at this point in the history
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
  • Loading branch information
skyjake committed Nov 24, 2018
1 parent 196e80e commit f9565d4
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 22 deletions.
2 changes: 1 addition & 1 deletion doomsday/apps/plugins/common/include/g_common.h
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions doomsday/apps/plugins/common/src/game/g_game.cpp
Expand Up @@ -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;
}
Expand Down
15 changes: 12 additions & 3 deletions doomsday/apps/plugins/common/src/world/p_sound.cpp
Expand Up @@ -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;
Expand Down
42 changes: 27 additions & 15 deletions doomsday/apps/plugins/importidtech1/src/mapinfotranslator.cpp
Expand Up @@ -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())
{
Expand Down

0 comments on commit f9565d4

Please sign in to comment.