Skip to content

Commit

Permalink
Fixed: Don't assume a sprite is in Patch format
Browse files Browse the repository at this point in the history
At sprite definition time validate whether the associated resource
is a Patch and if so, obtain the world dimension and offset values
to attribute with the sprite. Otherwise, ignore the resource for
now and allow the texture loader to attribute the world dimensions
from the pixel dimensions of image resource at load time.
  • Loading branch information
danij-deng committed Dec 9, 2012
1 parent 073ee3b commit 5cbeee8
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions doomsday/engine/src/resource/r_data.cpp
Expand Up @@ -742,8 +742,7 @@ void R_DefineSpriteTexture(TextureManifest &manifest)
de::Texture *tex = manifest.derive();
if(!tex)
{
LOG_WARNING("Failed to define Texture for sprite \"%s\", ignoring.")
<< manifest.composeUri();
LOG_WARNING("Failed to define Texture for sprite \"%s\", ignoring.") << manifest.composeUri();
return;
}

Expand All @@ -755,16 +754,34 @@ void R_DefineSpriteTexture(TextureManifest &manifest)
lumpnum_t lumpNum = resourceUri.path().toString().toInt();
de::File1& file = App_FileSystem()->nameIndex().lump(lumpNum);

/// @todo fixme: Ensure this is in Patch format.
// If this is from an add-on flag it as "custom".
if(file.container().hasCustom())
{
tex->flags() |= de::Texture::Custom;
}

// If this is a Patch read the world dimension and origin offset values.
ByteRefArray fileData = ByteRefArray(file.cache(), file.size());
de::Reader from = de::Reader(fileData);
Patch::Header patchHdr;
from >> patchHdr;
if(Patch::recognize(fileData))
{
try
{
de::Reader from = de::Reader(fileData);
Patch::Header hdr;
from >> hdr;

tex->setOrigin(QPoint(-patchHdr.origin.x(), -patchHdr.origin.y()));
tex->setDimensions(patchHdr.dimensions);
if(file.hasCustom())
tex->flags() |= de::Texture::Custom;
tex->setDimensions(hdr.dimensions);
tex->setOrigin(QPoint(-hdr.origin.x(), -hdr.origin.y()));
}
catch(IByteArray::OffsetError const &)
{
LOG_WARNING("File \"%s:%s\" does not appear to be a valid Patch.\n"
"World dimension and origin offset not set for sprite \"%s\".")
<< NativePath(file.container().composePath()).pretty()
<< NativePath(file.composePath()).pretty()
<< manifest.composeUri();
}
}

file.unlock();
}
Expand Down

0 comments on commit 5cbeee8

Please sign in to comment.