Skip to content

Commit

Permalink
Refactor|libcommon: Use a map URI with G_NewGame() and G_DeferredNewG…
Browse files Browse the repository at this point in the history
…ame()

At present the logical episode and map numbers are parsed from the
map URI. In the future the episode should be specified in MAPINFO.
  • Loading branch information
danij-deng committed Feb 8, 2014
1 parent d3af953 commit 44cb574
Show file tree
Hide file tree
Showing 33 changed files with 404 additions and 400 deletions.
17 changes: 3 additions & 14 deletions doomsday/plugins/common/include/g_common.h
Expand Up @@ -69,13 +69,12 @@ void G_EndGame(void);
dd_bool G_QuitInProgress(void);

/**
* @param episode Logical episode number.
* @param map Logical map number (i.e., not a warp/translated number).
* @param mapUri Map identifier.
* @param mapEntrance Logical map entry point number.
* @param rules Game rules to apply.
*/
void G_NewGame(uint episode, uint map, uint mapEntrance, GameRuleset const *rules);
void G_DeferredNewGame(uint episode, uint map, uint mapEntrance, GameRuleset const *rules);
void G_NewGame(Uri const *mapUri, uint mapEntrance, GameRuleset const *rules);
void G_DeferredNewGame(Uri const *mapUri, uint mapEntrance, GameRuleset const *rules);

/**
* Signal that play on the current map may now begin.
Expand Down Expand Up @@ -103,16 +102,6 @@ void G_LeaveMap(uint newMap, uint mapEntryPoint, dd_bool secretExit);
*/
Uri *G_ComposeMapUri(uint episode, uint map);

/**
* Compose the Uri for the @em current map.
*
* @note Some APIs are designed such that a NULL uri pointer means the "current map",
* so, calling this may be unnecessary.
*
* @return Resultant Uri. Must be destroyed with Uri_Delete() when no longer needed.
*/
Uri *G_CurrentMapUri(void);

/**
* Determine if the specified @a episode and @a map value pair are valid and if not,
* adjust their are values within the ranges defined by the current game type and mode.
Expand Down
13 changes: 10 additions & 3 deletions doomsday/plugins/common/include/p_mapsetup.h
Expand Up @@ -46,12 +46,19 @@ void P_FinalizeMapChange(Uri const *uri);
*/
void P_SetupMap(Uri *uri);

/**
* @param mapUri Identifier of the map to lookup the author of. Can be @c 0 in which
* case the author for the @em current map will be returned (if set).
*/
char const *P_MapAuthor(Uri const *mapUri, dd_bool supressGameAuthor);

/**
* @param mapUri Identifier of the map to lookup the title of. Can be @c 0 in which
* case the title for the @em current map will be returned (if set).
*/
char const *P_MapTitle(Uri const *mapUri);
patchid_t P_MapTitlePatch(uint episode, uint map);

char const *P_CurrentMapAuthor(dd_bool supressGameAuthor);
char const *P_CurrentMapTitle(void);
patchid_t P_MapTitlePatch(uint episode, uint map);

#if __JDOOM__ || __JDOOM64__ || __JHERETIC__
void P_FindSecrets(void);
Expand Down
24 changes: 14 additions & 10 deletions doomsday/plugins/common/src/d_net.c
Expand Up @@ -126,7 +126,7 @@ void NetSv_ApplyGameRulesFromConfig(void)
*/
int D_NetServerStarted(int before)
{
uint netMap, netEpisode;
Uri *netMapUri = 0;
GameRuleset netRules = gameRules; // Make a copy of the current rules.

if(before) return true;
Expand All @@ -144,26 +144,30 @@ int D_NetServerStarted(int before)
// Set the game parameters.
NetSv_ApplyGameRulesFromConfig();

// Hexen has translated map numbers.
#if __JHEXEN__
netMap = P_TranslateMap(cfg.netMap);
{
#if __JDOOM64__
uint netEpisode = 0;
#else
netMap = cfg.netMap;
uint netEpisode = cfg.netEpisode;
#endif

#if __JDOOM64__
netEpisode = 0;
#if __JHEXEN__ // Map numbers need to be translated.
uint netMap = P_TranslateMap(cfg.netMap);
#else
netEpisode = cfg.netEpisode;
uint netMap = cfg.netMap;
#endif

netMapUri = G_ComposeMapUri(netEpisode, netMap);
}

netRules.skill = cfg.netSkill;

G_NewGame(netEpisode, netMap, 0/*default*/, &netRules);
G_NewGame(netMapUri, 0/*default*/, &netRules);

/// @todo Necessary?
G_SetGameAction(GA_NONE);

Uri_Delete(netMapUri);

return true;
}

Expand Down
22 changes: 12 additions & 10 deletions doomsday/plugins/common/src/d_netcl.c
Expand Up @@ -42,10 +42,10 @@ void NetCl_UpdateGameState(Reader* msg)
byte len;
byte gsFlags = 0;
char gsGameIdentity[256];
Uri* mapUri;
byte gsEpisode = 0;
byte gsMap = 0;
byte gsMapEntrance = 0;
Uri *mapUri;
uint gsEpisode = 0;
uint gsMap = 0;
uint gsMapEntrance = 0;
byte configFlags = 0;
//byte gsDeathmatch = 0;
//byte gsMonsters = 0;
Expand All @@ -65,13 +65,12 @@ void NetCl_UpdateGameState(Reader* msg)
gsGameIdentity[len] = 0;

