Skip to content

Commit

Permalink
libdoomsday|FS1: Added FS1::lump(), LumpIndex::contains()
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Jun 14, 2014
1 parent 49b7f11 commit 466dd74
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 64 deletions.
25 changes: 11 additions & 14 deletions doomsday/client/src/dd_wad.cpp
Expand Up @@ -40,7 +40,7 @@ size_t W_LumpLength(lumpnum_t lumpNum)
{
try
{
return App_FileSystem().nameIndex()[lumpNum].info().size;
return App_FileSystem().lump(lumpNum).info().size;
}
catch(LumpIndex::NotFoundError const &er)
{
Expand All @@ -55,7 +55,7 @@ AutoStr *W_LumpName(lumpnum_t lumpNum)
{
try
{
String const& name = App_FileSystem().nameIndex()[lumpNum].name();
String const &name = App_FileSystem().lump(lumpNum).name();
QByteArray nameUtf8 = name.toUtf8();
return AutoStr_FromTextStd(nameUtf8.constData());
}
Expand All @@ -72,7 +72,7 @@ uint W_LumpLastModified(lumpnum_t lumpNum)
{
try
{
return App_FileSystem().nameIndex()[lumpNum].info().lastModified;
return App_FileSystem().lump(lumpNum).info().lastModified;
}
catch(LumpIndex::NotFoundError const &er)
{
Expand All @@ -87,8 +87,7 @@ AutoStr *W_LumpSourceFile(lumpnum_t lumpNum)
{
try
{
de::File1 const& lump = App_FileSystem().nameIndex()[lumpNum];
QByteArray path = lump.container().composePath().toUtf8();
QByteArray path = App_FileSystem().lump(lumpNum).container().composePath().toUtf8();
return AutoStr_FromText(path.constData());
}
catch(LumpIndex::NotFoundError const &er)
Expand All @@ -104,8 +103,7 @@ dd_bool W_LumpIsCustom(lumpnum_t lumpNum)
{
try
{
de::File1 const& lump = App_FileSystem().nameIndex()[lumpNum];
return lump.container().hasCustom();
return App_FileSystem().lump(lumpNum).container().hasCustom();
}
catch(LumpIndex::NotFoundError const &er)
{
Expand Down Expand Up @@ -140,11 +138,11 @@ lumpnum_t W_GetLumpNumForName(char const *name)
}

#undef W_ReadLump
size_t W_ReadLump(lumpnum_t lumpNum, uint8_t* buffer)
size_t W_ReadLump(lumpnum_t lumpNum, uint8_t *buffer)
{
try
{
de::File1& lump = App_FileSystem().nameIndex()[lumpNum];
de::File1 &lump = App_FileSystem().lump(lumpNum);
return lump.read(buffer, 0, lump.size());
}
catch(LumpIndex::NotFoundError const &er)
Expand All @@ -156,12 +154,11 @@ size_t W_ReadLump(lumpnum_t lumpNum, uint8_t* buffer)
}

#undef W_ReadLumpSection
size_t W_ReadLumpSection(lumpnum_t lumpNum, uint8_t* buffer, size_t startOffset, size_t length)
size_t W_ReadLumpSection(lumpnum_t lumpNum, uint8_t *buffer, size_t startOffset, size_t length)
{
try
{
de::File1& lump = App_FileSystem().nameIndex()[lumpNum];
return lump.read(buffer, startOffset, length);
return App_FileSystem().lump(lumpNum).read(buffer, startOffset, length);
}
catch(LumpIndex::NotFoundError const &er)
{
Expand All @@ -176,7 +173,7 @@ uint8_t const *W_CacheLump(lumpnum_t lumpNum)
{
try
{
return App_FileSystem().nameIndex()[lumpNum].cache();
return App_FileSystem().lump(lumpNum).cache();
}
catch(LumpIndex::NotFoundError const &er)
{
Expand All @@ -191,7 +188,7 @@ void W_UnlockLump(lumpnum_t lumpNum)
{
try
{
App_FileSystem().nameIndex()[lumpNum].unlock();
App_FileSystem().lump(lumpNum).unlock();
}
catch(LumpIndex::NotFoundError const &er)
{
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/gl/gl_texmanager.cpp
Expand Up @@ -291,7 +291,7 @@ static res::Source loadRaw(image_t &image, rawtex_t const &raw)

try
{
de::FileHandle &file = fileSys.openLump(fileSys.nameIndex()[raw.lumpNum]);
de::FileHandle &file = fileSys.openLump(fileSys.lump(raw.lumpNum));
if(Image_LoadFromFile(image, file))
{
fileSys.releaseFile(file.file());
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/resource/compositetexture.cpp
Expand Up @@ -199,7 +199,7 @@ CompositeTexture *CompositeTexture::constructFrom(de::Reader &reader,
/// There is now one more found component.
foundComponentCount += 1;

de::File1 &file = App_FileSystem().nameIndex()[comp.lumpNum()];
de::File1 &file = App_FileSystem().lump(comp.lumpNum());

// If this a "custom" component - the whole texture is.
if(file.container().hasCustom())
Expand Down
33 changes: 16 additions & 17 deletions doomsday/client/src/resource/image.cpp
Expand Up @@ -655,7 +655,7 @@ static Source loadPatchComposite(image_t &image, Texture const &tex,
CompositeTexture const &texDef = *reinterpret_cast<CompositeTexture *>(tex.userDataPointer());
DENG2_FOR_EACH_CONST(CompositeTexture::Components, i, texDef.components())
{
de::File1 &file = App_FileSystem().nameIndex()[i->lumpNum()];
de::File1 &file = App_FileSystem().lump(i->lumpNum());
ByteRefArray fileData = ByteRefArray(file.cache(), file.size());

// A DOOM patch?
Expand Down Expand Up @@ -767,6 +767,8 @@ static Source loadDetail(image_t &image, de::FileHandle &hndl)
Source GL_LoadSourceImage(image_t &image, Texture const &tex,
TextureVariantSpec const &spec)
{
de::FS1 &fileSys = App_FileSystem();

Source source = None;
variantspecification_t const &vspec = spec.variant;
if(!tex.manifest().schemeName().compareWithoutCase("Textures"))
Expand Down Expand Up @@ -818,13 +820,12 @@ Source GL_LoadSourceImage(image_t &image, Texture const &tex,
{
try
{
lumpnum_t lumpNum = resourceUri.path().toString().toInt();
de::File1 &lump = App_FileSystem().nameIndex()[lumpNum];
de::FileHandle &hndl = App_FileSystem().openLump(lump);
lumpnum_t const lumpNum = resourceUri.path().toString().toInt();
de::FileHandle &hndl = fileSys.openLump(fileSys.lump(lumpNum));

source = loadFlat(image, hndl);

App_FileSystem().releaseFile(hndl.file());
fileSys.releaseFile(hndl.file());
delete &hndl;
}
catch(LumpIndex::NotFoundError const&)
Expand Down Expand Up @@ -858,13 +859,12 @@ Source GL_LoadSourceImage(image_t &image, Texture const &tex,
{
try
{
lumpnum_t lumpNum = resourceUri.path().toString().toInt();
de::File1 &lump = App_FileSystem().nameIndex()[lumpNum];
de::FileHandle &hndl = App_FileSystem().openLump(lump);
lumpnum_t const lumpNum = resourceUri.path().toString().toInt();
de::FileHandle &hndl = fileSys.openLump(fileSys.lump(lumpNum));

source = loadPatch(image, hndl, tclass, tmap, vspec.border);

App_FileSystem().releaseFile(hndl.file());
fileSys.releaseFile(hndl.file());
delete &hndl;
}
catch(LumpIndex::NotFoundError const&)
Expand Down Expand Up @@ -912,13 +912,12 @@ Source GL_LoadSourceImage(image_t &image, Texture const &tex,
{
try
{
lumpnum_t lumpNum = resourceUri.path().toString().toInt();
de::File1 &lump = App_FileSystem().nameIndex()[lumpNum];
de::FileHandle &hndl = App_FileSystem().openLump(lump);
lumpnum_t const lumpNum = resourceUri.path().toString().toInt();
de::FileHandle &hndl = fileSys.openLump(fileSys.lump(lumpNum));

source = loadPatch(image, hndl, tclass, tmap, vspec.border);

App_FileSystem().releaseFile(hndl.file());
fileSys.releaseFile(hndl.file());
delete &hndl;
}
catch(LumpIndex::NotFoundError const&)
Expand All @@ -938,15 +937,15 @@ Source GL_LoadSourceImage(image_t &image, Texture const &tex,
}
else
{
lumpnum_t lumpNum = App_FileSystem().lumpNumForName(resourceUri.path());
lumpnum_t const lumpNum = fileSys.lumpNumForName(resourceUri.path());
try
{
de::File1 &lump = App_FileSystem().nameIndex()[lumpNum];
de::FileHandle &hndl = App_FileSystem().openLump(lump);
de::File1 &lump = fileSys.lump(lumpNum);
de::FileHandle &hndl = fileSys.openLump(lump);

source = loadDetail(image, hndl);

App_FileSystem().releaseFile(hndl.file());
fileSys.releaseFile(hndl.file());
delete &hndl;
}
catch(LumpIndex::NotFoundError const&)
Expand Down
10 changes: 5 additions & 5 deletions doomsday/client/src/resource/resourcesystem.cpp
Expand Up @@ -995,7 +995,7 @@ DENG2_PIMPL(ResourceSystem)
PatchNames pnames;
try
{
pnames = loadPatchNames(fileSys().nameIndex()[fileSys().lumpNumForName("PNAMES")]);
pnames = loadPatchNames(fileSys().lump(fileSys().lumpNumForName("PNAMES")));
}
catch(LumpIndex::NotFoundError const &er)
{
Expand Down Expand Up @@ -2558,14 +2558,14 @@ patchid_t ResourceSystem::declarePatch(String encodedName)
{} // Ignore this error.

Path lumpPath = uri.path() + ".lmp";
lumpnum_t lumpNum = d->fileSys().nameIndex().findLast(lumpPath);
if(lumpNum < 0)
if(!d->fileSys().nameIndex().contains(lumpPath))
{
LOG_RES_WARNING("Failed to locate lump for \"%s\"") << uri;
return 0;
}

de::File1 &file = d->fileSys().nameIndex().toLump(lumpNum);
lumpnum_t const lumpNum = d->fileSys().nameIndex().findLast(lumpPath);
de::File1 &file = d->fileSys().lump(lumpNum);

Texture::Flags flags;
if(file.container().hasCustom()) flags |= Texture::Custom;
Expand Down Expand Up @@ -2647,7 +2647,7 @@ rawtex_t *ResourceSystem::declareRawTexture(lumpnum_t lumpNum)
if(!raw)
{
// An entirely new raw texture.
String const &name = App_FileSystem().nameIndex()[lumpNum].name();
String const &name = App_FileSystem().lump(lumpNum).name();
raw = new rawtex_t(name, lumpNum);
d->rawTexHash.insert(lumpNum, raw);
}
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/world/worldsystem.cpp
Expand Up @@ -388,7 +388,7 @@ DENG2_PIMPL(WorldSystem)
/*lumpnum_t markerLumpNum = App_FileSystem().lumpNumForName(uri.path().toString().toLatin1().constData());
if(markerLumpNum >= 0)
{
File1 &lump = App_FileSystem().nameIndex().lump(markerLumpNum);
File1 &lump = App_FileSystem().lump(markerLumpNum);
String cacheDir = cachePath(lump.container().composePath());
rec.path = cacheDir + lump.name() + ".dcm";
Expand Down Expand Up @@ -433,7 +433,7 @@ DENG2_PIMPL(WorldSystem)
}

// Generate and attribute the old unique map id.
File1 &markerLump = App_FileSystem().nameIndex()[markerLumpNum];
File1 &markerLump = App_FileSystem().lump(markerLumpNum);
String uniqueId = composeUniqueMapId(markerLump);
QByteArray uniqueIdUtf8 = uniqueId.toUtf8();
newMap->setOldUniqueId(uniqueIdUtf8.constData());
Expand Down
2 changes: 0 additions & 2 deletions doomsday/libdoomsday/include/doomsday/filesys/file.h
Expand Up @@ -40,8 +40,6 @@

namespace de {

class LumpIndex;

/**
* File1 is a core component of the filesystem intended for use as the base
* for all types of (pseudo-)file resources.
Expand Down
9 changes: 9 additions & 0 deletions doomsday/libdoomsday/include/doomsday/filesys/fs_main.h
Expand Up @@ -50,6 +50,7 @@
#include "filetype.h"
#include "searchpath.h"
#include "../resource/resourceclass.h"
#include "../filesys/lumpindex.h"

/**
* @defgroup fs File System
Expand Down Expand Up @@ -413,6 +414,14 @@ class LIBDOOMSDAY_PUBLIC FS1
*/
LumpIndex const &nameIndex() const;

/**
* Convenient method of looking up a file from the lump name index given its
* unique @a lumpnum.
*
* @see nameIndex(), LumpIndex::toLump()
*/
inline File1 &lump(lumpnum_t lumpnum) const { return nameIndex()[lumpnum]; }

/**
* Opens the given file (will be translated) for reading.
*
Expand Down
5 changes: 5 additions & 0 deletions doomsday/libdoomsday/include/doomsday/filesys/lumpindex.h
Expand Up @@ -68,6 +68,11 @@ class LIBDOOMSDAY_PUBLIC LumpIndex
*/
bool hasLump(lumpnum_t lumpNum) const;

/**
* Returns @c true iff the index contains one or more lumps with a matching @a path.
*/
bool contains(Path const &path) const;

/**
* Finds all indices for lumps with a matching @a path.
*
Expand Down

0 comments on commit 466dd74

Please sign in to comment.