Skip to content

Commit

Permalink
Refactor|FS1: Made the Wad LumpIndexes of FS1 publically visible
Browse files Browse the repository at this point in the history
Rather than wrapping access to the internal indexes, make these
available (via const reference) to users of the FS1 class. This
avoids the needless API duplication and call routing previously
done by the FS1 module.

The only method of FS1 which takes a lump number as argument is
nameIndexForLump(), which given an absolute index, returns the
applicable LumpIndex (and translates the lump number into range).
  • Loading branch information
danij-deng committed Oct 19, 2012
1 parent a9e8fd1 commit a417cff
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 91 deletions.
35 changes: 18 additions & 17 deletions doomsday/engine/portable/include/fs_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,25 +173,24 @@ namespace de

int removeFiles(char const* const* paths, int num, bool permitRequired = false);

/// @return Number of lumps in the currently active LumpIndex.
int lumpCount();

bool isValidLumpNum(lumpnum_t absoluteLumpNum);

lumpnum_t lumpNumForName(char const* name, bool silent = true);

/**
* Retrieve the FileInfo metadata record for a lump in the Wad lump index.
*
* @post The active LumpIndex may have changed!
*
* @param absoluteLumpNum Logical lumpnum associated to the file being looked up.
*
* @return Metadata record for the lump.
* Provides access to the currently active Wad lump name index. This can
* be used for efficiently looking up files based on name.
*/
LumpIndex const& nameIndex() const;

/**
* Provides access to the Wad lump name index which is applicable to the
* specified @a absoluteLumpNum. This can be used for efficiently looking
* up files based on name.
*
* @throws NotFoundError If the requested file could not be found.
* @param absoluteLumpNum Determines which lump index to return. This
* number is then translated into the range for
* the selected index.
*/
FileInfo const& lumpInfo(lumpnum_t absoluteLumpNum);
LumpIndex const& nameIndexForLump(lumpnum_t& absoluteLumpNum) const;

/**
* Retrieve the FileInfo metadata record for a lump in the Zip lump index.
Expand Down Expand Up @@ -229,13 +228,15 @@ namespace de
/**
* Try to locate the specified lump for reading.
*
* @param absoluteLumpNum Logical lumpnum associated to the file being looked up.
* @param info Meta data descriptior for the file to be opened.
*
* @return Handle to the opened file.
*
* @throws NotFoundError If the requested lump could not be found.
* @todo This method is no longer necessary at this level. Opening a file which
* is already present in the file system should not require calling back to a
* method of the file system itself (bad OO design).
*/
FileHandle& openLump(lumpnum_t absoluteLumpNum);
FileHandle& openLump(FileInfo const& info);

/// Clear all references to this file.
void releaseFile(File1& file);
Expand Down
16 changes: 12 additions & 4 deletions doomsday/engine/portable/include/lumpindex.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "fileinfo.h"

#include <QList>
#include <de/Error>

