Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Oct 31, 2012
1 parent 3f5143f commit 5716d0b
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 57 deletions.
2 changes: 1 addition & 1 deletion doomsday/engine/portable/include/sys_direc.h
Expand Up @@ -51,7 +51,7 @@ directory_t* Dir_NewFromCWD(void);
* \note if not absolute then it will be interpeted as relative to the current
* working directory path.
*/
directory_t* Dir_ConstructFromPathDir(const char* path);
directory_t* Dir_FromText(const char* path);

void Dir_Delete(directory_t* dir);

Expand Down
9 changes: 3 additions & 6 deletions doomsday/engine/portable/src/dd_main.cpp
Expand Up @@ -1426,14 +1426,11 @@ boolean DD_Init(void)

while(++p != CommandLine_Count() && !CommandLine_IsOption(p))
{
char const* filePath = CommandLine_PathAt(p);
directory_t* dir;
Uri* searchPath;

/// @todo Do not add these as search paths, publish them directly
/// to the "packages" ResourceNamespace.
dir = Dir_ConstructFromPathDir(filePath);
searchPath = Uri_NewWithPath2(Dir_Path(dir), RC_PACKAGE);

directory_t* dir = Dir_FromText(CommandLine_PathAt(p));
Uri* searchPath = Uri_NewWithPath2(Dir_Path(dir), RC_PACKAGE);

rnamespace->addSearchPath(ResourceNamespace::DefaultPaths, searchPath, SPF_NO_DESCEND);

Expand Down
5 changes: 4 additions & 1 deletion doomsday/engine/portable/src/def_read.c
Expand Up @@ -840,11 +840,14 @@ static int DED_ReadData(ded_t* ded, const char* buffer, const char* _sourceFile)
if(ISTOKEN("ModelPath"))
{
Uri* newSearchPath;
AutoStr* path;

READSTR(label);
CHECKSC;

newSearchPath = Uri_NewWithPath2(label, RC_NULL);
path = AutoStr_FromTextStd(label);
F_AppendMissingSlash(path);
newSearchPath = Uri_NewWithPath2(Str_Text(path), RC_NULL);
F_AddExtraSearchPathToResourceNamespace(F_DefaultResourceNamespaceForClass(RC_MODEL),
0, newSearchPath);
Uri_Delete(newSearchPath);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/fs_util.cpp
Expand Up @@ -50,7 +50,7 @@ using namespace de;
void F_FileDir(ddstring_t* dst, const ddstring_t* src)
{
/// @todo Potentially truncates @a src to FILENAME_T_MAXLEN
directory_t* dir = Dir_ConstructFromPathDir(Str_Text(src));
directory_t* dir = Dir_FromText(Str_Text(src));
Str_Set(dst, Dir_Path(dir));
Dir_Delete(dir);
}
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/r_data.c
Expand Up @@ -2441,7 +2441,7 @@ static boolean expandSkinName(ddstring_t* foundPath, const char* skin, const cha
if(modelfn)
{
// The "first choice" directory is that in which the model file resides.
directory_t* mydir = Dir_ConstructFromPathDir(modelfn);
directory_t* mydir = Dir_FromText(modelfn);
Str_Appendf(&searchPath, "%s%s", mydir->path, skin);
found = F_FindResourceStr2(RC_GRAPHIC, &searchPath, foundPath) != 0;
Dir_Delete(mydir);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/r_model.c
Expand Up @@ -532,7 +532,7 @@ static int R_LoadModel(const Uri* uri)
if(!foundSkins)
{
// Lastly try a skin named similarly to the model in the same directory.
directory_t* mydir = Dir_ConstructFromPathDir(mdl->fileName);
directory_t* mydir = Dir_FromText(mdl->fileName);
AutoStr* skinSearchPath = AutoStr_NewStd();

F_FileName(skinSearchPath, mdl->fileName);
Expand Down
79 changes: 44 additions & 35 deletions doomsday/engine/portable/src/resourcenamespace.cpp
Expand Up @@ -35,34 +35,49 @@ extern "C" filename_t ddBasePath;

namespace de {

struct ResourceNode
class Resource
{
/// Directory node for this resource in the owning PathTree
PathTree::Node* directoryNode;

public:
Resource(PathTree::Node& _directoryNode) : directoryNode_(&_directoryNode) {
#if _DEBUG
/// Symbolic name of this resource.
ddstring_t name;
Str_Init(&name_);
#endif
}

ResourceNode(PathTree::Node& _directoryNode) : directoryNode(&_directoryNode) {
~Resource() {
#if _DEBUG
Str_Init(&name);
Str_Free(&name_);
#endif
}

~ResourceNode() {
#if _DEBUG
Str_Free(&name);
#endif
PathTree::Node& directoryNode() const {
return *directoryNode_;
}

Resource& setDirectoryNode(PathTree::Node& newDirectoryNode) {
directoryNode_ = &newDirectoryNode;
return *this;
}

#if _DEBUG
ResourceNode& setName(char const* newName) {
Str_Set(&name, newName);
ddstring_t const& name() const {
return name_;
}

Resource& setName(char const* newName) {
Str_Set(&name_, newName);
return *this;
}
#endif

private:
/// Directory node for this resource in the owning PathTree
PathTree::Node* directoryNode_;

#if _DEBUG
/// Symbolic name of this resource.
ddstring_t name_;
#endif
};

/**
Expand All @@ -80,7 +95,7 @@ struct NameHash
struct Node
{
Node* next;
ResourceNode resource;
Resource resource;

Node(PathTree::Node& resourceNode)
: next(0), resource(resourceNode)
Expand Down Expand Up @@ -206,7 +221,7 @@ struct ResourceNamespace::Instance
PathTree::Node const& ptNode)
{
NameHash::Node* node = nameHash.buckets[key].first;
while(node && node->resource.directoryNode != &ptNode)
while(node && &node->resource.directoryNode() != &ptNode)
{
node = node->next;
}
Expand Down Expand Up @@ -305,41 +320,35 @@ bool ResourceNamespace::add(PathTree::Node& resourceNode)
}

// (Re)configure this record.
ResourceNode* res = &hashNode->resource;
res->directoryNode = &resourceNode;
Resource* res = &hashNode->resource;
res->setDirectoryNode(resourceNode);

return isNewNode;
}

bool ResourceNamespace::addSearchPath(PathGroup group, Uri const* _searchPath, int flags)
{
// Is this suitable?
// Ensure this is a well formed path.
if(!_searchPath || Str_IsEmpty(Uri_Path(_searchPath)) ||
!Str_CompareIgnoreCase(Uri_Path(_searchPath), "/"))
!Str_CompareIgnoreCase(Uri_Path(_searchPath), "/") ||
Str_RAt(Uri_Path(_searchPath), 0) != '/')
return false;

// Ensure this is a well formed path (only directories can be search paths).
AutoStr* path = Uri_Compose(_searchPath);
F_AppendMissingSlash(path);

Uri* searchPath = Uri_NewWithPath2(Str_Text(path), RC_NULL);

// The addition of a new search path means the namespace is now dirty.
d->flags |= RNF_IS_DIRTY;

// Have we seen this path already (we don't want duplicates)?
DENG2_FOR_EACH(SearchPaths, i, d->searchPaths)
{
if(Uri_Equality(i->uri(), searchPath))
if(Uri_Equality(i->uri(), _searchPath))
{
i->setFlags(flags);
Uri_Delete(searchPath);
return true;
}
}

// Prepend to the path list - newer paths have priority.
d->searchPaths.insert(group, SearchPath(flags, searchPath));
d->searchPaths.insert(group, SearchPath(flags, Uri_NewCopy(_searchPath)));

return true;
}
Expand Down Expand Up @@ -386,11 +395,11 @@ void ResourceNamespace::debugPrint() const
NameHash::Bucket& bucket = d->nameHash.buckets[key];
for(NameHash::Node* node = bucket.first; node; node = node->next)
{
ResourceNode const& res = node->resource;
AutoStr* path = res.directoryNode->composePath(AutoStr_NewStd(), NULL);
Resource const& res = node->resource;
AutoStr* path = res.directoryNode().composePath(AutoStr_NewStd(), NULL);

LOG_DEBUG(" %u - %u:\"%s\" => %s")
<< resIdx << key << Str_Text(&res.name) << Str_Text(path);
<< resIdx << key << Str_Text(&res.name()) << Str_Text(path);

++resIdx;
}
Expand Down Expand Up @@ -427,10 +436,10 @@ int ResourceNamespace::findAll(ddstring_t const* searchPath, ResourceList& found
NameHash::Bucket& bucket = d->nameHash.buckets[key];
for(NameHash::Node* hashNode = bucket.first; hashNode; hashNode = hashNode->next)
{
ResourceNode& resource = hashNode->resource;
if(name && qstrnicmp(Str_Text(name), Str_Text(resource.directoryNode->name()), Str_Length(name))) continue;
Resource& resource = hashNode->resource;
if(name && qstrnicmp(Str_Text(name), Str_Text(resource.directoryNode().name()), Str_Length(name))) continue;

found.push_back(resource.directoryNode);
found.push_back(&resource.directoryNode());
}
}

Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/sys_direc.c
Expand Up @@ -81,7 +81,7 @@ directory_t* Dir_NewFromCWD(void)
return dir;
}

directory_t* Dir_ConstructFromPathDir(const char* path)
directory_t* Dir_FromText(const char* path)
{
directory_t* dir;
if(!path || !path[0])
Expand Down
9 changes: 2 additions & 7 deletions doomsday/engine/portable/src/sys_reslocator.cpp
Expand Up @@ -626,18 +626,13 @@ void F_CreateNamespacesForFileResourcePaths(void)
if(def->optOverridePath && CommandLine_CheckWith(def->optOverridePath, 1))
{
char const* path = CommandLine_NextAsPath();
ddstring_t path2;

// Override paths are added in reverse order.
Str_Init(&path2);
Str_Appendf(&path2, "%s/$(Game.IdentityKey)", path);
Uri_SetUri3(uri, Str_Text(&path2), RC_NULL);
QByteArray path2 = String("%1$(Game.IdentityKey)/").arg(path).toUtf8();
Uri_SetUri3(uri, path2.constData(), RC_NULL);
rnamespace->addSearchPath(ResourceNamespace::OverridePaths, uri, def->searchPathFlags);

Uri_SetUri3(uri, path, RC_NULL);
rnamespace->addSearchPath(ResourceNamespace::OverridePaths, uri, def->searchPathFlags);

Str_Free(&path2);
}

if(def->optFallbackPath && CommandLine_CheckWith(def->optFallbackPath, 1))
Expand Down
6 changes: 3 additions & 3 deletions doomsday/engine/win32/src/dd_winit.c
Expand Up @@ -178,7 +178,7 @@ static void determineGlobalPaths(application_t* app)
// Ensure it ends with a directory separator.
F_AppendMissingSlashCString(path, FILENAME_T_MAXLEN);
Dir_MakeAbsolutePath(path);
temp = Dir_ConstructFromPathDir(path);
temp = Dir_FromText(path);
strncpy(ddBinPath, Str_Text(temp), FILENAME_T_MAXLEN);
Dir_Delete(temp);
}
Expand All @@ -188,11 +188,11 @@ static void determineGlobalPaths(application_t* app)
#ifdef UNICODE
wchar_t path[FILENAME_T_MAXLEN];
GetModuleFileName(app->hInstance, path, FILENAME_T_MAXLEN);
temp = Dir_ConstructFromPathDir(ToAnsiString(path));
temp = Dir_FromText(ToAnsiString(path));
#else
filename_t path;
GetModuleFileName(app->hInstance, path, FILENAME_T_MAXLEN);
temp = Dir_ConstructFromPathDir(path);
temp = Dir_FromText(path);
#endif
strncpy(ddBinPath, Dir_Path(temp), FILENAME_T_MAXLEN);
Dir_Delete(temp);
Expand Down

0 comments on commit 5716d0b

Please sign in to comment.