Skip to content

Commit

Permalink
Continued refactoring the resource locator; defer the use of resource…
Browse files Browse the repository at this point in the history
…namespace_ts until search-time (alongside file hash (re)build).
  • Loading branch information
danij-deng committed Nov 28, 2010
1 parent dc916d3 commit 18e26fb
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 76 deletions.
6 changes: 2 additions & 4 deletions doomsday/engine/portable/include/dd_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ materialnum_t DD_MaterialForTexture(uint ofTypeId, gltexture_type_t type);

const char* value_Str(int val);

resourcenamespace_t* DD_ResourceNamespace(resourcenamespaceid_t rni);

/**
* @return Ptr to the currently active GameInfo structure (always succeeds).
*/
Expand All @@ -93,8 +91,8 @@ boolean DD_IsNullGameInfo(gameinfo_t* info);
void DD_DestroyGameInfo(void);

void DD_ShutdownResourceSearchPaths(void);
void DD_ClearResourceSearchPathList(resourcenamespaceid_t rni);
const ddstring_t* DD_ResourceSearchPaths(resourcenamespaceid_t rni);
void DD_ClearResourceSearchPathList(resourceclass_t rclass);
const ddstring_t* DD_ResourceSearchPaths(resourceclass_t rclass);

D_CMD(ListGames);

Expand Down
14 changes: 6 additions & 8 deletions doomsday/engine/portable/include/gameinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,15 @@ void P_DestroyGameInfo(gameinfo_t* info);
*
* \note Resource registration order defines the order in which resources of each type are loaded.
*
* @param class Class of resource being added.
* @param rni Namespace to associate the resource with.
* @param rclass Class of resource being added.
* @param name Potential resource name.
*/
gameresource_record_t* GameInfo_AddResource(gameinfo_t* info, resourceclass_t rclass,
resourcenamespaceid_t rni, const ddstring_t* name);
gameresource_record_t* GameInfo_AddResource(gameinfo_t* info, resourceclass_t rclass, const ddstring_t* name);

/**
* Add a new file path to the list of resource-locator search paths.
*/
boolean GameInfo_AddResourceSearchPath(gameinfo_t* info, resourcenamespaceid_t rni, const char* newPath, boolean append);
boolean GameInfo_AddResourceSearchPath(gameinfo_t* info, resourceclass_t rclass, const char* newPath, boolean append);

/**
* Clear resource-locator search paths for all namespaces.
Expand All @@ -136,12 +134,12 @@ void GameInfo_ClearResourceSearchPaths(gameinfo_t* info);
/**
* Clear resource-locator search paths for a specific resource namespace.
*/
void GameInfo_ClearResourceSearchPaths2(gameinfo_t* info, resourcenamespaceid_t rni);
void GameInfo_ClearResourceSearchPaths2(gameinfo_t* info, resourceclass_t rclass);

/**
* @return Ptr to a string containing the resource search path list.
*/
const ddstring_t* GameInfo_ResourceSearchPaths(gameinfo_t* info, resourcenamespaceid_t rni);
const ddstring_t* GameInfo_ResourceSearchPaths(gameinfo_t* info, resourceclass_t rclass);

