Skip to content

Commit

Permalink
Refactor|FS1: Publishing lumps to indexes is now handled by FS1
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Oct 18, 2012
1 parent 55914c7 commit ef299c4
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 102 deletions.
13 changes: 2 additions & 11 deletions doomsday/engine/portable/include/abstractfile.h
Expand Up @@ -151,7 +151,7 @@ class AbstractFile

DFile& handle();

/**
/*
* Access interfaces:
*
* @todo Extract these into one or more interface classes/subcomponents.
Expand Down Expand Up @@ -268,16 +268,7 @@ class AbstractFile
virtual size_t readLump(int lumpIdx, uint8_t* buffer, size_t startOffset, size_t length,
bool tryCache = true) = 0;

/**
* Publish this lump to the end of the specified @a index.
*
* @param index Index to publish to.
*
* @return Number of lumps published to the index.
*/
virtual int publishLumpsToIndex(LumpIndex& index) = 0;

/**
/*
* Lump caching interface:
*/

Expand Down
9 changes: 0 additions & 9 deletions doomsday/engine/portable/include/genericfile.h
Expand Up @@ -130,15 +130,6 @@ class GenericFile : public AbstractFile
*/
GenericFile& unlockLump(int lumpIdx);

/**
* Publish this lump to the end of the specified @a index.
*
* @param index Index to publish to.
*
* @return Number of lumps published to the index. Always @c =1
*/
int publishLumpsToIndex(LumpIndex& index);

private:
struct Instance;
Instance* d;
Expand Down
9 changes: 0 additions & 9 deletions doomsday/engine/portable/include/lumpfile.h
Expand Up @@ -133,15 +133,6 @@ class LumpFile : public AbstractFile
*/
LumpFile& unlockLump(int lumpIdx);

/**
* Publish this lump to the end of the specified @a index.
*
* @param index Index to publish to.
*
* @return Number of lumps published to the index. Always @c =1
*/
int publishLumpsToIndex(LumpIndex& index);

private:
struct Instance;
Instance* d;
Expand Down
10 changes: 0 additions & 10 deletions doomsday/engine/portable/include/wadfile.h
Expand Up @@ -179,16 +179,6 @@ class WadFile : public AbstractFile
*/
WadFile& clearLumpCache();

/**
* Publish lumps to the end of the specified @a index.
*
* @param index Index to publish to.
*
* @return Number of lumps published to the index. Note that this is not
* necessarily equal to the the number of lumps in the file.
*/
int publishLumpsToIndex(LumpIndex& index);

/**
* @attention Uses an extremely simple formula which does not conform to any CRC
* standard. Should not be used for anything critical.
Expand Down
10 changes: 0 additions & 10 deletions doomsday/engine/portable/include/zipfile.h
Expand Up @@ -174,16 +174,6 @@ class ZipFile : public AbstractFile
*/
ZipFile& clearLumpCache();

/**
* Publish lumps to the end of the specified @a index.
*
* @param index Index to publish to.
*
* @return Number of lumps published to the index. Note that this is not
* necessarily equal to the the number of lumps in the file.
*/
int publishLumpsToIndex(LumpIndex& index);

// Static members ------------------------------------------------------------------

/**
Expand Down
37 changes: 23 additions & 14 deletions doomsday/engine/portable/src/fs_main.cpp
Expand Up @@ -221,17 +221,6 @@ struct FS1::Instance
ActiveWadLumpIndex = 0;
}

de::LumpIndex* lumpIndexForFileType(filetype_t fileType)
{
switch(fileType)
{
case FT_ZIPFILE: return &zipLumpIndex;
case FT_LUMPFILE:
case FT_WADFILE: return ActiveWadLumpIndex;
default: return NULL;
}
}

void usePrimaryWadLumpIndex()
{
ActiveWadLumpIndex = &primaryWadLumpIndex;
Expand Down Expand Up @@ -460,10 +449,30 @@ static FS1::FileList::iterator findListFileByPath(FS1::FileList& list, char cons
void FS1::index(de::AbstractFile& file)
{
// Publish lumps to an index?
LumpIndex* lumpIndex = d->lumpIndexForFileType(file.type());
if(lumpIndex)
if(ZipFile* zip = dynamic_cast<ZipFile*>(&file))
{
if(zip->empty()) return;

LumpIndex& index = d->zipLumpIndex;
// Insert the lumps into their rightful places in the index.
index.catalogLumps(*zip, 0, zip->lumpCount());
return;
}
if(WadFile* wad = dynamic_cast<WadFile*>(&file))
{
if(wad->empty()) return;

LumpIndex& index = *d->ActiveWadLumpIndex;
// Insert the lumps into their rightful places in the index.
index.catalogLumps(*wad, 0, wad->lumpCount());
return;
}
if(LumpFile* lump = dynamic_cast<LumpFile*>(&file))
{
file.publishLumpsToIndex(*lumpIndex);
LumpIndex& index = *d->ActiveWadLumpIndex;
// This *is* the lump, so insert ourself as a lump of our container in the index.
index.catalogLumps(lump->container(), lump->info().lumpIdx, lump->lumpCount());
return;
}
}

Expand Down
8 changes: 0 additions & 8 deletions doomsday/engine/portable/src/genericfile.cpp
Expand Up @@ -84,12 +84,4 @@ GenericFile& GenericFile::unlockLump(int /*lumpIdx*/)
throw de::Error("GenericFile::unlockLump", "Not yet implemented");
}

