Skip to content

Commit

Permalink
Refactor: Moved Games and Game to libdoomsday
Browse files Browse the repository at this point in the history
The Games instance is now owned by DoomsdayApp.
  • Loading branch information
skyjake committed Jul 23, 2015
1 parent c145078 commit 083acf1
Show file tree
Hide file tree
Showing 23 changed files with 102 additions and 124 deletions.
34 changes: 1 addition & 33 deletions doomsday/apps/api/api_base.h
Expand Up @@ -23,45 +23,13 @@

#include <de/str.h>
#include <doomsday/resource/resourceclass.h>
#include <doomsday/game.h>
#include "apis.h"
#include "api_uri.h"

/// @addtogroup game
/// @{

/**
* 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).
*/
char const *identityKey;

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

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

/*
* Used when converting legacy savegames:
*/
char const *legacySavegameNameExp;
char const *legacySavegameSubfolder;

/// Primary MAPINFO definition dat, if any (translated during game init).
char const *mainMapInfo;
} GameDef;

/**
* Extended info about a registered game component.
* @see DD_GameInfo() @ingroup game
Expand Down
2 changes: 0 additions & 2 deletions doomsday/apps/client/include/clientapp.h
Expand Up @@ -32,7 +32,6 @@
#include "resource/resourcesystem.h"
#include "updater.h"
#include "busyrunner.h"
#include "Games"
#include "world/worldsystem.h"

/**
Expand Down Expand Up @@ -76,7 +75,6 @@ class ClientApp : public de::BaseGuiApp, public DoomsdayApp
static ClientWindowSystem &windowSystem();
static RenderSystem &renderSystem();
static ResourceSystem &resourceSystem();
static de::Games &games();
static de::WorldSystem &worldSystem();

static bool hasInputSystem();
Expand Down
7 changes: 1 addition & 6 deletions doomsday/apps/client/include/dd_main.h
Expand Up @@ -27,7 +27,7 @@
#include <doomsday/resource/resourceclass.h>
#include <doomsday/gameapi.h>
#include <doomsday/plugins.h>
#include "Games"
#include <doomsday/Games>

#include "resource/resourcesystem.h"
#include "world/worldsystem.h"
Expand Down Expand Up @@ -87,11 +87,6 @@ void DD_UpdateEngineState();
*/
bool App_ChangeGame(de::Game &game, bool allowReload = false);

/**
* Returns @c true if a game module is presently loaded.
*/
dd_bool App_GameLoaded();

/**
* Returns the application's global Games (collection).
*/
Expand Down
3 changes: 2 additions & 1 deletion doomsday/apps/client/include/de_base.h
Expand Up @@ -34,16 +34,17 @@

#include "dd_def.h"
#include "dd_share.h"
#include "games.h"
#include "dd_main.h"
#include "dd_loop.h"
#include "busyrunner.h"
#include "ui/ddevent.h"
#include "ui/nativeui.h"
#include "ui/zonedebug.h"

#include <doomsday/library.h>
#include <doomsday/gameapi.h>
#include <doomsday/plugins.h>
#include <doomsday/games.h>
#include <doomsday/uri.h>
#include <doomsday/help.h>

Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/include/resource/mapdef.h
Expand Up @@ -22,10 +22,10 @@

#include <doomsday/filesys/file.h>
#include <doomsday/filesys/lumpindex.h>
#include <doomsday/Game>
#include <de/PathTree>
#include <de/Record>
#include <de/String>
#include "Game"

