From 83087c640d752b9d926c0db6cc6bf60739fcddd1 Mon Sep 17 00:00:00 2001 From: danij Date: Wed, 23 Jan 2013 23:11:10 +0000 Subject: [PATCH] Refactor|Material: Relocated is-autogenerated classification to MaterialManifest This classification now belongs at manifest level. --- doomsday/client/include/resource/material.h | 3 --- .../include/resource/materialmanifest.h | 7 +++++- doomsday/client/src/def_main.cpp | 3 ++- doomsday/client/src/resource/material.cpp | 6 ----- .../client/src/resource/materialmanifest.cpp | 23 ++++++++++++++----- doomsday/client/src/resource/materials.cpp | 1 + 6 files changed, 26 insertions(+), 17 deletions(-) diff --git a/doomsday/client/include/resource/material.h b/doomsday/client/include/resource/material.h index 1ed6287229..82efb4636f 100644 --- a/doomsday/client/include/resource/material.h +++ b/doomsday/client/include/resource/material.h @@ -455,9 +455,6 @@ class Material : public de::MapElement /// Returns @c true if the material has at least one animated layer. bool isAnimated() const; - /// Returns @c true if the material is marked as "autogenerated". - bool isAutoGenerated() const; - /// Returns @c true if the material has one or more (light) decorations. /// Equivalent to @code decorationCount() != 0; @endcode, for convenience. inline bool isDecorated() const { return decorationCount() != 0; } diff --git a/doomsday/client/include/resource/materialmanifest.h b/doomsday/client/include/resource/materialmanifest.h index 450b81e987..c30b982985 100644 --- a/doomsday/client/include/resource/materialmanifest.h +++ b/doomsday/client/include/resource/materialmanifest.h @@ -75,7 +75,12 @@ class MaterialManifest : public PathTree::Node void setId(materialid_t newId); - /// @return @c true if the manifest is not derived from an original game resource. + /// @c true if the manifest was automatically produced for a game/add-on resource. + bool isAutoGenerated() const; + + void setAutoGenerated(bool yes); + + /// @c true if the manifest was not produced for an original game resource. bool isCustom() const; void setCustom(bool yes); diff --git a/doomsday/client/src/def_main.cpp b/doomsday/client/src/def_main.cpp index e3745193c6..de56aa4a89 100644 --- a/doomsday/client/src/def_main.cpp +++ b/doomsday/client/src/def_main.cpp @@ -1031,7 +1031,8 @@ static void updateMaterialFromDef(Material &material, ded_material_t &def) material.setDimensions(QSize(def.width, def.height)); material.setAudioEnvironment(S_AudioEnvironmentForMaterial(def.uri)); - // Update custom status. + // Update manifest classification. + manifest.setAutoGenerated(def.autoGenerated); /// @todo This should take into account the whole definition, not just whether /// the primary layer's first texture is custom or not. manifest.setCustom(false); diff --git a/doomsday/client/src/resource/material.cpp b/doomsday/client/src/resource/material.cpp index 141a610f69..b6ba913df6 100644 --- a/doomsday/client/src/resource/material.cpp +++ b/doomsday/client/src/resource/material.cpp @@ -256,12 +256,6 @@ bool Material::isAnimated() const return false; // Not at all. } -bool Material::isAutoGenerated() const -{ - /// @todo fixme: We should not need a definition to determine this. - return (d->def && d->def->autoGenerated); -} - bool Material::isDetailed() const { /// @todo fixme: Determine this from our own configuration. diff --git a/doomsday/client/src/resource/materialmanifest.cpp b/doomsday/client/src/resource/materialmanifest.cpp index d8a45ab7ee..b5835f1831 100644 --- a/doomsday/client/src/resource/materialmanifest.cpp +++ b/doomsday/client/src/resource/materialmanifest.cpp @@ -37,10 +37,13 @@ struct MaterialManifest::Instance /// Unique identifier. materialid_t id; - /// @c true if the material is not derived from an original game resource. + /// @c true if the manifest was automatically produced for a game/add-on resource. + bool isAutoGenerated; + + /// @c true if the manifest was not produced for an original game resource. bool isCustom; - Instance() : material(0), id(0), isCustom(false) + Instance() : material(0), id(0), isAutoGenerated(false), isCustom(false) {} }; @@ -65,6 +68,11 @@ void MaterialManifest::setId(materialid_t id) d->id = id; } +void MaterialManifest::setAutoGenerated(bool yes) +{ + d->isAutoGenerated = yes; +} + void MaterialManifest::setCustom(bool yes) { d->isCustom = yes; @@ -98,10 +106,8 @@ Uri MaterialManifest::composeUri(QChar sep) const String MaterialManifest::sourceDescription() const { - /// @todo We should not need a material to determine this. - if(!d->material || !d->material->isValid()) return "unknown"; - if(!isCustom()) return "game"; - if(d->material->isAutoGenerated()) return "add-on"; // Unintuitive but correct. + if(!d->isCustom) return "game"; + if(d->isAutoGenerated) return "add-on"; // Unintuitive but correct. return "def"; } @@ -110,6 +116,11 @@ materialid_t MaterialManifest::id() const return d->id; } +bool MaterialManifest::isAutoGenerated() const +{ + return d->isAutoGenerated; +} + bool MaterialManifest::isCustom() const { return d->isCustom; diff --git a/doomsday/client/src/resource/materials.cpp b/doomsday/client/src/resource/materials.cpp index 1984be697f..1bb00608df 100644 --- a/doomsday/client/src/resource/materials.cpp +++ b/doomsday/client/src/resource/materials.cpp @@ -524,6 +524,7 @@ Material *Materials::newFromDef(ded_material_t &def) { manifest = &newManifest(scheme(uri.scheme()), uri.path()); } + manifest->setAutoGenerated(CPP_BOOL(def.autoGenerated)); manifest->setCustom(tex->flags().testFlag(Texture::Custom)); // Create a material for this right away.