From 933c905863c6b9b8edc306a758a10a3d50a7ab6f Mon Sep 17 00:00:00 2001 From: danij Date: Sat, 25 Jan 2014 07:45:34 +0000 Subject: [PATCH] Hexen|SndInfoParser: Fix patching of MAPINFO (lump) definitions with SNDINFO-read values (The only time a mapinfo_t is modified outside of MapInfoParser). --- doomsday/plugins/common/include/hexlex.h | 1 - doomsday/plugins/common/include/p_sound.h | 3 +++ doomsday/plugins/common/src/g_game.c | 4 ++-- doomsday/plugins/common/src/hexlex.cpp | 6 ------ doomsday/plugins/common/src/p_mapsetup.cpp | 2 +- doomsday/plugins/common/src/p_sound.cpp | 14 +++++++++----- doomsday/plugins/hexen/include/p_mapinfo.h | 4 ++-- doomsday/plugins/hexen/src/p_mapinfo.cpp | 3 +-- doomsday/plugins/hexen/src/p_spec.c | 2 +- 9 files changed, 19 insertions(+), 20 deletions(-) diff --git a/doomsday/plugins/common/include/hexlex.h b/doomsday/plugins/common/include/hexlex.h index 03e4a32775..48ff2c9977 100644 --- a/doomsday/plugins/common/include/hexlex.h +++ b/doomsday/plugins/common/include/hexlex.h @@ -78,7 +78,6 @@ class HexLex int readNumber(); int readSoundIndex(); - uint readMapNumber(); Uri *readUri(char const *defaultScheme = ""); /** diff --git a/doomsday/plugins/common/include/p_sound.h b/doomsday/plugins/common/include/p_sound.h index 6079838da1..eaa2dda15c 100644 --- a/doomsday/plugins/common/include/p_sound.h +++ b/doomsday/plugins/common/include/p_sound.h @@ -63,6 +63,9 @@ int S_GetSoundID(char const *name); /** * Attempt to parse the script on the identified @a path as "sound definition" data. + * + * Important: This should never be called @em before MapInfoParser, as this may need + * to patch those definitions... */ void SndInfoParser(Str const *path); #endif diff --git a/doomsday/plugins/common/src/g_game.c b/doomsday/plugins/common/src/g_game.c index 0df2017a78..ceb21619d6 100644 --- a/doomsday/plugins/common/src/g_game.c +++ b/doomsday/plugins/common/src/g_game.c @@ -1157,7 +1157,7 @@ static void printMapBanner(void) { char buf[64]; #if __JHEXEN__ - mapinfo_t *mapInfo = P_MapInfo(mapUri); + mapinfo_t const *mapInfo = P_MapInfo(mapUri); int warpNum = (mapInfo? mapInfo->warpTrans : -1); dd_snprintf(buf, 64, "Map %u (%u): " DE2_ESC(b) "%s", warpNum + 1, gameMap + 1, title); #else @@ -1265,7 +1265,7 @@ static void initFogForMap(ddmapinfo_t *mapInfo) #if __JHEXEN__ { Uri *mapUri = G_ComposeMapUri(gameEpisode, gameMap); - mapinfo_t *mapInfo = P_MapInfo(mapUri); + mapinfo_t const *mapInfo = P_MapInfo(mapUri); if(mapInfo) { int fadeTable = mapInfo->fadeTable; diff --git a/doomsday/plugins/common/src/hexlex.cpp b/doomsday/plugins/common/src/hexlex.cpp index fe1d8af990..993ed6227d 100644 --- a/doomsday/plugins/common/src/hexlex.cpp +++ b/doomsday/plugins/common/src/hexlex.cpp @@ -222,12 +222,6 @@ Uri *HexLex::readUri(char const *defaultScheme) return uri; } -uint HexLex::readMapNumber() -{ - uint num = readNumber(); - return num > 0? num - 1 : num; -} - int HexLex::readSoundIndex() { return Def_Get(DD_DEF_SOUND_BY_NAME, Str_Text(readString()), 0); diff --git a/doomsday/plugins/common/src/p_mapsetup.cpp b/doomsday/plugins/common/src/p_mapsetup.cpp index 6c50fda566..b4c2e79e1d 100644 --- a/doomsday/plugins/common/src/p_mapsetup.cpp +++ b/doomsday/plugins/common/src/p_mapsetup.cpp @@ -1060,7 +1060,7 @@ char const *P_MapTitle(uint episode, uint map) // In Hexen we can also look in MAPINFO for the map title. if(!title) { - if(mapinfo_t *mapInfo = P_MapInfo(mapUri)) + if(mapinfo_t const *mapInfo = P_MapInfo(mapUri)) { title = mapInfo->title; } diff --git a/doomsday/plugins/common/src/p_sound.cpp b/doomsday/plugins/common/src/p_sound.cpp index 30ef79ba5c..807775fff5 100644 --- a/doomsday/plugins/common/src/p_sound.cpp +++ b/doomsday/plugins/common/src/p_sound.cpp @@ -26,6 +26,7 @@ #include "dmu_lib.h" #include "hexlex.h" #ifdef __JHEXEN__ +# include "g_common.h" # include "p_mapinfo.h" #endif @@ -121,15 +122,18 @@ void SndInfoParser(Str const *path) { // $map int(map-number) string(lump-name) // Associate a music lump to a map. - Uri *mapUri = lexer.readUri(); + int mapNumber = lexer.readNumber(); Str const *lumpName = lexer.readString(); - if(mapinfo_t *mapInfo = P_MapInfo(mapUri)) + if(mapNumber > 0) { - strncpy(mapInfo->songLump, Str_Text(lumpName), sizeof(mapInfo->songLump)); + Uri *mapUri = G_ComposeMapUri(0, mapNumber - 1); + if(mapinfo_t *mapInfo = P_MapInfo(mapUri)) + { + strncpy(mapInfo->songLump, Str_Text(lumpName), sizeof(mapInfo->songLump)); + } + Uri_Delete(mapUri); } - - Uri_Delete(mapUri); continue; } if(!Str_CompareIgnoreCase(lexer.token(), "$registered")) // Unused. diff --git a/doomsday/plugins/hexen/include/p_mapinfo.h b/doomsday/plugins/hexen/include/p_mapinfo.h index 99f074a8d2..c505df945c 100644 --- a/doomsday/plugins/hexen/include/p_mapinfo.h +++ b/doomsday/plugins/hexen/include/p_mapinfo.h @@ -30,10 +30,10 @@ typedef struct mapinfo_s { uint map; ///< Logical map number. - short cluster; + int cluster; uint warpTrans; uint nextMap; - short cdTrack; + int cdTrack; char title[32]; materialid_t sky1Material; materialid_t sky2Material; diff --git a/doomsday/plugins/hexen/src/p_mapinfo.cpp b/doomsday/plugins/hexen/src/p_mapinfo.cpp index 4bd3c8bbaf..d6acdb0113 100644 --- a/doomsday/plugins/hexen/src/p_mapinfo.cpp +++ b/doomsday/plugins/hexen/src/p_mapinfo.cpp @@ -139,7 +139,7 @@ void MapInfoParser(Str const *path) } Uri_Delete(mapUri); - // Map name must follow the number. + // Map title must follow the number. strcpy(info->title, Str_Text(lexer.readString())); // Process optional tokens. @@ -198,7 +198,6 @@ void MapInfoParser(Str const *path) Con_Error("MapInfoParser: Invalid map warp-number '%s' in \"%s\" on line #%i", lexer.token(), F_PrettyPath(Str_Text(path)), lexer.lineNumber()); } - info->warpTrans = (unsigned) mapWarpNum - 1; continue; } diff --git a/doomsday/plugins/hexen/src/p_spec.c b/doomsday/plugins/hexen/src/p_spec.c index 71988f0a3d..311de4c11c 100644 --- a/doomsday/plugins/hexen/src/p_spec.c +++ b/doomsday/plugins/hexen/src/p_spec.c @@ -1006,7 +1006,7 @@ void P_InitLightning(void) { int i, secCount; Uri *mapUri = G_ComposeMapUri(gameEpisode, gameMap); - mapinfo_t *mapInfo = P_MapInfo(mapUri); + mapinfo_t const *mapInfo = P_MapInfo(mapUri); Uri_Delete(mapUri); if(!mapInfo || !mapInfo->lightning)