/**
* Definition/manifeset for a map asset/resource.
Expand Down
10 changes: 2 additions & 8 deletions doomsday/apps/client/src/clientapp.cpp
Expand Up @@ -124,7 +124,6 @@ DENG2_PIMPL(ClientApp)
ClientWindowSystem *winSys;
InFineSystem infineSys; // instantiated at construction time
ServerLink *svLink;
Games games;
WorldSystem *worldSys;

/**
Expand Down Expand Up @@ -206,7 +205,7 @@ DENG2_PIMPL(ClientApp)
LogBuffer::get().addSink(logAlarm);
DoomsdayApp::plugins().audienceForPublishAPI() += this;
DoomsdayApp::plugins().audienceForNotification() += this;
games.audienceForProgress() += this;
self.games().audienceForProgress() += this;
}

~Instance()
Expand Down Expand Up @@ -347,7 +346,7 @@ ClientApp::ClientApp(int &argc, char **argv)
setTerminateFunc(handleLegacyCoreTerminate);

// We must presently set the current game manually (the collection is global).
setGame(d->games.nullGame());
setGame(games().nullGame());

d->binder.init(scriptSystem().nativeModule("App"))
<< DENG2_FUNC_NOARG (App_GamePlugin, "gamePlugin")
Expand Down Expand Up @@ -578,11 +577,6 @@ ClientWindowSystem &ClientApp::windowSystem()
return *a.d->winSys;
}

Games &ClientApp::games()
{
return app().d->games;
}

WorldSystem &ClientApp::worldSystem()
{
ClientApp &a = ClientApp::app();
Expand Down
3 changes: 1 addition & 2 deletions doomsday/apps/client/src/con_config.cpp
Expand Up @@ -29,13 +29,12 @@
#include <doomsday/console/knownword.h>
#include <doomsday/filesys/fs_main.h>
#include <doomsday/filesys/fs_util.h>
#include <doomsday/Games>

#include "dd_main.h"
#include "dd_def.h"
#include "m_misc.h"

#include "Games"

#ifdef __CLIENT__
# include "clientapp.h"

Expand Down
9 changes: 1 addition & 8 deletions doomsday/apps/client/src/dd_main.cpp
Expand Up @@ -1212,13 +1212,6 @@ de::Games &App_Games()
throw Error("App_Games", "App not yet initialized");
}

dd_bool App_GameLoaded()
{
if(!App::appExists()) return false;

return !App_CurrentGame().isNull();
}

void App_ClearGames()
{
App_Games().clear();
Expand Down Expand Up @@ -1327,7 +1320,7 @@ gameid_t DD_GameIdForKey(char const *identityKey)

de::Game &App_CurrentGame()
{
return App::game().as<de::Game>();
return DoomsdayApp::currentGame();
}

bool App_ChangeGame(Game &game, bool allowReload)
Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/ui/infine/finaleinterpreter.cpp
Expand Up @@ -24,6 +24,7 @@
#include <doomsday/doomsdayapp.h>
#include <doomsday/console/cmd.h>
#include <doomsday/console/exec.h>
#include <doomsday/Game>

#include "de_base.h"
#include "ui/infine/finaleinterpreter.h"
Expand All @@ -33,7 +34,6 @@

#include "dd_main.h"
#include "dd_def.h"
#include "Game"

#include "api_material.h"
#include "api_render.h"
Expand Down
Expand Up @@ -25,9 +25,9 @@
#include "ui/widgets/savedsessionmenuwidget.h"
#include "CommandAction"
#include "clientapp.h"
#include "games.h"
#include "dd_main.h"

#include <doomsday/games.h>
#include <de/MenuWidget>
#include <de/SequentialLayout>
#include <de/FoldPanelWidget>
Expand Down
2 changes: 2 additions & 0 deletions doomsday/apps/client/src/ui/widgets/tutorialwidget.cpp
Expand Up @@ -23,6 +23,8 @@
#include "dd_version.h"
#include "dd_main.h"

#include <doomsday/doomsdayapp.h>

#include <de/MessageDialog>
#include <de/SignalAction>
#include <de/Untrapper>
Expand Down
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions doomsday/apps/libdoomsday/include/doomsday/doomsdayapp.h
Expand Up @@ -20,6 +20,7 @@
#define LIBDOOMSDAY_DOOMSDAYAPP_H

#include "plugins.h"
#include "games.h"
#include "busymode.h"
#include "gameapi.h"

Expand All @@ -45,10 +46,17 @@ class LIBDOOMSDAY_PUBLIC DoomsdayApp
public:
static DoomsdayApp &app();
static Plugins &plugins();
static de::Games &games();
static de::Game &currentGame();
static BusyMode &busyMode();

private:
DENG2_PRIVATE(d)
};

/**
* Returns @c true if a game module is presently loaded.
*/
LIBDOOMSDAY_PUBLIC bool App_GameLoaded();

#endif // LIBDOOMSDAY_DOOMSDAYAPP_H
Expand Up @@ -18,19 +18,52 @@
* 02110-1301 USA</small>
*/

#ifndef DENG_GAME_H
#define DENG_GAME_H
#ifndef LIBDOOMSDAY_GAME_H
#define LIBDOOMSDAY_GAME_H

/**
* 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).
*/
char const *identityKey;

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

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

/*
* Used when converting legacy savegames:
*/
char const *legacySavegameNameExp;
char const *legacySavegameSubfolder;

/// Primary MAPINFO definition dat, if any (translated during game init).
char const *mainMapInfo;
} GameDef;

#ifdef __cplusplus

#include "api_base.h"
#include <doomsday/plugins.h>
#include <doomsday/resource/resourceclass.h>
#include <de/Error>
#include <de/Path>
#include <de/String>
#include <de/game/Game>
#include <QMultiMap>

struct manifest_s;
struct gamedef_s;
class ResourceManifest;

namespace de {
Expand Down Expand Up @@ -159,7 +192,7 @@ class Game : public de::game::Game
*
* @param manifest Manifest to add.
*/
void addManifest(ResourceManifest &manifest);
virtual void addManifest(ResourceManifest &manifest);

bool allStartupFilesFound() const;

Expand Down Expand Up @@ -232,27 +265,13 @@ class NullGame : public Game
public:
NullGame();

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

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

bool allStartupFilesFound() const {
return true; // Always.
}

struct manifest_s *const *manifests(resourceclassid_t /*classId*/, int * /*count*/) const {
return 0;
}

static Game *fromDef(GameDef const & /*def*/) {
throw NullObjectError("NullGame::fromDef", "Not valid for null-object");
}
};

} // namespace de

#endif /* DENG_GAME_H */
#endif // __cplusplus

#endif /* LIBDOOMSDAY_GAME_H */
Expand Up @@ -18,11 +18,10 @@
* 02110-1301 USA</small>
*/

#ifndef LIBDENG_GAMES_H
#define LIBDENG_GAMES_H
#ifndef LIBDOOMSDAY_GAMES_H
#define LIBDOOMSDAY_GAMES_H

#include "game.h"
#include "dd_share.h"
#include <de/types.h>
#include <de/str.h>
#include <de/Observers>
Expand Down Expand Up @@ -164,4 +163,4 @@ class Games

} // namespace de

#endif // LIBDENG_GAMES_H
#endif // LIBDOOMSDAY_GAMES_H

0 comments on commit 083acf1

Please sign in to comment.