Skip to content

Commit

Permalink
Misc clean up:
Browse files Browse the repository at this point in the history
* Reworked ccmd "listgames" into a summary of the known games, sorted by title.
* Print the known game list if automatic game selection fails.
* Added generic ccmd "printinfo" - print extended information about a named object in the console. Can be used to get extended information about a known game e.g., "printinfo doom1-ultimate"
* Ensure the identity key is not longer than the expected length in DD_AddGame.
  • Loading branch information
danij-deng committed Dec 10, 2010
1 parent c741db3 commit 8cd1e59
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 20 deletions.
14 changes: 10 additions & 4 deletions doomsday/engine/data/cphelp.txt
Expand Up @@ -384,6 +384,9 @@ desc = List all console commands.
[listfiles]
desc = List all the loaded data files and show information about them.

[listgames]
desc = List all games.

[listmaterials]
desc = List all known surface materials.

Expand All @@ -394,8 +397,8 @@ desc = List all known mobj types.
desc = List all console variables and their values.

[load]
desc = Load data file(s) (a WAD or a lump).
inf = Params: load (file) ...\nFor example, 'load mylevel.wad'.
desc = Load a complete game or one or more data files (e.g., a WAD or a lump).
inf = Params: load (name) ...\nFor example, 'load (gamename)' or 'load mylevel.wad'.

