Skip to content

Commit

Permalink
Resource System|Game: Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Mar 20, 2014
1 parent 72c956d commit be4b55d
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 47 deletions.
15 changes: 15 additions & 0 deletions doomsday/client/include/game.h
Expand Up @@ -124,6 +124,21 @@ class Game : public de::game::Game
*/
de::String logoImageId() const;

/**
* Returns the file extension used by legacy savegame files.
*/
String legacySavegameExtension() const;

/**
* Determine the absolute path to the legacy savegame folder for the specified @a game.
* If there is no possibility of a legacy savegame existing (e.g., because the game is
* newer than the introduction of the modern, package-based .save format) then a zero
* length string is returned.
*
* @param game Game to return the legacy savegame folder path for.
*/
String legacySavegamePath() const;

/**
* Add a new manifest to the list of manifests.
*
Expand Down
5 changes: 5 additions & 0 deletions doomsday/client/include/resource/resourcesystem.h
Expand Up @@ -870,6 +870,11 @@ class ResourceSystem : public de::System
*/
de::game::SavedSessionRepository &savedSessionRepository() const;

/**
* Returns the native path of the root of the saved session repository
*/
de::NativePath nativeSavePath();

public: /// @todo Should be private:
void initCompositeTextures();
void initFlatTextures();
Expand Down
37 changes: 37 additions & 0 deletions doomsday/client/src/game.cpp
Expand Up @@ -24,6 +24,7 @@
#include "con_main.h"
#include "filesys/manifest.h"

#include <de/App>
#include <de/Error>
#include <de/game/SavedSession>
#include <de/Log>
Expand Down Expand Up @@ -169,6 +170,42 @@ String Game::logoImageId() const
return "logo.game." + plugName;
}

String Game::legacySavegameExtension() const
{
String const idKey = identityKey();
/// @todo Use GameDef to define these.
if(idKey.beginsWith("doom")) return ".dsg";
if(idKey.beginsWith("heretic")) return ".hsg";
if(idKey.beginsWith("hexen")) return ".hxs";
if(idKey.beginsWith("chex")) return ".dsg";
if(idKey.beginsWith("hacx")) return ".dsg";
return "";
}

String Game::legacySavegamePath() const
{
NativePath nativeSavePath = App_ResourceSystem().nativeSavePath();

if(nativeSavePath.isEmpty()) return "";
if(isNull()) return "";

if(App::commandLine().has("-savedir"))
{
// A custom path. The savegames are in the root of this folder.
return nativeSavePath;
}

// The default save path. The savegames are in a game-specific folder.
String const idKey = identityKey();
if(idKey.beginsWith("doom")) return App::app().nativeHomePath() / "savegame" / idKey;
if(idKey.beginsWith("heretic")) return App::app().nativeHomePath() / "savegame" / idKey;
if(idKey.beginsWith("hexen")) return App::app().nativeHomePath() / "hexndata" / idKey;
if(idKey.beginsWith("chex")) return App::app().nativeHomePath() / "savegame" / idKey;
if(idKey.beginsWith("hacx")) return App::app().nativeHomePath() / "savegame" / idKey;

return "";
}

Path const &Game::mainConfig() const
{
return d->mainConfig;
Expand Down
54 changes: 7 additions & 47 deletions doomsday/client/src/resource/resourcesystem.cpp
Expand Up @@ -1915,51 +1915,6 @@ DENG2_PIMPL(ResourceSystem)

#endif // __CLIENT__

/// @todo Move to Game?
String legacySavegameExtension(Game const &game)
{
String const gameId = game.identityKey();
if(gameId.beginsWith("doom")) return ".dsg";
if(gameId.beginsWith("heretic")) return ".hsg";
if(gameId.beginsWith("hexen")) return ".hxs";
if(gameId.beginsWith("doom")) return ".dsg";
if(gameId.beginsWith("chex")) return ".dsg";
if(gameId.beginsWith("hacx")) return ".dsg";
return "";
}

/**
* Determine the absolute path to the legacy savegame folder for the specified @a game.
* If there is no possibility of a legacy savegame existing (e.g., because the game is
* newer than the introduction of the modern, package-based .save format) then a zero
* length string is returned.
*
* @param game Game to return the legacy savegame folder path for.
*
* @todo Move to Game?
*/
String legacySavegamePath(Game const &game)
{
if(nativeSavePath.isEmpty()) return "";
if(game.isNull()) return "";

if(App::commandLine().has("-savedir"))
{
// A custom path. The savegames are in the root of this folder.
return nativeSavePath;
}

// The default save path. The savegames are in a game-specific folder.
String const gameId = game.identityKey();
if(gameId.beginsWith("doom")) return App::app().nativeHomePath() / "savegame" / gameId;
if(gameId.beginsWith("heretic")) return App::app().nativeHomePath() / "savegame" / gameId;
if(gameId.beginsWith("hexen")) return App::app().nativeHomePath() / "hexndata" / gameId;
if(gameId.beginsWith("chex")) return App::app().nativeHomePath() / "savegame" / gameId;
if(gameId.beginsWith("hacx")) return App::app().nativeHomePath() / "savegame" / gameId;

return "";
}

/**
* Insert/replace a SavedSession in the db.
*
Expand Down Expand Up @@ -2037,10 +1992,10 @@ DENG2_PIMPL(ResourceSystem)
}

// Perhaps there are legacy saved game sessions which need to be converted?
NativePath const oldSavePath = legacySavegamePath(game);
NativePath const oldSavePath = game.legacySavegamePath();
if(oldSavePath.exists() && oldSavePath.isReadable())
{
String const oldSaveExt = legacySavegameExtension(game);
String const oldSaveExt = game.legacySavegameExtension();
DENG2_ASSERT(!oldSaveExt.isEmpty());

Folder &sourceFolder = App::fileSystem().makeFolder("/oldsavegames");
Expand Down Expand Up @@ -3995,6 +3950,11 @@ game::SavedSessionRepository &ResourceSystem::savedSessionRepository() const
return d->saveRepo;
}

NativePath ResourceSystem::nativeSavePath()
{
return d->nativeSavePath;
}

byte precacheMapMaterials = true;
byte precacheSprites = true;
byte texGammaLut[256];
Expand Down

0 comments on commit be4b55d

Please sign in to comment.