Skip to content

Commit

Permalink
Fixed|Graphics: World dimensions of high resolution sprite replacements
Browse files Browse the repository at this point in the history
The world dimensions of a sprite are determined by those defined by
the metadata for the original Patch graphic format.

Also, switched to using LumpDir URNs for sprites as this avoids the
potential mix up with other lumps.
  • Loading branch information
danij-deng committed Dec 8, 2012
1 parent bddcbd2 commit 3a2828e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 56 deletions.
4 changes: 2 additions & 2 deletions doomsday/engine/include/gl/gl_texmanager.h
Expand Up @@ -199,8 +199,8 @@ TexSource GL_LoadExtTexture(struct image_s* image, const char* name, gfxmode_t m

TexSource GL_LoadFlatLump(struct image_s* image, FileHandle* file);

TexSource GL_LoadPatchLumpAsPatch(struct image_s* image, FileHandle* file, int tclass,
int tmap, int border, Texture* tex);
TexSource GL_LoadPatchLump(struct image_s* image, FileHandle* file, int tclass,
int tmap, int border);

TexSource GL_LoadDetailTextureLump(struct image_s* image, FileHandle* file);

Expand Down
4 changes: 2 additions & 2 deletions doomsday/engine/include/resource/texturemanifest.h
Expand Up @@ -50,15 +50,15 @@ class TextureManifest : public PathTree::Node
*
* @param flags Texture classification flags.
*/
Texture *derive(Texture::Flags flags);
Texture *derive(Texture::Flags flags = 0);

/**
* @copydoc derive()
* @param dimensions Logical dimensions. Components can be @c 0 in which
* case their value will be inherited from the actual
* pixel dimensions of the image at load time.
*/
Texture *derive(QSize const &dimensions, Texture::Flags flags);
Texture *derive(QSize const &dimensions, Texture::Flags flags = 0);

/**
* Returns the owning scheme of the TextureManifest.
Expand Down
64 changes: 24 additions & 40 deletions doomsday/engine/src/gl/gl_texmanager.cpp
Expand Up @@ -758,9 +758,8 @@ static TexSource loadSourceImage(de::Texture &tex, texturevariantspecification_t
de::File1 &lump = App_FileSystem()->nameIndex().lump(lumpNum);
de::FileHandle &hndl = App_FileSystem()->openLump(lump);

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

App_FileSystem()->releaseFile(hndl.file());
delete &hndl;
Expand Down Expand Up @@ -804,24 +803,30 @@ 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_t lumpNum = App_FileSystem()->lumpNumForName(resourceUri.path());
try
{
de::File1 &lump = App_FileSystem()->nameIndex().lump(lumpNum);
de::FileHandle &hndl = App_FileSystem()->openLump(lump);
lumpNum = App_FileSystem()->lumpNumForName(resourceUri.path());
}
else if(!resourceUri.scheme().compareWithoutCase("LumpDir"))
{
lumpNum = resourceUri.path().toString().toInt();
}

source = GL_LoadPatchLumpAsPatch(&image, reinterpret_cast<filehandle_s *>(&hndl),
tclass, tmap, spec->border,
reinterpret_cast<texture_s *>(&tex));
try
{
de::File1 &lump = App_FileSystem()->nameIndex().lump(lumpNum);
de::FileHandle &hndl = App_FileSystem()->openLump(lump);

App_FileSystem()->releaseFile(hndl.file());
delete &hndl;
}
catch(LumpIndex::NotFoundError const&)
{} // Ignore this error.
source = GL_LoadPatchLump(&image, reinterpret_cast<filehandle_s *>(&hndl),
tclass, tmap, spec->border);

App_FileSystem()->releaseFile(hndl.file());
delete &hndl;
}
catch(LumpIndex::NotFoundError const&)
{} // Ignore this error.
}
}
else if(!tex.manifest().schemeName().compareWithoutCase("Details"))
Expand Down Expand Up @@ -2408,10 +2413,10 @@ TexSource GL_LoadFlatLump(image_t* image, filehandle_s* file)
return source;
}

static TexSource loadPatchLump(image_t *image, filehandle_s *hndl, int tclass, int tmap, int border)
TexSource GL_LoadPatchLump(image_t *image, filehandle_s *hndl, int tclass, int tmap, int border)
{
DENG_ASSERT(image && hndl);
LOG_AS("loadPatchLump");
LOG_AS("GL_LoadPatchLump");

TexSource source = TEXS_NONE;

Expand Down Expand Up @@ -2465,27 +2470,6 @@ static TexSource loadPatchLump(image_t *image, filehandle_s *hndl, int tclass, i
return source;
}

TexSource GL_LoadPatchLumpAsPatch(image_t *image, filehandle_s *hndl, int tclass, int tmap, int border,
texture_s *_tex)
{
TexSource source = loadPatchLump(image, hndl, tclass, tmap, border);
if(source == TEXS_ORIGINAL && _tex)
{
// Loaded from a lump assumed to be in DOOM's Patch format.
de::Texture &tex = reinterpret_cast<de::Texture &>(*_tex);

// Read the world origin offset from the lump.
de::File1 &file = reinterpret_cast<de::File1 &>(*FileHandle_File(hndl));
uint8_t const *dataBuffer = file.cache();

doompatch_header_t const &hdr = reinterpret_cast<doompatch_header_t const &>(*dataBuffer);
tex.setOrigin(QPoint(-SHORT(hdr.leftOffset), -SHORT(hdr.topOffset)));

file.unlock();
}
return source;
}

DGLuint GL_PrepareExtTexture(const char* name, gfxmode_t mode, int useMipmap,
int /*minFilter*/, int magFilter, int /*anisoFilter*/, int wrapS, int wrapT, int otherFlags)
{
Expand Down Expand Up @@ -3290,7 +3274,7 @@ static bool tryLoadImageAndPrepareVariant(de::Texture &tex,
if(tex.dimensions().isEmpty())
{
#if _DEBUG
LOG_VERBOSE("Logical dimensions for \"%s\" taken from image pixels (%ix%i).")
LOG_VERBOSE("World dimensions for \"%s\" taken from image pixels (%ix%i).")
<< tex.manifest().composeUri() << image.size.width << image.size.height;
#endif
tex.setDimensions(QSize(image.size.width, image.size.height));
Expand Down
19 changes: 7 additions & 12 deletions doomsday/engine/src/resource/r_data.cpp
Expand Up @@ -161,10 +161,7 @@ patchid_t R_DeclarePatch(char const *name)
if(monochrome) flags |= de::Texture::Monochrome;
if(upscaleAndSharpenPatches) flags |= de::Texture::UpscaleAndSharpen;

/**
* @todo: Cannot be sure this is in Patch format until a load attempt
* is made. We should not read this info here!
*/
/// @todo fixme: Ensure this is in Patch format.
ByteRefArray fileData = ByteRefArray(file.cache(), file.size());
de::Reader from = de::Reader(fileData);
PatchHeader patchHdr;
Expand All @@ -187,8 +184,8 @@ patchid_t R_DeclarePatch(char const *name)
else
{
tex->setOrigin(QPoint(-patchHdr.origin.x(), -patchHdr.origin.y()));
tex->flags() = flags;
tex->setDimensions(patchHdr.dimensions);
tex->flags() = flags;
}

return uniqueId;
Expand Down Expand Up @@ -742,7 +739,7 @@ void R_DefineSpriteTexture(TextureManifest &manifest)
if(manifest.texture()) return;

// A new sprite texture.
de::Texture *tex = manifest.derive(0);
de::Texture *tex = manifest.derive();
if(!tex)
{
LOG_WARNING("Failed to define Texture for sprite \"%s\", ignoring.")
Expand All @@ -755,15 +752,16 @@ void R_DefineSpriteTexture(TextureManifest &manifest)

try
{
String const &resourcePath = resourceUri.resolvedRef();
lumpnum_t lumpNum = App_FileSystem()->nameIndex().lastIndexForPath(resourcePath);
lumpnum_t lumpNum = resourceUri.path().toString().toInt();
de::File1& file = App_FileSystem()->nameIndex().lump(lumpNum);

/// @todo fixme: Ensure this is in Patch format.
ByteRefArray fileData = ByteRefArray(file.cache(), file.size());
de::Reader from = de::Reader(fileData);
PatchHeader patchHdr;
from >> patchHdr;

tex->setOrigin(QPoint(-patchHdr.origin.x(), -patchHdr.origin.y()));
tex->setDimensions(patchHdr.dimensions);
if(file.hasCustom())
tex->flags() |= de::Texture::Custom;
Expand Down Expand Up @@ -811,12 +809,10 @@ static bool validateSpriteName(String name)
* in the global LumpIndex. This is necessary because of the way id tech 1
* manages patch references.
*/
#if 0
static inline de::Uri composeSpriteResourceUrn(lumpnum_t lumpNum)
{
return de::Uri("LumpDir", Path(String("%1").arg(lumpNum)));
}
#endif

void R_InitSpriteTextures()
{
Expand Down Expand Up @@ -862,8 +858,7 @@ void R_InitSpriteTextures()
}

// Compose the data resource path.
//de::Uri resourceUri = composeSpriteResourceUrn(i);
de::Uri resourceUri("Lumps", Path(fileName));
de::Uri resourceUri = composeSpriteResourceUrn(i);

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

0 comments on commit 3a2828e

Please sign in to comment.