Skip to content

Commit

Permalink
Refactor: Replaced AbstractResource with a C++ class named ResourceRe…
Browse files Browse the repository at this point in the history
…cord

ResourceRecord performs much the same role as AbstractResource did
previously. The main difference is that location and validation of
the associated resource is now encapsulated by ResourceRecord.

Also, ResourceRecord's API is a lot nicer.
  • Loading branch information
danij-deng committed Nov 4, 2012
1 parent cf94d99 commit f8f2da0
Show file tree
Hide file tree
Showing 13 changed files with 480 additions and 601 deletions.
4 changes: 2 additions & 2 deletions doomsday/engine/engine.pro
Expand Up @@ -126,7 +126,6 @@ DENG_HEADERS += \

# Private headers.
DENG_HEADERS += \
portable/include/abstractresource.h \
portable/include/audiodriver.h \
portable/include/audiodriver_music.h \
portable/include/b_command.h \
Expand Down Expand Up @@ -312,6 +311,7 @@ DENG_HEADERS += \
portable/include/resource/texturevariant.h \
portable/include/resource/texturevariantspecification.h \
portable/include/resourcenamespace.h \
portable/include/resourcerecord.h \
portable/include/s_cache.h \
portable/include/s_environ.h \
portable/include/s_logic.h \
Expand Down Expand Up @@ -435,7 +435,6 @@ deng_nodisplaymode {

# Platform-independent sources.
SOURCES += \
portable/src/abstractresource.cpp \
portable/src/animator.c \
portable/src/audiodriver.cpp \
portable/src/audiodriver_music.c \
Expand Down Expand Up @@ -601,6 +600,7 @@ SOURCES += \
portable/src/resource/textures.cpp \
portable/src/resource/texturevariant.cpp \
portable/src/resourcenamespace.cpp \
portable/src/resourcerecord.cpp \
portable/src/s_cache.c \
portable/src/s_environ.cpp \
portable/src/s_logic.c \
Expand Down
118 changes: 0 additions & 118 deletions doomsday/engine/portable/include/abstractresource.h

This file was deleted.

2 changes: 1 addition & 1 deletion doomsday/engine/portable/include/colorpalette.h
@@ -1,4 +1,4 @@
/**\file abstractresource.h
/**\file colorpalette.h
*\section License
* License: GPL
* Online License Link: http://www.gnu.org/licenses/gpl.html
Expand Down
15 changes: 8 additions & 7 deletions doomsday/engine/portable/include/game.h
Expand Up @@ -43,7 +43,7 @@ extern "C" {
#define PGF_EVERYTHING (PGF_BANNER|PGF_STATUS|PGF_LIST_STARTUP_RESOURCES|PGF_LIST_OTHER_RESOURCES)
///@}

struct AbstractResource_s;
struct resourcerecord_s;
struct gamedef_s;

#ifdef __cplusplus
Expand All @@ -54,6 +54,7 @@ struct gamedef_s;

namespace de {

class ResourceRecord;
class File1;
class GameCollection;

Expand Down Expand Up @@ -111,7 +112,7 @@ class Game
*
* @param rclass Class of resource being added.
*/
Game& addResource(resourceclass_t rclass, struct AbstractResource_s& record);
Game& addResource(resourceclass_t rclass, ResourceRecord& record);

bool allStartupResourcesFound() const;

Expand All @@ -121,7 +122,7 @@ class Game
* @param rclass Class of resource to collect.
* @return Vector of selected resource records.
*/
struct AbstractResource_s* const* resources(resourceclass_t rclass, int* count) const;
ResourceRecord* const* resources(resourceclass_t rclass, int* count) const;

/**
* Is @a file required by this game? This decision is made by comparing the
Expand Down Expand Up @@ -190,7 +191,7 @@ class NullGame : public Game
public:
NullGame();

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

Expand All @@ -202,7 +203,7 @@ class NullGame : public Game
return true; // Always.
}

struct AbstractResource_s* const* resources(resourceclass_t /*rclass*/, int* /*count*/) const {
struct resourcerecord_s* const* resources(resourceclass_t /*rclass*/, int* /*count*/) const {
return 0;
}

Expand Down Expand Up @@ -234,7 +235,7 @@ void Game_Delete(Game* game);

boolean Game_IsNullObject(Game const* game);

struct game_s* Game_AddResource(Game* game, resourceclass_t rclass, struct AbstractResource_s* record);
struct game_s* Game_AddResource(Game* game, resourceclass_t rclass, struct resourcerecord_s* record);

boolean Game_AllStartupResourcesFound(Game const* game);

Expand All @@ -252,7 +253,7 @@ ddstring_t const* Game_MainConfig(Game const* game);

ddstring_t const* Game_BindingConfig(Game const* game);

struct AbstractResource_s* const* Game_Resources(Game const* game, resourceclass_t rclass, int* count);
struct resourcerecord_s* const* Game_Resources(Game const* game, resourceclass_t rclass, int* count);

Game* Game_FromDef(GameDef const* def);

Expand Down
116 changes: 116 additions & 0 deletions doomsday/engine/portable/include/resourcerecord.h
@@ -0,0 +1,116 @@
/**
* @file resourcerecord.h
*
* Resource Record.
*
* @ingroup resource
*
* @author Copyright &copy; 2010-2012 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA</small>
*/

#ifndef LIBDENG_RESOURCERECORD_H
#define LIBDENG_RESOURCERECORD_H

#include <QString>
#include <QStringList>
#include "uri.h"

namespace de
{
/**
* ResourceRecord. Stores high-level metadata for and manages a logical resource.
*
* @ingroup core
*/
class ResourceRecord
{
public:
/**
* @param rClass Class of resource.
* @param rFlags @ref resourceFlags
* @param name An expected name for the associated resource.
*/
ResourceRecord(resourceclass_t rClass, int rFlags, QString* name = 0);
~ResourceRecord();

/// @return Class of resource.
resourceclass_t resourceClass() const;

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

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

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

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

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

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

/**
* Add a new sub-resource identity key to the list for this record.
*
* @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(QString newIdentityKey, bool* didAdd = 0);

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

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

private:
struct Instance;
Instance* d;
};

} // namespace de

#endif /* LIBDENG_RESOURCERECORD_H */
31 changes: 8 additions & 23 deletions doomsday/engine/portable/include/sys_reslocator.h
Expand Up @@ -31,7 +31,7 @@

#include "dd_types.h"

#include "abstractresource.h"
//#include "resourcerecord.h"
#include "uri.h"

#ifdef __cplusplus
Expand Down Expand Up @@ -145,22 +145,6 @@ ResourceNamespace* F_ToResourceNamespace(resourcenamespaceid_t rni);
boolean F_AddExtraSearchPathToResourceNamespace(resourcenamespaceid_t rni, int flags,
struct uri_s const* searchPath);

/**
* Attempt to locate a known resource.
*
* @param record Record of the resource being searched for.
*
* @param foundPath If found, the fully qualified path is written back here.
* Can be @c NULL, changing this routine to only check that
* resource exists is readable.
*
* @return The index+1 of the path in the list of search paths for this resource
* if found, else @c 0
*/
uint F_FindResourceForRecord(struct AbstractResource_s* rec, ddstring_t* foundPath);

uint F_FindResourceForRecord2(AbstractResource* rec, ddstring_t* foundPath, struct uri_s const* const* searchPaths);

/**
* Attempt to locate a named resource.
*
Expand All @@ -185,14 +169,15 @@ uint F_FindResourceForRecord2(AbstractResource* rec, ddstring_t* foundPath, stru
* @return The index+1 of the path in @a searchPaths if found, else @c 0
*/
uint F_FindResourceStr4(resourceclass_t rclass, ddstring_t const* searchPaths, ddstring_t* foundPath, int flags, ddstring_t const* optionalSuffix);
uint F_FindResourceStr3(resourceclass_t rclass, ddstring_t const* searchPaths, ddstring_t* foundPath, int flags); /*optionalSuffix=NULL*/
uint F_FindResourceStr2(resourceclass_t rclass, ddstring_t const* searchPaths, ddstring_t* foundPath); /*flags=RLF_DEFAULT*/
uint F_FindResourceStr(resourceclass_t rclass, ddstring_t const* searchPaths); /*foundPath=NULL*/
uint F_FindResourceStr3(resourceclass_t rclass, ddstring_t const* searchPaths, ddstring_t* foundPath, int flags/*, optionalSuffix = NULL*/);
uint F_FindResourceStr2(resourceclass_t rclass, ddstring_t const* searchPaths, ddstring_t* foundPath/*, flags = RLF_DEFAULT*/);
uint F_FindResourceStr(resourceclass_t rclass, ddstring_t const* searchPaths/*, foundPath = NULL*/);

uint F_FindResource5(resourceclass_t rclass, struct uri_s const** searchPaths, ddstring_t* foundPath, int flags, ddstring_t const* optionalSuffix);
uint F_FindResource4(resourceclass_t rclass, char const* searchPaths, ddstring_t* foundPath, int flags, char const* optionalSuffix);
uint F_FindResource3(resourceclass_t rclass, char const* searchPaths, ddstring_t* foundPath, int flags); /*optionalSuffix=NULL*/
uint F_FindResource2(resourceclass_t rclass, char const* searchPaths, ddstring_t* foundPath); /*flags=RLF_DEFAULT*/
uint F_FindResource(resourceclass_t rclass, char const* searchPaths); /*foundPath=NULL*/
uint F_FindResource3(resourceclass_t rclass, char const* searchPaths, ddstring_t* foundPath, int flags/*, optionalSuffix = NULL*/);
uint F_FindResource2(resourceclass_t rclass, char const* searchPaths, ddstring_t* foundPath/*, flags = RLF_DEFAULT*/);
uint F_FindResource(resourceclass_t rclass, char const* searchPaths/*, foundPath = NULL*/);

/**
* @return Default class associated with resources of type @a type.
Expand Down

0 comments on commit f8f2da0

Please sign in to comment.