Skip to content

Commit

Permalink
Cleanup: Implemented GameDef
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Dec 29, 2011
1 parent 4c744ea commit 3289b2a
Show file tree
Hide file tree
Showing 10 changed files with 193 additions and 233 deletions.
29 changes: 29 additions & 0 deletions doomsday/engine/api/dd_share.h
Expand Up @@ -319,6 +319,35 @@ enum {
//
//------------------------------------------------------------------------

/**
* GameDef. Record (POD) structure for use with DD_DefineGame, to define
* the numerous high-level properties of a logical game component.
*/
typedef struct GameDef_s {
/**
* 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).
*/
const char* identityKey;

/// The base directory for all data-class resources.
const char* dataPath;

/// The base directory for all defs-class resources.
const char* defsPath;

/// The name of the main config file. Can be @c NULL
const char* mainConfig;

/// Default title. May be overridden later.
const char* defaultTitle;

/// Default author. May be overridden later.
/// Used for (e.g.) the map author name if not specified in a Map Info definition.
const char* defaultAuthor;
} GameDef;

/**
* Extended info about a registered game component.
* Used with DD_GameInfo.
Expand Down
7 changes: 3 additions & 4 deletions doomsday/engine/api/doomsday.def
Expand Up @@ -3,7 +3,7 @@
; Highest ordinal is currently: --> 702 <--
; Other free ordinals:
;
; 126 formerly DGL_DrawRawScreen
; 7, 126

NAME "DOOMSDAY"

Expand All @@ -14,10 +14,9 @@ EXPORTS
Plug_CheckForHook @3 NONAME

; Base.
DD_AddGame @4 NONAME
DD_DefineGame @4 NONAME
DD_AddGameResource @5 NONAME
DD_GameInfo @6 NONAME
DD_GetGameInfo2 @7 NONAME
DD_GameInfo @6 NONAME
DD_GetInteger @8 NONAME
DD_SetInteger @9 NONAME
DD_SetVariable @10 NONAME
Expand Down
35 changes: 8 additions & 27 deletions doomsday/engine/api/doomsday.h
Expand Up @@ -85,32 +85,21 @@ struct font_s;
//------------------------------------------------------------------------

/**
* Registers a new game.
* Register a new game.
*
* \note Game registration order defines the order of the automatic game identification/selection logic.
* \note Game registration order defines the order of the automatic game
* identification/selection logic.
*
* @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 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
* if not specified in a Map Info definition.
* @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.
* @param definition GameDef structure defining the new game.
* @return Unique identifier/name assigned to resultant game.
*/
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);
gameid_t DD_DefineGame(const GameDef* definition);

/**
* Registers a new resource for the specified game.
*
* \note Resource registration order defines the load order of resources (among those of the same type).
* \note Resource registration order defines the load order of resources
* (among those of the same type).
*
* @param game Unique identifier/name of the game.
* @param rclass Class of resource being added.
Expand All @@ -121,14 +110,6 @@ gameid_t DD_AddGame(const char* identityKey, const char* dataPath, const char* d
*/
void DD_AddGameResource(gameid_t game, resourceclass_t rclass, int rflags, const char* names, void* params);

/**
* Retrieve extended info about the specified game.
*
* @param game Unique identifier/name of the game.
* @param info Info structure to be populated.
*/
void DD_GetGameInfo2(gameid_t game, ddgameinfo_t* info);

/**
* Retrieve extended info about the current game.
*
Expand Down
31 changes: 16 additions & 15 deletions doomsday/engine/portable/include/gameinfo.h
Expand Up @@ -27,6 +27,7 @@
#include "dd_string.h"

struct resourcerecord_s;
struct GameDef;

typedef struct {
struct resourcerecord_s** records;
Expand Down Expand Up @@ -65,29 +66,23 @@ typedef struct {
/// Name of the file used for control bindings, set automatically at creation time.
ddstring_t _bindingConfig;

/// Command-line selection flags.
ddstring_t* _cmdlineFlag, *_cmdlineFlag2;

/// Vector of records for required game resources (e.g., doomu.wad).
resourcerecordset_t _requiredResources[RESOURCECLASS_COUNT];
} gameinfo_t;

/**
* Construct a new GameInfo instance.
*
* @param pluginId Unique identifier of the plugin to associate with this game.
* @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 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* GameInfo_New(pluginid_t pluginId, const char* identityKey, const ddstring_t* dataPath,
const ddstring_t* defsPath, const char* mainConfig, const char* title, const char* author,
const ddstring_t* cmdlineFlag, const ddstring_t* cmdlineFlag2);
gameinfo_t* GameInfo_New(const char* identityKey, const ddstring_t* dataPath,
const ddstring_t* defsPath, const char* mainConfig, const char* title,
const char* author);

void GameInfo_Delete(gameinfo_t* info);

Expand All @@ -103,6 +98,13 @@ void GameInfo_Delete(gameinfo_t* info);
struct resourcerecord_s* GameInfo_AddResource(gameinfo_t* info,
resourceclass_t rclass, struct resourcerecord_s* record);

/**
* Change the identfier of the plugin associated with this.
* @param pluginId New identifier.
* @return Same as @a pluginId for convenience.
*/
pluginid_t GameInfo_SetPluginId(gameinfo_t* info, pluginid_t pluginId);

/**
* Accessor methods.
*/
Expand All @@ -124,12 +126,6 @@ const ddstring_t* GameInfo_MainConfig(gameinfo_t* info);
/// @return String containing the name of the binding config file.
const ddstring_t* GameInfo_BindingConfig(gameinfo_t* info);

/// @return String containing command line (name) flag.
const ddstring_t* GameInfo_CmdlineFlag(gameinfo_t* info);

/// @return String containing command line (name) flag2.
const ddstring_t* GameInfo_CmdlineFlag2(gameinfo_t* info);

/**
* Retrieve a subset of the resource collection associated with this.
*
Expand All @@ -155,4 +151,9 @@ const ddstring_t* GameInfo_DataPath(gameinfo_t* info);
*/
const ddstring_t* GameInfo_DefsPath(gameinfo_t* info);

/**
* Static non-members:
*/
gameinfo_t* GameInfo_FromDef(const GameDef* def);

#endif /* LIBDENG_GAMEINFO_H */

0 comments on commit 3289b2a

Please sign in to comment.