Skip to content

Commit

Permalink
Fixed|Resources: Model skin selection error
Browse files Browse the repository at this point in the history
When (re)building the #skin => Texture map one must ensure that the
indices uses in the MD2/DMD internal skin table are respected, else
the selector mechanism will choose the wrong skin. This means that
"duplicated" slots must map to the same Texture and missing textures
result in a NULL mapping for that skin number.

Issue #1871
  • Loading branch information
danij-deng committed Oct 3, 2014
1 parent 45642af commit e4c9618
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
8 changes: 3 additions & 5 deletions doomsday/client/src/resource/model.cpp
Expand Up @@ -756,7 +756,8 @@ int Model::skinNumber(String name) const
{
if(!name.isEmpty())
{
for(int i = 0; i < d->skins.count(); ++i)
// Reverse iteration so that later skins override earlier ones.
for(int i = d->skins.count(); i--> 0; )
{
Skin const &skin = d->skins.at(i);
if(!skin.name.compareWithoutCase(name))
Expand All @@ -779,10 +780,7 @@ Model::Skin &Model::skin(int number) const
Model::Skin &Model::newSkin(String name)
{
LOG_AS("Model");
if(int index = skinNumber(name) > 0)
{
return skin(index);
}
// Allow duplicates so that skin indices remain unchanged for selection by index.
d->skins.append(ModelSkin(name));
return d->skins.last();
}
Expand Down
17 changes: 6 additions & 11 deletions doomsday/client/src/resource/resourcesystem.cpp
Expand Up @@ -1149,7 +1149,7 @@ DENG2_PIMPL(ResourceSystem)
if(!mdl) continue;

// Load all skins.
foreach(ModelSkin const &skin, mdl->skins())
for(ModelSkin const &skin : mdl->skins())
{
if(Texture *tex = skin.texture)
{
Expand Down Expand Up @@ -1681,10 +1681,6 @@ DENG2_PIMPL(ResourceSystem)
for(int i = 0; i < mdl.skinCount(); ++i)
{
ModelSkin &skin = mdl.skin(i);

if(skin.name.isEmpty())
continue;

try
{
de::Uri foundResourceUri(Path(findSkinPath(skin.name, modelFilePath)));
Expand All @@ -1694,18 +1690,17 @@ DENG2_PIMPL(ResourceSystem)
// We have found one more skin for this model.
numFoundSkins += 1;
}
catch(FS1::NotFoundError const&)
catch(FS1::NotFoundError const &)
{
LOG_RES_WARNING("Failed to locate \"%s\" (#%i) for model \"%s\"")
<< skin.name << i << NativePath(modelFilePath).pretty();
<< skin.name << i << NativePath(modelFilePath).pretty();
}
}

if(!numFoundSkins)
{
// Lastly try a skin named similarly to the model in the same directory.
de::Uri searchPath(modelFilePath.fileNamePath() / modelFilePath.fileNameWithoutExtension(), RC_GRAPHIC);

try
{
String foundPath = fileSys().findPath(searchPath, RLF_DEFAULT,
Expand Down Expand Up @@ -1737,10 +1732,10 @@ DENG2_PIMPL(ResourceSystem)
for(ModelSkin const &skin : mdl.skins())
{
TextureManifest const *texManifest = skin.texture? &skin.texture->manifest() : 0;
LOGDEV_RES_XVERBOSE(" %i: %s")
LOGDEV_RES_XVERBOSE(" %i: %s %s")
<< (skinIdx++) << skin.name
<< (texManifest? texManifest->composeUri() : "(missing texture)")
<< (texManifest? String(" => ") + NativePath(texManifest->resourceUri().compose()).pretty() : "");
<< (texManifest? (String("\"") + texManifest->composeUri() + "\"") : "(missing texture)")
<< (texManifest? (String(" => \"") + NativePath(texManifest->resourceUri().compose()).pretty() + "\"") : "");
}
#endif
}
Expand Down

0 comments on commit e4c9618

Please sign in to comment.