Skip to content

Commit

Permalink
Refactored away the need to specify the gamemode_t constant for DD_Ad…
Browse files Browse the repository at this point in the history
…dGame()
  • Loading branch information
danij-deng committed Nov 23, 2010
1 parent 36621ae commit cbf537b
Show file tree
Hide file tree
Showing 33 changed files with 184 additions and 264 deletions.
2 changes: 1 addition & 1 deletion doomsday/engine/api/dd_api.h
Expand Up @@ -60,7 +60,7 @@ typedef struct {

// Base-level.
void (*PreInit) (void);
void (*PostInit) (int mode);
void (*PostInit) (gameid_t gameId);
void (*Shutdown) (void);
void (*UpdateState) (int step);
int (*GetInteger) (int id);
Expand Down
7 changes: 5 additions & 2 deletions doomsday/engine/api/dd_share.h
Expand Up @@ -317,11 +317,14 @@ enum {
//
//------------------------------------------------------------------------

/**
* Extended info about a registered game component.
* Used with DD_GetGameInfo.
*/
typedef struct {
const char* title;
const char* author;
int mode;
const char* modeString;
const char* identityKey;
} ddgameinfo_t;

//------------------------------------------------------------------------
Expand Down
13 changes: 6 additions & 7 deletions doomsday/engine/api/doomsday.h
Expand Up @@ -79,22 +79,21 @@ extern "C" {
*
* \note Game registration order defines the order of the automatic game identification/selection logic.
*
* @param mode Unique game mode id.
* @param modeString Unique game mode string key/identifier, 16 chars max (e.g., "doom1-ultimate").
* Sent out in netgames, and the PCL_HELLO2 packet contains it. A client can't connect unless mode strings match.
* @param identityKey Unique game mode key/identifier, 16 chars max (e.g., "doom1-ultimate").
* - Used during resource location for mode-specific assets.
* - Sent out in netgames (a client can't connect unless mode strings match).
* @param dataPath The base directory for all data-class resources.
* @param defsPath The base directory for all defs-class resources.
* @param mainDef The main/top-level definition file. Can be @c NULL.
* @param defaultTitle Default game title. May be overridden later.
* @param defaultAuthor Default game author used for (e.g.) map author info if not specified. May be overridden later.
* @param defaultAuthor Default game author. Used for (e.g.) map author info if not specified. May be overridden later.
* @param cmdlineFlag Command-line game selection override argument (e.g., "ultimate"). Can be @c NULL.
* @param cmdlineFlag2 Alternative override. Can be @c NULL.
*
* @return Unique identifier/name assigned to the game.
*/
gameid_t DD_AddGame(int mode, const char* modeString, const char* dataPath, const char* defsPath,
const char* mainDef, const char* defaultTitle, const char* defaultAuthor, const char* cmdlineFlag,
const char* cmdlineFlag2);
gameid_t DD_AddGame(const char* identityKey, const char* dataPath, const char* defsPath, const char* mainDef,
const char* defaultTitle, const char* defaultAuthor, const char* cmdlineFlag, const char* cmdlineFlag2);

/**
* Registers a new resource to the list of resources for the specified game.
Expand Down
18 changes: 5 additions & 13 deletions doomsday/engine/portable/include/gameinfo.h
Expand Up @@ -61,11 +61,8 @@ typedef struct {
/// Unique identifier of the plugin which registered this game.
pluginid_t _pluginId;

/// Mode id supplied by the plugin which registered this game.
int _mode;

/// Unique mode identifier string (e.g., "doom1-ultimate").
ddstring_t _modeIdentifier;
/// Unique identifier string (e.g., "doom1-ultimate").
ddstring_t _identityKey;

/// Formatted default title suitable for printing (e.g., "The Ultimate DOOM").
ddstring_t _title;
Expand Down Expand Up @@ -95,9 +92,7 @@ typedef struct {
/**
* Create a new GameInfo.
*
* @param mode Unique game mode id.
* @param modeString Unique game mode string key/identifier, 16 chars max (e.g., "doom1-ultimate").
* Sent out in netgames, and the PCL_HELLO2 packet contains it. A client can't connect unless mode strings match.
* @param identityKey Unique game mode key/identifier, 16 chars max (e.g., "doom1-ultimate").
* @param dataPath The base directory for all data-class resources.
* @param defsPath The base directory for all defs-class resources.
* @param mainDef The main/top-level definition file. Can be @c NULL.
Expand All @@ -106,7 +101,7 @@ typedef struct {
* @param cmdlineFlag Command-line game selection override argument (e.g., "ultimate"). Can be @c NULL.
* @param cmdlineFlag2 Alternative override. Can be @c NULL.
*/
gameinfo_t* P_CreateGameInfo(pluginid_t pluginId, int mode, const char* modeString, const char* dataPath,
gameinfo_t* P_CreateGameInfo(pluginid_t pluginId, const char* identityKey, const char* dataPath,
const char* defsPath, const ddstring_t* mainDef, const char* title, const char* author,
const ddstring_t* cmdlineFlag, const ddstring_t* cmdlineFlag2);

Expand Down Expand Up @@ -150,11 +145,8 @@ const ddstring_t* GameInfo_ResourceSearchPaths(gameinfo_t* info, ddresourceclass
/// @return Unique plugin identifier attributed to that which registered this.
pluginid_t GameInfo_PluginId(gameinfo_t* info);

/// @return Integer mode id provided by the plugin which registered this.
int GameInfo_Mode(gameinfo_t* info);

/// @return Ptr to a string containing the mode-identifier.
const ddstring_t* GameInfo_ModeIdentifier(gameinfo_t* info);
const ddstring_t* GameInfo_IdentityKey(gameinfo_t* info);

/// @return Ptr to a string containing the default title.
const ddstring_t* GameInfo_Title(gameinfo_t* info);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/cl_main.c
Expand Up @@ -136,7 +136,7 @@ void Cl_SendHello(void)

// The game mode is included in the hello packet.
memset(buf, 0, sizeof(buf));
strncpy(buf, Str_Text(GameInfo_ModeIdentifier(DD_GameInfo())), sizeof(buf) - 1);
strncpy(buf, Str_Text(GameInfo_IdentityKey(DD_GameInfo())), sizeof(buf) - 1);

#ifdef _DEBUG
Con_Message("Cl_SendHello: game mode = %s\n", buf);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/dam_main.c
Expand Up @@ -396,7 +396,7 @@ void DAM_GetCachedMapDir(char* dir, int mainLump, size_t len)
}

// The cached map directory is relative to the runtime directory.
dd_snprintf(dir, len, "%s%s\\%s-%04X\\", mapCacheDir, Str_Text(GameInfo_ModeIdentifier(DD_GameInfo())), base, identifier);
dd_snprintf(dir, len, "%s%s\\%s-%04X\\", mapCacheDir, Str_Text(GameInfo_IdentityKey(DD_GameInfo())), base, identifier);

M_TranslatePath(dir, dir, len);
}
Expand Down
49 changes: 16 additions & 33 deletions doomsday/engine/portable/src/dd_main.c
Expand Up @@ -140,26 +140,14 @@ static gameinfo_t* findGameInfoForId(gameid_t gameId)
return 0; // Not found.
}

static gameinfo_t* findGameInfoForMode(pluginid_t pluginId, int mode)
{
{ uint i;
for(i = 0; i < numGameInfo; ++i)
{
gameinfo_t* info = gameInfo[i];
if(GameInfo_PluginId(info) == pluginId && GameInfo_Mode(info) == mode)
return info;
}}
return 0; // Not found.
}

static gameinfo_t* findGameInfoForModeIdentifier(const char* modeIdentifier)
static gameinfo_t* findGameInfoForIdentityKey(const char* modeIdentifier)
{
assert(modeIdentifier && modeIdentifier[0]);
{ uint i;
for(i = 0; i < numGameInfo; ++i)
{
gameinfo_t* info = gameInfo[i];
if(!stricmp(Str_Text(GameInfo_ModeIdentifier(info)), modeIdentifier))
if(!stricmp(Str_Text(GameInfo_IdentityKey(info)), modeIdentifier))
return info;
}}
return 0; // Not found.
Expand Down Expand Up @@ -229,12 +217,12 @@ static void destroyPathList(ddstring_t*** list, size_t* listSize)
*listSize = 0;
}

static gameinfo_t* addGameInfoRecord(pluginid_t pluginId, int mode, const char* modeString, const char* dataPath,
static gameinfo_t* addGameInfoRecord(pluginid_t pluginId, const char* identityKey, const char* dataPath,
const char* defsPath, const ddstring_t* mainDef, const char* title, const char* author, const ddstring_t* cmdlineFlag,
const ddstring_t* cmdlineFlag2)
{
gameInfo = M_Realloc(gameInfo, sizeof(*gameInfo) * (numGameInfo + 1));
gameInfo[numGameInfo] = P_CreateGameInfo(pluginId, mode, modeString, dataPath, defsPath, mainDef, title, author, cmdlineFlag, cmdlineFlag2);
gameInfo[numGameInfo] = P_CreateGameInfo(pluginId, identityKey, dataPath, defsPath, mainDef, title, author, cmdlineFlag, cmdlineFlag2);
return gameInfo[numGameInfo++];
}

Expand Down Expand Up @@ -271,10 +259,9 @@ boolean DD_GetGameInfo(ddgameinfo_t* ex)
{ gameinfo_t* info = DD_GameInfo();
if(!DD_IsNullGameInfo(info))
{
ex->identityKey = Str_Text(GameInfo_IdentityKey(info));
ex->title = Str_Text(GameInfo_Title(info));
ex->author = Str_Text(GameInfo_Author(info));
ex->modeString = Str_Text(GameInfo_ModeIdentifier(info));
ex->mode = GameInfo_Mode(info);
return true;
}}

Expand Down Expand Up @@ -330,23 +317,19 @@ void DD_AddGameResource(gameid_t gameId, resourcetype_t resType, ddresourceclass
}}
}

gameid_t DD_AddGame(int mode, const char* modeString, const char* _dataPath, const char* _defsPath, const char* _mainDef,
gameid_t DD_AddGame(const char* identityKey, const char* _dataPath, const char* _defsPath, const char* _mainDef,
const char* defaultTitle, const char* defaultAuthor, const char* _cmdlineFlag, const char* _cmdlineFlag2)
{
assert(modeString && modeString[0] && _dataPath && _dataPath[0] && _defsPath && _defsPath[0] && defaultTitle && defaultTitle[0] && defaultAuthor && defaultAuthor[0]);
assert(identityKey && identityKey[0] && _dataPath && _dataPath[0] && _defsPath && _defsPath[0] && defaultTitle && defaultTitle[0] && defaultAuthor && defaultAuthor[0]);
{
gameinfo_t* info;
ddstring_t mainDef, cmdlineFlag, cmdlineFlag2;
filename_t dataPath, defsPath;
pluginid_t pluginId = Plug_PluginIdForActiveHook();

// Game mode must be unique among games registered by this plugin.
if((info = findGameInfoForMode(pluginId, mode)))
Con_Error("DD_AddGame: Failed adding game \"%s\", mode '%i' already in use.", defaultTitle, mode);

// Game mode identifiers must be unique. Ensure that is the case.
if((info = findGameInfoForModeIdentifier(modeString)))
Con_Error("DD_AddGame: Failed adding game \"%s\", mode identifier '%s' already in use.", defaultTitle, modeString);
// Game mode identity keys must be unique. Ensure that is the case.
if((info = findGameInfoForIdentityKey(identityKey)))
Con_Error("DD_AddGame: Failed adding game \"%s\", identity key '%s' already in use.", defaultTitle, identityKey);

M_TranslatePath(dataPath, _dataPath, FILENAME_T_MAXLEN);
Dir_ValidDir(dataPath, FILENAME_T_MAXLEN);
Expand Down Expand Up @@ -378,7 +361,7 @@ gameid_t DD_AddGame(int mode, const char* modeString, const char* _dataPath, con
/**
* Looking good. Add this game to our records.
*/
info = addGameInfoRecord(pluginId, mode, modeString, dataPath, defsPath, &mainDef, defaultTitle, defaultAuthor, _cmdlineFlag? &cmdlineFlag : 0, _cmdlineFlag2? &cmdlineFlag2 : 0);
info = addGameInfoRecord(pluginId, identityKey, dataPath, defsPath, &mainDef, defaultTitle, defaultAuthor, _cmdlineFlag? &cmdlineFlag : 0, _cmdlineFlag2? &cmdlineFlag2 : 0);

Str_Free(&mainDef);
Str_Free(&cmdlineFlag);
Expand Down Expand Up @@ -544,7 +527,7 @@ static void printGameInfo(gameinfo_t* info)
Con_Printf("Game: %s - %s\n", Str_Text(GameInfo_Title(info)), Str_Text(GameInfo_Author(info)));
#if _DEBUG
Con_Printf(" PluginId: %i\n", (int)GameInfo_PluginId(info));
Con_Printf(" Meta: mode:%i modeStr:\"%s\" data:\"%s\" defs:\"%s\"\n", GameInfo_Mode(info), Str_Text(GameInfo_ModeIdentifier(info)), M_PrettyPath(Str_Text(GameInfo_DataPath(info))), M_PrettyPath(Str_Text(GameInfo_DefsPath(info))));
Con_Printf(" Meta: identitykey:\"%s\" data:\"%s\" defs:\"%s\"\n", Str_Text(GameInfo_IdentityKey(info)), M_PrettyPath(Str_Text(GameInfo_DataPath(info))), M_PrettyPath(Str_Text(GameInfo_DefsPath(info))));
#endif

{ int i;
Expand Down Expand Up @@ -838,7 +821,7 @@ static int DD_ChangeGameWorker(void* parm)
if(gx.PostInit)
{
Con_SetProgress(180);
gx.PostInit(GameInfo_Mode(info));
gx.PostInit((gameid_t)gameInfoIndex(info));
}

Con_SetProgress(200);
Expand All @@ -854,7 +837,7 @@ void DD_ChangeGame(gameinfo_t* info)
{
assert(info);

Con_Message("DD_ChangeGame: Selecting \"%s\".\n", Str_Text(GameInfo_ModeIdentifier(info)));
Con_Message("DD_ChangeGame: Selecting \"%s\".\n", Str_Text(GameInfo_IdentityKey(info)));
if(!exchangeEntryPoints(GameInfo_PluginId(info)))
{
Con_Message("DD_ChangeGame: Warning, error exchanging entrypoints with plugin %i - aborting.\n", (int)GameInfo_PluginId(info));
Expand Down Expand Up @@ -993,7 +976,7 @@ void DD_AutoselectGame(void)
switch(pass)
{
case 0: // Command line modestring match for-development/debug (e.g., "-game doom1-ultimate").
if(!Str_CompareIgnoreCase(GameInfo_ModeIdentifier(info), expGame))
if(!Str_CompareIgnoreCase(GameInfo_IdentityKey(info), expGame))
DD_ChangeGame(info);
break;

Expand Down Expand Up @@ -1228,7 +1211,7 @@ static int DD_StartupWorker(void* parm)
Dir_ValidDir(dataPath, FILENAME_T_MAXLEN);
M_TranslatePath(defsPath, DD_BASEPATH_DEFS, FILENAME_T_MAXLEN);
Dir_ValidDir(defsPath, FILENAME_T_MAXLEN);
currentGameInfoIndex = gameInfoIndex(addGameInfoRecord(0, -1, 0, dataPath, defsPath, 0, 0, 0, 0, 0));
currentGameInfoIndex = gameInfoIndex(addGameInfoRecord(0, 0, dataPath, defsPath, 0, 0, 0, 0, 0));
}

// Initialize the key mappings.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/def_read.c
Expand Up @@ -666,7 +666,7 @@ static boolean DED_CheckCondition(const char* cond, boolean expected)
}
else if(isalnum(cond[0]))
{ // A game mode.
value = !stricmp(cond, Str_Text(GameInfo_ModeIdentifier(DD_GameInfo())));
value = !stricmp(cond, Str_Text(GameInfo_IdentityKey(DD_GameInfo())));
}

return value == expected;
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/edit_bias.c
Expand Up @@ -413,7 +413,7 @@ static boolean SBE_Save(const char *name)

// Since there can be quite a lot of these, make sure we'll skip
// the ones that are definitely not suitable.
fprintf(file, "SkipIf Not %s\n", Str_Text(GameInfo_ModeIdentifier(DD_GameInfo())));
fprintf(file, "SkipIf Not %s\n", Str_Text(GameInfo_IdentityKey(DD_GameInfo())));

s = SB_GetSource(0);
for(i = 0; i < numSources; ++i, ++s)
Expand Down
33 changes: 13 additions & 20 deletions doomsday/engine/portable/src/gameinfo.c
Expand Up @@ -188,19 +188,19 @@ static void buildResourceClassPathList(gameinfo_t* info, ddresourceclass_t rc)
break;
case RCP_GAMEMODEPATH_DATA:
usingGameModePathData = true;
if(resourceClassDefaultPaths[(int)rc] && Str_Length(&info->_modeIdentifier))
if(resourceClassDefaultPaths[(int)rc] && Str_Length(&info->_identityKey))
{
filename_t newPath;
dd_snprintf(newPath, FILENAME_T_MAXLEN, "%s%s%s", Str_Text(&info->_dataPath), resourceClassDefaultPaths[(int)rc], Str_Text(&info->_modeIdentifier));
dd_snprintf(newPath, FILENAME_T_MAXLEN, "%s%s%s", Str_Text(&info->_dataPath), resourceClassDefaultPaths[(int)rc], Str_Text(&info->_identityKey));
GameInfo_AddResourceSearchPath(info, rc, newPath, false);
}
break;
case RCP_GAMEMODEPATH_DEFS:
usingGameModePathDefs = true;
if(resourceClassDefaultPaths[(int)rc] && Str_Length(&info->_modeIdentifier))
if(resourceClassDefaultPaths[(int)rc] && Str_Length(&info->_identityKey))
{
filename_t newPath;
dd_snprintf(newPath, FILENAME_T_MAXLEN, "%s%s%s", Str_Text(&info->_defsPath), resourceClassDefaultPaths[(int)rc], Str_Text(&info->_modeIdentifier));
dd_snprintf(newPath, FILENAME_T_MAXLEN, "%s%s%s", Str_Text(&info->_defsPath), resourceClassDefaultPaths[(int)rc], Str_Text(&info->_identityKey));
GameInfo_AddResourceSearchPath(info, rc, newPath, false);
}
break;
Expand All @@ -224,10 +224,10 @@ static void buildResourceClassPathList(gameinfo_t* info, ddresourceclass_t rc)
M_TranslatePath(newPath, ArgNext(), FILENAME_T_MAXLEN);
GameInfo_AddResourceSearchPath(info, rc, newPath, false);

if((usingGameModePathData || usingGameModePathDefs) && Str_Length(&info->_modeIdentifier))
if((usingGameModePathData || usingGameModePathDefs) && Str_Length(&info->_identityKey))
{
filename_t other;
dd_snprintf(other, FILENAME_T_MAXLEN, "%s\\%s", newPath, Str_Text(&info->_modeIdentifier));
dd_snprintf(other, FILENAME_T_MAXLEN, "%s\\%s", newPath, Str_Text(&info->_identityKey));
GameInfo_AddResourceSearchPath(info, rc, other, false);
}
}
Expand All @@ -250,18 +250,17 @@ static __inline void clearResourceClassSearchPathList(gameinfo_t* info, ddresour
Str_Free(&info->_searchPathLists[resClass]);
}

gameinfo_t* P_CreateGameInfo(pluginid_t pluginId, int mode, const char* modeString, const char* dataPath,
gameinfo_t* P_CreateGameInfo(pluginid_t pluginId, const char* identityKey, const char* dataPath,
const char* defsPath, const ddstring_t* mainDef, const char* title, const char* author, const ddstring_t* cmdlineFlag,
const ddstring_t* cmdlineFlag2)
{
gameinfo_t* info = M_Malloc(sizeof(*info));

info->_pluginId = pluginId;
info->_mode = mode;

Str_Init(&info->_modeIdentifier);
if(modeString)
Str_Set(&info->_modeIdentifier, modeString);
Str_Init(&info->_identityKey);
if(identityKey)
Str_Set(&info->_identityKey, identityKey);

Str_Init(&info->_dataPath);
if(dataPath)
Expand Down Expand Up @@ -316,7 +315,7 @@ void P_DestroyGameInfo(gameinfo_t* info)

GameInfo_ClearResourceSearchPaths(info);

Str_Free(&info->_modeIdentifier);
Str_Free(&info->_identityKey);
Str_Free(&info->_dataPath);
Str_Free(&info->_defsPath);
Str_Free(&info->_mainDef);
Expand Down Expand Up @@ -455,16 +454,10 @@ pluginid_t GameInfo_PluginId(gameinfo_t* info)
return info->_pluginId;
}

int GameInfo_Mode(gameinfo_t* info)
const ddstring_t* GameInfo_IdentityKey(gameinfo_t* info)
{
assert(info);
return info->_mode;
}

const ddstring_t* GameInfo_ModeIdentifier(gameinfo_t* info)
{
assert(info);
return &info->_modeIdentifier;
return &info->_identityKey;
}

const ddstring_t* GameInfo_DataPath(gameinfo_t* info)
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/p_data.c
Expand Up @@ -150,7 +150,7 @@ const char* P_GenerateUniqueMapID(const char* mapID)
int lump = W_GetNumForName(mapID);

M_ExtractFileBase(base, W_LumpSourceFile(lump), FILENAME_T_MAXLEN);
dd_snprintf(uid, 255, "%s|%s|%s|%s", mapID, base, (W_LumpFromIWAD(lump) ? "iwad" : "pwad"), Str_Text(GameInfo_ModeIdentifier(DD_GameInfo())));
dd_snprintf(uid, 255, "%s|%s|%s|%s", mapID, base, (W_LumpFromIWAD(lump) ? "iwad" : "pwad"), Str_Text(GameInfo_IdentityKey(DD_GameInfo())));
strlwr(uid);

return uid;
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/rend_console.c
Expand Up @@ -233,7 +233,7 @@ void Con_InitUI(void)
if(!DD_IsNullGameInfo(DD_GameInfo()))
{
strncpy(secondaryTitleText, (char*) gx.GetVariable(DD_GAME_ID), sizeof(secondaryTitleText) - 1);
strncpy(statusText, Str_Text(GameInfo_ModeIdentifier(DD_GameInfo())), sizeof(statusText) - 1);
strncpy(statusText, Str_Text(GameInfo_IdentityKey(DD_GameInfo())), sizeof(statusText) - 1);
return;
}
// No game currently loaded.
Expand Down

0 comments on commit cbf537b

Please sign in to comment.