Skip to content

Commit

Permalink
libcommon|GameSession: Switched GameSession to use textual episode id…
Browse files Browse the repository at this point in the history
…entifiers

A valid episode id is required in order to begin a new game session.
The GPT_GAME_STATE packet now includes the current episode id. Always
force a new game session when the episode specified to the "warp" set
of commands differs from the current. Added convenience methods to
common::GameSession for returning the current episode id and map URI.

Added G_EpisodeTitle as a convenient way of retrieving an episode
title by episode id and improved the map title banner to include it.
  • Loading branch information
danij-deng committed Aug 11, 2014
1 parent 1b5536b commit 0bef1b1
Show file tree
Hide file tree
Showing 10 changed files with 291 additions and 191 deletions.
22 changes: 11 additions & 11 deletions doomsday/plugins/common/include/g_common.h
@@ -1,7 +1,7 @@
/** @file g_common.h Top-level (common) game routines.
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2005-2013 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 2005-2014 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
Expand Down Expand Up @@ -29,7 +29,6 @@

DENG_EXTERN_C dd_bool singledemo;

DENG_EXTERN_C uint gameEpisode;
DENG_EXTERN_C uint gameMapEntrance;

#if __cplusplus
Expand Down Expand Up @@ -65,11 +64,13 @@ void G_SetGameAction(gameaction_t action);
/**
* Schedule a new game session (deferred).
*
* @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.
*/
void G_SetGameActionNewSession(de::Uri const &mapUri, uint mapEntrance, GameRuleset const &rules);
void G_SetGameActionNewSession(GameRuleset const &rules, de::String episodeId,
de::Uri const &mapUri, uint mapEntrance = 0);

/**
* Schedule a game session save (deferred).
Expand Down Expand Up @@ -119,6 +120,12 @@ char const *G_InFineBriefing(de::Uri const *mapUri = 0);
*/
char const *G_InFineDebriefing(de::Uri const *mapUri = 0);

/**
* @param mapUri Identifier of the episode to lookup the title of. Can be @c 0 in which
* case the title for the @em current episode will be returned (if set).
*/
de::String G_EpisodeTitle(de::String const *episodeId = 0);

/**
* @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).
Expand Down Expand Up @@ -187,13 +194,6 @@ void G_IntermissionDone(void);
#if __cplusplus
} // extern "C"

/**
* Returns the logical episode number assigned to the identified map (in MapInfo).
*
* @param mapUri Unique identifier of the map to lookup.
*/
uint G_EpisodeNumberFor(de::Uri const &mapUri);

/**
* Returns the logical map number for the identified map.
*
Expand Down
24 changes: 19 additions & 5 deletions doomsday/plugins/common/include/gamesession.h
Expand Up @@ -63,23 +63,35 @@ class GameSession : public de::game::Session
bool loadingPossible();

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

/**
* Returns the (current) MapGraphNode definition for the game session in progress. If the
* Returns the current episode id for the game session in progress. If the session has not
* yet begun then a zero-length string is returned.
*/
de::String episodeId();

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

/**
* Returns the (current) MapInfo definition for the game session in progress. If the session
* 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.
*/
de::Record *mapInfo();

/**
* Returns the current map URI for the game session in progress. If the session has not
* yet begun then an empty URI is returned.
*/
de::Uri mapUri();

/**
* Resolves a named exit according to the map progression.
*/
Expand Down Expand Up @@ -120,13 +132,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.
*
* @throws InProgressError if the session has already begun.
*/
void begin(de::Uri const &mapUri, uint mapEntrance, GameRuleset const &rules);
void begin(GameRuleset const &rules, de::String const &episodeId, de::Uri const &mapUri,
uint mapEntrance = 0);

/**
* Reload the @em current map, automatically loading any saved progress from the backing
Expand Down
15 changes: 8 additions & 7 deletions doomsday/plugins/common/src/d_net.cpp
@@ -1,7 +1,7 @@
/** @file d_net.cpp Common code related to net games.
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2013 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 2006-2014 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 2007 Jamie Jones <jamie_jones_au@yahoo.com.au>
*
* @par License
Expand Down Expand Up @@ -29,6 +29,7 @@
#include "p_start.h"
#include "fi_lib.h"

using namespace de;
using namespace common;

D_CMD(SetColor);
Expand All @@ -41,8 +42,8 @@ static void D_NetMessageEx(int player, char const *msg, dd_bool playSound);

float netJumpPower = 9;

static Writer *netWriter;
static Reader *netReader;
static writer_s *netWriter;
static reader_s *netReader;

static void notifyAllowCheatsChange()
{
Expand Down Expand Up @@ -70,7 +71,7 @@ void D_NetConsoleRegistration()
C_CMD ("message", "s", LocalMessage);
}

Writer *D_NetWrite()
writer_s *D_NetWrite()
{
if(netWriter)
{
Expand All @@ -80,7 +81,7 @@ Writer *D_NetWrite()
return netWriter;
}

Reader *D_NetRead(byte const *buffer, size_t len)
reader_s *D_NetRead(byte const *buffer, size_t len)
{
// Get rid of the old reader.
if(netReader)
Expand Down Expand Up @@ -128,7 +129,7 @@ int D_NetServerStarted(int before)
netRules.skill = skillmode_t(cfg.netSkill);

COMMON_GAMESESSION->end();
COMMON_GAMESESSION->begin(netMapUri, 0/*default*/, netRules);
COMMON_GAMESESSION->begin(netRules, netEpisode, netMapUri);
G_SetGameAction(GA_NONE); /// @todo Necessary?

return true;
Expand Down Expand Up @@ -357,7 +358,7 @@ int D_NetWorldEvent(int type, int parm, void *data)

void D_HandlePacket(int fromplayer, int type, void *data, size_t length)
{
Reader *reader = D_NetRead((byte *)data, length);
reader_s *reader = D_NetRead((byte *)data, length);

//
// Server events.
Expand Down

0 comments on commit 0bef1b1

Please sign in to comment.