Skip to content

Commit

Permalink
Refactor|libhexen: Prefer the term 'hub' wrt map progression in MAPINFO
Browse files Browse the repository at this point in the history
The term 'cluster' is less descriptive and map authors generally use
'hub' in any case.
  • Loading branch information
danij-deng committed Feb 10, 2014
1 parent 7b364bd commit 4a8ff0e
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 49 deletions.
8 changes: 4 additions & 4 deletions doomsday/plugins/common/include/p_saveg.h
Expand Up @@ -198,22 +198,22 @@ void SV_TranslateLegacyMobjFlags(mobj_t *mo, int ver);

#if __JHEXEN__
void SV_HxInitBaseSlot(void);
void SV_HxSaveClusterMap(void);
void SV_HxLoadClusterMap(void);
void SV_HxSaveHubMap(void);
void SV_HxLoadHubMap(void);

typedef struct {
player_t player;
uint numInventoryItems[NUM_INVENTORYITEM_TYPES];
inventoryitemtype_t readyItem;
} playerbackup_t;

void SV_HxBackupPlayersInCluster(playerbackup_t playerBackup[MAXPLAYERS]);
void SV_HxBackupPlayersInHub(playerbackup_t playerBackup[MAXPLAYERS]);

/**
* @param playerBackup Player state backup.
* @param entryPoint Logical identifier for the entry point used to enter the map.
*/
void SV_HxRestorePlayersInCluster(playerbackup_t playerBackup[MAXPLAYERS], uint entryPoint);
void SV_HxRestorePlayersInHub(playerbackup_t playerBackup[MAXPLAYERS], uint entryPoint);
#endif

void SV_InitThingArchiveForLoad(uint size);
Expand Down
4 changes: 2 additions & 2 deletions doomsday/plugins/common/src/fi_lib.c
Expand Up @@ -101,15 +101,15 @@ static void initStateConditions(fi_state_t *s)
#endif

