Skip to content

Commit

Permalink
Refactor|Textures: Switched Flat and Patch to use LumpDir resource URNs
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Dec 8, 2012
1 parent 3a2828e commit 153402a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 67 deletions.
68 changes: 27 additions & 41 deletions doomsday/engine/src/gl/gl_texmanager.cpp
Expand Up @@ -705,29 +705,22 @@ static TexSource loadSourceImage(de::Texture &tex, texturevariantspecification_t
if(source == TEXS_NONE)
{
de::Uri const &resourceUri = tex.manifest().resourceUri();
lumpnum_t lumpNum = -1;

if(!resourceUri.scheme().compareWithoutCase("Lumps"))
{
lumpNum = App_FileSystem()->lumpNumForName(resourceUri.path());
}
else if(!resourceUri.scheme().compareWithoutCase("LumpDir"))
{
lumpNum = resourceUri.path().toString().toInt();
}

try
if(!resourceUri.scheme().compareWithoutCase("LumpDir"))
{
de::File1 &lump = App_FileSystem()->nameIndex().lump(lumpNum);
de::FileHandle &hndl = App_FileSystem()->openLump(lump);
try
{
lumpnum_t lumpNum = resourceUri.path().toString().toInt();
de::File1 &lump = App_FileSystem()->nameIndex().lump(lumpNum);
de::FileHandle &hndl = App_FileSystem()->openLump(lump);

source = GL_LoadFlatLump(&image, reinterpret_cast<filehandle_s *>(&hndl));
source = GL_LoadFlatLump(&image, reinterpret_cast<filehandle_s *>(&hndl));

App_FileSystem()->releaseFile(hndl.file());
delete &hndl;
App_FileSystem()->releaseFile(hndl.file());
delete &hndl;
}
catch(LumpIndex::NotFoundError const&)
{} // Ignore this error.
}
catch(LumpIndex::NotFoundError const&)
{} // Ignore this error.
}
}
else if(!tex.manifest().schemeName().compareWithoutCase("Patches"))
Expand All @@ -750,11 +743,11 @@ static TexSource loadSourceImage(de::Texture &tex, texturevariantspecification_t
if(source == TEXS_NONE)
{
de::Uri const &resourceUri = tex.manifest().resourceUri();
if(!resourceUri.scheme().compareWithoutCase("Lumps"))
if(!resourceUri.scheme().compareWithoutCase("LumpDir"))
{
lumpnum_t lumpNum = App_FileSystem()->lumpNumForName(resourceUri.path());
try
{
lumpnum_t lumpNum = resourceUri.path().toString().toInt();
de::File1 &lump = App_FileSystem()->nameIndex().lump(lumpNum);
de::FileHandle &hndl = App_FileSystem()->openLump(lump);

Expand Down Expand Up @@ -803,30 +796,23 @@ static TexSource loadSourceImage(de::Texture &tex, texturevariantspecification_t
if(source == TEXS_NONE)
{
de::Uri const &resourceUri = tex.manifest().resourceUri();
lumpnum_t lumpNum = -1;

if(!resourceUri.scheme().compareWithoutCase("Lumps"))
if(!resourceUri.scheme().compareWithoutCase("LumpDir"))
{
lumpNum = App_FileSystem()->lumpNumForName(resourceUri.path());
}
else if(!resourceUri.scheme().compareWithoutCase("LumpDir"))
{
lumpNum = resourceUri.path().toString().toInt();
}

try
{
de::File1 &lump = App_FileSystem()->nameIndex().lump(lumpNum);
de::FileHandle &hndl = App_FileSystem()->openLump(lump);
try
{
lumpnum_t lumpNum = resourceUri.path().toString().toInt();
de::File1 &lump = App_FileSystem()->nameIndex().lump(lumpNum);
de::FileHandle &hndl = App_FileSystem()->openLump(lump);

source = GL_LoadPatchLump(&image, reinterpret_cast<filehandle_s *>(&hndl),
tclass, tmap, spec->border);
source = GL_LoadPatchLump(&image, reinterpret_cast<filehandle_s *>(&hndl),
tclass, tmap, spec->border);

App_FileSystem()->releaseFile(hndl.file());
delete &hndl;
App_FileSystem()->releaseFile(hndl.file());
delete &hndl;
}
catch(LumpIndex::NotFoundError const&)
{} // Ignore this error.
}
catch(LumpIndex::NotFoundError const&)
{} // Ignore this error.
}
}
else if(!tex.manifest().schemeName().compareWithoutCase("Details"))
Expand Down
41 changes: 15 additions & 26 deletions doomsday/engine/src/resource/r_data.cpp
Expand Up @@ -49,6 +49,18 @@ using namespace de;

static QList<PatchName> patchNames;

/**
* Compose the path to the data resource.
* @note We do not use the lump name, instead we use the logical lump index
* in the global LumpIndex. This is necessary because of the way id tech 1
* manages graphic references in animations (intermediate frames are chosen
* by their 'original indices' rather than by name).
*/
static inline de::Uri composeLumpIndexResourceUrn(lumpnum_t lumpNum)
{
return de::Uri("LumpDir", Path(String("%1").arg(lumpNum)));
}

void R_InitSystemTextures()
{
LOG_AS("R_InitSystemTextures");
Expand Down Expand Up @@ -147,7 +159,7 @@ patchid_t R_DeclarePatch(char const *name)

// Compose the path to the data resource.
de::File1 &file = App_FileSystem()->nameIndex().lump(lumpNum);
de::Uri resourceUri("Lumps", Path(file.name()));
de::Uri resourceUri = composeLumpIndexResourceUrn(lumpNum);

int uniqueId = textures.scheme("Patches").count() + 1; // 1-based index.
TextureManifest *manifest = textures.declare(uri, uniqueId, &resourceUri);
Expand Down Expand Up @@ -646,18 +658,6 @@ static inline de::Uri composeFlatUri(String percentEncodedPath)
return de::Uri("Flats", Path(percentEncodedPath.fileNameWithoutExtension()));
}

/**
* Compose the path to the data resource.
* @note We do not use the lump name, instead we use the logical lump index
* in the global LumpIndex. This is necessary because of the way id tech 1
* manages flat references in animations (intermediate frames are chosen by their
* 'original indices' rather than by name).
*/
static inline de::Uri composeFlatResourceUrn(lumpnum_t lumpNum)
{
return de::Uri("LumpDir", Path(String("%1").arg(lumpNum)));
}

void R_InitFlatTextures()
{
de::Time begunAt;
Expand Down Expand Up @@ -714,7 +714,7 @@ void R_InitFlatTextures()
* @todo Always determine size from the lowres original.
*/
int const uniqueId = lumpNum - (firstFlatMarkerLumpNum + 1);
de::Uri resourcePath = composeFlatResourceUrn(lumpNum);
de::Uri resourcePath = composeLumpIndexResourceUrn(lumpNum);
TextureManifest *manifest = textures.declare(uri, uniqueId, &resourcePath);

de::Texture::Flags flags;
Expand Down Expand Up @@ -803,17 +803,6 @@ static bool validateSpriteName(String name)
return true;
}

/**
* Compose the path to the data resource.
* @note We do not use the lump name, instead we use the logical lump index
* in the global LumpIndex. This is necessary because of the way id tech 1
* manages patch references.
*/
static inline de::Uri composeSpriteResourceUrn(lumpnum_t lumpNum)
{
return de::Uri("LumpDir", Path(String("%1").arg(lumpNum)));
}

void R_InitSpriteTextures()
{
de::Time begunAt;
Expand Down Expand Up @@ -858,7 +847,7 @@ void R_InitSpriteTextures()
}

// Compose the data resource path.
de::Uri resourceUri = composeSpriteResourceUrn(i);
de::Uri resourceUri = composeLumpIndexResourceUrn(i);

if(!App_Textures()->declare(de::Uri("Sprites", Path(fileName)), uniqueId, &resourceUri))
{
Expand Down

0 comments on commit 153402a

Please sign in to comment.