From c3a2a9e0b14185a86686ef7db5d3cf96046c36c9 Mon Sep 17 00:00:00 2001 From: danij Date: Mon, 25 Aug 2014 00:13:28 +0100 Subject: [PATCH] libcommon: Cleanup --- doomsday/plugins/common/include/g_common.h | 147 +++++++------- doomsday/plugins/common/src/g_game.cpp | 208 ++++++++++---------- doomsday/plugins/common/src/gamesession.cpp | 28 ++- 3 files changed, 181 insertions(+), 202 deletions(-) diff --git a/doomsday/plugins/common/include/g_common.h b/doomsday/plugins/common/include/g_common.h index a6a72f132a..3ec935c827 100644 --- a/doomsday/plugins/common/include/g_common.h +++ b/doomsday/plugins/common/include/g_common.h @@ -27,34 +27,10 @@ #include "player.h" #include -DENG_EXTERN_C dd_bool singledemo; - #if __cplusplus -extern GameRuleset defaultGameRules; - -extern "C" { -#endif - -dd_bool G_QuitInProgress(void); - -/** - * Returns the current logical game state. - */ -gamestate_t G_GameState(void); - -/** - * Change the game's state. - * - * @param state The state to change to. - */ -void G_ChangeGameState(gamestate_t state); - -gameaction_t G_GameAction(void); - -void G_SetGameAction(gameaction_t action); +class SaveSlots; -#if __cplusplus -} // extern "C" +extern GameRuleset defaultGameRules; /** * Schedule a new game session (deferred). @@ -120,67 +96,93 @@ de::String G_MapTitle(de::Uri const &mapUri); */ patchid_t G_MapTitlePatch(de::Uri const &mapUri); +/** + * Attempt to extract the logical map number encoded in the @a mapUri. Assumes the default + * form for the current game mode (i.e., MAPXX or EXMY). + * + * @param mapUri Unique identifier of the map. + * + * @return Extracted/decoded map number, otherwise @c 0. + * + * @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 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. + * + * @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_ComposeMapUri(uint episode, uint map); + +/** + * Chooses a default user description for a saved session. + * + * @param saveName Name of the saved session from which the existing description should + * be re-used. Use a zero-length string to disable. + * @param autogenerate @c true to generate a useful description (map name, map time, etc...) + * if none exists for the @a saveName referenced. + */ +de::String G_DefaultSavedSessionUserDescription(de::String const &saveName, bool autogenerate = true); + +/** + * Returns the game's SaveSlots. + */ +SaveSlots &G_SaveSlots(); + extern "C" { #endif /** - * Reveal the game @em help display. + * Returns @c true, if the game is currently quiting. */ -void G_StartHelp(void); +dd_bool G_QuitInProgress(void); -/// @todo Should not be a global function; mode breaks game session separation. -dd_bool G_StartFinale(char const *script, int flags, finale_mode_t mode, char const *defId); +/** + * Returns the current logical game state. + */ +gamestate_t G_GameState(void); /** - * Signal that play on the current map may now begin. + * Change the current logical game state to @a newState. */ -void G_BeginMap(void); +void G_ChangeGameState(gamestate_t newState); /** - * Determines whether an intermission should be scheduled (if any) when the players leave the - * @em current map. + * Returns the current game action. */ -dd_bool G_IntermissionActive(void); +gameaction_t G_GameAction(void); /** - * To be called to initiate the intermission. + * Change the current game action to @a newAction. */ -void G_IntermissionBegin(void); +void G_SetGameAction(gameaction_t newAction); /** - * To be called when the intermission ends. + * Reveal the game @em help display. */ -void G_IntermissionDone(void); +void G_StartHelp(void); -#if __cplusplus -} // extern "C" +/// @todo Should not be a global function; mode breaks game session separation. +dd_bool G_StartFinale(char const *script, int flags, finale_mode_t mode, char const *defId); /** - * Returns the logical map number for the identified map. - * - * @param mapUri Unique identifier of the map to lookup. - * - * @deprecated Should use map URIs instead. + * Signal that play on the current map may now begin. */ -uint G_MapNumberFor(de::Uri const &mapUri); +void G_BeginMap(void); /** - * 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. - * - * @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. + * To be called when the intermission ends. */ -de::Uri G_ComposeMapUri(uint episode, uint map); - -extern "C" { -#endif +void G_IntermissionDone(void); AutoStr *G_CurrentMapUriPath(void); @@ -207,25 +209,8 @@ D_CMD( CCmdExitLevel ); #if __cplusplus } // extern "C" +#endif -#include - -class SaveSlots; - -/** - * Chooses a default user description for a saved session. - * - * @param saveName Name of the saved session from which the existing description should be - * re-used. Use a zero-length string to disable. - * @param autogenerate @c true= generate a useful description (map name, map time, etc...) if none - * exists for the referenced save @a slotId. - */ -de::String G_DefaultSavedSessionUserDescription(de::String const &saveName, bool autogenerate = true); - -/** - * Returns the game's SaveSlots. - */ -SaveSlots &G_SaveSlots(); +DENG_EXTERN_C dd_bool singledemo; -#endif // __cplusplus #endif // LIBCOMMON_GAME_H diff --git a/doomsday/plugins/common/src/g_game.cpp b/doomsday/plugins/common/src/g_game.cpp index c26c89b457..49500b581c 100644 --- a/doomsday/plugins/common/src/g_game.cpp +++ b/doomsday/plugins/common/src/g_game.cpp @@ -1535,6 +1535,88 @@ static sfxenum_t randomQuitSound() return SFX_NONE; } +/** + * Determines whether an intermission is enabled and will be scheduled when the players + * leave the @em current map. + */ +static bool intermissionEnabled() +{ +#if __JDOOM__ || __JHERETIC__ || __JDOOM64__ + if(Record const *mapInfo = COMMON_GAMESESSION->mapInfo()) + { + if(mapInfo->geti("flags") & MIF_NO_INTERMISSION) + { + return false; + } + } +#elif __JHEXEN__ + if(!COMMON_GAMESESSION->rules().deathmatch) + { + return false; + } +#endif + return true; +} + +#if __JDOOM__ || __JDOOM64__ +void G_PrepareWIData() +{ + wbstartstruct_t *info = &::wmInfo; + + info->maxFrags = 0; + + // See if there is a par time definition. + info->parTime = -1; // Unknown. + if(Record const *mapInfo = COMMON_GAMESESSION->mapInfo()) + { + float parTime = mapInfo->getf("parTime"); + if(parTime > 0) + { + info->parTime = TICRATE * int(parTime); + } + } + + info->pNum = CONSOLEPLAYER; + for(int i = 0; i < MAXPLAYERS; ++i) + { + player_t const *p = &players[i]; + wbplayerstruct_t *pStats = &info->plyr[i]; + + pStats->inGame = p->plr->inGame; + pStats->kills = p->killCount; + pStats->items = p->itemCount; + pStats->secret = p->secretCount; + pStats->time = mapTime; + std::memcpy(pStats->frags, p->frags, sizeof(pStats->frags)); + } +} +#endif + +static int prepareIntermission(void * /*context*/) +{ + ::wmInfo.nextMap = ::nextMapUri; +#if __JHEXEN__ + ::wmInfo.nextMapEntryPoint = ::nextMapEntryPoint; +#endif +#if __JDOOM__ || __JDOOM64__ || __JHERETIC__ + ::wmInfo.currentMap = COMMON_GAMESESSION->mapUri(); + ::wmInfo.didSecret = ::players[CONSOLEPLAYER].didSecret; +# if __JDOOM__ || __JDOOM64__ + ::wmInfo.maxKills = de::max(1, ::totalKills); + ::wmInfo.maxItems = de::max(1, ::totalItems); + ::wmInfo.maxSecret = de::max(1, ::totalSecret); + + G_PrepareWIData(); +# endif +#endif + + IN_Begin(::wmInfo); + G_ChangeGameState(GS_INTERMISSION); + + BusyMode_WorkerEnd(); + return 0; +} + static void runGameAction() { #define QUITWAIT_MILLISECONDS 1500 @@ -1669,7 +1751,7 @@ static void runGameAction() } // Go to an intermission? - if(G_IntermissionActive()) + if(intermissionEnabled()) { #if __JDOOM__ // Has the secret map been completed? @@ -1689,7 +1771,25 @@ static void runGameAction() } #endif - G_IntermissionBegin(); +#if __JDOOM64__ + S_StartMusic("dm2int", true); +#elif __JDOOM__ + S_StartMusic((::gameModeBits & GM_ANY_DOOM2)? "dm2int" : "inter", true); +#elif __JHERETIC__ + S_StartMusic("intr", true); +#elif __JHEXEN__ + S_StartMusic("hub", true); +#endif + S_PauseMusic(true); + + BusyMode_RunNewTask(BUSYF_TRANSITION, prepareIntermission, NULL); +#if __JHERETIC__ + // @todo is this necessary at this time? + NetSv_SendGameState(0, DDSP_ALL_PLAYERS); +#endif + NetSv_Intermission(IMF_BEGIN, 0, 0); + + S_PauseMusic(false); } else { @@ -2144,109 +2244,6 @@ byte G_Ruleset_RespawnMonsters() } #endif -static int prepareIntermission(void * /*context*/) -{ - ::wmInfo.nextMap = ::nextMapUri; -#if __JHEXEN__ - ::wmInfo.nextMapEntryPoint = ::nextMapEntryPoint; -#endif -#if __JDOOM__ || __JDOOM64__ || __JHERETIC__ - ::wmInfo.currentMap = COMMON_GAMESESSION->mapUri(); - ::wmInfo.didSecret = ::players[CONSOLEPLAYER].didSecret; - -# if __JDOOM__ || __JDOOM64__ - ::wmInfo.maxKills = de::max(1, ::totalKills); - ::wmInfo.maxItems = de::max(1, ::totalItems); - ::wmInfo.maxSecret = de::max(1, ::totalSecret); - - G_PrepareWIData(); -# endif -#endif - - IN_Begin(::wmInfo); - G_ChangeGameState(GS_INTERMISSION); - - BusyMode_WorkerEnd(); - return 0; -} - -#if __JDOOM__ || __JDOOM64__ -void G_PrepareWIData() -{ - wbstartstruct_t *info = &::wmInfo; - - info->maxFrags = 0; - - // See if there is a par time definition. - info->parTime = -1; // Unknown. - if(Record const *mapInfo = COMMON_GAMESESSION->mapInfo()) - { - float parTime = mapInfo->getf("parTime"); - if(parTime > 0) - { - info->parTime = TICRATE * int(parTime); - } - } - - info->pNum = CONSOLEPLAYER; - for(int i = 0; i < MAXPLAYERS; ++i) - { - player_t const *p = &players[i]; - wbplayerstruct_t *pStats = &info->plyr[i]; - - pStats->inGame = p->plr->inGame; - pStats->kills = p->killCount; - pStats->items = p->itemCount; - pStats->secret = p->secretCount; - pStats->time = mapTime; - std::memcpy(pStats->frags, p->frags, sizeof(pStats->frags)); - } -} -#endif - -dd_bool G_IntermissionActive() -{ -#if __JDOOM__ || __JHERETIC__ || __JDOOM64__ - if(Record const *mapInfo = COMMON_GAMESESSION->mapInfo()) - { - if(mapInfo->geti("flags") & MIF_NO_INTERMISSION) - { - return false; - } - } -#elif __JHEXEN__ - if(!COMMON_GAMESESSION->rules().deathmatch) - { - return false; - } -#endif - return true; -} - -void G_IntermissionBegin() -{ -#if __JDOOM64__ - S_StartMusic("dm2int", true); -#elif __JDOOM__ - S_StartMusic((gameModeBits & GM_ANY_DOOM2)? "dm2int" : "inter", true); -#elif __JHERETIC__ - S_StartMusic("intr", true); -#elif __JHEXEN__ - S_StartMusic("hub", true); -#endif - S_PauseMusic(true); - BusyMode_RunNewTask(BUSYF_TRANSITION, prepareIntermission, NULL); - -#if __JHERETIC__ - // @todo is this necessary at this time? - NetSv_SendGameState(0, DDSP_ALL_PLAYERS); -#endif - - NetSv_Intermission(IMF_BEGIN, 0, 0); - - S_PauseMusic(false); -} - /** * Lookup the debriefing Finale for the current episode and map (if any). */ @@ -2359,7 +2356,6 @@ String G_DefaultSavedSessionUserDescription(String const &saveName, bool autogen return description; } -/// @todo Get this from MAPINFO uint G_MapNumberFor(de::Uri const &mapUri) { String path = mapUri.path(); diff --git a/doomsday/plugins/common/src/gamesession.cpp b/doomsday/plugins/common/src/gamesession.cpp index d1b73fec37..3020726631 100644 --- a/doomsday/plugins/common/src/gamesession.cpp +++ b/doomsday/plugins/common/src/gamesession.cpp @@ -164,16 +164,15 @@ DENG2_PIMPL(GameSession), public SavedSession::IMapStateReaderFactory for(int i = 0; i < MAXPLAYERS; ++i) { player_t *plr = &players[i]; - if(plr->plr->inGame) - { - // Force players to be initialized upon first map load. - plr->playerState = PST_REBORN; + if(!plr->plr->inGame) continue; + + // Force players to be initialized upon first map load. + plr->playerState = PST_REBORN; #if __JHEXEN__ - plr->worldTimer = 0; + plr->worldTimer = 0; #else - plr->didSecret = false; + plr->didSecret = false; #endif - } } } @@ -479,17 +478,16 @@ DENG2_PIMPL(GameSession), public SavedSession::IMapStateReaderFactory { for(int i = 0; i < MAXPLAYERS; ++i) { - player_t *plr = players + i; - if(plr->plr->inGame) - { - // Force players to be initialized upon first map load. - plr->playerState = PST_REBORN; + player_t *plr = &players[i]; + if(!plr->plr->inGame) continue; + + // Force players to be initialized upon first map load. + plr->playerState = PST_REBORN; #if __JHEXEN__ - plr->worldTimer = 0; + plr->worldTimer = 0; #else - plr->didSecret = false; + plr->didSecret = false; #endif - } } }