Skip to content

Commit

Permalink
Refactor|libcommon|GameSession: Moved global variable gameMapEntrance…
Browse files Browse the repository at this point in the history
… to common::GameSession, cleanup
  • Loading branch information
danij-deng committed Aug 20, 2014
1 parent 39ea024 commit 9dbd3b5
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 105 deletions.
2 changes: 0 additions & 2 deletions doomsday/plugins/common/include/g_common.h
Expand Up @@ -29,8 +29,6 @@

DENG_EXTERN_C dd_bool singledemo;

DENG_EXTERN_C uint gameMapEntrance;

#if __cplusplus
extern GameRuleset defaultGameRules;

Expand Down
22 changes: 14 additions & 8 deletions doomsday/plugins/common/include/gamesession.h
Expand Up @@ -64,7 +64,7 @@ class GameSession : public de::game::Session

/**
* Returns the current Episode definition for the game session in progress. If the session
* has not yet begun then @c NULL is returned.
* has not yet begun then @c nullptr is returned.
*/
de::Record *episodeDef();

Expand All @@ -76,13 +76,13 @@ class GameSession : public de::game::Session

/**
* Returns the current MapGraphNode definition for the game session in progress. If the
* session has not yet begun then @c NULL is returned.
* session has not yet begun then @c nullptr is returned.
*/
de::Record *mapGraphNodeDef();

/**
* Returns the current MapInfo definition for the game session in progress. If the session
* has not yet begun, or no definition exists for the current map then @c NULL is returned.
* has not yet begun, or no definition exists for the current map then @c nullptr is returned.
*/
de::Record *mapInfo();

Expand All @@ -92,6 +92,12 @@ class GameSession : public de::game::Session
*/
de::Uri mapUri();

/**
* Returns the player entry point for the current map, for the game session in progress.
* The entry point determines where players will be reborn.
*/
uint mapEntryPoint();

/**
* Resolves a named exit according to the map progression.
*/
Expand Down Expand Up @@ -132,15 +138,15 @@ class GameSession : public de::game::Session
* Configure and begin a new game session. Note that a @em new session cannot @em begin if
* one already @ref hasBegun() (if so, the session must be ended first).
*
* @param rules Game rules to apply.
* @param episodeId Episode identifier.
* @param mapUri Map identifier.
* @param mapEntrance Logical map entry point number.
* @param rules Game rules to apply.
* @param episodeId Episode identifier.
* @param mapUri Map identifier.
* @param mapEntryPoint Map entry point number, for player reborn.
*
* @throws InProgressError if the session has already begun.
*/
void begin(GameRuleset const &rules, de::String const &episodeId, de::Uri const &mapUri,
uint mapEntrance = 0);
uint mapEntryPoint = 0);

/**
* Reload the @em current map, automatically loading any saved progress from the backing
Expand Down
6 changes: 2 additions & 4 deletions doomsday/plugins/common/src/d_netcl.cpp
Expand Up @@ -115,7 +115,7 @@ void NetCl_UpdateGameState(reader_s *msg)
COMMON_GAMESESSION->end();
COMMON_GAMESESSION->begin(gsRules, Str_Text(gsEpisodeId),
*reinterpret_cast<de::Uri *>(gsMapUri),
gameMapEntrance /*gsMapEntrance*/);
COMMON_GAMESESSION->mapEntryPoint() /*gsMapEntrance*/);
}
else
{
Expand All @@ -125,8 +125,6 @@ void NetCl_UpdateGameState(reader_s *msg)
DENG2_ASSERT(*reinterpret_cast<de::Uri *>(gsMapUri) == COMMON_GAMESESSION->mapUri());

COMMON_GAMESESSION->applyNewRules(gsRules);
//COMMON_GAMESESSION->setMap(*gsMapUri);
//gameMapEntrance = gsMapEntrance;
}

// Set gravity.
Expand Down Expand Up @@ -664,7 +662,7 @@ void NetCl_Intermission(reader_s *msg)
# endif
# if __JHEXEN__
Uri_Read(reinterpret_cast<uri_s *>(&::nextMapUri), msg);
::nextMapEntrance = Reader_ReadByte(msg);
::nextMapEntryPoint = Reader_ReadByte(msg);
# else
Uri_Read(reinterpret_cast<uri_s *>(&wmInfo.nextMap), msg);
Uri_Read(reinterpret_cast<uri_s *>(&wmInfo.currentMap), msg);
Expand Down
4 changes: 2 additions & 2 deletions doomsday/plugins/common/src/d_netsv.cpp
Expand Up @@ -570,7 +570,7 @@ void NetSv_NewPlayerEnters(int plrNum)
playerclass_t pClass = P_ClassForPlayerWhenRespawning(plrNum, false);
playerstart_t const *start;

