Navigation Menu

Skip to content

Commit

Permalink
Refactor: Renamed ResourceRecord as MetaFile and moved to filesys
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Nov 19, 2012
1 parent aef12e3 commit 3a923a7
Show file tree
Hide file tree
Showing 16 changed files with 190 additions and 192 deletions.
8 changes: 4 additions & 4 deletions doomsday/engine/api/dd_share.h
Expand Up @@ -362,12 +362,12 @@ typedef struct gameinfo_s {
void Game_Notify(int notification, void* param);

/**
* @defgroup resourceFlags Resource Flags
* @ingroup apiFlags resource
* @defgroup fileFlags File Flags
* @ingroup apiFlags fs
*/
///@{
#define RF_STARTUP 0x1 ///< A required resource needed for and loaded during game start up (can't be a virtual file).
#define RF_FOUND 0x2 ///< Resource has been located.
#define FF_STARTUP 0x1 ///< A required file needed for and loaded during game start up (can't be a virtual file).
#define FF_FOUND 0x2 ///< File has been located.
///@}

/**
Expand Down
6 changes: 3 additions & 3 deletions doomsday/engine/api/doomsday.h
Expand Up @@ -160,8 +160,8 @@ gameid_t DD_GameIdForKey(char const* identityKey);
* recent.
*
* @param game Unique identifier/name of the game.
* @param classId Class of resource being added.
* @param rflags Resource flags (see @ref resourceFlags).
* @param classId Class of resource being defined.
* @param fFlags File flags (see @ref fileFlags).
* @param names One or more known potential names, seperated by semicolon
* (e.g., <pre> "name1;name2" </pre>). Valid names include
* absolute or relative file paths, possibly with encoded
Expand All @@ -171,7 +171,7 @@ gameid_t DD_GameIdForKey(char const* identityKey);
* For package resources this may be C-String containing a
* semicolon delimited list of identity keys.
*/
void DD_AddGameResource(gameid_t game, fileclassid_t classId, int rflags,
void DD_AddGameResource(gameid_t game, fileclassid_t classId, int fFlags,
const char* names, void* params);

/**
Expand Down
4 changes: 2 additions & 2 deletions doomsday/engine/engine.pro
Expand Up @@ -188,6 +188,7 @@ DENG_HEADERS += \
include/filesys/fs_util.h \
include/filesys/locator.h \
include/filesys/lumpindex.h \
include/filesys/metafile.h \
include/filesys/sys_direc.h \
include/filesys/sys_findfile.h \
include/filesys/wad.h \
Expand Down Expand Up @@ -306,7 +307,6 @@ DENG_HEADERS += \
include/resource/models.h \
include/resource/pcx.h \
include/resource/r_data.h \
include/resource/resourcerecord.h \
include/resource/texture.h \
include/resource/textures.h \
include/resource/texturevariant.h \
Expand Down Expand Up @@ -475,6 +475,7 @@ SOURCES += \
src/filesys/fs_util.cpp \
src/filesys/locator.cpp \
src/filesys/lumpindex.cpp \
src/filesys/metafile.cpp \
src/filesys/sys_direc.c \
src/filesys/wad.cpp \
src/filesys/zip.cpp \
Expand Down Expand Up @@ -588,7 +589,6 @@ SOURCES += \
src/resource/models.cpp \
src/resource/pcx.c \
src/resource/r_data.c \
src/resource/resourcerecord.cpp \
src/resource/texture.cpp \
src/resource/textures.cpp \
src/resource/texturevariant.cpp \
Expand Down
1 change: 1 addition & 0 deletions doomsday/engine/include/de_filesys.h
Expand Up @@ -34,6 +34,7 @@
#include "filesys/fs_util.h"
#include "filesys/locator.h"
#include "filesys/lumpindex.h"
#include "filesys/metafile.h"
#include "filesys/sys_direc.h"
#include "filesys/sys_findfile.h"
#include "filesys/wad.h"
Expand Down
1 change: 0 additions & 1 deletion doomsday/engine/include/de_resource.h
Expand Up @@ -30,6 +30,5 @@
#include "resource/font.h"
#include "resource/fonts.h"
#include "resource/models.h"
#include "resource/resourcerecord.h"

#endif /* LIBDENG_RESOURCE_SUBSYSTEM_H */
@@ -1,11 +1,10 @@
/**
* @file resourcerecord.h
* @file metafile.h
*
* Resource Record.
*
* @ingroup resource
* Metafile. @ingroup fs
*
* @author Copyright &copy; 2010-2012 Daniel Swanson <danij@dengine.net>
* @author Copyright &copy; 2010-2012 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
Expand All @@ -22,8 +21,8 @@
* 02110-1301 USA</small>
*/

#ifndef LIBDENG_RESOURCERECORD_H
#define LIBDENG_RESOURCERECORD_H
#ifndef LIBDENG_METAFILE_H
#define LIBDENG_METAFILE_H

#ifdef __cplusplus

Expand All @@ -35,79 +34,79 @@
namespace de
{
/**
* Stores high-level metadata for and manages a logical resource.
* Stores high-level metadata for and manages a logical file resource.
*
* @ingroup core
*/
class ResourceRecord
class MetaFile
{
public:
/**
* @param rClass Class of resource.
* @param rFlags @ref resourceFlags
* @param name An expected name for the associated resource.
* @param fClass Class of file.
* @param fFlags @ref fileFlags
* @param name An expected name for the associated file.
*/
ResourceRecord(fileclassid_t rClass, int rFlags, String* name = 0);
~ResourceRecord();
MetaFile(fileclassid_t fClass, int fFlags, String* name = 0);
~MetaFile();

/// @return Class of resource.
/// @return Class of file.
fileclassid_t fileClass() const;

/// @return Flags for this resource.
int resourceFlags() const;
/// @return Flags for this file.
int fileFlags() const;

/// @return List of "identity keys" used to identify the resource.
/// @return List of "identity keys" used to identify the file.
QStringList const& identityKeys() const;

/// @return List of names for the associated resource.
/// @return List of names for the associated file.
QStringList const& names() const;

/**
* Attempt to locate this resource by systematically resolving and then
* Attempt to locate this file by systematically resolving and then
* checking each search path.
*/
ResourceRecord& locateResource();
MetaFile& locateFile();

/**
* "Forget" the currently located resource if one has been found.
* "Forget" the currently located file if one has been found.
*/
ResourceRecord& forgetResource();
MetaFile& forgetFile();

/**
* Attempt to resolve a path to (and maybe locate) this resource.
* Attempt to resolve a path to (and maybe locate) this file.
*
* @param tryLocate Attempt to locate the resource now.
* @param tryLocate @c true= Attempt to locate the file now.
*
* @return Path to the found resource or an empty string.
* @return Path to the found file or an empty string.
*
* @see locateResource()
* @see locateFile()
*/
String const& resolvedPath(bool tryLocate = true);

/**
* Add a new sub-resource identity key to the list for this record.
* Add a new file segment identity key to the list for this metafile.
*
* @param newIdentityKey New identity key (e.g., a lump/file name).
* @param didAdd If not @c =0, the outcome will be written here.
*/
ResourceRecord& addIdentityKey(String newIdentityKey, bool* didAdd = 0);
MetaFile& addIdentityKey(String newIdentityKey, bool* didAdd = 0);

/**
* Add a new resource name to the list of names for this record.
* Add a new file name to the list of names for this metafile.
*
* @param newName New name for this resource. Newer names have precedence.
* @param newName New name for this file. Newer names have precedence.
* @param didAdd If not @c =0, the outcome will be written here.
*/
ResourceRecord& addName(String newName, bool* didAdd = 0);
MetaFile& addName(String newName, bool* didAdd = 0);

/**
* Print information about a resource to the console.
* Print information about a file to the console.
*
* @param record Record for the resource.
* @param metafile Metafile for the file.
* @param showStatus @c true = print loaded/located status for the
* associated resource.
* associated file.
*/
static void consolePrint(ResourceRecord& record, bool showStatus = true);
static void consolePrint(MetaFile& metafile, bool showStatus = true);

private:
struct Instance;
Expand All @@ -118,4 +117,4 @@ namespace de

#endif // __cplusplus

#endif /* LIBDENG_RESOURCERECORD_H */
#endif /* LIBDENG_METAFILE_H */
41 changes: 20 additions & 21 deletions doomsday/engine/include/game.h
Expand Up @@ -44,7 +44,7 @@ extern "C" {
#define PGF_EVERYTHING (PGF_BANNER|PGF_STATUS|PGF_LIST_STARTUP_RESOURCES|PGF_LIST_OTHER_RESOURCES)
///@}

struct resourcerecord_s;
struct metafile_s;
struct gamedef_s;

#ifdef __cplusplus
Expand All @@ -57,8 +57,8 @@ struct gamedef_s;

namespace de {

class ResourceRecord;
class File1;
class MetaFile;
class GameCollection;

/**
Expand All @@ -70,7 +70,7 @@ class GameCollection;
class Game
{
public:
typedef QMultiMap<fileclassid_t, ResourceRecord*> Resources;
typedef QMultiMap<fileclassid_t, MetaFile*> MetaFiles;

public:
/**
Expand Down Expand Up @@ -111,21 +111,20 @@ class Game
Game& setPluginId(pluginid_t newId);

/**
* Add a new resource to the list of resources.
* Add a new metafile to the list of metafiles.
*
* @note Resource registration order defines the order in which resources of each
* type are loaded.
* @note Registration order defines load order (among files of the same class).
*
* @param record ResourceRecord to add.
* @param metafile MetaFile to add.
*/
Game& addResource(ResourceRecord& record);
Game& addMetafile(MetaFile& metafile);

bool allStartupResourcesFound() const;
bool allStartupFilesFound() const;

/**
* Provides access to resources for efficent traversals.
* Provides access to the metafiles for efficent traversals.
*/
Resources const& resources() const;
MetaFiles const& metafiles() const;

/**
* Is @a file required by this game? This decision is made by comparing the
Expand Down Expand Up @@ -159,15 +158,15 @@ class Game
static void printBanner(Game const& game);

/**
* Print the list of resources for @a Game.
* Print the list of resource files for @a Game.
*
* @param game Game to list resources of.
* @param rflags Only consider resources whose @ref resourceFlags match
* @param game Game to list the files of.
* @param rflags Only consider files whose @ref fileFlags match
* this value. If @c <0 the flags are ignored.
* @param printStatus @c true to include the current availability/load status
* of each resource.
* of each file.
*/
static void printResources(Game const& game, int rflags, bool printStatus = true);
static void printFiles(Game const& game, int rflags, bool printStatus = true);

/**
* Print extended information about game @a info.
Expand All @@ -194,19 +193,19 @@ class NullGame : public Game
public:
NullGame();

Game& addResource(struct resourcerecord_s& /*record*/) {
Game& addMetafile(struct metafile_s& /*record*/) {
throw NullObjectError("NullGame::addResource", "Invalid action on null-object");
}

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

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

struct resourcerecord_s* const* resources(fileclassid_t /*classId*/, int* /*count*/) const {
struct metafile_s* const* metafiles(fileclassid_t /*classId*/, int* /*count*/) const {
return 0;
}

Expand Down Expand Up @@ -238,9 +237,9 @@ void Game_Delete(Game* game);

boolean Game_IsNullObject(Game const* game);

struct game_s* Game_AddResource(Game* game, struct resourcerecord_s* record);
struct game_s* Game_AddMetafile(Game* game, struct metafile_s* record);

boolean Game_AllStartupResourcesFound(Game const* game);
boolean Game_AllStartupFilesFound(Game const* game);

Game* Game_SetPluginId(Game* game, pluginid_t pluginId);

Expand Down
18 changes: 9 additions & 9 deletions doomsday/engine/src/dd_games.cpp
Expand Up @@ -25,7 +25,7 @@
#include "de_filesys.h"
#include "dd_games.h"

#include "resource/resourcerecord.h"
#include "filesys/metafile.h"
#include "filesys/zip.h"

namespace de {
Expand Down Expand Up @@ -103,7 +103,7 @@ int GameCollection::numPlayable() const
DENG2_FOR_EACH_CONST(Games, i, d->games)
{
Game* game = *i;
if(!game->allStartupResourcesFound()) continue;
if(!game->allStartupFilesFound()) continue;
++count;
}
return count;
Expand All @@ -114,7 +114,7 @@ Game* GameCollection::firstPlayable() const
DENG2_FOR_EACH_CONST(Games, i, d->games)
{
Game* game = *i;
if(game->allStartupResourcesFound()) return game;
if(game->allStartupFilesFound()) return game;
}
return NULL;
}
Expand Down Expand Up @@ -198,14 +198,14 @@ GameCollection& GameCollection::locateStartupResources(Game& game)
F_ResetAllFileNamespaces();
}

DENG2_FOR_EACH_CONST(Game::Resources, i, game.resources())
DENG2_FOR_EACH_CONST(Game::MetaFiles, i, game.metafiles())
{
ResourceRecord& record = **i;
MetaFile& record = **i;

// We are only interested in startup resources at this time.
if(!(record.resourceFlags() & RF_STARTUP)) continue;
if(!(record.fileFlags() & FF_STARTUP)) continue;

record.locateResource();
record.locateFile();
}

if(d->currentGame != oldGame)
Expand Down Expand Up @@ -275,11 +275,11 @@ D_CMD(ListGames)
de::Game* game = i->game;

Con_Printf(" %s %-16s %s (%s)\n", games->isCurrentGame(*game)? "*" :
!game->allStartupResourcesFound()? "!" : " ",
!game->allStartupFilesFound()? "!" : " ",
Str_Text(&game->identityKey()), Str_Text(&game->title()),
Str_Text(&game->author()));

if(game->allStartupResourcesFound())
if(game->allStartupFilesFound())
numCompleteGames++;
}

Expand Down

0 comments on commit 3a923a7

Please sign in to comment.