Skip to content

Commit

Permalink
Refactor: Dumped de::Game's now redundant C wrapper interface
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Feb 12, 2013
1 parent 5863629 commit 3984314
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 250 deletions.
70 changes: 9 additions & 61 deletions doomsday/client/include/game.h
Expand Up @@ -24,10 +24,6 @@
#include "api_plugin.h"
#include <de/ddstring.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
* @defgroup printGameFlags Print Game Flags
* @ingroup flags
Expand All @@ -41,18 +37,12 @@ extern "C" {
#define PGF_EVERYTHING (PGF_BANNER|PGF_STATUS|PGF_LIST_STARTUP_RESOURCES|PGF_LIST_OTHER_RESOURCES)
///@}

struct manifest_s;
struct gamedef_s;

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

#ifdef __cplusplus

#include <de/Error>
#include <QMultiMap>

struct manifest_s;
struct gamedef_s;

namespace de {

class File1;
Expand Down Expand Up @@ -81,10 +71,14 @@ class Game
char const *title = "Unnamed", char const *author = "Unknown");
virtual ~Game();

/// @return Collection in which this game exists.
/**
* Returns the owning Games collection.
*/
Games &collection() const;

/// @return @c true= @a game is the currently active game.
/**
* Returns @a true if the game is currently active in the owning collection.
*/
bool isCurrent() const;

/// @return Unique plugin identifier attributed to that which registered this.
Expand Down Expand Up @@ -223,50 +217,4 @@ inline bool isNullGame(Game const &game) {

} // namespace de

extern "C" {
#endif // __cplusplus

/**
* C wrapper API:
*/

struct game_s; // The game instance (opaque).
typedef struct game_s Game;

Game *Game_New(char const *identityKey, char const *configDir, char const *title, char const *author);

void Game_Delete(Game *game);

boolean Game_IsNullObject(Game const *game);

struct game_s *Game_AddManifest(Game *game, struct manifest_s *manifest);

boolean Game_AllStartupFilesFound(Game const *game);

Game *Game_SetPluginId(Game *game, pluginid_t pluginId);

pluginid_t Game_PluginId(Game const *game);

ddstring_t const *Game_IdentityKey(Game const *game);

ddstring_t const *Game_Title(Game const *game);

ddstring_t const *Game_Author(Game const *game);

ddstring_t const *Game_MainConfig(Game const *game);

ddstring_t const *Game_BindingConfig(Game const *game);

Game *Game_FromDef(GameDef const *def);

void Game_PrintBanner(Game const *game);

void Game_PrintResources(Game const *game, boolean printStatus, int rflags);

void Game_Print(Game const *game, int flags);

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

#endif /* LIBDENG_GAME_H */
48 changes: 14 additions & 34 deletions doomsday/client/src/con_main.cpp
Expand Up @@ -57,12 +57,13 @@
#include "ui/displaymode.h"
#include "ui/busyvisual.h"
#include "cbuffer.h"
#include "Game"

#ifdef __CLIENT__
# include "updater/downloaddialog.h"
#endif

// MACROS ------------------------------------------------------------------
using namespace de;

#define SC_EMPTY_QUOTE -1

Expand Down Expand Up @@ -90,8 +91,6 @@ enum {
: src == CMDS_CMDLINE? "the command line" \
: src == CMDS_SCRIPT? "an action command" : "???")

// TYPES -------------------------------------------------------------------

typedef struct execbuff_s {
boolean used; // Is this in use?
timespan_t when; // System time when to execute the command.
Expand All @@ -101,10 +100,6 @@ typedef struct execbuff_s {
char subCmd[1024]; // A single command w/args.
} execbuff_t;

// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------

// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------

D_CMD(AddSub);
D_CMD(IncDec);
D_CMD(Alias);
Expand All @@ -126,19 +121,13 @@ D_CMD(InspectMobj);
D_CMD(DebugCrash);
D_CMD(DebugError);

// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------

static int executeSubCmd(const char *subCmd, byte src, boolean isNetCmd);
static void Con_SplitIntoSubCommands(const char *command,
timespan_t markerOffset, byte src,
boolean isNetCmd);

static void Con_ClearExecBuffer(void);

// EXTERNAL DATA DECLARATIONS ----------------------------------------------

// PUBLIC DATA DEFINITIONS -------------------------------------------------

int CmdReturnValue = 0;

byte ConsoleSilent = false;
Expand All @@ -151,8 +140,6 @@ byte consoleSnapBackOnPrint = false;

char* prbuff = NULL; // Print buffer, used by conPrintf.

// PRIVATE DATA DEFINITIONS ------------------------------------------------

static CBuffer* histBuf = NULL; // The console history buffer (log).
static uint bLineOff; // How many lines from the last in the histBuf?

Expand Down Expand Up @@ -184,8 +171,6 @@ static void (*consolePrintFilter) (char* text); // Maybe alters text.
static uint complPos; // Where is the completion cursor?
static uint lastCompletion; // The last completed known word match (1-based index).

// CODE --------------------------------------------------------------------

void Con_Register(void)
{
C_CMD("add", NULL, AddSub);
Expand Down Expand Up @@ -1004,11 +989,9 @@ static int executeSubCmd(const char *subCmd, byte src, boolean isNetCmd)
break;
case CVT_URIPTR: {
/// @todo Sanitize and validate against known schemas.
Uri* uri = Uri_NewWithPath2(argptr, RC_NULL);
CVar_SetUri(cvar, uri);
Uri_Delete(uri);
break;
}
de::Uri uri(argptr, RC_NULL);
CVar_SetUri(cvar, reinterpret_cast<uri_s *>(&uri));
break; }
default: break;
}
}
Expand Down Expand Up @@ -1259,8 +1242,8 @@ static int completeWord(int mode)
break;
}
case WT_GAME: {
Game* game = (Game*)(*match)->data;
foundWord = Str_Text(Game_IdentityKey(game));
Game *game = (Game *)(*match)->data;
foundWord = Str_Text(game->identityKey());
if(printCompletions)
Con_FPrintf(CPF_LIGHT|CPF_BLUE, " %s\n", foundWord);
break;
Expand Down Expand Up @@ -1296,7 +1279,7 @@ static int completeWord(int mode)
AutoStr* foundName = CVar_ComposePath((cvar_t*)completeWord->data);
str = Str_Text(foundName);
break; }
case WT_GAME: str = Str_Text(Game_IdentityKey((Game*)completeWord->data)); break;
case WT_GAME: str = Str_Text(reinterpret_cast<Game *>(completeWord->data)->identityKey()); break;
default:
Con_Error("completeWord: Invalid word type %i.", (int)completeWord->type);
exit(1); // Unreachable.
Expand Down Expand Up @@ -2581,9 +2564,8 @@ D_CMD(Font)

