Skip to content

Commit

Permalink
Refactored game and game resource registration so that any needed top…
Browse files Browse the repository at this point in the history
…-level definition files can be specified as game resources using DD_AddGameResource.

Stop the title finale in DD_ChangeGame if it is currently playing at this time.
  • Loading branch information
danij-deng committed Dec 10, 2010
1 parent 210d7c5 commit ed08b20
Show file tree
Hide file tree
Showing 11 changed files with 127 additions and 110 deletions.
7 changes: 7 additions & 0 deletions doomsday/engine/api/dd_share.h
Expand Up @@ -331,6 +331,13 @@ typedef struct {
const char* identityKey;
} ddgameinfo_t;

/**
* @defgroup resourceFlags ResourceFlags
*/
/*{@*/
#define RF_STARTUP 0x1 // A required resource needed for and loaded during game start up (can't be a virtual file).
/*}@*/

//------------------------------------------------------------------------
//
// Fixed-Point Math
Expand Down
5 changes: 2 additions & 3 deletions doomsday/engine/api/doomsday.h
Expand Up @@ -84,7 +84,6 @@ extern "C" {
* - 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 name of the main/top-level definition file. Can be @c NULL.
* @param mainConfig The name of the main game config file. Can be @c NULL.
* @param defaultTitle Default game title. May be overridden later.
* @param defaultAuthor Default game author. May be overridden later. Used for (e.g.) the map author name
Expand All @@ -94,7 +93,7 @@ extern "C" {
*
* @return Unique identifier/name assigned to the game.
*/
gameid_t DD_AddGame(const char* identityKey, const char* dataPath, const char* defsPath, const char* mainDef,
gameid_t DD_AddGame(const char* identityKey, const char* dataPath, const char* defsPath,
const char* mainConfig, const char* defaultTitle, const char* defaultAuthor, const char* cmdlineFlag,
const char* cmdlineFlag2);

Expand All @@ -105,7 +104,7 @@ gameid_t DD_AddGame(const char* identityKey, const char* dataPath, const char* d
*
* @param game Unique identifier/name of the game.
* @param rclass Class of resource being added.
* @param rflags Presently unused. Reserved for future use.
* @param rflags @see resourceFlags
* @param names One or more known potential names, seperated by semicolon e.g., "name1;name2".
* Names may include valid absolute, or relative file paths. These paths include
* valid symbolbolic escape tokens, predefined symbols into the virtual file system.
Expand Down
18 changes: 8 additions & 10 deletions doomsday/engine/portable/include/gameinfo.h
Expand Up @@ -36,6 +36,9 @@ typedef struct {
/// Class of resource.
resourceclass_t rclass;

/// @see resourceFlags.
int rflags;

/// List of known potential names. Seperated with a semicolon.
ddstring_t names;

Expand Down Expand Up @@ -77,9 +80,6 @@ typedef struct {
/// The base directory for all defs-class resources.
ddstring_t _defsPath;

/// Name of the main/top-level definition file (e.g., "jdoom.ded").
ddstring_t _mainDef;

/// Name of the main config file (e.g., "jdoom.cfg").
ddstring_t _mainConfig;

Expand All @@ -100,16 +100,15 @@ typedef struct {
* @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.
* @param mainConfig The main config file. Can be @c NULL.
* @param title Default game title.
* @param author Default game author.
* @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, const char* identityKey, const char* dataPath,
const char* defsPath, const ddstring_t* mainDef, const ddstring_t* mainConfig, const char* title,
const char* author, const ddstring_t* cmdlineFlag, const ddstring_t* cmdlineFlag2);
const char* defsPath, const ddstring_t* mainConfig, const char* title, const char* author,
const ddstring_t* cmdlineFlag, const ddstring_t* cmdlineFlag2);

void P_DestroyGameInfo(gameinfo_t* info);

Expand All @@ -119,9 +118,11 @@ void P_DestroyGameInfo(gameinfo_t* info);
* \note Resource registration order defines the order in which resources of each type are loaded.
*
* @param rclass Class of resource being added.
* @param rflags @see resourceFlags.
* @param name Potential resource name.
*/
gameresource_record_t* GameInfo_AddResource(gameinfo_t* info, resourceclass_t rclass, const ddstring_t* name);
gameresource_record_t* GameInfo_AddResource(gameinfo_t* info, resourceclass_t rclass, int rflags,
const ddstring_t* name);

/**
* Accessor methods.
Expand All @@ -138,9 +139,6 @@ const ddstring_t* GameInfo_Title(gameinfo_t* info);
/// @return Ptr to a string containing the default author.
const ddstring_t* GameInfo_Author(gameinfo_t* info);

/// @return Ptr to a string containing the name of the main definition file.
const ddstring_t* GameInfo_MainDef(gameinfo_t* info);

/// @return Ptr to a string containing the name of the main config file.
const ddstring_t* GameInfo_MainConfig(gameinfo_t* info);

Expand Down
39 changes: 23 additions & 16 deletions doomsday/engine/portable/src/dd_main.c
Expand Up @@ -217,11 +217,11 @@ static void destroyPathList(ddstring_t*** list, size_t* listSize)
}

static gameinfo_t* addGameInfoRecord(pluginid_t pluginId, const char* identityKey, const char* dataPath,
const char* defsPath, const ddstring_t* mainDef, const ddstring_t* mainConfig, const char* title,
const char* author, const ddstring_t* cmdlineFlag, const ddstring_t* cmdlineFlag2)
const char* defsPath, const ddstring_t* mainConfig, 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, identityKey, dataPath, defsPath, mainDef, mainConfig, title, author, cmdlineFlag, cmdlineFlag2);
gameInfo[numGameInfo] = P_CreateGameInfo(pluginId, identityKey, dataPath, defsPath, mainConfig, title, author, cmdlineFlag, cmdlineFlag2);
return gameInfo[numGameInfo++];
}

Expand Down Expand Up @@ -305,7 +305,7 @@ void DD_AddGameResource(gameid_t gameId, resourceclass_t rclass, int rflags, con

Str_Init(&name);
{ gameresource_record_t* rec;
if((rec = GameInfo_AddResource(info, rclass, &names)))
if((rec = GameInfo_AddResource(info, rclass, rflags, &names)))
{
if(params)
switch(rec->rclass)
Expand Down Expand Up @@ -338,14 +338,14 @@ void DD_AddGameResource(gameid_t gameId, resourceclass_t rclass, int rflags, con
Str_Free(&names);
}

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

Expand All @@ -359,10 +359,6 @@ gameid_t DD_AddGame(const char* identityKey, const char* _dataPath, const char*
M_TranslatePath(defsPath, _defsPath, FILENAME_T_MAXLEN);
Dir_ValidDir(defsPath, FILENAME_T_MAXLEN);

Str_Init(&mainDef);
if(_mainDef)
Str_Set(&mainDef, _mainDef);

Str_Init(&mainConfig);
if(_mainConfig)
Str_Set(&mainConfig, _mainConfig);
Expand All @@ -387,9 +383,8 @@ gameid_t DD_AddGame(const char* identityKey, const char* _dataPath, const char*
/**
* Looking good. Add this game to our records.
*/
info = addGameInfoRecord(pluginId, identityKey, dataPath, defsPath, &mainDef, &mainConfig, defaultTitle, defaultAuthor, _cmdlineFlag? &cmdlineFlag : 0, _cmdlineFlag2? &cmdlineFlag2 : 0);
info = addGameInfoRecord(pluginId, identityKey, dataPath, defsPath, &mainConfig, defaultTitle, defaultAuthor, _cmdlineFlag? &cmdlineFlag : 0, _cmdlineFlag2? &cmdlineFlag2 : 0);

Str_Free(&mainDef);
Str_Free(&mainConfig);
Str_Free(&cmdlineFlag);
Str_Free(&cmdlineFlag2);
Expand Down Expand Up @@ -497,7 +492,12 @@ static void locateGameResources(gameinfo_t* info)
if((records = GameInfo_Resources(info, (resourceclass_t)i, 0)))
{
for(; *records; records++)
validateGameResource(*records, Str_Text(&(*records)->names));
{
gameresource_record_t* rec = *records;
if(!(rec->rflags & RF_STARTUP))
continue;
validateGameResource(rec, Str_Text(&rec->names));
}
}
}}
Str_Free(&name);
Expand All @@ -524,7 +524,8 @@ static boolean allGameResourcesFound(gameinfo_t* info)
if((records = GameInfo_Resources(info, (resourceclass_t)i, 0)))
do
{
if(Str_Length(&(*records)->path) == 0)
gameresource_record_t* rec = *records;
if((rec->rflags & RF_STARTUP) && Str_Length(&rec->path) == 0)
return false;
} while(*(++records));
}
Expand Down Expand Up @@ -578,7 +579,7 @@ static void printGameInfo(gameinfo_t* info)
Con_Printf(" %s:\n", F_ResourceClassStr((resourceclass_t)i));
do
{
Con_Printf(" %i: \"%s\" > %s\n", n++, Str_Text(&(*records)->names), Str_Length(&(*records)->path) == 0? "--(!)missing" : M_PrettyPath(Str_Text(&(*records)->path)));
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)));
} while(*(++records));
}
}}
Expand Down Expand Up @@ -866,6 +867,12 @@ boolean DD_ChangeGame(gameinfo_t* info)
return false;
}

