Skip to content

Commit

Permalink
libcommon: G_ComposeMapUri() and G_MapNumberFor() are now deprecated
Browse files Browse the repository at this point in the history
Map references composed of a logical episode and map number pair are
a historical legacy that should only be used when necessary for
compatibility reasons.

As of this commit episode numbering is completely separate from map
identifiers and one should no longer assume that this information can
be extracted from them. The assumption being that the episode number
is defined in MapInfo.
  • Loading branch information
danij-deng committed Jul 10, 2014
1 parent 5cac419 commit 60ede52
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 94 deletions.
27 changes: 17 additions & 10 deletions doomsday/plugins/common/include/g_common.h
Expand Up @@ -29,6 +29,7 @@

DENG_EXTERN_C dd_bool singledemo;

DENG_EXTERN_C uint gameEpisode;
DENG_EXTERN_C uint gameMapEntrance;

#if __cplusplus
Expand Down Expand Up @@ -187,40 +188,46 @@ void G_IntermissionDone(void);
} // extern "C"

/**
* Returns the logical episode number for the identified map.
* Returns the logical episode number assigned to the identified map (in MapInfo).
*
* @param mapUri Unique identifier of the map to lookup.
*/
uint G_EpisodeNumberFor(de::Uri const &mapUri);

/**
* Determines the next map according to the default map progression.
*
* @param secretExit @c true= choose the map assigned to the secret exit.
*/
de::Uri G_NextMap(dd_bool secretExit);

/**
* Returns the logical map number for the identified map.
*
* @param mapUri Unique identifier of the map to lookup.
*
* @deprecated Should use map URIs instead.
*/
uint G_MapNumberFor(de::Uri const &mapUri);

/**
* Compose a Uri for the identified @a episode and @a map combination.
* Compose a Uri for the identified @a episode and @a map combination using the default
* form for the current game mode (i.e., MAPXX or EXMY).
*
* @param episode Logical episode number.
* @param map Logical map number.
*
* @return Resultant Uri.
*/
de::Uri G_ComposeMapUri(uint episode, uint map);

/**
* Determines the next map according to the default map progression.
*
* @param secretExit @c true= choose the map assigned to the secret exit.
* @deprecated Should use map URIs instead. Map references composed of a logical episode
* and map number pair are a historical legacy that should only be used when necessary,
* for compatibility reasons.
*/
de::Uri G_NextMap(dd_bool secretExit);
de::Uri G_ComposeMapUri(uint episode, uint map);