if(!stricmp(argv[1], "default"))
{
Uri* uri = Uri_NewWithPath2(R_ChooseFixedFont(), RC_NULL);
fontid_t newFont = Fonts_ResolveUri(uri);
Uri_Delete(uri);
de::Uri uri(R_ChooseFixedFont(), RC_NULL);
fontid_t newFont = Fonts_ResolveUri(reinterpret_cast<uri_s *>(&uri));
if(newFont)
{
Con_SetFont(newFont);
Expand All @@ -2596,20 +2578,18 @@ D_CMD(Font)

if(!stricmp(argv[1], "name") && argc == 3)
{
Uri* uri = Uri_SetUri2(Uri_New(), argv[2], RC_NULL);
fontid_t newFont = Fonts_ResolveUri2(uri, true/*quiet please*/);
Uri_Delete(uri);
de::Uri uri(String(argv[2]), RC_NULL);
fontid_t newFont = Fonts_ResolveUri2(reinterpret_cast<uri_s *>(&uri), true/*quiet please*/);
if(newFont)
{
Uri* uri = Fonts_ComposeUri(newFont);
QScopedPointer<de::Uri> uri(reinterpret_cast<de::Uri *>(Fonts_ComposeUri(newFont)));
Con_SetFont(newFont);
if(!Str_CompareIgnoreCase(Uri_Scheme(uri), "Game"))
if(!uri->scheme().compareWithoutCase("Game"))
{
Con_SetFontScale(1.5f, 2);
Con_SetFontLeading(1.25f);
Con_SetFontTracking(1);
}
Uri_Delete(uri);
return true;
}
Con_Printf("Unknown font '%s'\n", argv[2]);
Expand Down

0 comments on commit 3984314

Please sign in to comment.