Skip to content

Commit

Permalink
Cleanup: Use LumpIndex::findAll() for processing DD_DIREC/DD_DEFNS lumps
Browse files Browse the repository at this point in the history
Also moved printing of the lump index contents out of LumpIndex.
  • Loading branch information
danij-deng committed Jun 14, 2014
1 parent 1088c65 commit e7e5059
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 61 deletions.
12 changes: 5 additions & 7 deletions doomsday/client/src/dd_main.cpp
Expand Up @@ -1071,16 +1071,14 @@ static void initPathLumpMappings()
uint8_t *buf = 0;

// Add the contents of all DD_DIREC lumps.
DENG2_FOR_EACH_CONST(LumpIndex::Lumps, i, App_FileSystem().nameIndex().allLumps())
LumpIndex const &lumpIndex = App_FileSystem().nameIndex();
LumpIndex::FoundIndices foundDirecs;
lumpIndex.findAll("DD_DIREC", foundDirecs);
DENG2_FOR_EACH_CONST(LumpIndex::FoundIndices, i, foundDirecs) // in load order
{
de::File1 &lump = **i;
de::File1 &lump = lumpIndex[*i];
FileInfo const &lumpInfo = lump.info();

if(!lump.name().beginsWith("DD_DIREC", Qt::CaseInsensitive))
{
continue;
}

// Make a copy of it so we can ensure it ends in a null.
if(bufSize < lumpInfo.size + 1)
{
Expand Down
16 changes: 6 additions & 10 deletions doomsday/client/src/def_main.cpp
Expand Up @@ -481,23 +481,19 @@ static void Def_ReadLumpDefs()
{
LOG_AS("Def_ReadLumpDefs");

int numProcessedLumps = 0;

LumpIndex const &lumpIndex = App_FileSystem().nameIndex();
for(lumpnum_t i = 0; i < lumpIndex.size(); ++i)
LumpIndex::FoundIndices foundDefns;
lumpIndex.findAll("DD_DEFNS", foundDefns);
DENG2_FOR_EACH_CONST(LumpIndex::FoundIndices, i, foundDefns)
{
de::File1 const &lump = lumpIndex[i];
if(!lump.name().beginsWith("DD_DEFNS", Qt::CaseInsensitive)) continue;

numProcessedLumps += 1;

if(!DED_ReadLump(&defs, i))
if(!DED_ReadLump(&defs, *i))
{
QByteArray path = NativePath(lump.container().composePath()).pretty().toUtf8();
QByteArray path = NativePath(lumpIndex[*i].container().composePath()).pretty().toUtf8();
App_Error("Def_ReadLumpDefs: Parse error reading \"%s:DD_DEFNS\".\n", path.constData());
}
}

int const numProcessedLumps = foundDefns.size();
if(verbose && numProcessedLumps > 0)
{
LOG_RES_NOTE("Processed %i %s")
Expand Down
5 changes: 0 additions & 5 deletions doomsday/libdoomsday/include/doomsday/filesys/lumpindex.h
Expand Up @@ -158,11 +158,6 @@ class LIBDOOMSDAY_PUBLIC LumpIndex
*/
bool pruneLump(File1 &lump);

/**
* Print contents of index @a index.
*/
static void print(LumpIndex const &index);

private:
DENG2_PRIVATE(d)
};
Expand Down
45 changes: 32 additions & 13 deletions doomsday/libdoomsday/src/filesys/fs_main.cpp
Expand Up @@ -467,7 +467,7 @@ static FS1::FileList::iterator findListFileByPath(FS1::FileList& list, String pa
return i;
}

void FS1::index(de::File1& file)
void FS1::index(de::File1 &file)
{
#ifdef DENG_DEBUG
// Ensure this hasn't yet been indexed.
Expand All @@ -477,14 +477,14 @@ void FS1::index(de::File1& file)
#endif

// Publish lumps to one or more indexes?
if(Zip* zip = dynamic_cast<Zip*>(&file))
if(Zip *zip = dynamic_cast<Zip *>(&file))
{
if(!zip->empty())
{
// Insert the lumps into their rightful places in the index.
for(int i = 0; i < zip->lumpCount(); ++i)
{
File1& lump = zip->lump(i);
File1 &lump = zip->lump(i);

d->primaryIndex.catalogLump(lump);

Expand All @@ -493,22 +493,22 @@ void FS1::index(de::File1& file)
}
}
}
else if(Wad* wad = dynamic_cast<Wad*>(&file))
else if(Wad *wad = dynamic_cast<Wad *>(&file))
{
if(!wad->empty())
{
// Insert the lumps into their rightful places in the index.
for(int i = 0; i < wad->lumpCount(); ++i)
{
File1& lump = wad->lump(i);
File1 &lump = wad->lump(i);
d->primaryIndex.catalogLump(lump);
}
}
}

// Add a handle to the loaded files list.
FileHandle* loadedFilesHndl = FileHandleBuilder::fromFile(file);
d->loadedFiles.push_back(loadedFilesHndl); loadedFilesHndl->setList(reinterpret_cast<struct filelist_s*>(&d->loadedFiles));
FileHandle *loadedFilesHndl = FileHandleBuilder::fromFile(file);
d->loadedFiles.push_back(loadedFilesHndl); loadedFilesHndl->setList(reinterpret_cast<struct filelist_s *>(&d->loadedFiles));
d->loadedFilesCRC = 0;
}

Expand Down Expand Up @@ -1174,21 +1174,40 @@ D_CMD(DumpLump)
/// List virtual files inside containers.
D_CMD(ListLumps)
{
DENG_UNUSED(src); DENG_UNUSED(argc); DENG_UNUSED(argv);
DENG2_UNUSED3(src, argc, argv);

if(fileSystem)
if(!fileSystem) return false;

LumpIndex const &lumpIndex = App_FileSystem().nameIndex();

int const numRecords = lumpIndex.size();
int const numIndexDigits = de::max(3, M_NumDigits(numRecords));

LOG_RES_MSG("LumpIndex %p (%i records):") << &lumpIndex << numRecords;

int idx = 0;
DENG2_FOR_EACH_CONST(LumpIndex::Lumps, i, lumpIndex.allLumps())
{
LumpIndex::print(App_FileSystem().nameIndex());
return true;
de::File1 const &lump = **i;
String containerPath = NativePath(lump.container().composePath()).pretty();
String lumpPath = NativePath(lump.composePath()).pretty();

LOG_RES_MSG(String("%1 - \"%2:%3\" (size: %4 bytes%5)")
.arg(idx++, numIndexDigits, 10, QChar('0'))
.arg(containerPath)
.arg(lumpPath)
.arg(lump.info().size)
.arg(lump.info().isCompressed()? " compressed" : ""));
}
LOG_RES_MSG("---End of lumps---");

return false;
return true;
}

/// List presently loaded files in original load order.
D_CMD(ListFiles)
{
DENG_UNUSED(src); DENG_UNUSED(argc); DENG_UNUSED(argv);
DENG2_UNUSED3(src, argc, argv);

LOG_RES_MSG(_E(b) "Loaded Files " _E(l) "(in load order)" _E(w) ":");

Expand Down
27 changes: 1 addition & 26 deletions doomsday/libdoomsday/src/filesys/lumpindex.cpp
Expand Up @@ -27,7 +27,6 @@
#include <QBitArray>
#include <QVector>
#include <de/Log>
#include <de/NativePath>

namespace de {
namespace internal
Expand Down Expand Up @@ -309,7 +308,7 @@ bool LumpIndex::pruneLump(File1 &lump)
void LumpIndex::catalogLump(File1 &lump)
{
d->lumps.push_back(&lump);
d->lumpsByPath.reset(); // We'll need to rebuild the name hash chains.
d->lumpsByPath.reset(); // We'll need to rebuild the path hash chains.

if(d->pathsAreUnique)
{
Expand Down Expand Up @@ -420,28 +419,4 @@ lumpnum_t LumpIndex::findFirst(Path const &path) const
return earliest; // Not found.
}

void LumpIndex::print(LumpIndex const &index)
{
int const numRecords = index.size();
int const numIndexDigits = de::max(3, M_NumDigits(numRecords));

LOG_RES_MSG("LumpIndex %p (%i records):") << &index << numRecords;

int idx = 0;
DENG2_FOR_EACH_CONST(Lumps, i, index.allLumps())
{
File1 const &lump = **i;
String containerPath = NativePath(lump.container().composePath()).pretty();
String lumpPath = NativePath(lump.composePath()).pretty();

LOG_RES_MSG(QString("%1 - \"%2:%3\" (size: %4 bytes%5)")
.arg(idx++, numIndexDigits, 10, QChar('0'))
.arg(containerPath)
.arg(lumpPath)
.arg(lump.info().size)
.arg(lump.info().isCompressed()? " compressed" : ""));
}
LOG_RES_MSG("---End of lumps---");
}

} // namespace de

0 comments on commit e7e5059

Please sign in to comment.