Skip to content

Commit

Permalink
Refactor: Moved the Games collection into new source files
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Sep 30, 2012
1 parent 17b366d commit fd8c2de
Show file tree
Hide file tree
Showing 12 changed files with 634 additions and 500 deletions.
4 changes: 2 additions & 2 deletions doomsday/engine/api/doomsday.h
Expand Up @@ -134,7 +134,7 @@ struct font_s;
* @note Game registration order defines the order of the automatic game
* identification/selection logic.
*/
gameid_t DD_DefineGame(const GameDef* definition);
gameid_t DD_DefineGame(GameDef const* definition);

/**
* Retrieves the game identifier for a previously defined game.
Expand All @@ -143,7 +143,7 @@ gameid_t DD_DefineGame(const GameDef* definition);
* @param identityKey Identity key of the game.
* @return Game identifier.
*/
gameid_t DD_GameIdForKey(const char* identityKey);
gameid_t DD_GameIdForKey(char const* identityKey);

/**
* Registers a new resource for the specified game.
Expand Down
2 changes: 2 additions & 0 deletions doomsday/engine/engine.pro
Expand Up @@ -175,6 +175,7 @@ DENG_HEADERS += \
portable/include/dam_file.h \
portable/include/dam_main.h \
portable/include/dd_def.h \
portable/include/dd_games.h \
portable/include/dd_help.h \
portable/include/dd_input.h \
portable/include/dd_loop.h \
Expand Down Expand Up @@ -479,6 +480,7 @@ SOURCES += \
portable/src/con_main.c \
portable/src/dam_file.c \
portable/src/dam_main.c \
portable/src/dd_games.cpp \
portable/src/dd_help.c \
portable/src/dd_init.cpp \
portable/src/dd_input.c \
Expand Down
8 changes: 8 additions & 0 deletions doomsday/engine/portable/include/abstractresource.h
Expand Up @@ -26,6 +26,10 @@

#include "uri.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* AbstractResource. (Record) Stores high-level metadata for a known resource.
*
Expand Down Expand Up @@ -104,4 +108,8 @@ ddstring_t* const* AbstractResource_IdentityKeys(AbstractResource* resource);

Uri* const* AbstractResource_SearchPaths(AbstractResource* resource);

#ifdef __cplusplus
} // extern "C"
#endif

#endif /* LIBDENG_ABSTRACTRESOURCE_H */
131 changes: 131 additions & 0 deletions doomsday/engine/portable/include/dd_games.h
@@ -0,0 +1,131 @@
/**
* @file dd_games.h
*
* The Game collection.
*
* @ingroup core
*
* @author Copyright &copy; 2003-2012 Jaakko Keränen <jaakko.keranen@iki.fi>
* @author Copyright &copy; 2005-2012 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA</small>
*/

#ifndef LIBDENG_GAMES_H
#define LIBDENG_GAMES_H

#include <de/types.h>
#include "game.h"

struct gameinfo_s;
struct gamedef_s;

#ifdef __cplusplus
extern "C" {
#endif

#ifndef WIN32
extern GETGAMEAPI GetGameAPI;
#endif

/// Currently active game.
extern Game* theGame;

/// The special "null-game" object instance.
extern Game* nullGame;

void Games_Shutdown(void);

/// @return Total number of registered games.
int Games_Count(void);

/// @return Number of games marked as currently playable.
int Games_NumPlayable(void);

/**
* @param game Game instance.
* @return Unique identifier associated with @a game.
*/
gameid_t Games_Id(Game* game);

/**
* @return Game associated with unique index @a idx else @c NULL.
*/
Game* Games_ByIndex(int idx);

/**
* @return Game associated with @a identityKey else @c NULL.
*/
Game* Games_ByIdentityKey(char const* identityKey);

/**
* Is this the special "null-game" object (not a real playable game).
* @todo Implement a proper null-game object for this.
*/
boolean Games_IsNullObject(Game const* game);

/// @return The first playable game in the collection according to registration order.
Game* Games_FirstPlayable(void);

/**
* Print a game mode banner with rulers.
*/
void Games_PrintBanner(Game* game);

/**
* Print the list of resources for @a Game.
*
* @param game Game to list resources of.
* @param printStatus @c true= Include the current availability/load status
* of each resource.
* @param rflags Only consider resources whose @ref resourceFlags match
* this value. If @c <0 the flags are ignored.
*/
void Games_PrintResources(Game* game, boolean printStatus, int rflags);

/**
* @defgroup printGameFlags Print Game Flags.
*/
///@{
#define PGF_BANNER 0x1
#define PGF_STATUS 0x2
#define PGF_LIST_STARTUP_RESOURCES 0x4
#define PGF_LIST_OTHER_RESOURCES 0x8

#define PGF_EVERYTHING (PGF_BANNER|PGF_STATUS|PGF_LIST_STARTUP_RESOURCES|PGF_LIST_OTHER_RESOURCES)
///@}

/**
* Print extended information about game @a info.
* @param info Game record to be printed.
* @param flags &see printGameFlags
*/
void Games_Print(Game* game, int flags);

boolean DD_GameInfo(struct gameinfo_s* info);

void DD_AddGameResource(gameid_t gameId, resourceclass_t rclass, int rflags, char const* _names, void* params);

gameid_t DD_DefineGame(struct gamedef_s const* def);

gameid_t DD_GameIdForKey(char const* identityKey);

D_CMD(ListGames);

#ifdef __cplusplus
} // extern "C"
#endif