extern "C" {
#endif

uint G_CurrentEpisodeNumber(void);
uint G_CurrentMapNumber(void);

int G_Ruleset_Skill();
Expand Down
9 changes: 5 additions & 4 deletions doomsday/plugins/common/src/d_netcl.cpp
Expand Up @@ -650,19 +650,20 @@ void NetCl_Intermission(Reader *msg)
SN_StopAllSequences();
#endif

/// @todo Map references should be transmitted as URI.
#if __JDOOM__ || __JDOOM64__
wmInfo.maxKills = de::max<int>(1, Reader_ReadUInt16(msg));
wmInfo.maxItems = de::max<int>(1, Reader_ReadUInt16(msg));
wmInfo.maxSecret = de::max<int>(1, Reader_ReadUInt16(msg));
wmInfo.nextMap = G_ComposeMapUri(G_CurrentEpisodeNumber(), Reader_ReadByte(msg));
wmInfo.currentMap = G_ComposeMapUri(G_CurrentEpisodeNumber(), Reader_ReadByte(msg));
wmInfo.nextMap = G_ComposeMapUri(::gameEpisode, Reader_ReadByte(msg));
wmInfo.currentMap = G_ComposeMapUri(::gameEpisode, Reader_ReadByte(msg));
wmInfo.didSecret = Reader_ReadByte(msg);

G_PrepareWIData();
#elif __JHERETIC__
// @todo jHeretic does not transmit the intermission info!
/// @todo jHeretic does not transmit the intermission info!
#elif __JHEXEN__
::nextMapUri = G_ComposeMapUri(G_CurrentEpisodeNumber(), Reader_ReadByte(msg));
::nextMapUri = G_ComposeMapUri(::gameEpisode, Reader_ReadByte(msg));
::nextMapEntrance = Reader_ReadByte(msg);
#endif

Expand Down
3 changes: 2 additions & 1 deletion doomsday/plugins/common/src/d_netsv.cpp
Expand Up @@ -680,7 +680,8 @@ void NetSv_SendGameState(int flags, int to)
Uri_Write(reinterpret_cast<Uri *>(&gameMapUri), writer);

// Also include the episode and map numbers.
Writer_WriteByte(writer, G_CurrentEpisodeNumber());
/// @todo Map references should be transmitted as URI.
Writer_WriteByte(writer, ::gameEpisode);
Writer_WriteByte(writer, G_CurrentMapNumber());

Writer_WriteByte(writer, (COMMON_GAMESESSION->rules().deathmatch & 0x3)
Expand Down
12 changes: 4 additions & 8 deletions doomsday/plugins/common/src/g_game.cpp
Expand Up @@ -112,6 +112,7 @@ int Hook_DemoStop(int hookType, int val, void *parm);

game_config_t cfg; // The global cfg.

uint gameEpisode;
de::Uri gameMapUri;
uint gameMapEntrance; ///< Entry point, for reborn.

Expand Down Expand Up @@ -2382,11 +2383,6 @@ uint G_MapNumberFor(de::Uri const &mapUri)
return 0;
}

uint G_CurrentEpisodeNumber()
{
return G_EpisodeNumberFor(gameMapUri);
}

uint G_CurrentMapNumber()
{
return G_MapNumberFor(gameMapUri);
Expand Down Expand Up @@ -2419,7 +2415,7 @@ de::Uri G_NextMap(dd_bool secretExit)
DENG2_UNUSED(secretExit);

#elif __JDOOM64__
uint episode = G_CurrentEpisodeNumber();
uint episode = ::gameEpisode;
uint map = G_CurrentMapNumber();

if(secretExit)
Expand Down Expand Up @@ -2455,7 +2451,7 @@ de::Uri G_NextMap(dd_bool secretExit)
return G_ComposeMapUri(episode, map);

#elif __JDOOM__
uint episode = G_CurrentEpisodeNumber();
uint episode = ::gameEpisode;
uint map = G_CurrentMapNumber();

if(gameModeBits & GM_ANY_DOOM2)
Expand Down Expand Up @@ -2518,7 +2514,7 @@ de::Uri G_NextMap(dd_bool secretExit)
}

#elif __JHERETIC__
uint episode = G_CurrentEpisodeNumber();
uint episode = ::gameEpisode;
uint map = G_CurrentMapNumber();

// Going to the secret map?
Expand Down
8 changes: 5 additions & 3 deletions doomsday/plugins/common/src/gamesession.cpp
Expand Up @@ -476,16 +476,18 @@ DENG2_PIMPL(GameSession), public SavedSession::IMapStateReaderFactory
DENG2_ASSERT(inProgress);

::gameMapUri = mapUri;

// Check that the map truly exists.
if(!P_MapExists(::gameMapUri.compose().toUtf8().constData()))
{
::gameMapUri = G_ComposeMapUri(0, 0); // Should exist always?
}

// Determine the episode for the map (should come from MapInfo).
::gameEpisode = G_EpisodeNumberFor(::gameMapUri);

// Update game status cvars:
Con_SetInteger2("map-id", (unsigned)G_CurrentMapNumber(), SVF_WRITE_OVERRIDE);
Con_SetInteger2("map-episode", (unsigned)G_CurrentEpisodeNumber(), SVF_WRITE_OVERRIDE);
Con_SetInteger2("map-episode", (unsigned)::gameEpisode, SVF_WRITE_OVERRIDE);
Con_SetInteger2("map-id", (unsigned)G_CurrentMapNumber(), SVF_WRITE_OVERRIDE);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions doomsday/plugins/common/src/p_xgline.cpp
Expand Up @@ -2086,7 +2086,7 @@ int XLTrav_LineTeleport(Line *newLine, dd_bool /*ceiling*/, void *context,
dd_bool XL_ValidateMap(uint *map, int /*type*/)
{
// Check that the map truly exists.
if(P_MapExists(G_ComposeMapUri(G_CurrentEpisodeNumber(), *map).compose().toUtf8().constData()))
if(P_MapExists(G_ComposeMapUri(::gameEpisode, *map).compose().toUtf8().constData()))
return true;

XG_Dev("XLTrav_LeaveMap: NOT A VALID MAP NUMBER %u, next will be map 1", *map);
Expand Down Expand Up @@ -2142,7 +2142,7 @@ int XLTrav_LeaveMap(Line *line, dd_bool /*ceiling*/, void * /*context*/,
if(mapSpecified)
{
XG_Dev("XLTrav_LeaveMap: Next map set to %u", map+1);
newMapUri = G_ComposeMapUri(G_CurrentEpisodeNumber(), map);
newMapUri = G_ComposeMapUri(::gameEpisode, map);
}
else
{
Expand Down
10 changes: 5 additions & 5 deletions doomsday/plugins/doom/src/p_enemy.c
Expand Up @@ -1563,17 +1563,17 @@ void C_DECL A_BossDeath(mobj_t *mo)
* Many classic PWADS such as "Doomsday of UAC" (UAC_DEAD.wad) rely on the
* old behavior. Episode 4 is exempt by PrBoom's precedent.
*/
else if(cfg.anyBossDeath && G_CurrentEpisodeNumber() < 3)
else if(cfg.anyBossDeath && gameEpisode < 3)
{
if(G_CurrentMapNumber() != 7)
return;

if(G_CurrentEpisodeNumber() != 0 && mo->type == MT_BRUISER)
if(gameEpisode != 0 && mo->type == MT_BRUISER)
return;
}
else
{
switch(G_CurrentEpisodeNumber())
switch(gameEpisode)
{
case 0:
if(G_CurrentMapNumber() != 7)
Expand Down Expand Up @@ -1669,7 +1669,7 @@ void C_DECL A_BossDeath(mobj_t *mo)
}
else
{
if(G_CurrentEpisodeNumber() == 0)
if(gameEpisode == 0)
{
Line *dummyLine = P_AllocDummyLine();
P_ToXLine(dummyLine)->tag = 666;
Expand All @@ -1678,7 +1678,7 @@ void C_DECL A_BossDeath(mobj_t *mo)
return;
}

if(G_CurrentEpisodeNumber() == 3)
if(gameEpisode == 3)
{
if(G_CurrentMapNumber() == 5)
{
Expand Down
47 changes: 20 additions & 27 deletions doomsday/plugins/doom/src/wi_stuff.cpp
Expand Up @@ -232,15 +232,14 @@ static void drawBackground()

GL_DrawPatchXY3(pBackground, 0, 0, ALIGN_TOPLEFT, DPF_NO_OFFSET);

uint const episode = G_EpisodeNumberFor(wbs->currentMap);
if(!(gameModeBits & GM_ANY_DOOM2) && episode < 3)
if(!(gameModeBits & GM_ANY_DOOM2) && ::gameEpisode < 3)
{
FR_SetFont(FID(GF_FONTB));
FR_LoadDefaultAttrib();

for(int i = 0; i < animCounts[episode]; ++i)
for(int i = 0; i < animCounts[::gameEpisode]; ++i)
{
wianimdef_t const *def = &animDefs[episode][i];
wianimdef_t const *def = &animDefs[::gameEpisode][i];
wianimstate_t *state = &animStates[i];

// Has the animation begun yet?
Expand Down Expand Up @@ -372,12 +371,11 @@ static void beginAnimations()
{
if(gameModeBits & GM_ANY_DOOM2) return;

uint const episode = G_EpisodeNumberFor(wbs->currentMap);
if(episode > 2) return;
if(::gameEpisode > 2) return;

for(int i = 0; i < animCounts[episode]; ++i)
for(int i = 0; i < animCounts[::gameEpisode]; ++i)
{
wianimdef_t const *def = &animDefs[episode][i];
wianimdef_t const *def = &animDefs[::gameEpisode][i];
wianimstate_t *state = &animStates[i];

// Is the animation active for the current map?
Expand Down Expand Up @@ -408,12 +406,11 @@ static void animateBackground()
{
if(gameModeBits & GM_ANY_DOOM2) return;

uint const episode = G_EpisodeNumberFor(wbs->currentMap);
if(episode > 2) return;
if(::gameEpisode > 2) return;

for(int i = 0; i < animCounts[episode]; ++i)
for(int i = 0; i < animCounts[::gameEpisode]; ++i)
{
wianimdef_t const *def = &animDefs[episode][i];
wianimdef_t const *def = &animDefs[::gameEpisode][i];
wianimstate_t *state = &animStates[i];

// Is the animation active for the current map?
Expand Down Expand Up @@ -541,9 +538,7 @@ static void tickShowNextMap()

static void drawLocationMarks()
{
uint const episode = G_EpisodeNumberFor(wbs->currentMap);

if((gameModeBits & GM_ANY_DOOM) && episode < 3)
if((gameModeBits & GM_ANY_DOOM) && ::gameEpisode < 3)
{
DGL_Enable(DGL_TEXTURE_2D);
DGL_Color4f(1, 1, 1, 1);
Expand All @@ -556,18 +551,18 @@ static void drawLocationMarks()

for(int i = 0; i <= last; ++i)
{
drawPatchIfFits(pSplat, &locations[episode][i]);
drawPatchIfFits(pSplat, &locations[::gameEpisode][i]);
}

// Splat the secret map?
if(wbs->didSecret)
{
drawPatchIfFits(pSplat, &locations[episode][8]);
drawPatchIfFits(pSplat, &locations[::gameEpisode][8]);
}

if(drawYouAreHere)
{
Point2Raw const *origin = &locations[episode][G_MapNumberFor(wbs->nextMap)];
Point2Raw const *origin = &locations[::gameEpisode][G_MapNumberFor(wbs->nextMap)];
patchid_t const patchId = chooseYouAreHerePatch(origin);
if(patchId)
{
Expand Down Expand Up @@ -1276,30 +1271,28 @@ void WI_Ticker()

static void loadData()
{
uint const episode = G_EpisodeNumberFor(wbs->currentMap);

if((gameModeBits & GM_ANY_DOOM2) || (gameMode == doom_ultimate && episode > 2))
if((gameModeBits & GM_ANY_DOOM2) || (gameMode == doom_ultimate && ::gameEpisode > 2))
{
pBackground = R_DeclarePatch("INTERPIC");
}
else
{
char name[9]; sprintf(name, "WIMAP%u", episode);
char name[9]; sprintf(name, "WIMAP%u", ::gameEpisode);
pBackground = R_DeclarePatch(name);
}

if((gameModeBits & GM_ANY_DOOM) && episode < 3)
if((gameModeBits & GM_ANY_DOOM) && ::gameEpisode < 3)
{
pYouAreHereRight = R_DeclarePatch("WIURH0");
pYouAreHereLeft = R_DeclarePatch("WIURH1");
pSplat = R_DeclarePatch("WISPLAT");

animStates = (wianimstate_t *)Z_Realloc(animStates, sizeof(*animStates) * animCounts[episode], PU_GAMESTATIC);
std::memset(animStates, 0, sizeof(*animStates) * animCounts[episode]);
animStates = (wianimstate_t *)Z_Realloc(animStates, sizeof(*animStates) * animCounts[::gameEpisode], PU_GAMESTATIC);
std::memset(animStates, 0, sizeof(*animStates) * animCounts[::gameEpisode]);

for(int i = 0; i < animCounts[episode]; ++i)
for(int i = 0; i < animCounts[::gameEpisode]; ++i)
{
wianimdef_t const *def = &animDefs[episode][i];
wianimdef_t const *def = &animDefs[::gameEpisode][i];
wianimstate_t *state = &animStates[i];

state->frame = -1; // Not yet begun.
Expand Down

0 comments on commit 60ede52

Please sign in to comment.