diff --git a/doomsday/engine/include/filesys/lumpindex.h b/doomsday/engine/include/filesys/lumpindex.h index b1b6cc0bda..d04666e2da 100644 --- a/doomsday/engine/include/filesys/lumpindex.h +++ b/doomsday/engine/include/filesys/lumpindex.h @@ -74,8 +74,11 @@ class LumpIndex /// @return @c true iff @a lumpNum can be interpreted as a valid lump index. bool isValidIndex(lumpnum_t lumpNum) const; - /// @return Index associated with the last lump with variable-length @a path if found else @c -1 - lumpnum_t indexForPath(Uri const& path) const; + /// Returns the index associated to the last lump matching @a path; otherwise @c -1. + lumpnum_t lastIndexForPath(Path const& path) const; + + /// Returns the index associated to the first lump matching @a path; otherwise @c -1. + lumpnum_t firstIndexForPath(Path const &path) const; /** * Lookup a file at specific offset in the index. diff --git a/doomsday/engine/src/filesys/fs_main.cpp b/doomsday/engine/src/filesys/fs_main.cpp index 5192a653f0..0e0554d131 100644 --- a/doomsday/engine/src/filesys/fs_main.cpp +++ b/doomsday/engine/src/filesys/fs_main.cpp @@ -244,7 +244,7 @@ struct FS1::Instance } // First check the Zip lump index. - lumpnum_t lumpNum = zipFileIndex.indexForPath(de::Uri(path, RC_NULL)); + lumpnum_t lumpNum = zipFileIndex.lastIndexForPath(path); if(lumpNum >= 0) { return &zipFileIndex.lump(lumpNum); @@ -731,7 +731,7 @@ lumpnum_t FS1::lumpNumForName(String name) } // Perform the search. - return d->primaryIndex.indexForPath(de::Uri(name, RC_NULL)); + return d->primaryIndex.lastIndexForPath(Path(name)); } void FS1::releaseFile(de::File1& file) diff --git a/doomsday/engine/src/filesys/lumpindex.cpp b/doomsday/engine/src/filesys/lumpindex.cpp index fb54fc8903..011e714123 100644 --- a/doomsday/engine/src/filesys/lumpindex.cpp +++ b/doomsday/engine/src/filesys/lumpindex.cpp @@ -371,9 +371,9 @@ bool LumpIndex::catalogues(File1& file) return false; } -lumpnum_t LumpIndex::indexForPath(de::Uri const& search) const +lumpnum_t LumpIndex::lastIndexForPath(Path const& path) const { - if(search.isEmpty() || d->lumps.empty()) return -1; + if(path.isEmpty() || d->lumps.empty()) return -1; // We may need to prune path-duplicate lumps. d->pruneDuplicates(); @@ -383,7 +383,7 @@ lumpnum_t LumpIndex::indexForPath(de::Uri const& search) const DENG_ASSERT(d->hashMap); // Perform the search. - ushort hash = search.path().lastSegment().hash() % d->hashMap->size(); + ushort hash = path.lastSegment().hash() % d->hashMap->size(); if((*d->hashMap)[hash].head == -1) return -1; for(int idx = (*d->hashMap)[hash].head; idx != -1; idx = (*d->hashMap)[idx].next) @@ -391,7 +391,7 @@ lumpnum_t LumpIndex::indexForPath(de::Uri const& search) const File1 const& lump = *d->lumps[idx]; PathTree::Node const& node = lump.directoryNode(); - if(node.comparePath(search.path(), 0)) continue; + if(node.comparePath(path, 0)) continue; // This is the lump we are looking for. return idx; @@ -400,6 +400,32 @@ lumpnum_t LumpIndex::indexForPath(de::Uri const& search) const return -1; } +/// @todo Make use of the hash! +lumpnum_t LumpIndex::firstIndexForPath(Path const &path) const +{ + if(path.isEmpty() || d->lumps.empty()) return -1; + + // We may need to prune path-duplicate lumps. + d->pruneDuplicates(); + + // We may need to rebuild the path hash map. + d->buildHashMap(); + DENG_ASSERT(d->hashMap); + + // Perform the search. + for(lumpnum_t idx = 0; idx < d->lumps.size(); ++idx) + { + File1 const& lump = *d->lumps[idx]; + PathTree::Node const& node = lump.directoryNode(); + + if(node.comparePath(path, 0)) continue; + + // This is the lump we are looking for. + return idx; + } + return -1; +} + void LumpIndex::print(LumpIndex const& index) { int const numRecords = index.size(); diff --git a/doomsday/engine/src/filesys/metafile.cpp b/doomsday/engine/src/filesys/metafile.cpp index f4e6746d9c..bdc9ea71e5 100644 --- a/doomsday/engine/src/filesys/metafile.cpp +++ b/doomsday/engine/src/filesys/metafile.cpp @@ -29,6 +29,8 @@ #include "resource/wad.h" #include "resource/zip.h" +#include + namespace de { struct MetaFile::Instance @@ -166,7 +168,7 @@ static lumpnum_t lumpNumForIdentityKey(LumpIndex const& lumpIndex, String idKey) name += ".lmp"; } - lumpnum_t lumpNum = lumpIndex.indexForPath(de::Uri(name, RC_NULL)); + lumpnum_t lumpNum = lumpIndex.lastIndexForPath(Path(name)); if(lumpNum < 0) return -1; // Check the condition.