Skip to content

Commit

Permalink
Refactor|LumpIndex: Switched LumpIndex to use de::File1 pointers
Browse files Browse the repository at this point in the history
Next step: Remove the numerous now-redundant methods of de::File1
  • Loading branch information
danij-deng committed Oct 20, 2012
1 parent c1fedd2 commit 9c076e1
Show file tree
Hide file tree
Showing 13 changed files with 200 additions and 198 deletions.
15 changes: 15 additions & 0 deletions doomsday/engine/portable/include/file.h
Expand Up @@ -225,6 +225,21 @@ class File1
*/
virtual AutoStr* composeLumpPath(int lumpIdx, char delimiter = '/');

/**
* Retrieve a lump contained by this file.
*
* @param lumpIdx Logical index for the lump in this file's directory.
*
* @return The lump.
*
* @throws de::Error If @a lumpIdx is not valid.
*
* @attention This default implementation assumes there is only one lump in
* the file and therefore *this* is that lump. Subclasses with multiple lumps
* should override this function accordingly.
*/
virtual File1& lump(int /*lumpIdx*/) { return *this; }

/**
* Retrieve the FileInfo descriptor for a lump contained by this file.
*
Expand Down
12 changes: 6 additions & 6 deletions doomsday/engine/portable/include/lumpindex.h
Expand Up @@ -56,7 +56,7 @@ class LumpIndex
/// No file(s) found. @ingroup errors
DENG2_ERROR(NotFoundError);

typedef QList<FileInfo const*> Lumps;
typedef QList<File1*> Lumps;

public:
/**
Expand All @@ -75,15 +75,15 @@ class LumpIndex
lumpnum_t indexForPath(char const* path);

/**
* Retrieve the FileInfo metadata record for a lump in the Wad lump index.
* Lookup a file at specific offset in the index.
*
* @param lumpNum Logical lumpnum associated to the file being looked up.
*
* @return Metadata record for the lump.
* @return The requested file.
*
* @throws NotFoundError If the requested file could not be found.
*/
FileInfo const& lumpInfo(lumpnum_t lumpNum) const;
File1& lump(lumpnum_t lumpNum) const;

/**
* Provides access to the list of lumps for efficient traversals.
Expand Down Expand Up @@ -127,11 +127,11 @@ class LumpIndex
/**
* Prune the lump referenced by @a lumpInfo.
*
* @param lumpInfo Unique info descriptor for the lump to prune.
* @param lump Lump file to prune.
*
* @return @c true if found and pruned.
*/
bool pruneLump(FileInfo& lumpInfo);
bool pruneLump(File1& lump);

/**
* Print contents of index @a index.
Expand Down
11 changes: 11 additions & 0 deletions doomsday/engine/portable/include/wad.h
Expand Up @@ -101,6 +101,17 @@ class Wad : public File1
*/
AutoStr* composeLumpPath(int lumpIdx, char delimiter = '/');

/**
* Retrieve a lump contained by this file.
*
* @param lumpIdx Logical index for the lump in this file's directory.
*
* @return The lump.
*
* @throws NotFoundError If @a lumpIdx is not valid.
*/
File1& lump(int lumpIdx);

/**
* Retrieve the FileInfo descriptor for a lump contained by this file.
*
Expand Down
11 changes: 11 additions & 0 deletions doomsday/engine/portable/include/zip.h
Expand Up @@ -103,6 +103,17 @@ class Zip : public File1
*/
AutoStr* composeLumpPath(int lumpIdx, char delimiter = '/');

/**
* Retrieve a lump contained by this file.
*
* @param lumpIdx Logical index for the lump in this file's directory.
*
* @return The lump.
*
* @throws NotFoundError If @a lumpIdx is not valid.
*/
File1& lump(int lumpIdx);