int GenericFile::publishLumpsToIndex(LumpIndex& index)
{
LOG_AS("GenericFile");
// This *is* the lump, so insert ourself in the index.
index.catalogLumps(*this, 0, 1);
return 1;
}

} // namespace de
7 changes: 0 additions & 7 deletions doomsday/engine/portable/src/lumpfile.cpp
Expand Up @@ -76,11 +76,4 @@ LumpFile& LumpFile::unlockLump(int /*lumpIdx*/)
return *this;
}

int LumpFile::publishLumpsToIndex(LumpIndex& index)
{
// This *is* the lump, so insert ourself as a lump of our container in the index.
index.catalogLumps(container(), info().lumpIdx, 1);
return 1;
}

} // namespace de
15 changes: 3 additions & 12 deletions doomsday/engine/portable/src/wadfile.cpp
Expand Up @@ -231,6 +231,8 @@ struct WadFile::Instance
{
LOG_AS("WadFile");
if(arcRecordsCount <= 0) return;
// Already been here?
if(lumpDirectory) return;

// We'll load the lump directory using one continous read into a temporary
// local buffer before we process it into our runtime representation.
Expand Down Expand Up @@ -316,6 +318,7 @@ int WadFile::lastIndex()

int WadFile::lumpCount()
{
d->readLumpDirectory();
return d->lumpDirectory? d->lumpDirectory->size() : 0;
}

Expand Down Expand Up @@ -363,18 +366,6 @@ AutoStr* WadFile::composeLumpPath(int lumpIdx, char delimiter)
return node.composePath(AutoStr_NewStd(), NULL, delimiter);
}

int WadFile::publishLumpsToIndex(LumpIndex& index)
{
LOG_AS("WadFile");
d->readLumpDirectory();
if(empty()) return 0;

// Insert the lumps into their rightful places in the index.
int numPublished = lumpCount();
index.catalogLumps(*this, 0, numPublished);
return numPublished;
}

WadFile& WadFile::clearCachedLump(int lumpIdx, bool* retCleared)
{
LOG_AS("WadFile::clearCachedLump");
Expand Down
13 changes: 1 addition & 12 deletions doomsday/engine/portable/src/zipfile.cpp
Expand Up @@ -485,6 +485,7 @@ int ZipFile::lastIndex()

int ZipFile::lumpCount()
{
d->readLumpDirectory();
return d->lumpDirectory? d->lumpDirectory->size() : 0;
}

Expand Down Expand Up @@ -531,18 +532,6 @@ AutoStr* ZipFile::composeLumpPath(int lumpIdx, char delimiter)
return node.composePath(AutoStr_NewStd(), NULL, delimiter);
}

int ZipFile::publishLumpsToIndex(LumpIndex& index)
{
LOG_AS("ZipFile");
d->readLumpDirectory();
if(empty()) return 0;

// Insert the lumps into their rightful places in the index.
int numPublished = lumpCount();
index.catalogLumps(*this, 0, numPublished);
return numPublished;
}

ZipFile& ZipFile::clearCachedLump(int lumpIdx, bool* retCleared)
{
LOG_AS("ZipFile::clearCachedLump");
Expand Down

0 comments on commit ef299c4

Please sign in to comment.