Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
libdoomsday: Built-in game profiles; load packages in profiles
The packages specified in game profiles are now loaded when a game
is loaded.
  • Loading branch information
skyjake committed Mar 8, 2016
1 parent 7f8ec2c commit 7dfb3ca
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 33 deletions.
Expand Up @@ -65,7 +65,7 @@ DENG_GUI_PIMPL(SingleplayerSessionMenuWidget)

void setDataFiles(StringList const &paths)
{
game->setUserFiles(paths);
//game->setUserFiles(paths);
owner->updateItemLabels();
}
};
Expand Down Expand Up @@ -137,10 +137,10 @@ DENG_GUI_PIMPL(SingleplayerSessionMenuWidget)
.arg(game.title())
.arg(game.id());

if(!game.userFiles().isEmpty())
/*if(!game.userFiles().isEmpty())
{
label += _E(b) " +" + QString::number(game.userFiles().size());
}
}*/
return label;
}

Expand Down Expand Up @@ -168,9 +168,9 @@ DENG_GUI_PIMPL(SingleplayerSessionMenuWidget)

void updateWidgetAction(GameItem const &item)
{
self.itemWidget<GameSessionWidget>(item).
/*self.itemWidget<GameSessionWidget>(item).
setDataFileAction(item.game.userFiles().isEmpty()? GameSessionWidget::Select :
GameSessionWidget::Clear);
GameSessionWidget::Clear);*/
}

void updateWidgetWithGameStatus(ui::Item const &menuItem)
Expand Down
1 change: 1 addition & 0 deletions doomsday/apps/libdoomsday/include/doomsday/DoomsdayApp
@@ -0,0 +1 @@
#include "doomsdayapp.h"
4 changes: 3 additions & 1 deletion doomsday/apps/libdoomsday/include/doomsday/doomsdayapp.h
Expand Up @@ -32,8 +32,9 @@

namespace res { class Bundles; }

class Games;
class Game;
class Games;
class GameProfiles;

/**
* Common application-level state and components.
Expand Down Expand Up @@ -121,6 +122,7 @@ class LIBDOOMSDAY_PUBLIC DoomsdayApp
static res::Bundles &bundles();
static Plugins &plugins();
static Games &games();
static GameProfiles &gameProfiles();
static Players &players();
static BusyMode &busyMode();
static de::NativePath steamBasePath();
Expand Down
4 changes: 0 additions & 4 deletions doomsday/apps/libdoomsday/include/doomsday/game.h
Expand Up @@ -100,10 +100,6 @@ class LIBDOOMSDAY_PUBLIC Game : public de::IObject

void addRequiredPackage(de::String const &packageId);

void setUserFiles(de::StringList const &nativePaths);

de::StringList const &userFiles() const;

/**
* Returns the list of required package IDs for loading the game.
*/
Expand Down
15 changes: 14 additions & 1 deletion doomsday/apps/libdoomsday/include/doomsday/gameprofiles.h
Expand Up @@ -23,6 +23,8 @@

#include <de/Profiles>

class Games;

/**
* Game configuration profiles.
*/
Expand All @@ -35,7 +37,7 @@ class LIBDOOMSDAY_PUBLIC GameProfiles : public de::Profiles
class LIBDOOMSDAY_PUBLIC Profile : public AbstractProfile
{
public:
Profile();
Profile(de::String const &name = "");

void setGame(de::String const &id);
void setPackages(de::StringList const &packagesInOrder);
Expand All @@ -53,8 +55,19 @@ class LIBDOOMSDAY_PUBLIC GameProfiles : public de::Profiles
public:
GameProfiles();

/**
* Sets the games collection associated with these profiles. Each of the games
* will get their own matching profile.
*
* @param games Games.
*/
void setGames(Games &games);

protected:
AbstractProfile *profileFromInfoBlock(de::Info::BlockElement const &block);

private:
DENG2_PRIVATE(d)
};

#endif // LIBDOOMSDAY_GAMEPROFILES_H
16 changes: 12 additions & 4 deletions doomsday/apps/libdoomsday/src/doomsdayapp.cpp
Expand Up @@ -61,7 +61,7 @@ static String const PATH_LOCAL_WADS("/local/wads");

static DoomsdayApp *theDoomsdayApp = nullptr;

