Skip to content

Commit

Permalink
Refactor|Game: Game now uses de::String and de::Path to represent att…
Browse files Browse the repository at this point in the history
…ributes
  • Loading branch information
danij-deng committed Jan 4, 2014
1 parent 5a0dffc commit 33d4b98
Show file tree
Hide file tree
Showing 27 changed files with 264 additions and 296 deletions.
35 changes: 18 additions & 17 deletions doomsday/api/api_base.h
Expand Up @@ -21,6 +21,7 @@
#ifndef DOOMSDAY_API_BASE_H
#define DOOMSDAY_API_BASE_H

#include <de/str.h>
#include "apis.h"
#include "api_uri.h"
#include "api_resourceclass.h"
Expand All @@ -29,37 +30,37 @@
/// @{

/**
* Defines the numerous high-level properties of a logical game component.
* Note that this is POD; no construction or destruction is needed.
* Defines the high-level properties of a logical game component. Note that this
* is POD; no construction or destruction is needed.
* @see DD_DefineGame() @ingroup game
*/
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;
char const *identityKey;

/// Name of the config directory.
const char* configDir;
char const *configDir;

/// Default title. May be overridden later.
const char* defaultTitle;
char const *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;
char const *defaultAuthor;
} GameDef;

/**
* Extended info about a registered game component.
* @see DD_GameInfo() @ingroup game
*/
typedef struct gameinfo_s {
const char* title;
const char* author;
const char* identityKey;
AutoStr *title;
AutoStr *author;
AutoStr *identityKey;
} GameInfo;

/// @}
Expand All @@ -73,8 +74,8 @@ DENG_API_TYPEDEF(Base) // v1

int (*GetInteger)(int ddvalue);
void (*SetInteger)(int ddvalue, int parm);
void* (*GetVariable)(int ddvalue);
void (*SetVariable)(int ddvalue, void* ptr);
void *(*GetVariable)(int ddvalue);
void (*SetVariable)(int ddvalue, void *ptr);

/**
* Register a new game.
Expand All @@ -86,7 +87,7 @@ DENG_API_TYPEDEF(Base) // v1
* @note Game registration order defines the order of the automatic game
* identification/selection logic.
*/
gameid_t (*DefineGame)(GameDef const* definition);
gameid_t (*DefineGame)(GameDef const *definition);

/**
* Retrieves the game identifier for a previously defined game.
Expand All @@ -96,7 +97,7 @@ DENG_API_TYPEDEF(Base) // v1
*
* @return Game identifier.
*/
gameid_t (*GameIdForKey)(char const* identityKey);
gameid_t (*GameIdForKey)(char const *identityKey);

/**
* Adds a new resource to the list for the identified @a game.
Expand All @@ -118,7 +119,7 @@ DENG_API_TYPEDEF(Base) // v1
* semicolon delimited list of identity keys.
*/
void (*AddGameResource)(gameid_t game, resourceclassid_t classId, int fFlags,
const char* names, void* params);
char const *names, void *params);

/**
* Retrieve extended info about the current game.
Expand All @@ -127,7 +128,7 @@ DENG_API_TYPEDEF(Base) // v1
*
* @return @c true if successful else @c false (i.e., no game loaded).
*/
boolean (*gameInfo)(GameInfo* info);
boolean (*gameInfo)(GameInfo *info);

/**
* Determines whether the current run of the thinkers should be considered a
Expand All @@ -151,7 +152,7 @@ DENG_API_TYPEDEF(Base) // v1
* @param data Data of the packet.
* @param length Length of the data.
*/
void (*SendPacket)(int to_player, int type, const void* data, size_t length);
void (*SendPacket)(int to_player, int type, void const *data, size_t length);

/**
* To be called by the game after loading a save state to instruct the engine
Expand Down
7 changes: 6 additions & 1 deletion doomsday/client/include/client/cl_def.h
Expand Up @@ -45,7 +45,12 @@ void Cl_CleanUp(void);
void Cl_GetPackets(void);
void Cl_Ticker(timespan_t ticLength);
int Cl_GameReady(void);
void Cl_SendHello(void);

/**
* Sends a hello packet.
* PCL_HELLO2 includes the Game ID (16 chars).
*/
void Cl_SendHello();

#ifdef __cplusplus
} // extern "C"
Expand Down
46 changes: 27 additions & 19 deletions doomsday/client/include/game.h
Expand Up @@ -21,12 +21,12 @@
#ifndef DENG_GAME_H
#define DENG_GAME_H

#include <QMultiMap>

#include "api_plugin.h"
#include <de/ddstring.h>
#include <de/Error>
#include <de/Path>
#include <de/String>
#include <de/game/Game>
#include <QMultiMap>

/**
* @defgroup printGameFlags Print Game Flags
Expand Down Expand Up @@ -64,31 +64,39 @@ class Game : public de::game::Game
/**
* @param identityKey Unique game mode key/identifier, 16 chars max (e.g., "doom1-ultimate").
* @param configDir Name of the config directory.
* @param title Default game title.
* @param author Default game author.
*/
Game(char const *identityKey, char const *configDir,
char const *title = "Unnamed", char const *author = "Unknown");
Game(String const &identityKey, Path const &configDir,
String const &title = "Unnamed", String const &author = "Unknown");