// If the title finale is in progress, stop it.
if(titleFinale != 0)
{
FI_ScriptTerminate(titleFinale); titleFinale = 0;
}

P_InitMapUpdate();
DAM_Init();

Expand Down Expand Up @@ -994,7 +1001,7 @@ int DD_EarlyInit(void)
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, "null-game", dataPath, defsPath, 0, 0, 0, 0, 0, 0));
currentGameInfoIndex = gameInfoIndex(addGameInfoRecord(0, "null-game", dataPath, defsPath, 0, 0, 0, 0, 0));
}
return true;
}
Expand Down
36 changes: 19 additions & 17 deletions doomsday/engine/portable/src/def_main.c
Expand Up @@ -740,25 +740,27 @@ static void readAllDefinitions(void)
Con_Error("readAllDefinitions: Error, failed to locate main engine definition file \"doomsday.ded\".");
}

// Next the game's main/top-level definition file.
{ const ddstring_t* mainDef;
if((mainDef = GameInfo_MainDef(DD_GameInfo())) && Str_Length(mainDef) != 0)
// Now any definition files required by the game on load.
if(!DD_IsNullGameInfo(DD_GameInfo()))
{
filename_t foundPath;
if(F_FindResource(RC_DEFINITION, foundPath, Str_Text(mainDef), 0, FILENAME_T_MAXLEN))
readDefinitionFile(foundPath);
else
Con_Error("readAllDefinitions: Error, failed to locate main game definition file \"%s\".", Str_Text(mainDef));
}}
gameinfo_t* info = DD_GameInfo();
gameresource_record_t* const* records;
if((records = GameInfo_Resources(info, RC_DEFINITION, 0)))
do
{
gameresource_record_t* rec = *records;
if(Str_Length(&rec->path) == 0)
{
filename_t foundPath;
if(F_FindResource(rec->rclass, foundPath, Str_Text(&rec->names), 0, FILENAME_T_MAXLEN))
Str_Set(&rec->path, foundPath);
}

// Now any extra definition files required by the game.
{ gameresource_record_t* const* records;
if((records = GameInfo_Resources(DD_GameInfo(), RC_DEFINITION, 0)))
do
{
if(Str_Length(&(*records)->path) != 0)
readDefinitionFile(Str_Text(&(*records)->path));
} while(records++);
if(Str_Length(&rec->path) == 0)
Con_Error("readAllDefinitions: Error, failed to locate required game definition file \"%s\".", Str_Text(&rec->names));

readDefinitionFile(Str_Text(&rec->path));
} while(*(++records));
}