#endif /* LIBDENG_GAMES_H */
51 changes: 4 additions & 47 deletions doomsday/engine/portable/include/dd_main.h
Expand Up @@ -31,8 +31,7 @@

#include "dd_types.h"
#include "dd_plugin.h"
#ifndef __cplusplus // Kludge: these aren't yet C++ compatible
# include "game.h"
#ifndef __cplusplus // Kludge: this isn't yet C++ compatible
# include "textures.h"
#endif
#include "sys_direc.h"
Expand Down Expand Up @@ -72,16 +71,16 @@ extern finaleid_t titleFinale;
extern GETGAMEAPI GetGameAPI;
#endif

/// Currently active game.
extern struct Game_s* theGame;

int DD_EarlyInit(void);
void DD_FinishInitializationAfterWindowReady(void);
boolean DD_Init(void);

/// @return @c true if shutdown is in progress.
boolean DD_IsShuttingDown(void);

/// @return @c true iff there is presently a game loaded.
boolean DD_GameLoaded(void);

void DD_CheckTimeDemo(void);
void DD_UpdateEngineState(void);

Expand Down Expand Up @@ -121,47 +120,6 @@ materialid_t DD_MaterialForTextureUniqueId(texturenamespaceid_t texNamespaceId,

const char* value_Str(int val);

/// @return @c true iff there is presently a game loaded.
boolean DD_GameLoaded(void);

/// @return Current number of Game records.
int DD_GameCount(void);

/**
* @return Game associated with unique index @a idx else @c NULL.
*/
struct Game_s* DD_GameByIndex(int idx);

/**
* @return Game associated with @a identityKey else @c NULL.
*/
struct Game_s* DD_GameByIdentityKey(const char* identityKey);

/**
* Is this the special "null-game" object (not a real playable game).
* \todo Implement a proper null-game object for this.
*/
boolean DD_IsNullGame(const struct Game_s* game);

/**
* @defgroup printGameFlags Print Game Flags.
* @{
*/
#define PGF_BANNER 0x1
#define PGF_STATUS 0x2
#define PGF_LIST_STARTUP_RESOURCES 0x4
#define PGF_LIST_OTHER_RESOURCES 0x8

#define PGF_EVERYTHING (PGF_BANNER|PGF_STATUS|PGF_LIST_STARTUP_RESOURCES|PGF_LIST_OTHER_RESOURCES)
/**@}*/

/**
* Print extended information about game @a info.
* @param info Game record to be printed.
* @param flags &see printGameFlags
*/
void DD_PrintGame(struct Game_s* game, int flags);

/**
* Frees the info structures for all registered games.
*/
Expand All @@ -171,7 +129,6 @@ D_CMD(Load);
D_CMD(Unload);
D_CMD(Reset);
D_CMD(ReloadGame);
D_CMD(ListGames);

#ifdef __cplusplus
} // extern "C"
Expand Down
1 change: 1 addition & 0 deletions doomsday/engine/portable/include/de_base.h
Expand Up @@ -44,6 +44,7 @@
#include "dd_def.h"
#include "dd_share.h"
#include "dd_api.h"
#include "dd_games.h"
#include "dd_plugin.h"
#include "dd_main.h"
#include "dd_input.h"
Expand Down
2 changes: 2 additions & 0 deletions doomsday/engine/portable/include/game.h
Expand Up @@ -76,6 +76,8 @@ struct AbstractResource_s* Game_AddResource(Game* game, resourceclass_t rclass,
*/
boolean Game_IsRequiredResource(Game* game, const char* absolutePath);

boolean Game_AllStartupResourcesFound(Game* game);

/**
* Change the identfier of the plugin associated with this.
* @param pluginId New identifier.
Expand Down
10 changes: 5 additions & 5 deletions doomsday/engine/portable/src/con_data.c
Expand Up @@ -390,7 +390,7 @@ static void updateKnownWords(void)
PathDirectory_Iterate2_Const(cvarDirectory, PCF_NO_BRANCH, NULL, PATHDIRECTORY_NOHASH, countVariable, &countCVarParams);

// Build the known words table.
numKnownWords = numUniqueNamedCCmds + countCVarParams.count + numCAliases + DD_GameCount();
numKnownWords = numUniqueNamedCCmds + countCVarParams.count + numCAliases + Games_Count();
len = sizeof(knownword_t) * numKnownWords;
knownWords = realloc(knownWords, len);
memset(knownWords, 0, len);
Expand Down Expand Up @@ -430,10 +430,10 @@ static void updateKnownWords(void)
}

// Add games?
gameCount = DD_GameCount();
gameCount = Games_Count();
for(i = 0; i < gameCount; ++i)
{
Game* game = DD_GameByIndex(i+1);
Game* game = Games_ByIndex(i+1);

knownWords[c].type = WT_GAME;
knownWords[c].data = game;
Expand Down Expand Up @@ -1593,10 +1593,10 @@ static void printHelpAbout(const char* query)

if(found == 0) // Perhaps a game?
{
Game* game = DD_GameByIdentityKey(query);
Game* game = Games_ByIdentityKey(query);
if(game)
{
DD_PrintGame(game, PGF_EVERYTHING);
Games_Print(game, PGF_EVERYTHING);
found = true;
}
}
Expand Down

0 comments on commit fd8c2de

Please sign in to comment.