virtual ~Game();

/// @return Unique plugin identifier attributed to that which registered this.
pluginid_t pluginId() const;

/// @return String containing the identity key.
ddstring_t const *identityKey() const;
/**
* Returns the unique identity key of the game.
*/
de::String const &identityKey() const;

/// @return String containing the default title.
ddstring_t const *title() const;
/**
* Returns the title of the game, as text.
*/
de::String const &title() const;

/// @return String containing the default author.
ddstring_t const *author() const;
/**
* Returns the author of the game, as text.
*/
de::String const &author() const;

/// @return String containing the name of the main config file.
ddstring_t const *mainConfig() const;
/**
* Returns the name of the main config file for the game.
*/
de::Path const &mainConfig() const;

/// @return String containing the name of the binding config file.
ddstring_t const *bindingConfig() const;
/**
* Returns the name of the binding config file for the game.
*/
de::Path const &bindingConfig() const;

/**
* Change the identfier of the plugin associated with this.
Expand Down Expand Up @@ -180,11 +188,11 @@ class NullGame : public Game
public:
NullGame();

Game& addManifest(struct manifest_s& /*record*/) {
Game &addManifest(struct manifest_s & /*record*/) {
throw NullObjectError("NullGame::addResource", "Invalid action on null-object");
}

bool isRequiredResource(char const* /*absolutePath*/) {
bool isRequiredResource(char const * /*absolutePath*/) {
return false; // Never.
}

Expand Down
41 changes: 14 additions & 27 deletions doomsday/client/include/games.h
@@ -1,7 +1,7 @@
/** @file games.h Specialized collection for a set of logical Games.
/** @file games.h Specialized collection for a set of logical Games.
*
* @authors Copyright &copy; 2012-2013 Daniel Swanson <danij@dengine.net>
* @authors Copyright &copy; 2012-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2012-2013 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 2012-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
Expand Down Expand Up @@ -48,31 +48,24 @@ class Games
{
Game *game;

GameListItem(Game *_game = 0) : game(_game)
GameListItem(Game *game = 0) : game(game)
{}

/// @return @c true= this game's title is lexically less than that of @a other.
bool operator < (GameListItem const &other) const
{
return Str_CompareIgnoreCase(game->title(), Str_Text(other.game->title())) < 0;
bool operator < (GameListItem const &other) const {
return game->title().compareWithoutCase(other.game->title()) < 0;
}
};
typedef QList<GameListItem> GameList;

/// Game instances.
typedef QList<GameListItem> GameList;
typedef QList<Game *> All;

/**
* Notified when a new game is added.
*/
/// Notified when a new game is added.
DENG2_DEFINE_AUDIENCE(Addition, void gameAdded(Game &game))

public:
Games();

/// Register the console commands, variables, etc..., of this module.
static void consoleRegister();

/// @return The special "null" Game instance.
Game &nullGame() const;

Expand All @@ -93,7 +86,7 @@ class Games
*
* @throws NotFoundError if no game is associated with @a identityKey.
*/
Game &byIdentityKey(char const *identityKey) const;
Game &byIdentityKey(String identityKey) const;

/**
* @return Game associated with @a gameId.
Expand Down Expand Up @@ -148,20 +141,14 @@ class Games
*/
void locateStartupResources(Game &game);

public:
/// Register the console commands, variables, etc..., of this module.
static void consoleRegister();

private:
DENG2_PRIVATE(d)
};

} // namespace de

#ifdef __cplusplus
extern "C" {
#endif

D_CMD(ListGames);

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

#endif /* LIBDENG_GAMES_H */
#endif // LIBDENG_GAMES_H
12 changes: 3 additions & 9 deletions doomsday/client/src/client/cl_main.cpp
Expand Up @@ -102,20 +102,14 @@ void Cl_CleanUp()
GL_SetFilter(false);
}

/**
* Sends a hello packet.
* PCL_HELLO2 includes the Game ID (16 chars).
*/
void Cl_SendHello(void)
void Cl_SendHello()
{
char buf[256];

Msg_Begin(PCL_HELLO2);
Writer_WriteUInt32(msgWriter, clientID);

// The game mode is included in the hello packet.
memset(buf, 0, sizeof(buf));
strncpy(buf, Str_Text(App_CurrentGame().identityKey()), sizeof(buf) - 1);
char buf[256]; zap(buf);
strncpy(buf, App_CurrentGame().identityKey().toUtf8().constData(), sizeof(buf) - 1);

#ifdef _DEBUG
Con_Message("Cl_SendHello: game mode = %s", buf);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/con_config.cpp
Expand Up @@ -275,7 +275,7 @@ boolean Con_WriteState(const char* fileName, const char* bindingsFileName)
void Con_SaveDefaults()
{
Con_WriteState(cfgFile, (!isDedicated && App_GameLoaded()?
Str_Text(App_CurrentGame().bindingConfig()) : 0));
App_CurrentGame().bindingConfig().toUtf8().constData() : 0));
}

D_CMD(WriteConsole)
Expand Down

0 comments on commit 33d4b98

Please sign in to comment.