Skip to content

Commit

Permalink
Hexen|MapInfoParser: Fixed map music assignment; cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Jan 24, 2014
1 parent 72ff01d commit a5a96c2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 44 deletions.
12 changes: 8 additions & 4 deletions doomsday/plugins/common/src/p_sound.cpp
Expand Up @@ -25,13 +25,18 @@

#include "dmu_lib.h"
#include "hexlex.h"
#ifdef __JHEXEN__
# include "p_mapinfo.h"
#endif

void S_MapMusic(uint episode, uint map)
{
#ifdef __JHEXEN__
mapinfo_t const *mapInfo = P_MapInfo(map);

int const defIndex = Def_Get(DD_DEF_MUSIC, "currentmap", 0);
int const cdTrack = P_MapInfo(map)->cdTrack;
char const *lump = P_GetMapSongLump(map);
int const cdTrack = mapInfo->cdTrack;
char const *lump = strcasecmp(mapInfo->songLump, "DEFSONG")? mapInfo->songLump : 0;

// Update the 'currentmap' music definition.

Expand Down Expand Up @@ -121,9 +126,8 @@ void SndInfoParser(Str const *path)
uint const map = lexer.readMapNumber();
AutoStr const *lumpName = lexer.readLumpName();

if(map >= 0 && map >= P_MapInfoCount())
if(mapinfo_t *mapInfo = P_MapInfo(map))
{
mapinfo_t *mapInfo = P_MapInfo(map);
strncpy(mapInfo->songLump, Str_Text(lumpName), sizeof(mapInfo->songLump));
}
continue;
Expand Down
15 changes: 0 additions & 15 deletions doomsday/plugins/hexen/include/p_mapinfo.h
Expand Up @@ -65,11 +65,6 @@ void MapInfoParser(Str const *path);
*/
mapinfo_t *P_MapInfo(uint map);

/**
* Returns the total number of MapInfo definitions.
*/
uint P_MapInfoCount();

#define P_INVALID_LOGICAL_MAP 0xffffffff

/**
Expand All @@ -93,16 +88,6 @@ uint P_TranslateMapIfExists(uint map);
*/
uint P_TranslateMap(uint map);

/**
* Retrieve the song lump name for the given map.
*
* @param map The map (logical number) to be queried.
*
* @return @c NULL, if the map is set to use the default song lump, else a ptr
* to a string containing the name of the song lump.
*/
char *P_GetMapSongLump(uint map);

#if __cplusplus
} // extern "C"
#endif
Expand Down
30 changes: 5 additions & 25 deletions doomsday/plugins/hexen/src/p_mapinfo.cpp
Expand Up @@ -35,16 +35,13 @@
static mapinfo_t MapInfo[99];
static uint mapCount;

static uint qualifyMap(uint map)
{
return (map >= mapCount) ? 0 : map;
}

/**
* Update the Music definition @a musicId with the specified CD @a track number.
*/
static void setMusicCDTrack(char const *musicId, int track)
{
App_Log(DE2_DEV_RES_VERBOSE, "setSongCDTrack: musicId=%s, track=%i", musicId, track);
App_Log(DE2_DEV_RES_VERBOSE, "setMusicCDTrack: musicId=%s, track=%i", musicId, track);

// Update the corresponding Music definition.
int cdTrack = track;
Def_Set(DD_DEF_MUSIC, Def_Get(DD_DEF_MUSIC, musicId, 0), DD_CD_TRACK, &cdTrack);
}
Expand Down Expand Up @@ -267,12 +264,7 @@ void P_InitMapInfo()

mapinfo_t *P_MapInfo(uint map)
{
return &MapInfo[qualifyMap(map)];
}

uint P_MapInfoCount()
{
return mapCount;
return &MapInfo[(map >= mapCount) ? 0 : map];
}

uint P_TranslateMapIfExists(uint map)
Expand Down Expand Up @@ -314,15 +306,3 @@ uint P_TranslateMap(uint map)
}
return translated;
}

char *P_GetMapSongLump(uint map)
{
if(!strcasecmp(MapInfo[qualifyMap(map)].songLump, "DEFSONG"))
{
return NULL;
}
else
{
return MapInfo[qualifyMap(map)].songLump;
}
}

0 comments on commit a5a96c2

Please sign in to comment.