#if __JHEXEN__
// Leaving the current cluster?
// Leaving the current hub?
{
Uri *nextMapUri = G_ComposeMapUri(gameEpisode, nextMap);

mapinfo_t *curMapInfo = P_MapInfo(0/*current map*/);
mapinfo_t *nextMapInfo = P_MapInfo(nextMapUri);
if(curMapInfo && nextMapInfo)
{
s->conditions.leave_hub = (curMapInfo->cluster != nextMapInfo->cluster);
s->conditions.leave_hub = (curMapInfo->hub != nextMapInfo->hub);
}

Uri_Delete(nextMapUri);
Expand Down
26 changes: 13 additions & 13 deletions doomsday/plugins/common/src/g_game.c
Expand Up @@ -1300,7 +1300,7 @@ int G_DoLoadMap(loadmap_params_t *p)
if(p->revisit)
{
// We've been here before; deserialize this map's save state.
SV_HxLoadClusterMap();
SV_HxLoadHubMap();
}
#endif

Expand Down Expand Up @@ -1760,13 +1760,13 @@ void G_PlayerLeaveMap(int player)
int flightPower;
#endif
player_t *p = &players[player];
dd_bool newCluster = true;
dd_bool newHub = true;

#if __JHEXEN__
{
Uri *nextMapUri = G_ComposeMapUri(gameEpisode, nextMap);

newCluster = (P_MapInfo(0/*current map*/)->cluster != P_MapInfo(nextMapUri)->cluster);
newHub = (P_MapInfo(0/*current map*/)->hub != P_MapInfo(nextMapUri)->hub);

Uri_Delete(nextMapUri);
}
Expand Down Expand Up @@ -1798,7 +1798,7 @@ void G_PlayerLeaveMap(int player)
#endif

#if __JHEXEN__
if(newCluster)
if(newHub)
{
uint count = P_InventoryCount(player, IIT_FLY);

Expand All @@ -1812,7 +1812,7 @@ void G_PlayerLeaveMap(int player)
memset(p->powers, 0, sizeof(p->powers));

#if __JHEXEN__
if(!newCluster && !gameRules.deathmatch)
if(!newHub && !gameRules.deathmatch)
p->powers[PT_FLIGHT] = flightPower; // Restore flight.
#endif

Expand All @@ -1821,7 +1821,7 @@ void G_PlayerLeaveMap(int player)
p->update |= PSF_KEYS;
memset(p->keys, 0, sizeof(p->keys));
#else
if(!gameRules.deathmatch && newCluster)
if(!gameRules.deathmatch && newHub)
p->keys = 0;
#endif

Expand Down Expand Up @@ -2599,18 +2599,18 @@ void G_DoLeaveMap(void)
revisit = SV_HxHaveMapStateForSlot(BASE_SLOT, nextMap);
if(gameRules.deathmatch) revisit = false;

// Same cluster?
// Same hub?
{
Uri *nextMapUri = G_ComposeMapUri(gameEpisode, nextMap);
if(P_MapInfo(0/*current map*/)->cluster == P_MapInfo(nextMapUri)->cluster)
if(P_MapInfo(0/*current map*/)->hub == P_MapInfo(nextMapUri)->hub)
{
if(!gameRules.deathmatch)
{
// Save current map.
SV_HxSaveClusterMap();
SV_HxSaveHubMap();
}
}
else // Entering new cluster.
else // Entering new hub.
{
if(!gameRules.deathmatch)
{
Expand All @@ -2623,7 +2623,7 @@ void G_DoLeaveMap(void)

// Take a copy of the player objects (they will be cleared in the process
// of calling P_SetupMap() and we need to restore them after).
SV_HxBackupPlayersInCluster(playerBackup);
SV_HxBackupPlayersInHub(playerBackup);

// Disable class randomization (all players must spawn as their existing class).
oldRandomClassesRule = gameRules.randomClasses;
Expand Down Expand Up @@ -2698,7 +2698,7 @@ void G_DoLeaveMap(void)
P_RemoveAllPlayerMobjs();
}

SV_HxRestorePlayersInCluster(playerBackup, nextMapEntrance);
SV_HxRestorePlayersInHub(playerBackup, nextMapEntrance);

// Restore the random class rule.
gameRules.randomClasses = oldRandomClassesRule;
Expand Down Expand Up @@ -3510,7 +3510,7 @@ int G_DebriefingEnabled(Uri const *mapUri, ddfinale_t *fin)
!(nextMap == DDMAXINT && nextMapEntrance == DDMAXINT))
{
Uri *nextMapUri = G_ComposeMapUri(gameEpisode, nextMap);
if(P_MapInfo(mapUri)->cluster != P_MapInfo(nextMapUri)->cluster)
if(P_MapInfo(mapUri)->hub != P_MapInfo(nextMapUri)->hub)
{
Uri_Delete(nextMapUri);
return false;
Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/common/src/mapstatereader.cpp
Expand Up @@ -456,7 +456,7 @@ DENG2_PIMPL(MapStateReader)
{
#if __JHEXEN__
checkSegment(ASEG_SCRIPTS);
Game_ACScriptInterpreter().readMapScriptData(reader, mapVersion);
Game_ACScriptInterpreter().readMapScriptData(thisPublic);
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/common/src/mapstatewriter.cpp
Expand Up @@ -171,7 +171,7 @@ DENG2_PIMPL(MapStateWriter)
{
#if __JHEXEN__
beginSegment(ASEG_SCRIPTS);
Game_ACScriptInterpreter().writeMapScriptData(writer);
Game_ACScriptInterpreter().writeMapScriptData(thisPublic);
#endif
}

Expand Down
10 changes: 5 additions & 5 deletions doomsday/plugins/common/src/p_saveg.cpp
@@ -1,4 +1,4 @@
/** @file p_saveg.cpp Common game-save state management.
/** @file p_saveg.cpp Common game-save state management.
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2005-2013 Daniel Swanson <danij@dengine.net>
Expand Down Expand Up @@ -3237,7 +3237,7 @@ dd_bool SV_SaveGame(int slot, char const *name)
}

#if __JHEXEN__
void SV_HxSaveClusterMap()
void SV_HxSaveHubMap()
{
playerHeaderOK = false; // Uninitialized.

Expand All @@ -3256,7 +3256,7 @@ void SV_HxSaveClusterMap()
Writer_Delete(writer);
}

void SV_HxLoadClusterMap()
void SV_HxLoadHubMap()
{
/// @todo fixme: do not assume this pointer is still valid!
DENG_ASSERT(curInfo != 0);
Expand All @@ -3276,7 +3276,7 @@ void SV_HxLoadClusterMap()
Reader_Delete(reader);
}

void SV_HxBackupPlayersInCluster(playerbackup_t playerBackup[MAXPLAYERS])
void SV_HxBackupPlayersInHub(playerbackup_t playerBackup[MAXPLAYERS])
{
DENG_ASSERT(playerBackup);

Expand All @@ -3296,7 +3296,7 @@ void SV_HxBackupPlayersInCluster(playerbackup_t playerBackup[MAXPLAYERS])
}
}

void SV_HxRestorePlayersInCluster(playerbackup_t playerBackup[MAXPLAYERS],
void SV_HxRestorePlayersInHub(playerbackup_t playerBackup[MAXPLAYERS],
uint entryPoint)
{
mobj_t *targetPlayerMobj;
Expand Down
6 changes: 3 additions & 3 deletions doomsday/plugins/hexen/include/acscript.h
Expand Up @@ -207,10 +207,10 @@ class ACScriptInterpreter
AutoStr *scriptDescription(int scriptNumber);

void writeWorldScriptData(Writer *writer);
void readWorldScriptData(Reader *reader, int mapVersion);
void readWorldScriptData(Reader *reader, int saveVersion);

void writeMapScriptData(Writer *writer);
void readMapScriptData(Reader *reader, int mapVersion);
void writeMapScriptData(MapStateWriter *msw);
void readMapScriptData(MapStateReader *msr);

public: /// @todo make private:
BytecodeScriptInfo &scriptInfoByIndex(int index);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/hexen/include/p_mapinfo.h
Expand Up @@ -30,7 +30,7 @@

typedef struct mapinfo_s {
uint map; ///< Logical map number.
int cluster;
int hub;
uint warpTrans;
uint nextMap;
int cdTrack;
Expand Down
14 changes: 9 additions & 5 deletions doomsday/plugins/hexen/src/acscript.cpp
Expand Up @@ -492,11 +492,11 @@ void ACScriptInterpreter::writeWorldScriptData(Writer *writer)
}
}

void ACScriptInterpreter::readWorldScriptData(Reader *reader, int mapVersion)
void ACScriptInterpreter::readWorldScriptData(Reader *reader, int saveVersion)
{
int ver = 1;

if(mapVersion >= 7)
if(saveVersion >= 7)
{
ver = Reader_ReadByte(reader);
}
Expand Down Expand Up @@ -541,15 +541,17 @@ void ACScriptInterpreter::readWorldScriptData(Reader *reader, int mapVersion)
}
}

if(mapVersion < 7)
if(saveVersion < 7)
{
SV_Seek(12); // Junk.
}
}
}

void ACScriptInterpreter::writeMapScriptData(Writer *writer)
void ACScriptInterpreter::writeMapScriptData(MapStateWriter *msw)
{
Writer *writer = msw->writer();

for(int i = 0; i < _scriptCount; ++i)
{
BytecodeScriptInfo &info = _scriptInfo[i];
Expand All @@ -563,8 +565,10 @@ void ACScriptInterpreter::writeMapScriptData(Writer *writer)
}
}

void ACScriptInterpreter::readMapScriptData(Reader *reader, int /*mapVersion*/)
void ACScriptInterpreter::readMapScriptData(MapStateReader *msr)
{
Reader *reader = msr->reader();

for(int i = 0; i < _scriptCount; ++i)
{
BytecodeScriptInfo &info = _scriptInfo[i];
Expand Down
28 changes: 14 additions & 14 deletions doomsday/plugins/hexen/src/p_mapinfo.cpp
Expand Up @@ -62,7 +62,7 @@ void MapInfoParser(Str const *path)
// Prepare a default-configured definition, for one-shot initialization.
mapinfo_t defMapInfo;
defMapInfo.map = -1; // Unknown.
defMapInfo.cluster = 0;
defMapInfo.hub = 0;
defMapInfo.warpTrans = 0;
defMapInfo.nextMap = 0; // Always go to map 0 if not specified.
defMapInfo.cdTrack = 1;
Expand Down Expand Up @@ -180,10 +180,10 @@ void MapInfoParser(Str const *path)
}
if(!Str_CompareIgnoreCase(lexer.token(), "cluster"))
{
info->cluster = lexer.readNumber();
if(info->cluster < 1)
info->hub = lexer.readNumber();
if(info->hub < 1)
{
Con_Error("MapInfoParser: Invalid cluster number '%s' in \"%s\" on line #%i",
Con_Error("MapInfoParser: Invalid 'cluster' (i.e., hub) number '%s' in \"%s\" on line #%i",
lexer.token(), F_PrettyPath(Str_Text(path)), lexer.lineNumber());
}
continue;
Expand Down Expand Up @@ -237,8 +237,8 @@ void MapInfoParser(Str const *path)
for(MapInfos::const_iterator i = mapInfos.begin(); i != mapInfos.end(); ++i)
{
mapinfo_t const &info = i->second;
App_Log(DE2_DEV_RES_MSG, "MAPINFO %s { title: \"%s\" cluster: %i map: %i warp: %i }",
i->first.c_str(), info.title, info.cluster, info.map, info.warpTrans);
App_Log(DE2_DEV_RES_MSG, "MAPINFO %s { title: \"%s\" hub: %i map: %i warp: %i }",
i->first.c_str(), info.title, info.hub, info.map, info.warpTrans);
}
#endif
}
Expand All @@ -258,29 +258,29 @@ mapinfo_t *P_MapInfo(Uri const *mapUri)

uint P_TranslateMapIfExists(uint map)
{
uint matchedWithoutCluster = P_INVALID_LOGICAL_MAP;
uint matchedWithoutHub = P_INVALID_LOGICAL_MAP;

for(MapInfos::const_iterator i = mapInfos.begin(); i != mapInfos.end(); ++i)
{
mapinfo_t const &info = i->second;

if(info.warpTrans == map)
{
if(info.cluster)
if(info.hub)
{
App_Log(DE2_DEV_MAP_VERBOSE, "Warp %i translated to logical map %i, cluster %i", map, info.map, info.cluster);
App_Log(DE2_DEV_MAP_VERBOSE, "Warp %i translated to logical map %i, hub %i", map, info.map, info.hub);
return info.map;
}

App_Log(DE2_DEV_MAP_VERBOSE, "Warp %i matches logical map %i, but it has no cluster", map, info.map);
matchedWithoutCluster = info.map;
App_Log(DE2_DEV_MAP_VERBOSE, "Warp %i matches logical map %i, but it has no hub", map, info.map);
matchedWithoutHub = info.map;
}
}

App_Log(DE2_DEV_MAP_NOTE, "Could not find warp %i, translating to logical map %i (without cluster)",
map, matchedWithoutCluster);
App_Log(DE2_DEV_MAP_NOTE, "Could not find warp %i, translating to logical map %i (without hub)",
map, matchedWithoutHub);

return matchedWithoutCluster;
return matchedWithoutHub;
}

uint P_TranslateMap(uint map)
Expand Down

0 comments on commit 4a8ff0e

Please sign in to comment.