/**
* Retrieve the FileInfo descriptor for a lump contained by this file.
*
Expand Down
14 changes: 6 additions & 8 deletions doomsday/engine/portable/src/dd_main.cpp
Expand Up @@ -627,22 +627,20 @@ static void initPathLumpMappings()
// Add the contents of all DD_DIREC lumps.
DENG2_FOR_EACH(i, App_FileSystem()->nameIndex().lumps(), LumpIndex::Lumps::const_iterator)
{
FileInfo const& info = **i;
DENG_ASSERT(info.container);
de::File1& file = *info.container;
de::File1 const& lump = **i;

if(strnicmp(Str_Text(file.lumpName(info.lumpIdx)), "DD_DIREC", 8)) continue;
if(strnicmp(Str_Text(lump.container().lumpName(lump.info().lumpIdx)), "DD_DIREC", 8)) continue;

// Make a copy of it so we can ensure it ends in a null.
if(bufSize < info.size + 1)
if(bufSize < lump.info().size + 1)
{
bufSize = info.size + 1;
bufSize = lump.info().size + 1;
buf = (uint8_t*) M_Realloc(buf, bufSize);
if(!buf) Con_Error("initPathLumpMappings: Failed on (re)allocation of %lu bytes for temporary read buffer.", (unsigned long) bufSize);
}

file.readLump(info.lumpIdx, buf, 0, info.size);
buf[info.size] = 0;
lump.container().readLump(lump.info().lumpIdx, buf, 0, lump.info().size);
buf[lump.info().size] = 0;
parsePathLumpMappings(reinterpret_cast<char const*>(buf));
}

Expand Down
46 changes: 16 additions & 30 deletions doomsday/engine/portable/src/dd_wad.cpp
Expand Up @@ -44,7 +44,7 @@ size_t W_LumpLength(lumpnum_t absoluteLumpNum)
try
{
lumpnum_t lumpNum = absoluteLumpNum;
return App_FileSystem()->nameIndexForLump(lumpNum).lumpInfo(lumpNum).size;
return App_FileSystem()->nameIndexForLump(lumpNum).lump(lumpNum).info().size;
}
catch(LumpIndex::NotFoundError const&)
{
Expand All @@ -58,10 +58,8 @@ char const* W_LumpName(lumpnum_t absoluteLumpNum)
try
{
lumpnum_t lumpNum = absoluteLumpNum;
FileInfo const& info = App_FileSystem()->nameIndexForLump(lumpNum).lumpInfo(lumpNum);
DENG_ASSERT(info.container);
de::File1& file = *info.container;
return Str_Text(file.lumpName(info.lumpIdx));
de::File1 const& lump = App_FileSystem()->nameIndexForLump(lumpNum).lump(lumpNum);
return Str_Text(lump.container().lumpName(lump.info().lumpIdx));
}
catch(FS1::NotFoundError const&)
{
Expand All @@ -75,7 +73,7 @@ uint W_LumpLastModified(lumpnum_t absoluteLumpNum)
try
{
lumpnum_t lumpNum = absoluteLumpNum;
return App_FileSystem()->nameIndexForLump(lumpNum).lumpInfo(lumpNum).lastModified;
return App_FileSystem()->nameIndexForLump(lumpNum).lump(lumpNum).info().lastModified;
}
catch(LumpIndex::NotFoundError const&)
{
Expand All @@ -89,10 +87,8 @@ char const* W_LumpSourceFile(lumpnum_t absoluteLumpNum)
try
{
lumpnum_t lumpNum = absoluteLumpNum;
FileInfo const& info = App_FileSystem()->nameIndexForLump(lumpNum).lumpInfo(lumpNum);
DENG_ASSERT(info.container);
de::File1& file = *info.container;
return Str_Text(file.path());
de::File1 const& lump = App_FileSystem()->nameIndexForLump(lumpNum).lump(lumpNum);
return Str_Text(lump.container().path());
}
catch(LumpIndex::NotFoundError const&)
{
Expand All @@ -106,10 +102,8 @@ boolean W_LumpIsCustom(lumpnum_t absoluteLumpNum)
try
{
lumpnum_t lumpNum = absoluteLumpNum;
FileInfo const& info = App_FileSystem()->nameIndexForLump(lumpNum).lumpInfo(lumpNum);
DENG_ASSERT(info.container);
de::File1& file = *info.container;
return file.hasCustom();
de::File1 const& lump = App_FileSystem()->nameIndexForLump(lumpNum).lump(lumpNum);
return lump.container().hasCustom();
}
catch(LumpIndex::NotFoundError const&)
{
Expand Down Expand Up @@ -153,10 +147,8 @@ size_t W_ReadLump(lumpnum_t absoluteLumpNum, uint8_t* buffer)
try
{
lumpnum_t lumpNum = absoluteLumpNum;
FileInfo const& info = App_FileSystem()->nameIndexForLump(lumpNum).lumpInfo(lumpNum);
DENG_ASSERT(info.container);
de::File1& file = *info.container;
return file.readLump(info.lumpIdx, buffer, 0, info.size);
de::File1 const& lump = App_FileSystem()->nameIndexForLump(lumpNum).lump(lumpNum);
return lump.container().readLump(lump.info().lumpIdx, buffer, 0, lump.info().size);
}
catch(LumpIndex::NotFoundError const&)
{
Expand All @@ -170,10 +162,8 @@ size_t W_ReadLumpSection(lumpnum_t absoluteLumpNum, uint8_t* buffer, size_t star
try
{
lumpnum_t lumpNum = absoluteLumpNum;
FileInfo const& info = App_FileSystem()->nameIndexForLump(lumpNum).lumpInfo(lumpNum);
DENG_ASSERT(info.container);
de::File1& file = *info.container;
return file.readLump(info.lumpIdx, buffer, startOffset, length);
de::File1 const& lump = App_FileSystem()->nameIndexForLump(lumpNum).lump(lumpNum);
return lump.container().readLump(lump.info().lumpIdx, buffer, startOffset, length);
}
catch(LumpIndex::NotFoundError const&)
{
Expand All @@ -187,10 +177,8 @@ uint8_t const* W_CacheLump(lumpnum_t absoluteLumpNum)
try
{
lumpnum_t lumpNum = absoluteLumpNum;
FileInfo const& info = App_FileSystem()->nameIndexForLump(lumpNum).lumpInfo(lumpNum);
DENG_ASSERT(info.container);
de::File1& file = *info.container;
return file.cacheLump(info.lumpIdx);
de::File1 const& lump = App_FileSystem()->nameIndexForLump(lumpNum).lump(lumpNum);
return lump.container().cacheLump(lump.info().lumpIdx);
}
catch(LumpIndex::NotFoundError const&)
{
Expand All @@ -204,10 +192,8 @@ void W_UnlockLump(lumpnum_t absoluteLumpNum)
try
{
lumpnum_t lumpNum = absoluteLumpNum;
FileInfo const& info = App_FileSystem()->nameIndexForLump(lumpNum).lumpInfo(lumpNum);
DENG_ASSERT(info.container);
de::File1& file = *info.container;
file.unlockLump(info.lumpIdx);
de::File1 const& lump = App_FileSystem()->nameIndexForLump(lumpNum).lump(lumpNum);
lump.container().unlockLump(lump.info().lumpIdx);
}
catch(LumpIndex::NotFoundError const&)
{
Expand Down
15 changes: 6 additions & 9 deletions doomsday/engine/portable/src/def_main.cpp
Expand Up @@ -769,19 +769,16 @@ void Def_CountMsg(int count, const char* label)
void Def_ReadLumpDefs(void)
{
int numProcessedLumps = 0;
int const numLumps = App_FileSystem()->nameIndex().size();
for(int i = 0; i < numLumps; ++i)
DENG2_FOR_EACH(i, App_FileSystem()->nameIndex().lumps(), de::LumpIndex::Lumps::const_iterator)
{
de::FileInfo const& info = App_FileSystem()->nameIndex().lumpInfo(i);
DENG_ASSERT(info.container);
de::File1& container = *info.container;
de::File1 const& lump = **i;
if(strnicmp(Str_Text(lump.container().lumpName(lump.info().lumpIdx)), "DD_DEFNS", 8)) continue;

if(strnicmp(Str_Text(container.lumpName(info.lumpIdx)), "DD_DEFNS", 8)) continue;
numProcessedLumps += 1;

numProcessedLumps++;
if(!DED_ReadLump(&defs, i))
if(!DED_ReadLump(&defs, lump.info().lumpIdx))
{
Con_Error("DD_ReadLumpDefs: Parse error when reading \"%s:DD_DEFNS\".\n", Str_Text(container.path()));
Con_Error("DD_ReadLumpDefs: Parse error when reading \"%s:DD_DEFNS\".\n", Str_Text(lump.container().path()));
}
}

Expand Down

0 comments on commit 9c076e1

Please sign in to comment.