// Next up are definition files in the /auto directory.
Expand Down
23 changes: 6 additions & 17 deletions doomsday/engine/portable/src/gameinfo.c
Expand Up @@ -29,8 +29,8 @@
#include "gameinfo.h"

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

Expand All @@ -48,10 +48,6 @@ gameinfo_t* P_CreateGameInfo(pluginid_t pluginId, const char* identityKey, const
if(defsPath)
Str_Set(&info->_defsPath, defsPath);

Str_Init(&info->_mainDef);
if(mainDef)
Str_Copy(&info->_mainDef, mainDef);

Str_Init(&info->_mainConfig);
Str_Init(&info->_bindingConfig);
if(mainConfig)
Expand Down Expand Up @@ -104,7 +100,6 @@ void P_DestroyGameInfo(gameinfo_t* info)
Str_Free(&info->_identityKey);
Str_Free(&info->_dataPath);
Str_Free(&info->_defsPath);
Str_Free(&info->_mainDef);
Str_Free(&info->_mainConfig);
Str_Free(&info->_bindingConfig);
Str_Free(&info->_title);
Expand Down Expand Up @@ -144,21 +139,21 @@ void P_DestroyGameInfo(gameinfo_t* info)
}

gameresource_record_t* GameInfo_AddResource(gameinfo_t* info, resourceclass_t rclass,
const ddstring_t* names)
int rflags, const ddstring_t* names)
{
assert(info && VALID_RESOURCE_CLASS(rclass) && names);
{
gameresource_recordset_t* rset = &info->_requiredResources[rclass];
gameresource_record_t* record;

rset->records = M_Realloc(rset->records, sizeof(*rset->records) * (rset->numRecords+2));
record = rset->records[rset->numRecords] = M_Malloc(sizeof(*record));
record = rset->records[rset->numRecords] = M_Calloc(sizeof(*record));
rset->records[rset->numRecords+1] = 0; // Terminate.
rset->numRecords++;

Str_Init(&record->names); Str_Copy(&record->names, names);
Str_Init(&record->path);
Str_Copy(&record->names, names);
record->rclass = rclass;
record->rflags = rflags;
switch(record->rclass)
{
case RC_PACKAGE:
Expand Down Expand Up @@ -195,12 +190,6 @@ const ddstring_t* GameInfo_DefsPath(gameinfo_t* info)
return &info->_defsPath;
}

const ddstring_t* GameInfo_MainDef(gameinfo_t* info)
{
assert(info);
return &info->_mainDef;
}

const ddstring_t* GameInfo_MainConfig(gameinfo_t* info)
{
assert(info);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/exampleplugin/src/example.c
Expand Up @@ -192,7 +192,7 @@ game_export_t* GetGameAPI(game_import_t* imports)
*/
int ExampleHook(int hookType, int parm, void *data)
{
DD_AddGame(PLUGIN_NAMETEXT, DD_BASEPATH_DATA PLUGIN_NAMETEXT "\\", DD_BASEPATH_DEFS PLUGIN_NAMETEXT "\\", 0, PLUGIN_NAMETEXT ".cfg", PLUGIN_NICENAME, PLUGIN_NICEAUTHOR, PLUGIN_NAMETEXT, 0);
DD_AddGame(PLUGIN_NAMETEXT, DD_BASEPATH_DATA PLUGIN_NAMETEXT "\\", DD_BASEPATH_DEFS PLUGIN_NAMETEXT "\\", PLUGIN_NAMETEXT ".cfg", PLUGIN_NICENAME, PLUGIN_NICEAUTHOR, PLUGIN_NAMETEXT, 0);
return true;
}

Expand Down

0 comments on commit ed08b20

Please sign in to comment.