if((start = P_GetPlayerStart(gameMapEntrance, plrNum, false)))
if((start = P_GetPlayerStart(COMMON_GAMESESSION->mapEntryPoint(), plrNum, false)))
{
mapspot_t const *spot = &mapSpots[start->spot];

Expand Down Expand Up @@ -617,7 +617,7 @@ void NetSv_Intermission(int flags, int state, int time)
Uri_Write(reinterpret_cast<uri_s *>(&::wmInfo.currentMap), msg);
#elif __JHEXEN__
Uri_Write(reinterpret_cast<uri_s *>(&::nextMapUri), msg);
Writer_WriteByte(msg, ::nextMapEntrance);
Writer_WriteByte(msg, ::nextMapEntryPoint);
#endif
#if __JDOOM__ || __JDOOM64__
Writer_WriteByte(msg, wmInfo.didSecret);
Expand Down
30 changes: 14 additions & 16 deletions doomsday/plugins/common/src/g_game.cpp
Expand Up @@ -110,10 +110,8 @@ int Hook_DemoStop(int hookType, int val, void *parm);

game_config_t cfg; // The global cfg.

uint gameMapEntrance; ///< Entry point, for reborn.

de::Uri nextMapUri;
uint nextMapEntrance;
uint nextMapEntryPoint;

#if __JDOOM__ || __JHERETIC__ || __JDOOM64__
dd_bool secretExit;
Expand Down Expand Up @@ -437,12 +435,12 @@ bool G_SetGameActionLoadSession(de::String slotId)
return false;
}

void G_SetGameActionMapCompleted(de::Uri const &nextMapUri, uint nextMapEntrance, dd_bool secretExit)
void G_SetGameActionMapCompleted(de::Uri const &nextMapUri, uint nextMapEntryPoint, dd_bool secretExit)
{
#if __JHEXEN__
DENG2_UNUSED(secretExit);
#else
DENG2_UNUSED(nextMapEntrance);
DENG2_UNUSED(nextMapEntryPoint);
#endif

if(IS_CLIENT) return;
Expand All @@ -461,11 +459,11 @@ void G_SetGameActionMapCompleted(de::Uri const &nextMapUri, uint nextMapEntrance
}
#endif

::nextMapUri = nextMapUri;
::nextMapUri = nextMapUri;
#if __JHEXEN__
::nextMapEntrance = nextMapEntrance;
::nextMapEntryPoint = nextMapEntryPoint;
#else
::secretExit = secretExit;
::secretExit = secretExit;

# if __JDOOM__
// If no Wolf3D maps, no secret exit!
Expand Down Expand Up @@ -1588,7 +1586,7 @@ static void runGameAction()
// Make note of the last used save slot.
Con_SetInteger2("game-save-last-slot", sslot.id().toInt(), SVF_WRITE_OVERRIDE);
}
catch(de::Error const &er)
catch(Error const &er)
{
LOG_RES_WARNING("Error loading from save slot #%s:\n")
<< gaLoadSessionSlot << er.asText();
Expand All @@ -1610,7 +1608,7 @@ static void runGameAction()
// Make note of the last used save slot.
Con_SetInteger2("game-save-last-slot", sslot.id().toInt(), SVF_WRITE_OVERRIDE);
}
catch(de::Error const &er)
catch(Error const &er)
{
LOG_RES_WARNING("Error saving to save slot #%s:\n")
<< gaSaveSessionSlot << er.asText();
Expand Down Expand Up @@ -1691,11 +1689,11 @@ static void runGameAction()

case GA_SCREENSHOT: {
// Find an unused screenshot file name.
de::String fileName = COMMON_GAMESESSION->gameId() + "-";
String fileName = COMMON_GAMESESSION->gameId() + "-";
int const numPos = fileName.length();
for(int i = 0; i < 1e6; ++i) // Stop eventually...
{
fileName += de::String("%1.png").arg(i, 3, 10, QChar('0'));
fileName += String("%1.png").arg(i, 3, 10, QChar('0'));
if(!F_FileExists(fileName.toUtf8().constData())) break;
fileName.truncate(numPos);
}
Expand All @@ -1705,13 +1703,13 @@ static void runGameAction()
/// @todo Do not use the console player's message log for this notification.
/// The engine should implement it's own notification UI system for
/// this sort of thing.
de::String msg = "Saved screenshot: " + de::NativePath(fileName).pretty();
String msg = "Saved screenshot: " + NativePath(fileName).pretty();
P_SetMessage(players + CONSOLEPLAYER, LMF_NO_HIDE, msg.toLatin1().constData());
}
else
{
LOG_RES_WARNING("Failed taking screenshot \"%s\"")
<< de::NativePath(fileName).pretty();
<< NativePath(fileName).pretty();
}
break; }

Expand Down Expand Up @@ -3275,8 +3273,8 @@ D_CMD(WarpMap)
if(!forceNewSession && COMMON_GAMESESSION->hasBegun())
{
#if __JHEXEN__
::nextMapUri = mapUri;
::nextMapEntrance = 0;
::nextMapUri = mapUri;
::nextMapEntryPoint = 0;
G_SetGameAction(GA_LEAVEMAP);
#else
G_SetGameActionNewSession(COMMON_GAMESESSION->rules(), COMMON_GAMESESSION->episodeId(),
Expand Down

0 comments on commit 9dbd3b5

Please sign in to comment.