diff --git a/doomsday/apps/api/api_base.h b/doomsday/apps/api/api_base.h index bd352ebdeb..19fe43bd76 100644 --- a/doomsday/apps/api/api_base.h +++ b/doomsday/apps/api/api_base.h @@ -23,45 +23,13 @@ #include #include +#include #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 diff --git a/doomsday/apps/client/include/clientapp.h b/doomsday/apps/client/include/clientapp.h index da236a9dc4..965bfa14cf 100644 --- a/doomsday/apps/client/include/clientapp.h +++ b/doomsday/apps/client/include/clientapp.h @@ -32,7 +32,6 @@ #include "resource/resourcesystem.h" #include "updater.h" #include "busyrunner.h" -#include "Games" #include "world/worldsystem.h" /** @@ -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(); diff --git a/doomsday/apps/client/include/dd_main.h b/doomsday/apps/client/include/dd_main.h index b698e50594..f9f040eb5c 100644 --- a/doomsday/apps/client/include/dd_main.h +++ b/doomsday/apps/client/include/dd_main.h @@ -27,7 +27,7 @@ #include #include #include -#include "Games" +#include #include "resource/resourcesystem.h" #include "world/worldsystem.h" @@ -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). */ diff --git a/doomsday/apps/client/include/de_base.h b/doomsday/apps/client/include/de_base.h index 58454bc44d..0551c79ec5 100644 --- a/doomsday/apps/client/include/de_base.h +++ b/doomsday/apps/client/include/de_base.h @@ -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 #include #include +#include #include #include diff --git a/doomsday/apps/client/include/resource/mapdef.h b/doomsday/apps/client/include/resource/mapdef.h index df2123f4ca..84e0b9edcd 100644 --- a/doomsday/apps/client/include/resource/mapdef.h +++ b/doomsday/apps/client/include/resource/mapdef.h @@ -22,10 +22,10 @@ #include #include +#include #include #include #include -#include "Game" /** * Definition/manifeset for a map asset/resource. diff --git a/doomsday/apps/client/src/clientapp.cpp b/doomsday/apps/client/src/clientapp.cpp index ce608194be..ef9e238f59 100644 --- a/doomsday/apps/client/src/clientapp.cpp +++ b/doomsday/apps/client/src/clientapp.cpp @@ -124,7 +124,6 @@ DENG2_PIMPL(ClientApp) ClientWindowSystem *winSys; InFineSystem infineSys; // instantiated at construction time ServerLink *svLink; - Games games; WorldSystem *worldSys; /** @@ -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() @@ -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") @@ -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(); diff --git a/doomsday/apps/client/src/con_config.cpp b/doomsday/apps/client/src/con_config.cpp index 2e642f4651..89c807bc6e 100644 --- a/doomsday/apps/client/src/con_config.cpp +++ b/doomsday/apps/client/src/con_config.cpp @@ -29,13 +29,12 @@ #include #include #include +#include #include "dd_main.h" #include "dd_def.h" #include "m_misc.h" -#include "Games" - #ifdef __CLIENT__ # include "clientapp.h" diff --git a/doomsday/apps/client/src/dd_main.cpp b/doomsday/apps/client/src/dd_main.cpp index d39f7cf948..26df1b6ee5 100644 --- a/doomsday/apps/client/src/dd_main.cpp +++ b/doomsday/apps/client/src/dd_main.cpp @@ -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(); @@ -1327,7 +1320,7 @@ gameid_t DD_GameIdForKey(char const *identityKey) de::Game &App_CurrentGame() { - return App::game().as(); + return DoomsdayApp::currentGame(); } bool App_ChangeGame(Game &game, bool allowReload) diff --git a/doomsday/apps/client/src/ui/infine/finaleinterpreter.cpp b/doomsday/apps/client/src/ui/infine/finaleinterpreter.cpp index 4f4512a0b9..7c0b000d4c 100644 --- a/doomsday/apps/client/src/ui/infine/finaleinterpreter.cpp +++ b/doomsday/apps/client/src/ui/infine/finaleinterpreter.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include "de_base.h" #include "ui/infine/finaleinterpreter.h" @@ -33,7 +34,6 @@ #include "dd_main.h" #include "dd_def.h" -#include "Game" #include "api_material.h" #include "api_render.h" diff --git a/doomsday/apps/client/src/ui/widgets/gameselectionwidget.cpp b/doomsday/apps/client/src/ui/widgets/gameselectionwidget.cpp index fa917ed3f0..c8aaf52a94 100644 --- a/doomsday/apps/client/src/ui/widgets/gameselectionwidget.cpp +++ b/doomsday/apps/client/src/ui/widgets/gameselectionwidget.cpp @@ -25,9 +25,9 @@ #include "ui/widgets/savedsessionmenuwidget.h" #include "CommandAction" #include "clientapp.h" -#include "games.h" #include "dd_main.h" +#include #include #include #include diff --git a/doomsday/apps/client/src/ui/widgets/tutorialwidget.cpp b/doomsday/apps/client/src/ui/widgets/tutorialwidget.cpp index c516842c64..5f079958a5 100644 --- a/doomsday/apps/client/src/ui/widgets/tutorialwidget.cpp +++ b/doomsday/apps/client/src/ui/widgets/tutorialwidget.cpp @@ -23,6 +23,8 @@ #include "dd_version.h" #include "dd_main.h" +#include + #include #include #include diff --git a/doomsday/apps/client/include/Game b/doomsday/apps/libdoomsday/include/doomsday/Game similarity index 100% rename from doomsday/apps/client/include/Game rename to doomsday/apps/libdoomsday/include/doomsday/Game diff --git a/doomsday/apps/client/include/Games b/doomsday/apps/libdoomsday/include/doomsday/Games similarity index 100% rename from doomsday/apps/client/include/Games rename to doomsday/apps/libdoomsday/include/doomsday/Games diff --git a/doomsday/apps/libdoomsday/include/doomsday/doomsdayapp.h b/doomsday/apps/libdoomsday/include/doomsday/doomsdayapp.h index 0eea33c8a3..74c7641fac 100644 --- a/doomsday/apps/libdoomsday/include/doomsday/doomsdayapp.h +++ b/doomsday/apps/libdoomsday/include/doomsday/doomsdayapp.h @@ -20,6 +20,7 @@ #define LIBDOOMSDAY_DOOMSDAYAPP_H #include "plugins.h" +#include "games.h" #include "busymode.h" #include "gameapi.h" @@ -45,10 +46,17 @@ class LIBDOOMSDAY_PUBLIC DoomsdayApp public: static DoomsdayApp &app(); static Plugins &plugins(); + static de::Games &games(); + static de::Game ¤tGame(); 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 diff --git a/doomsday/apps/client/include/game.h b/doomsday/apps/libdoomsday/include/doomsday/game.h similarity index 84% rename from doomsday/apps/client/include/game.h rename to doomsday/apps/libdoomsday/include/doomsday/game.h index af7dd1f7b3..45874264dd 100644 --- a/doomsday/apps/client/include/game.h +++ b/doomsday/apps/libdoomsday/include/doomsday/game.h @@ -18,19 +18,52 @@ * 02110-1301 USA */ -#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 +#include #include #include #include #include #include -struct manifest_s; -struct gamedef_s; class ResourceManifest; namespace de { @@ -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; @@ -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 */ diff --git a/doomsday/apps/client/include/games.h b/doomsday/apps/libdoomsday/include/doomsday/games.h similarity index 97% rename from doomsday/apps/client/include/games.h rename to doomsday/apps/libdoomsday/include/doomsday/games.h index 971a6af2bd..edad9bac55 100644 --- a/doomsday/apps/client/include/games.h +++ b/doomsday/apps/libdoomsday/include/doomsday/games.h @@ -18,11 +18,10 @@ * 02110-1301 USA */ -#ifndef LIBDENG_GAMES_H -#define LIBDENG_GAMES_H +#ifndef LIBDOOMSDAY_GAMES_H +#define LIBDOOMSDAY_GAMES_H #include "game.h" -#include "dd_share.h" #include #include #include @@ -164,4 +163,4 @@ class Games } // namespace de -#endif // LIBDENG_GAMES_H +#endif // LIBDOOMSDAY_GAMES_H diff --git a/doomsday/apps/libdoomsday/src/doomsdayapp.cpp b/doomsday/apps/libdoomsday/src/doomsdayapp.cpp index 02c0993226..43cd7194dd 100644 --- a/doomsday/apps/libdoomsday/src/doomsdayapp.cpp +++ b/doomsday/apps/libdoomsday/src/doomsdayapp.cpp @@ -38,6 +38,7 @@ static DoomsdayApp *theDoomsdayApp = nullptr; DENG2_PIMPL_NOREF(DoomsdayApp) { Plugins plugins; + Games games; BusyMode busyMode; /// @c true = We are using a custom user dir specified on the command line. @@ -184,6 +185,16 @@ Plugins &DoomsdayApp::plugins() return DoomsdayApp::app().d->plugins; } +Games &DoomsdayApp::games() +{ + return DoomsdayApp::app().d->games; +} + +Game &DoomsdayApp::currentGame() +{ + return App::game().as(); +} + BusyMode &DoomsdayApp::busyMode() { return DoomsdayApp::app().d->busyMode; @@ -200,3 +211,8 @@ void *DoomsdayApp::moduleHandle() const return d->hInstance; } #endif + +bool App_GameLoaded() +{ + return App::appExists() && !DoomsdayApp::currentGame().isNull(); +} diff --git a/doomsday/apps/client/src/game.cpp b/doomsday/apps/libdoomsday/src/game.cpp similarity index 95% rename from doomsday/apps/client/src/game.cpp rename to doomsday/apps/libdoomsday/src/game.cpp index 714bad31e6..189badcbb8 100644 --- a/doomsday/apps/client/src/game.cpp +++ b/doomsday/apps/libdoomsday/src/game.cpp @@ -18,11 +18,12 @@ * 02110-1301 USA */ -#include "de_base.h" -#include "game.h" - -#include -#include +#include "doomsday/game.h" +#include "doomsday/console/cmd.h" +#include "doomsday/filesys/file.h" +#include "doomsday/resource/manifest.h" +#include "doomsday/resource/system.h" +#include "doomsday/doomsdayapp.h" #include #include @@ -103,7 +104,7 @@ bool Game::allStartupFilesFound() const Game::Status Game::status() const { - if(App_GameLoaded() && &App_CurrentGame() == this) + if(App_GameLoaded() && &DoomsdayApp::currentGame() == this) { return Loaded; } @@ -185,7 +186,7 @@ String Game::legacySavegameNameExp() const String Game::legacySavegamePath() const { - NativePath nativeSavePath = App_ResourceSystem().nativeSavePath(); + NativePath nativeSavePath = res::System::get().nativeSavePath(); if(nativeSavePath.isEmpty()) return ""; if(isNull()) return ""; @@ -344,14 +345,14 @@ D_CMD(InspectGame) LOG_WARNING("No game is currently loaded.\nPlease specify the identity-key of the game to inspect."); return false; } - game = &App_CurrentGame(); + game = &DoomsdayApp::currentGame(); } else { String idKey = argv[1]; try { - game = &App_Games().byIdentityKey(idKey); + game = &DoomsdayApp::games().byIdentityKey(idKey); } catch(Games::NotFoundError const &) { diff --git a/doomsday/apps/client/src/games.cpp b/doomsday/apps/libdoomsday/src/games.cpp similarity index 96% rename from doomsday/apps/client/src/games.cpp rename to doomsday/apps/libdoomsday/src/games.cpp index fb954d4de7..6e5c410b24 100644 --- a/doomsday/apps/client/src/games.cpp +++ b/doomsday/apps/libdoomsday/src/games.cpp @@ -18,10 +18,7 @@ * 02110-1301 USA */ -#include "de_base.h" -#include "games.h" - -#include "dd_main.h" +#include "doomsday/games.h" #include #include @@ -37,7 +34,6 @@ namespace de { -/// @todo Belongs in App DENG2_PIMPL(Games) { /// The actual collection. @@ -211,7 +207,8 @@ void Games::add(Game &game) void Games::locateStartupResources(Game &game) { - Game *oldCurrentGame = &App_CurrentGame(); + Game *oldCurrentGame = &DoomsdayApp::currentGame(); + if(oldCurrentGame != &game) { /// @attention Kludge: Temporarily switch Game. @@ -258,7 +255,7 @@ void Games::locateAllResources() { int n = 1; DoomsdayApp::busyMode().runNewTaskWithName( - BUSYF_STARTUP | BUSYF_PROGRESS_BAR | (verbose? BUSYF_CONSOLE_OUTPUT : 0), + BUSYF_STARTUP | BUSYF_PROGRESS_BAR, "Locating game resources...", [this, &n] (void *) { forAll([this, &n] (Game &game) @@ -308,7 +305,7 @@ D_CMD(ListGames) { DENG2_UNUSED3(src, argc, argv); - Games &games = App_Games(); + Games &games = DoomsdayApp::games(); if(!games.count()) { LOG_MSG("No games are currently registered."); @@ -332,7 +329,7 @@ D_CMD(ListGames) DENG2_FOR_EACH_CONST(Games::GameList, i, found) { Game *game = i->game; - bool isCurrent = (&App_CurrentGame() == game); + bool isCurrent = (&DoomsdayApp::currentGame() == game); if(!list.isEmpty()) list += "\n"; diff --git a/doomsday/apps/server/CMakeLists.txt b/doomsday/apps/server/CMakeLists.txt index 2a00b16193..832b928f14 100644 --- a/doomsday/apps/server/CMakeLists.txt +++ b/doomsday/apps/server/CMakeLists.txt @@ -31,7 +31,6 @@ set (SHARED_WITH_CLIENT ${src}/include/color.h ${src}/include/con_config.h ${src}/include/dd_def.h - ${src}/include/games.h ${src}/include/dd_loop.h ${src}/include/dd_main.h ${src}/include/dd_pinit.h @@ -44,7 +43,6 @@ set (SHARED_WITH_CLIENT ${src}/include/def_main.h ${src}/include/edit_map.h ${src}/include/face.h - ${src}/include/game.h ${src}/include/hedge.h ${src}/include/m_decomp64.h ${src}/include/m_misc.h @@ -131,13 +129,11 @@ set (SHARED_WITH_CLIENT ${src}/src/audio/s_main.cpp ${src}/src/color.cpp ${src}/src/con_config.cpp - ${src}/src/games.cpp ${src}/src/dd_loop.cpp ${src}/src/dd_main.cpp ${src}/src/dd_pinit.cpp ${src}/src/def_main.cpp ${src}/src/face.cpp - ${src}/src/game.cpp ${src}/src/hedge.cpp ${src}/src/m_decomp64.cpp ${src}/src/m_misc.cpp diff --git a/doomsday/apps/server/include/serverapp.h b/doomsday/apps/server/include/serverapp.h index 07c0155233..e126334321 100644 --- a/doomsday/apps/server/include/serverapp.h +++ b/doomsday/apps/server/include/serverapp.h @@ -22,10 +22,10 @@ #include #include +#include #include "serversystem.h" #include "ui/infine/infinesystem.h" #include "resource/resourcesystem.h" -#include "Games" #include "world/worldsystem.h" /** @@ -48,7 +48,6 @@ class ServerApp : public de::TextApp, public DoomsdayApp static ServerSystem &serverSystem(); static InFineSystem &infineSystem(); static ResourceSystem &resourceSystem(); - static de::Games &games(); static de::WorldSystem &worldSystem(); private: diff --git a/doomsday/apps/server/src/serverapp.cpp b/doomsday/apps/server/src/serverapp.cpp index aa1c57151e..fe79cf032a 100644 --- a/doomsday/apps/server/src/serverapp.cpp +++ b/doomsday/apps/server/src/serverapp.cpp @@ -54,7 +54,6 @@ DENG2_PIMPL(ServerApp) , DENG2_OBSERVES(Plugins, PublishAPI) { QScopedPointer serverSystem; - Games games; QScopedPointer resourceSys; WorldSystem worldSys; InFineSystem infineSys; @@ -127,7 +126,7 @@ ServerApp::ServerApp(int &argc, char **argv) //addSystem(d->infineSys); // We must presently set the current game manually (the collection is global). - setGame(d->games.nullGame()); + setGame(games().nullGame()); } ServerApp::~ServerApp() @@ -207,11 +206,6 @@ ResourceSystem &ServerApp::resourceSystem() return *app().d->resourceSys; } -Games &ServerApp::games() -{ - return app().d->games; -} - WorldSystem &ServerApp::worldSystem() { return app().d->worldSys; diff --git a/doomsday/apps/server/src/shelluser.cpp b/doomsday/apps/server/src/shelluser.cpp index c405939b44..2fabe3614a 100644 --- a/doomsday/apps/server/src/shelluser.cpp +++ b/doomsday/apps/server/src/shelluser.cpp @@ -26,12 +26,11 @@ #include #include #include +#include #include "api_console.h" #include "dd_main.h" -#include "games.h" -#include "Game" #include "network/net_main.h" #include "world/map.h" #include "world/p_object.h"