namespace de {

Expand All @@ -52,6 +53,9 @@ namespace de {
class LumpIndex
{
public:
/// No file(s) found. @ingroup errors
DENG2_ERROR(NotFoundError);

typedef QList<FileInfo const*> Lumps;

public:
Expand All @@ -65,17 +69,21 @@ class LumpIndex
int size() const;

/// @return @c true iff @a lumpNum can be interpreted as a valid lump index.
bool isValidIndex(lumpnum_t lumpNum);
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(char const* path);

/**
* @return FileInfo for the lump with index @a lumpNum.
* Retrieve the FileInfo metadata record for a lump in the Wad lump index.
*
* @param lumpNum Logical lumpnum associated to the file being looked up.
*
* @return Metadata record for the lump.
*
* @throws de::Error If @a lumpNum is not valid.
* @throws NotFoundError If the requested file could not be found.
*/
FileInfo const& lumpInfo(lumpnum_t lumpNum);
FileInfo const& lumpInfo(lumpnum_t lumpNum) const;

/**
* Provides access to the list of lumps for efficient traversals.
Expand Down
44 changes: 27 additions & 17 deletions doomsday/engine/portable/src/dd_wad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "de_base.h"
#include "de_console.h"
#include "de_filesys.h"
#include "lumpindex.h"

using namespace de;

Expand All @@ -42,9 +43,10 @@ size_t W_LumpLength(lumpnum_t absoluteLumpNum)
{
try
{
return App_FileSystem()->lumpInfo(absoluteLumpNum).size;
lumpnum_t lumpNum = absoluteLumpNum;
return App_FileSystem()->nameIndexForLump(lumpNum).lumpInfo(lumpNum).size;
}
catch(FS1::NotFoundError const&)
catch(LumpIndex::NotFoundError const&)
{
W_Error("W_LumpLength: Invalid lumpnum %i.", absoluteLumpNum);
}
Expand All @@ -55,7 +57,8 @@ char const* W_LumpName(lumpnum_t absoluteLumpNum)
{
try
{
FileInfo const& info = App_FileSystem()->lumpInfo(absoluteLumpNum);
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));
Expand All @@ -71,9 +74,10 @@ uint W_LumpLastModified(lumpnum_t absoluteLumpNum)
{
try
{
return App_FileSystem()->lumpInfo(absoluteLumpNum).lastModified;
lumpnum_t lumpNum = absoluteLumpNum;
return App_FileSystem()->nameIndexForLump(lumpNum).lumpInfo(lumpNum).lastModified;
}
catch(FS1::NotFoundError const&)
catch(LumpIndex::NotFoundError const&)
{
W_Error("W_LumpLastModified: Invalid lumpnum %i.", absoluteLumpNum);
}
Expand All @@ -84,12 +88,13 @@ char const* W_LumpSourceFile(lumpnum_t absoluteLumpNum)
{
try
{
FileInfo const& info = App_FileSystem()->lumpInfo(absoluteLumpNum);
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());
}
catch(FS1::NotFoundError const&)
catch(LumpIndex::NotFoundError const&)
{
W_Error("W_LumpSourceFile: Invalid lumpnum %i.", absoluteLumpNum);
}
Expand All @@ -100,12 +105,13 @@ boolean W_LumpIsCustom(lumpnum_t absoluteLumpNum)
{
try
{
FileInfo const& info = App_FileSystem()->lumpInfo(absoluteLumpNum);
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();
}
catch(FS1::NotFoundError const&)
catch(LumpIndex::NotFoundError const&)
{
W_Error("W_LumpIsCustom: Invalid lumpnum %i.", absoluteLumpNum);
}
Expand Down Expand Up @@ -146,12 +152,13 @@ size_t W_ReadLump(lumpnum_t absoluteLumpNum, uint8_t* buffer)
{
try
{
FileInfo const& info = App_FileSystem()->lumpInfo(absoluteLumpNum);
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);
}
catch(FS1::NotFoundError const&)
catch(LumpIndex::NotFoundError const&)
{
W_Error("W_ReadLump: Invalid lumpnum %i.", absoluteLumpNum);
}
Expand All @@ -162,12 +169,13 @@ size_t W_ReadLumpSection(lumpnum_t absoluteLumpNum, uint8_t* buffer, size_t star
{
try
{
FileInfo const& info = App_FileSystem()->lumpInfo(absoluteLumpNum);
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);
}
catch(FS1::NotFoundError const&)
catch(LumpIndex::NotFoundError const&)
{
W_Error("W_ReadLumpSection: Invalid lumpnum %i.", absoluteLumpNum);
}
Expand All @@ -178,12 +186,13 @@ uint8_t const* W_CacheLump(lumpnum_t absoluteLumpNum)
{
try
{
FileInfo const& info = App_FileSystem()->lumpInfo(absoluteLumpNum);
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);
}
catch(FS1::NotFoundError const&)
catch(LumpIndex::NotFoundError const&)
{
W_Error("W_CacheLump: Invalid lumpnum %i.", absoluteLumpNum);
}
Expand All @@ -194,12 +203,13 @@ void W_UnlockLump(lumpnum_t absoluteLumpNum)
{
try
{
FileInfo const& info = App_FileSystem()->lumpInfo(absoluteLumpNum);
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);
}
catch(FS1::NotFoundError const&)
catch(LumpIndex::NotFoundError const&)
{
W_Error("W_UnlockLump: Invalid lumpnum %i.", absoluteLumpNum);
}
Expand Down
11 changes: 6 additions & 5 deletions doomsday/engine/portable/src/def_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@

#include "r_data.h"

#include "font.h"
#include "abstractresource.h"
#include "bitmapfont.h"
#include "texture.h"
#include "font.h"
#include "lumpindex.h"
#include "resourcenamespace.h"
#include "abstractresource.h"
#include "texture.h"

// XGClass.h is actually a part of the engine.
#include "../../../plugins/common/include/xgclass.h"
Expand Down Expand Up @@ -768,10 +769,10 @@ void Def_CountMsg(int count, const char* label)
void Def_ReadLumpDefs(void)
{
int numProcessedLumps = 0;
int const numLumps = App_FileSystem()->lumpCount();
int const numLumps = App_FileSystem()->nameIndex().size();
for(int i = 0; i < numLumps; ++i)
{
de::FileInfo const& info = App_FileSystem()->lumpInfo(i);
de::FileInfo const& info = App_FileSystem()->nameIndex().lumpInfo(i);
DENG_ASSERT(info.container);
de::File1& container = *info.container;

Expand Down
Loading

0 comments on commit a417cff

Please sign in to comment.