DENG2_PIMPL_NOREF(DoomsdayApp)
DENG2_PIMPL(DoomsdayApp)
{
std::string ddBasePath; // Doomsday root directory is at...?
std::string ddRuntimePath;
Expand Down Expand Up @@ -107,13 +107,16 @@ DENG2_PIMPL_NOREF(DoomsdayApp)

GameChangeScriptAudience scriptAudienceForGameChange;

Instance(Players::Constructor playerConstructor)
: players(playerConstructor)
Instance(Public *i, Players::Constructor playerConstructor)
: Base(i)
, players(playerConstructor)
{
Record &appModule = App::scriptSystem().nativeModule("App");
appModule.addArray("audienceForGameChange"); // game change observers
audienceForGameChange += scriptAudienceForGameChange;

gameProfiles.setGames(games);

#ifdef WIN32
hInstance = GetModuleHandle(NULL);
#endif
Expand Down Expand Up @@ -347,7 +350,7 @@ DENG2_AUDIENCE_METHOD(DoomsdayApp, GameChange)
DENG2_AUDIENCE_METHOD(DoomsdayApp, ConsoleRegistration)

DoomsdayApp::DoomsdayApp(Players::Constructor playerConstructor)
: d(new Instance(playerConstructor))
: d(new Instance(this, playerConstructor))
{
DENG2_ASSERT(!theDoomsdayApp);
theDoomsdayApp = this;
Expand Down Expand Up @@ -412,6 +415,11 @@ Games &DoomsdayApp::games()
return DoomsdayApp::app().d->games;
}

GameProfiles &DoomsdayApp::gameProfiles()
{
return DoomsdayApp::app().d->gameProfiles;
}

Players &DoomsdayApp::players()
{
return DoomsdayApp::app().d->players;
Expand Down
27 changes: 13 additions & 14 deletions doomsday/apps/libdoomsday/src/game.cpp
Expand Up @@ -20,12 +20,13 @@

#include "doomsday/game.h"
#include "doomsday/games.h"
#include "doomsday/doomsdayapp.h"
#include "doomsday/GameProfiles"
#include "doomsday/SavedSession"
#include "doomsday/console/cmd.h"
#include "doomsday/filesys/file.h"
#include "doomsday/resource/manifest.h"
#include "doomsday/resource/resources.h"
#include "doomsday/doomsdayapp.h"
#include "doomsday/SavedSession"

#include <de/App>
#include <de/Error>
Expand Down Expand Up @@ -54,7 +55,6 @@ DENG2_PIMPL(Game)
pluginid_t pluginId = 0; ///< Unique identifier of the registering plugin.
Record params;
StringList requiredPackages; ///< Packages required for starting the game.
StringList userFiles;

Manifests manifests; ///< Required resource files (e.g., doomu.wad).

Expand All @@ -79,6 +79,15 @@ DENG2_PIMPL(Game)
{
qDeleteAll(manifests);
}

StringList packagesFromProfile() const
{
auto const *profile = DoomsdayApp::gameProfiles().tryFind(self.title())->maybeAs<GameProfiles::Profile>();
if(profile)
{
return profile->packages();
}
}
};

Game::Game(String const &id, Record const &params)
Expand Down Expand Up @@ -129,16 +138,6 @@ void Game::addRequiredPackage(String const &packageId)
d->requiredPackages.append(packageId);
}

void Game::setUserFiles(StringList const &nativePaths)
{
d->userFiles = nativePaths;
}

StringList const &Game::userFiles() const
{
return d->userFiles;
}

StringList Game::requiredPackages() const
{
return d->requiredPackages;
Expand All @@ -156,7 +155,7 @@ void Game::addManifest(ResourceManifest &manifest)

bool Game::allStartupFilesFound() const
{
for(String const &pkg : d->requiredPackages)
for(String const &pkg : d->requiredPackages + d->packagesFromProfile())
{
if(!App::packageLoader().isAvailable(pkg))
return false;
Expand Down
3 changes: 2 additions & 1 deletion doomsday/apps/libdoomsday/src/game_init.cpp
Expand Up @@ -291,12 +291,13 @@ int loadAddonResourcesBusyWorker(void *context)
{
DoomsdayApp::GameChangeParameters &parms = *(DoomsdayApp::GameChangeParameters *) context;

/*
// User-selected files specified in the game itself.
for(String const &path : DoomsdayApp::game().userFiles())
{
NativePath const nativePath(path);
Session::profile().resourceFiles << nativePath.withSeparators('/');
}
}*/

char const *startupFiles = CVar_String(Con_FindVariable("file-startup"));

Expand Down
37 changes: 34 additions & 3 deletions doomsday/apps/libdoomsday/src/gameprofiles.cpp
Expand Up @@ -16,7 +16,9 @@
* http://www.gnu.org/licenses</small>
*/

#include "doomsday/gameprofiles.h"
#include "doomsday/GameProfiles"
#include "doomsday/Games"
#include "doomsday/DoomsdayApp"

#include <de/Record>

Expand All @@ -27,11 +29,38 @@ using namespace de;
static String const VAR_GAME ("game");
static String const VAR_PACKAGES("packages");

DENG2_PIMPL(GameProfiles)
, DENG2_OBSERVES(Games, Addition)
{
Instance(Public *i) : Base(i) {}

void gameAdded(Game &game)
{
/*
* Make sure there is a profile matching this game's title. The session
* configuration for each game is persistently stored using these profiles.
* (User-created profiles must use different names.)
*/
if(!self.tryFind(game.title()))
{
auto *prof = new Profile(game.title());
prof->setGame(game.id());
self.add(prof);
}
}
};

GameProfiles::GameProfiles()
: d(new Instance(this))
{
setPersistentName("game");
}

void GameProfiles::setGames(Games &games)
{
games.audienceForAddition() += d;
}

Profiles::AbstractProfile *GameProfiles::profileFromInfoBlock(Info::BlockElement const &block)
{
std::unique_ptr<Profile> prof(new Profile);
Expand All @@ -56,8 +85,10 @@ DENG2_PIMPL_NOREF(GameProfiles::Profile)
StringList packages;
};

GameProfiles::Profile::Profile() : d(new Instance)
{}
GameProfiles::Profile::Profile(String const &name) : d(new Instance)
{
setName(name);
}

void GameProfiles::Profile::setGame(String const &id)
{
Expand Down

0 comments on commit 7dfb3ca

Please sign in to comment.