Skip to content

Commit

Permalink
Resources|Server: Wait for all data files to be identified before sta…
Browse files Browse the repository at this point in the history
…rting game
  • Loading branch information
skyjake committed Nov 13, 2016
1 parent 46178e5 commit 615c948
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 3 deletions.
19 changes: 18 additions & 1 deletion doomsday/apps/client/src/dd_main.cpp
Expand Up @@ -70,6 +70,7 @@
#include <doomsday/resource/databundle.h>
#include <doomsday/resource/manifest.h>
#include <doomsday/resource/resources.h>
#include <doomsday/res/Bundles>
#include <doomsday/res/DoomsdayPackage>
#include <doomsday/res/MapManifests>
#include <doomsday/res/Sprites>
Expand Down Expand Up @@ -905,6 +906,7 @@ static GameProfile const *autoselectGameProfile()
{
// Make sure all files have been found so we can determine which games are playable.
Folder::waitForPopulation();
DoomsdayApp::bundles().waitForEverythingIdentified();

char const *identityKey = CommandLine_Next();

Expand Down Expand Up @@ -1059,7 +1061,22 @@ static void initialize()
// connections can only be made after a game is loaded and the
// server mode started.
/// @todo Allow shell connections in Home, too.
App_Error("No playable games available.");
String msg = "Could not determine which game to start. "
"Please specify one with the " _E(b) "-game" _E(.) " option. ";
auto const playable = DoomsdayApp::gameProfiles().allPlayableProfiles();
if (playable.isEmpty())
{
msg += "However, it seems all games are missing required data files. "
"Check that the " _E(b) "-iwad" _E(.) " option specifies a "
"folder with game WAD files.";
}
else
{
StringList ids;
foreach (GameProfile const *prof, playable) ids << prof->game();
msg += "The following games are playable: " + String::join(ids, ", ");
}
App_Error(msg.toLatin1());
}
#endif
}
Expand Down
3 changes: 3 additions & 0 deletions doomsday/apps/libdoomsday/include/doomsday/gameprofiles.h
Expand Up @@ -91,6 +91,9 @@ class LIBDOOMSDAY_PUBLIC GameProfiles : public de::Profiles
Profile const &builtInProfile(de::String const &gameId) const;

de::LoopResult forAll(std::function<de::LoopResult (Profile &)> func);
de::LoopResult forAll(std::function<de::LoopResult (Profile const &)> func) const;

QList<Profile const *> allPlayableProfiles() const;

static Profile const &null();

Expand Down
2 changes: 2 additions & 0 deletions doomsday/apps/libdoomsday/include/doomsday/resource/bundles.h
Expand Up @@ -81,6 +81,8 @@ class LIBDOOMSDAY_PUBLIC Bundles

bool isEverythingIdentified() const;

void waitForEverythingIdentified();

/**
* Finds a matching entry in the registry for a given data bundle.
* @param bundle Data bundle whose information to look for.
Expand Down
23 changes: 23 additions & 0 deletions doomsday/apps/libdoomsday/src/gameprofiles.cpp
Expand Up @@ -89,6 +89,29 @@ LoopResult GameProfiles::forAll(std::function<LoopResult (Profile &)> func)
});
}

LoopResult GameProfiles::forAll(std::function<LoopResult (Profile const &)> func) const
{
return Profiles::forAll([&func] (AbstractProfile const &prof) -> LoopResult
{
if (auto result = func(prof.as<Profile>()))
{
return result;
}
return LoopContinue;
});
}

QList<GameProfile const *> GameProfiles::allPlayableProfiles() const
{
QList<GameProfile const *> playable;
forAll([&playable] (Profile const &prof)
{
if (prof.isPlayable()) playable << &prof;
return LoopContinue;
});
return playable;
}

Profiles::AbstractProfile *GameProfiles::profileFromInfoBlock(Info::BlockElement const &block)
{
std::unique_ptr<Profile> prof(new Profile);
Expand Down
5 changes: 5 additions & 0 deletions doomsday/apps/libdoomsday/src/resource/bundles.cpp
Expand Up @@ -211,6 +211,11 @@ bool Bundles::isEverythingIdentified() const
return d->bundlesToIdentify.isEmpty();
}

void Bundles::waitForEverythingIdentified()
{
d->tasks.waitForDone();
}

Bundles::MatchResult Bundles::match(DataBundle const &bundle) const
{
using Info = de::Info;
Expand Down
2 changes: 1 addition & 1 deletion doomsday/sdk/libcore/include/de/data/profiles.h
Expand Up @@ -130,7 +130,7 @@ class DENG2_PUBLIC Profiles
*/
StringList profiles() const;

LoopResult forAll(std::function<LoopResult (AbstractProfile &)> func);
LoopResult forAll(std::function<LoopResult (AbstractProfile &)> func) const;

/**
* Returns the total number of profiles.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/sdk/libcore/src/data/profiles.cpp
Expand Up @@ -216,7 +216,7 @@ bool Profiles::isPersistent() const
return !d->persistentName.isEmpty();
}

LoopResult Profiles::forAll(std::function<LoopResult (AbstractProfile &)> func)
LoopResult Profiles::forAll(std::function<LoopResult (AbstractProfile &)> func) const
{
foreach (AbstractProfile *prof, d->profiles.values())
{
Expand Down

0 comments on commit 615c948

Please sign in to comment.