[login]
desc = Log in to server console.
Expand Down Expand Up @@ -433,6 +436,9 @@ desc = Ping the server (or a player if you're the server).
desc = Play a demo.
inf = Params: playdemo (fileName)\nFor example, 'playdemo demo1.dmo'.

[printinfo]
desc = Print extended information for the named object.

[playmusic]
desc = Play a music track, music lump, external file or a CD track.

Expand Down Expand Up @@ -522,8 +528,8 @@ desc = Change Doomsday user interface colors.
inf = Params: uicolor (object) (red) (green) (blue)\nFor example, 'uicolor text 1 1 1'.\nPossible objects are:\n text, shadow, bglight, bgmed, bgdark,\n borhigh, bormed, borlow, help

[unload]
desc = Unload a data file from memory.
inf = Params: unload (file) ...\nFor example, 'unload mylevel.wad'.
desc = Unload the current game or one or more data files.
inf = Params: unload (name) ...\nFor example, 'unload mylevel.wad'.

[version]
desc = Show detailed version information.
Expand Down
1 change: 1 addition & 0 deletions doomsday/engine/portable/include/dd_main.h
Expand Up @@ -88,6 +88,7 @@ void DD_DestroyGameInfo(void);

D_CMD(Load);
D_CMD(Unload);
D_CMD(PrintInfo);
D_CMD(ListGames);

#endif /* LIBDENG_MAIN_H */
1 change: 1 addition & 0 deletions doomsday/engine/portable/src/con_main.c
Expand Up @@ -215,6 +215,7 @@ void Con_Register(void)

// Games
C_CMD("listgames", "", ListGames);
C_CMD("printinfo", "s", PrintInfo);

// File
C_VAR_CHARPTR("file-startup", &gameStartupFiles, 0, 0, 0);
Expand Down
98 changes: 83 additions & 15 deletions doomsday/engine/portable/src/dd_main.c
Expand Up @@ -349,6 +349,8 @@ gameid_t DD_AddGame(const char* identityKey, const char* _dataPath, const char*
filename_t dataPath, defsPath;
pluginid_t pluginId = Plug_PluginIdForActiveHook();

if(strlen(identityKey) > 16)
Con_Error("DD_AddGame: Failed adding game \"s\", identity key '%s' is too long (max 16 characters).", defaultTitle, identityKey);
// 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);
Expand Down Expand Up @@ -566,24 +568,57 @@ 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(" Meta: pluginid:%i identitykey:\"%s\" data:\"%s\" defs:\"%s\"\n", (int)GameInfo_PluginId(info), Str_Text(GameInfo_IdentityKey(info)), M_PrettyPath(Str_Text(GameInfo_DataPath(info))), M_PrettyPath(Str_Text(GameInfo_DefsPath(info))));
Con_Printf("Meta: pluginid:%i identitykey:\"%s\" data:\"%s\" defs:\"%s\"\n", (int)GameInfo_PluginId(info), Str_Text(GameInfo_IdentityKey(info)), M_PrettyPath(Str_Text(GameInfo_DataPath(info))), M_PrettyPath(Str_Text(GameInfo_DefsPath(info))));
#endif

{ uint i;
// First output a list of startup resources.
Con_Printf("Startup resources:");
{ uint i; size_t n = 0;
for(i = 0; i < NUM_RESOURCE_CLASSES; ++i)
{
gameresource_record_t* const* records;
if((records = GameInfo_Resources(info, (resourceclass_t)i, 0)))
{
int n = 0;
Con_Printf(" %s:\n", F_ResourceClassStr((resourceclass_t)i));
do
{
Con_Printf(" %i: %s\"%s\" %s%s\n", n++, ((*records)->rflags & RF_STARTUP)? "* ":"", Str_Text(&(*records)->names), Str_Length(&(*records)->path) == 0? "" : "> ", (((*records)->rflags & RF_STARTUP) && Str_Length(&(*records)->path) == 0)? "--(!)missing" : M_PrettyPath(Str_Text(&(*records)->path)));
if((*records)->rflags & RF_STARTUP)
{
if(n == 0)
Con_Printf("\n");
Con_Printf(" %s \"%s\" %s%s\n", Str_Length(&(*records)->path) == 0? "!":" ", Str_Text(&(*records)->names), Str_Length(&(*records)->path) == 0? "- missing" : "> ", Str_Length(&(*records)->path) == 0? "" : M_PrettyPath(Str_Text(&(*records)->path)));
n++;
}
} while(*(++records));
}
}}
Con_Printf(" Status: %s\n", DD_GameInfo() == info? "Loaded" : allGameResourcesFound(info)? "Complete/Playable" : "Incomplete/Not playable");
}
if(n == 0)
Con_Printf(" None\n");
}

// Now output the rest of the known resources.
Con_Printf("Other resources:");
{ uint i; size_t n = 0;
for(i = 0; i < NUM_RESOURCE_CLASSES; ++i)
{
gameresource_record_t* const* records;
if((records = GameInfo_Resources(info, (resourceclass_t)i, 0)))
{
do
{
if(!((*records)->rflags & RF_STARTUP))
{
if(n == 0)
Con_Printf("\n");
Con_Printf(" \"%s\" %s%s\n", Str_Text(&(*records)->names), Str_Length(&(*records)->path) == 0? "" : "> ", Str_Length(&(*records)->path) == 0? "" : M_PrettyPath(Str_Text(&(*records)->path)));
n++;
}
} while(*(++records));
}
}
if(n == 0)
Con_Printf(" None\n");
}
Con_Printf("Status: %s\n", DD_GameInfo() == info? "Loaded" : allGameResourcesFound(info)? "Complete/Playable" : "Incomplete/Not playable");
}

