Skip to content

Commit

Permalink
All Games: Unified game session model
Browse files Browse the repository at this point in the history
All supported games now use the same logical model for managing the
game session and the associated saved sessions. An internal savegame
is now used for all games (irrespective of the user's savegame prefs)
which is now managed automatically by the GameSession class.

See the GameSession API documentation for full details of the changes.

Also tweaked the domain and verbosity of various log messages.

Todo for later: Cleanup GameSession-internal logic and FS2 usage.
  • Loading branch information
danij-deng committed Apr 1, 2014
1 parent f98eef6 commit 5d80f1f
Show file tree
Hide file tree
Showing 38 changed files with 1,608 additions and 1,297 deletions.
2 changes: 1 addition & 1 deletion doomsday/client/src/dd_main.cpp
Expand Up @@ -1472,7 +1472,7 @@ bool App_ChangeGame(Game &game, bool allowReload)

if(!game.isNull())
{
LOG_VERBOSE("Selecting game '%s'...") << game.identityKey();
LOG_MSG("Selecting game '%s'...") << game.identityKey();
}
else if(!isReload)
{
Expand Down
6 changes: 3 additions & 3 deletions doomsday/client/src/world/worldsystem.cpp
Expand Up @@ -522,7 +522,7 @@ DENG2_PIMPL(WorldSystem)
if(!map) return;

// We cannot make an editable map current.
DENG_ASSERT(!map->isEditable());
DENG2_ASSERT(!map->isEditable());

// Should we cache this map?
/*MapCacheRecord &rec = createCacheRecord(map->uri());
Expand All @@ -545,8 +545,8 @@ DENG2_PIMPL(WorldSystem)
#endif

// Print summary information about this map.
LOG_MAP_MSG(_E(b) "Current map elements:");
LOG_MAP_MSG("%s") << map->elementSummaryAsStyledText();
LOG_MAP_NOTE(_E(b) "Current map elements:");
LOG_MAP_NOTE("%s") << map->elementSummaryAsStyledText();

// See what MapInfo says about this map.
ded_mapinfo_t *mapInfo = Def_GetMapInfo(reinterpret_cast<uri_s const *>(&map->uri()));
Expand Down
4 changes: 2 additions & 2 deletions doomsday/plugins/common/common.pri
Expand Up @@ -24,7 +24,7 @@ HEADERS += \
$$common_inc/g_eventsequence.h \
$$common_inc/g_update.h \
$$common_inc/gamerules.h \
$$common_inc/gamesessionwriter.h \
$$common_inc/gamesession.h \
$$common_inc/gl_drawpatch.h \
$$common_inc/hexlex.h \
$$common_inc/hu_automap.h \
Expand Down Expand Up @@ -89,7 +89,7 @@ SOURCES += \
$$common_src/g_game.cpp \
$$common_src/g_update.c \
$$common_src/gamerules.cpp \
$$common_src/gamesessionwriter.cpp \
$$common_src/gamesession.cpp \
$$common_src/gl_drawpatch.c \
$$common_src/hexlex.cpp \
$$common_src/hu_automap.cpp \
Expand Down
143 changes: 65 additions & 78 deletions doomsday/plugins/common/include/g_common.h
Expand Up @@ -22,18 +22,25 @@
#define LIBCOMMON_GAME_H

#include "dd_share.h"
#include "fi_lib.h"
#include "mobj.h"
#include "player.h"

DENG_EXTERN_C dd_bool singledemo;

DENG_EXTERN_C dd_bool gameInProgress;
DENG_EXTERN_C uint gameEpisode;

DENG_EXTERN_C Uri *gameMapUri;
DENG_EXTERN_C uint gameMapEntrance;
DENG_EXTERN_C uint gameMap; ///< @todo refactor away.

// Game status cvars:
DENG_EXTERN_C int gsvEpisode;
DENG_EXTERN_C int gsvMap;
#if __JHEXEN__
DENG_EXTERN_C int gsvHub;
#endif

#if __cplusplus
extern "C" {
#endif
Expand All @@ -58,31 +65,80 @@ gameaction_t G_GameAction(void);

void G_SetGameAction(gameaction_t action);

#if __cplusplus
} // extern "C"

/**
* Begin the titlescreen animation sequence.
* Schedule a new game session (deferred).
*
* @param mapUri Map identifier.
* @param mapEntrance Logical map entry point number.
* @param rules Game rules to apply.
*/
void G_StartTitle(void);
void G_SetGameActionNewSession(Uri const &mapUri, uint mapEntrance, GameRuleset const &rules);

/**
* Begin the helpscreen animation sequence.
* Schedule a game session save (deferred).
*
* @param slotId Unique identifier of the save slot to use.
* @param userDescription New user description for the game-save. Can be @c NULL in which
* case it will not change if the slot has already been used.
* If an empty string a new description will be generated automatically.
*
* @return @c true iff @a slotId is valid and saving is presently possible.
*/
void G_StartHelp(void);
bool G_SetGameActionSaveSession(de::String slotId, de::String *userDescription = 0);

/**
* Signal that play on the current map may now begin.
* Schedule a game session load (deferred).
*
* @param slotId Unique identifier of the save slot to use.
*
* @return @c true iff @a slotId is in use and loading is presently possible.
*/
void G_BeginMap(void);
bool G_SetGameActionLoadSession(de::String slotId);

extern "C" {
#endif

/**
* Leave the current map and start intermission routine.
* Schedule a game session map exit, possibly leading into an intermission sequence.
* (if __JHEXEN__ the intermission will only be displayed when exiting a
* hub and in DeathMatch games)
*
* @param newMap Logical map number we are entering (i.e., not a warp/translated number).
* @param mapEntryPoint Logical map entry point on the new map.
* @param secretExit @c true if the exit taken was marked as 'secret'.
*/
void G_LeaveMap(uint newMap, uint mapEntryPoint, dd_bool secretExit);
void G_SetGameActionMapCompleted(uint newMap, uint entryPoint, dd_bool secretExit);

/**
* Returns the InFine script with the specified @a scriptId; otherwise @c 0.
*/
char const *G_InFine(char const *scriptId);

/**
* Returns the InFine @em briefing script for the specified @a mapUri; otherwise @c 0.
*/
char const *G_InFineBriefing(Uri const *mapUri);

/**
* Returns the InFine @em debriefing script for the specified @a mapUri; otherwise @c 0.
*/
char const *G_InFineDebriefing(Uri const *mapUri);

/**
* Reveal the game @em help display.
*/
void G_StartHelp(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);

/**
* Signal that play on the current map may now begin.
*/
void G_BeginMap(void);

/**
* Called when a player leaves a map.
Expand Down Expand Up @@ -172,77 +228,16 @@ D_CMD( CCmdExitLevel );
#endif

#if __cplusplus
#include <de/Folder>
#include <de/game/SavedSessionRepository>
#include <de/String>
#include "gamerules.h"

class SaveSlots;

char const *G_InFineBriefing(Uri const *mapUri);

char const *G_InFineDebriefing(Uri const *mapUri);

/**
* Returns the game identity key (from the engine).
*/
de::String G_IdentityKey();

/**
* @param mapUri Map identifier.
* @param mapEntrance Logical map entry point number.
* @param rules Game rules to apply.
*/
void G_NewSession(Uri const &mapUri, uint mapEntrance, GameRuleset const &rules);

void G_DeferredNewSession(Uri const &mapUri, uint mapEntrance, GameRuleset const &rules);

/**
* End the current game session.
*/
void G_EndSession();

/**
* Deletes the saved session at @a path (if any).
*/
void G_DeleteSavedSession(de::String const &path);

/**
* Copies the saved session at @a sourcePath to @a destPath.
*/
void G_CopySavedSession(de::String const &destPath, de::String const &sourcePath);

/**
* Determines whether game session loading is presently possible.
*/
bool G_SessionLoadingPossible();

/**
* Determines whether game session saving is presently possible.
*/
bool G_SessionSavingPossible();

/**
* Schedule a game session save (deferred).
*
* @param slotId Unique identifier of the save slot to use.
* @param userDescription New user description for the game-save. Can be @c NULL in which
* case it will not change if the slot has already been used.
* If an empty string a new description will be generated automatically.
*
* @return @c true iff @a slotId is valid and saving is presently possible.
*/
bool G_SaveSession(de::String slotId, de::String *userDescription = 0);

/**
* Schedule a game session load (deferred).
*
* @param slotId Unique identifier of the save slot to use.
*
* @return @c true iff @a slotId is in use and loading is presently possible.
*/
bool G_LoadSession(de::String slotId);

/**
* Chooses a default user description for a saved session.
*
Expand All @@ -265,11 +260,6 @@ void G_ApplyCurrentSessionMetadata(de::game::SessionMetadata &metadata);
*/
SaveSlots &G_SaveSlots();

/**
* Returns the game's (i.e., the app's) SavedSessionRepository.
*/
de::game::SavedSessionRepository &G_SavedSessionRepository();

/**
* Parse @a str and determine whether it references a logical game-save slot.
*
Expand Down Expand Up @@ -297,9 +287,6 @@ GameRuleset &G_Rules();
*/
void G_ApplyNewGameRules(GameRuleset const &rules);

void G_SetCurrentMap(Uri const &mapUri);

void G_LoadCurrentMap(bool revisit = false);
#endif // __cplusplus

#endif // LIBCOMMON_GAME_H

0 comments on commit 5d80f1f

Please sign in to comment.