// Current map.
mapUri = Uri_FromReader(msg);

mapUri = Uri_FromReader(msg);
gsEpisode = Reader_ReadByte(msg);
gsMap = Reader_ReadByte(msg);
gsMap = Reader_ReadByte(msg);

/// @todo Not communicated to clients??
//gsMapEntryPoint = ??;
//gsMapEntrance = ??;

configFlags = Reader_ReadByte(msg);
gsRules.deathmatch = configFlags & 0x3;
Expand All @@ -80,11 +79,13 @@ void NetCl_UpdateGameState(Reader* msg)
gsRules.respawnMonsters = (configFlags & 0x8? true : false);
#endif
gsJumping = (configFlags & 0x10? true : false);
gsRules.skill = Reader_ReadByte(msg);

gsRules.skill = Reader_ReadByte(msg);
// Interpret skill modes outside the normal range as "spawn no things".
if(gsRules.skill < SM_BABY || gsRules.skill >= NUM_SKILL_MODES)
{
gsRules.skill = SM_NOTHINGS;
}

gsGravity = Reader_ReadFloat(msg);

Expand Down Expand Up @@ -138,7 +139,7 @@ void NetCl_UpdateGameState(Reader* msg)
// Do we need to change the map?
if(gsFlags & GSF_CHANGE_MAP)
{
G_NewGame(gsEpisode, gsMap, gameMapEntrance /*gsMapEntrance*/, &gsRules);
G_NewGame(mapUri, gameMapEntrance /*gsMapEntrance*/, &gsRules);

/// @todo Necessary?
G_SetGameAction(GA_NONE);
Expand All @@ -147,6 +148,7 @@ void NetCl_UpdateGameState(Reader* msg)
{
gameEpisode = gsEpisode;
gameMap = gsMap;
Uri_Copy(gameMapUri, mapUri);
//gameMapEntrance = gsMapEntrance; /// @todo Not communicated to clients??
gameRules = gsRules;
}
Expand Down
12 changes: 4 additions & 8 deletions doomsday/plugins/common/src/d_netsv.c
Expand Up @@ -727,19 +727,17 @@ void NetSv_SendTotalCounts(int to)
void NetSv_SendGameState(int flags, int to)
{
int i;
Writer* writer;
Writer *writer;
GameInfo gameInfo;
Uri* mapUri;
AutoStr* str;
AutoStr *str;

if(!IS_NETWORK_SERVER)
return;

DD_GameInfo(&gameInfo);
mapUri = G_CurrentMapUri();

// Print a short message that describes the game state.
str = Uri_Resolved(mapUri);
str = Uri_Resolved(gameMapUri);

App_Log(DE2_NET_NOTE, "Sending game setup: %s %s %s",
Str_Text(gameInfo.identityKey), Str_Text(str), gameConfigString);
Expand All @@ -758,7 +756,7 @@ void NetSv_SendGameState(int flags, int to)
Writer_Write(writer, Str_Text(gameInfo.identityKey), Str_Length(gameInfo.identityKey));

// The current map.
Uri_Write(mapUri, writer);
Uri_Write(gameMapUri, writer);

// Also include the episode and map numbers.
Writer_WriteByte(writer, gameEpisode);
Expand Down Expand Up @@ -789,8 +787,6 @@ void NetSv_SendGameState(int flags, int to)
// Send the packet.
Net_SendPacket(i, GPT_GAME_STATE, Writer_Data(writer), Writer_Size(writer));
}

Uri_Delete(mapUri);
}

/**
Expand Down
10 changes: 2 additions & 8 deletions doomsday/plugins/common/src/fi_lib.c
Expand Up @@ -103,18 +103,16 @@ static void initStateConditions(fi_state_t *s)
#if __JHEXEN__
// Leaving the current cluster?
{
Uri *curMapUri = G_CurrentMapUri();
Uri *nextMapUri = G_ComposeMapUri(gameEpisode, nextMap);

mapinfo_t *curMapInfo = P_MapInfo(curMapUri);
mapinfo_t *curMapInfo = P_CurrentMapInfo();
mapinfo_t *nextMapInfo = P_MapInfo(nextMapUri);
if(curMapInfo && nextMapInfo)
{
s->conditions.leave_hub = (curMapInfo->cluster != nextMapInfo->cluster);
}

Uri_Delete(nextMapUri);
Uri_Delete(curMapUri);
}
App_Log(DE2_DEV_SCR_VERBOSE, "Infine state condition: leave_hub=%i", s->conditions.leave_hub);
#endif
Expand Down Expand Up @@ -453,14 +451,10 @@ int Hook_FinaleScriptStop(int hookType, int finaleId, void* parameters)
else if(mode == FIMODE_BEFORE) // A briefing has ended.
{
// Its time to start the map; que music and begin!
Uri *mapUri = G_CurrentMapUri();

S_MapMusic(mapUri);
S_MapMusic(0/*current map*/);
HU_WakeWidgets(-1 /* all players */);
G_BeginMap();
Pause_End(); // skip forced period

Uri_Delete(mapUri);
}
return true;
}
Expand Down

0 comments on commit 44cb574

Please sign in to comment.