/**
Expand Down Expand Up @@ -1126,15 +1161,13 @@ int DD_Main(void)
if(DD_IsNullGameInfo(info))
continue;
locateGameResources(info);
VERBOSE2( Con_Executef(CMDS_DDAY, false, "printinfo %s", Str_Text(GameInfo_IdentityKey(info))) );
}}
VERBOSE( Con_Execute(CMDS_DDAY, "listgames", false, false) );

// Attempt automatic game selection.
if(!ArgExists("-noautoselect"))
{
DD_AutoselectGame();
if(DD_IsNullGameInfo(DD_GameInfo()))
Con_Message("Automatic game selection failed.\n");
}

// Load resources specified using -file options on the command line.
Expand Down Expand Up @@ -1248,8 +1281,12 @@ int DD_Main(void)
titleFinale = FI_Execute(fin.script, FF_LOCAL);
}

// We'll open the console automatically too.
// We'll open the console and print a list of the known games too.
Con_Execute(CMDS_DDAY, "conopen", true, false);
if(!ArgExists("-noautoselect"))
Con_Printf("Automatic game selection failed.\n");
Con_Execute(CMDS_DDAY, "listgames", false, false);
Con_Message("Use the 'load' command to load a game. For example: \"load gamename\".\n");
}

// Start the game loop.
Expand Down Expand Up @@ -1913,22 +1950,53 @@ D_CMD(Unload)
return W_RemoveFiles(argv + 1, argc - 1);
}

D_CMD(PrintInfo)
{
{ gameinfo_t* info;
if((info = findGameInfoForIdentityKey(argv[1])))
{
printGameInfo(info);
return true;
}}
Con_Message("There is no extended info for \"%s\".\n", argv[1]);
return true;
}

static int C_DECL compareGameInfoByName(const void* a, const void* b)
{
return stricmp(Str_Text(&(*(gameinfo_t**)a)->_title), Str_Text(&(*(gameinfo_t**)b)->_title));
}

D_CMD(ListGames)
{
uint i, numAvailableGames = 0, numCompleteGames = 0;
gameinfo_t** infoPtrs;

Con_FPrintf(CBLF_YELLOW, "Registered Games:\n");
Con_Printf("Key: '!'= Incomplete/Not playable '*'= Loaded\n");
Con_FPrintf(CBLF_RULER, "");

// Sort a copy of gameInfo so we get a nice alphabetical list.
infoPtrs = M_Malloc(sizeof(*infoPtrs) * numGameInfo);
memcpy(infoPtrs, gameInfo, sizeof(*infoPtrs) * numGameInfo);
qsort(infoPtrs, numGameInfo, sizeof(*infoPtrs), compareGameInfoByName);

for(i = 0; i < numGameInfo; ++i)
{
gameinfo_t* info = gameInfo[i];

gameinfo_t* info = infoPtrs[i];
if(DD_IsNullGameInfo(info))
continue;

Con_Printf(" %s %-16s %s (%s)\n", DD_GameInfo() == info? "*" : !allGameResourcesFound(info)? "!" : " ", Str_Text(GameInfo_IdentityKey(info)), Str_Text(GameInfo_Title(info)), Str_Text(GameInfo_Author(info)));

numAvailableGames++;
printGameInfo(info);
if(allGameResourcesFound(info))
numCompleteGames++;
}
Con_Printf("%i of %i games playable.\n", numCompleteGames, numAvailableGames);
Con_FPrintf(CBLF_RULER, "");
Con_Printf("%u of %u games playable.\n", numCompleteGames, numAvailableGames);

M_Free(infoPtrs);
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/jdoom/src/d_main.c
Expand Up @@ -226,7 +226,7 @@ int G_RegisterGames(int hookType, int parm, void* data)
DD_AddGameResource(GID(doom2), RC_DEFINITION, 0, "doom2.ded", 0);

/* DOOM (Ultimate) */
gameIds[doom_ultimate] = DD_AddGame("doom1-ultimate", DATAPATH, DEFSPATH, MAINCONFIG, "The Ultimate DOOM", "id Software", "ultimatedoom", "udoom");
gameIds[doom_ultimate] = DD_AddGame("doom1-ultimate", DATAPATH, DEFSPATH, MAINCONFIG, "Ultimate DOOM", "id Software", "ultimatedoom", "udoom");
DD_AddGameResource(GID(doom_ultimate), RC_PACKAGE, RF_STARTUP, "doomu.wad;doom.wad", "E4M1;E4M2;E4M3;E4M4;E4M5;E4M6;E4M7;E4M8;E4M9;M_EPI4");
DD_AddGameResource(GID(doom_ultimate), RC_PACKAGE, RF_STARTUP, STARTUPPK3, 0);
DD_AddGameResource(GID(doom_ultimate), RC_DEFINITION, 0, "doom1-ultimate.ded", 0);
Expand Down

0 comments on commit 8cd1e59

Please sign in to comment.