/**
* Accessor methods.
Expand All @@ -168,7 +166,7 @@ const ddstring_t* GameInfo_CmdlineFlag(gameinfo_t* info);
const ddstring_t* GameInfo_CmdlineFlag2(gameinfo_t* info);

/// @return Ptr to a vector of required resource records.
gameresource_record_t* const* GameInfo_Resources(gameinfo_t* info, resourcenamespaceid_t rni, size_t* count);
gameresource_record_t* const* GameInfo_Resources(gameinfo_t* info, resourceclass_t rclass, size_t* count);

/**
* \note Unless caller is the resource locator then you probably shouldn't be calling.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/include/sys_reslocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void F_ShutdownResourceLocator(void);

boolean F_IsValidResourceNamespaceId(int val);
resourcenamespaceid_t F_ToResourceNamespaceId(int val);
resourcenamespace_t* F_ToResourceNamespace(resourcenamespaceid_t);
resourcenamespace_t* F_ToResourceNamespace(resourcenamespaceid_t rni);
uint F_NumResourceNamespaces(void);

resourcenamespaceid_t F_DefaultResourceNamespaceForClass(resourceclass_t rclass);
Expand Down
46 changes: 18 additions & 28 deletions doomsday/engine/portable/src/dd_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,24 +229,19 @@ static gameinfo_t* addGameInfoRecord(pluginid_t pluginId, const char* identityKe
return gameInfo[numGameInfo++];
}

resourcenamespace_t* DD_ResourceNamespace(resourcenamespaceid_t rni)
{
return F_ToResourceNamespace(rni);
}

void DD_ShutdownResourceSearchPaths(void)
{
GameInfo_ClearResourceSearchPaths(DD_GameInfo());
}

void DD_ClearResourceSearchPathList(resourcenamespaceid_t rni)
void DD_ClearResourceSearchPathList(resourceclass_t rclass)
{
GameInfo_ClearResourceSearchPaths2(DD_GameInfo(), rni);
GameInfo_ClearResourceSearchPaths2(DD_GameInfo(), rclass);
}

const ddstring_t* DD_ResourceSearchPaths(resourcenamespaceid_t rni)
const ddstring_t* DD_ResourceSearchPaths(resourceclass_t rclass)
{
return GameInfo_ResourceSearchPaths(DD_GameInfo(), rni);
return GameInfo_ResourceSearchPaths(DD_GameInfo(), rclass);
}

gameinfo_t* DD_GameInfo(void)
Expand Down Expand Up @@ -312,7 +307,6 @@ static void addIdentityKeyToResourceNamespaceRecord(gameresource_record_t* rec,
void DD_AddGameResource(gameid_t gameId, resourceclass_t rclass, const char* _names, void* params)
{
gameinfo_t* info = findGameInfoForId(gameId);
resourcenamespaceid_t rni;
ddstring_t names, name;

if(!info || DD_IsNullGameInfo(info))
Expand All @@ -328,12 +322,9 @@ void DD_AddGameResource(gameid_t gameId, resourceclass_t rclass, const char* _na
if(Str_RAt(&names, 0) != ';')
Str_Append(&names, ";");

if((rni = F_ParseResourceNamespace(Str_Text(&names))) == 0)
rni = F_DefaultResourceNamespaceForClass(rclass);

Str_Init(&name);
{ gameresource_record_t* rec;
if((rec = GameInfo_AddResource(info, rclass, rni, &names)))
if((rec = GameInfo_AddResource(info, rclass, &names)))
{
if(params)
switch(rec->rclass)
Expand Down Expand Up @@ -515,11 +506,11 @@ static void locateGameResources(gameinfo_t* info)
}

Str_Init(&name);
{ uint i, numResourceNamespaces = F_NumResourceNamespaces();
for(i = 1; i < numResourceNamespaces+1; ++i)
{ uint i;
for(i = 0; i < NUM_RESOURCE_CLASSES; ++i)
{
gameresource_record_t* const* records;
if((records = GameInfo_Resources(info, (resourcenamespaceid_t)i, 0)))
if((records = GameInfo_Resources(info, (resourceclass_t)i, 0)))
do
{
const char* p = Str_Text(&(*records)->names);
Expand All @@ -544,11 +535,11 @@ static boolean allGameResourcesFound(gameinfo_t* info)
assert(info);
if(!DD_IsNullGameInfo(info))
{
uint i, numResourceNamespaces = F_NumResourceNamespaces();
for(i = 1; i < numResourceNamespaces+1; ++i)
uint i;
for(i = 0; i < NUM_RESOURCE_CLASSES; ++i)
{
gameresource_record_t* const* records;
if((records = GameInfo_Resources(info, (resourcenamespaceid_t)i, 0)))
if((records = GameInfo_Resources(info, (resourceclass_t)i, 0)))
do
{
if(Str_Length(&(*records)->path) == 0)
Expand All @@ -563,13 +554,13 @@ static void loadGameResources(gameinfo_t* info, resourceclass_t rclass, const ch
{
assert(info && VALID_RESOURCE_CLASS(rclass) && searchPath);
{
resourcenamespaceid_t rni;
//resourcenamespaceid_t rni;

if((rni = F_ParseResourceNamespace(searchPath)) == 0)
rni = F_DefaultResourceNamespaceForClass(rclass);
//if((rni = F_ParseResourceNamespace(searchPath)) == 0)
// rni = F_DefaultResourceNamespaceForClass(rclass);

{gameresource_record_t* const* records;
if((records = GameInfo_Resources(info, rni, 0)))
if((records = GameInfo_Resources(info, rclass, 0)))
do
{
switch((*records)->rclass)
Expand All @@ -595,14 +586,13 @@ static void printGameInfo(gameinfo_t* info)
Con_Printf(" Meta: pluginid:%i identitykey:\"%s\" data:\"%s\" defs:\"%s\"\n", (int)GameInfo_PluginId(info), Str_Text(GameInfo_IdentityKey(info)), M_PrettyPath(Str_Text(GameInfo_DataPath(info))), M_PrettyPath(Str_Text(GameInfo_DefsPath(info))));
#endif

{ uint i, numResourceNamespaces = F_NumResourceNamespaces();
for(i = 1; i < numResourceNamespaces+1; ++i)
{ uint i;
for(i = 0; i < NUM_RESOURCE_CLASSES; ++i)
{
gameresource_record_t* const* records;
if((records = GameInfo_Resources(info, (resourcenamespaceid_t)i, 0)))
if((records = GameInfo_Resources(info, (resourceclass_t)i, 0)))
{
int n = 0;
Con_Printf(" Namespace: \"%s\"\n", Str_Text(&F_ToResourceNamespace((resourcenamespaceid_t)i)->_name));
do
{
Con_Printf(" %i:%s - \"%s\" > %s\n", n++, F_ResourceClassStr((*records)->rclass), Str_Text(&(*records)->names), Str_Length(&(*records)->path) == 0? "--(!)missing" : M_PrettyPath(Str_Text(&(*records)->path)));
Expand Down
4 changes: 2 additions & 2 deletions doomsday/engine/portable/src/def_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ static void readAllDefinitions(void)

// Now any extra definition files required by the game.
{ gameresource_record_t* const* records;
if((records = GameInfo_Resources(DD_GameInfo(), F_ResourceNamespaceForName("defs:"), 0)))
if((records = GameInfo_Resources(DD_GameInfo(), RC_DEFINITION, 0)))
do
{
if(Str_Length(&(*records)->path) != 0)
Expand Down Expand Up @@ -800,7 +800,7 @@ void Def_Read(void)
// Get rid of everything.
// \fixme dj: This is not correct. We do not want to clear all paths
// we should instead re-init to the default path set.
DD_ClearResourceSearchPathList(F_ResourceNamespaceForName("models:"));
DD_ClearResourceSearchPathList(RC_MODEL);
Def_Destroy();
}

Expand Down
48 changes: 22 additions & 26 deletions doomsday/engine/portable/src/gameinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,10 @@ static void collateResourceSearchPathSet(gameinfo_t* info)
formResourceSearchPaths(info, 1+RC_MODEL, &info->_searchPathLists[RC_MODEL], searchOrder, "models\\", "-modeldir", "-modeldir2");}
}

static __inline void clearResourceSearchPathList(gameinfo_t* info, resourcenamespaceid_t rni)
static __inline void clearResourceSearchPathList(gameinfo_t* info, resourceclass_t rclass)
{
assert(info && F_IsValidResourceNamespaceId(rni));
Str_Free(&info->_searchPathLists[rni]);
assert(info && VALID_RESOURCE_CLASS(rclass));
Str_Free(&info->_searchPathLists[rclass]);
}

gameinfo_t* P_CreateGameInfo(pluginid_t pluginId, const char* identityKey, const char* dataPath,
Expand Down Expand Up @@ -344,11 +344,11 @@ void P_DestroyGameInfo(gameinfo_t* info)
}

gameresource_record_t* GameInfo_AddResource(gameinfo_t* info, resourceclass_t rclass,
resourcenamespaceid_t rni, const ddstring_t* names)
const ddstring_t* names)
{
assert(info && VALID_RESOURCE_CLASS(rclass) && F_IsValidResourceNamespaceId(rni) && names);
assert(info && VALID_RESOURCE_CLASS(rclass) && names);
{
gameresource_recordset_t* rset = &info->_requiredResources[rni-1];
gameresource_recordset_t* rset = &info->_requiredResources[rclass];
gameresource_record_t* record;

rset->records = M_Realloc(rset->records, sizeof(*rset->records) * (rset->numRecords+2));
Expand All @@ -371,30 +371,30 @@ gameresource_record_t* GameInfo_AddResource(gameinfo_t* info, resourceclass_t rc
}
}

void GameInfo_ClearResourceSearchPaths2(gameinfo_t* info, resourcenamespaceid_t rni)
void GameInfo_ClearResourceSearchPaths2(gameinfo_t* info, resourceclass_t rclass)
{
assert(info);
if(rni == 0)
if(rclass == NUM_RESOURCE_CLASSES)
{
uint i, numResourceNamespaces = F_NumResourceNamespaces();
for(i = 1; i < numResourceNamespaces+1; ++i)
uint i;
for(i = 0; i < NUM_RESOURCE_CLASSES; ++i)
{
clearResourceSearchPathList(info, (resourcenamespaceid_t)i);
clearResourceSearchPathList(info, (resourceclass_t)i);
}
return;
}
clearResourceSearchPathList(info, rni);
clearResourceSearchPathList(info, rclass);
}

void GameInfo_ClearResourceSearchPaths(gameinfo_t* info)
{
GameInfo_ClearResourceSearchPaths2(info, 0);
}

boolean GameInfo_AddResourceSearchPath(gameinfo_t* info, resourcenamespaceid_t rni,
boolean GameInfo_AddResourceSearchPath(gameinfo_t* info, resourceclass_t rclass,
const char* newPath, boolean append)
{
assert(info && F_IsValidResourceNamespaceId(rni));
assert(info && VALID_RESOURCE_CLASS(rclass));
{
ddstring_t* pathList;
filename_t absNewPath;
Expand All @@ -409,7 +409,7 @@ boolean GameInfo_AddResourceSearchPath(gameinfo_t* info, resourcenamespaceid_t r
M_PrependBasePath(absNewPath, absNewPath, FILENAME_T_MAXLEN);

// Have we seen this path already?
pathList = &info->_searchPathLists[rni-1];
pathList = &info->_searchPathLists[rclass];
if(Str_Length(pathList))
{
const char* p = Str_Text(pathList);
Expand Down Expand Up @@ -442,12 +442,10 @@ boolean GameInfo_AddResourceSearchPath(gameinfo_t* info, resourcenamespaceid_t r
}
}

const ddstring_t* GameInfo_ResourceSearchPaths(gameinfo_t* info, resourcenamespaceid_t rni)
const ddstring_t* GameInfo_ResourceSearchPaths(gameinfo_t* info, resourceclass_t rclass)
{
assert(info);
if(!F_IsValidResourceNamespaceId(rni))
Con_Error("GameInfo_ResourceSearchPaths: Internal error, invalid resource namespace id %i.", (int)rni);
return &info->_searchPathLists[rni-1];
assert(info && VALID_RESOURCE_CLASS(rclass));
return &info->_searchPathLists[rclass];
}

pluginid_t GameInfo_PluginId(gameinfo_t* info)
Expand Down Expand Up @@ -504,12 +502,10 @@ const ddstring_t* GameInfo_Author(gameinfo_t* info)
return &info->_author;
}

gameresource_record_t* const* GameInfo_Resources(gameinfo_t* info, resourcenamespaceid_t rni, size_t* count)
gameresource_record_t* const* GameInfo_Resources(gameinfo_t* info, resourceclass_t rclass, size_t* count)
{
assert(info);
if(!F_IsValidResourceNamespaceId(rni))
Con_Error("GameInfo_Resources: Internal error, invalid resource namespace id %i.", (int)rni);
assert(info && VALID_RESOURCE_CLASS(rclass));
if(count)
*count = info->_requiredResources[rni-1].numRecords;
return info->_requiredResources[rni-1].records;
*count = info->_requiredResources[rclass].numRecords;
return info->_requiredResources[rclass].records;
}
14 changes: 7 additions & 7 deletions doomsday/engine/portable/src/sys_reslocator.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,16 @@ static __inline const resourcetypeinfo_t* getInfoForResourceType(resourcetype_t
return &typeInfo[((uint)type)-1];
}

static boolean tryFindFile(const char* searchPath, char* foundPath, size_t foundPathLen,
resourcenamespaceid_t rni)
static boolean tryFindFile(resourceclass_t rclass, const char* searchPath,
char* foundPath, size_t foundPathLen, resourcenamespaceid_t rni)
{
assert(inited && searchPath && searchPath[0]);

{ resourcenamespace_t* rnamespace;
if(rni != 0 && (rnamespace = DD_ResourceNamespace(rni)))
if(rni != 0 && (rnamespace = F_ToResourceNamespace(rni)))
{
if(!rnamespace->_fileHash)
rnamespace->_fileHash = FileHash_Create(Str_Text(DD_ResourceSearchPaths(rni)));
rnamespace->_fileHash = FileHash_Create(Str_Text(DD_ResourceSearchPaths(rclass)));
#if _DEBUG
VERBOSE2( Con_Message("Using filehash for rnamespace \"%s\" ...\n", rnamespace->_name) );
#endif
Expand All @@ -163,7 +163,7 @@ static boolean tryFindFile(const char* searchPath, char* foundPath, size_t found
/**
* Check all possible extensions to see if the resource exists.
*
* @param resType Type of resource being searched for @see resourceType.
* @param rclass Class of resource being searched for.
* @param searchPath File name/path to search for.
* @param foundPath Located path if found will be written back here.
* Can be @c NULL, in which case this is just a boolean query.
Expand All @@ -183,7 +183,7 @@ static boolean tryResourceFile(resourceclass_t rclass, const char* searchPath,
// Has an extension been specified?
ptr = M_FindFileExtension((char*)searchPath);
if(ptr && *ptr != '*') // Try this first.
found = tryFindFile(searchPath, foundPath, foundPathLen, rni);
found = tryFindFile(rclass, searchPath, foundPath, foundPathLen, rni);

if(!found)
{
Expand Down Expand Up @@ -216,7 +216,7 @@ static boolean tryResourceFile(resourceclass_t rclass, const char* searchPath,
{
Str_Copy(&tmp, &path2);
Str_Appendf(&tmp, "%s", *ext);
found = tryFindFile(Str_Text(&tmp), foundPath, foundPathLen, rni);
found = tryFindFile(rclass, Str_Text(&tmp), foundPath, foundPathLen, rni);
} while(!found && *(++ext));
}
} while(!found && *(++type) != RT_NONE);
Expand Down

0 comments on commit 18e26fb

Please sign in to comment.