Skip to content

Commit

Permalink
Cleanup: Added isFlagged() method to various material/texture system …
Browse files Browse the repository at this point in the history
…classes
  • Loading branch information
danij-deng committed Feb 28, 2013
1 parent 11827ca commit 39b6941
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 34 deletions.
15 changes: 13 additions & 2 deletions doomsday/client/include/resource/compositetexture.h
Expand Up @@ -159,11 +159,22 @@ class CompositeTexture
Components const &components() const;

/**
* Provides access to the usage flags for the texture for efficent manipulation.
* Returns @c true if the texture has flagged @a flagsToTest.
*/
Flags &flags();
inline bool isFlagged(Flags flagsToTest) const { return flags() & flagsToTest; }

/**
* Returns the flags for the composite texture.
*/
Flags flags() const;

/**
* Change the composite texture's flags.
*
* @param flagsToChange Flags to change the value of.
* @param set @c true to set, @c false to clear.
*/
void setFlags(Flags flagsToChange, bool set = true);

private:
DENG2_PRIVATE(d)
Expand Down
9 changes: 7 additions & 2 deletions doomsday/client/include/resource/material.h
Expand Up @@ -655,13 +655,13 @@ class Material : public de::MapElement
bool isDetailed() const;

/// Returns @c true if the material is considered drawable.
bool isDrawable() const { return !flags().testFlag(NoDraw); }
bool isDrawable() const { return !isFlagged(NoDraw); }

/// Returns @c true if the material has a shine texturing layer.
bool isShiny() const;

/// Returns @c true if the material is considered @em skymasked.
inline bool isSkyMasked() const { return flags().testFlag(SkyMask); }
inline bool isSkyMasked() const { return isFlagged(SkyMask); }

/// Returns @c true if one or more of the material's layers are glowing.
bool hasGlow() const;
Expand Down Expand Up @@ -695,6 +695,11 @@ class Material : public de::MapElement
*/
void setHeight(int newHeight);

/**
* Returns @c true if the material is flagged @a flagsToTest.
*/
inline bool isFlagged(Flags flagsToTest) const { return !!(flags() & flagsToTest); }

/**
* Returns the flags for the material.
*/
Expand Down
9 changes: 7 additions & 2 deletions doomsday/client/include/resource/materialmanifest.h
Expand Up @@ -101,10 +101,15 @@ class MaterialManifest : public PathTree::Node
void setId(materialid_t newId);

/// @c true if the manifest was automatically produced for a game/add-on resource.
inline bool isAutoGenerated() const { return flags().testFlag(AutoGenerated); }
inline bool isAutoGenerated() const { return isFlagged(AutoGenerated); }

/// @c true if the manifest was not produced for an original game resource.
inline bool isCustom() const { return flags().testFlag(Custom); }
inline bool isCustom() const { return isFlagged(Custom); }

/**
* Returns @c true if the manifest is flagged @a flagsToTest.
*/
inline bool isFlagged(Flags flagsToTest) const { return !!(flags() & flagsToTest); }

/**
* Returns the flags for the manifest.
Expand Down
14 changes: 12 additions & 2 deletions doomsday/client/include/resource/texture.h
Expand Up @@ -162,14 +162,19 @@ class Texture
void setCoords(float s, float t);

/// Returns @c true if the variant is flagged as "masked".
inline bool isMasked() const { return flags().testFlag(Masked); }
inline bool isMasked() const { return isFlagged(Masked); }

/// Returns @c true if the variant is flagged as "uploaded".
inline bool isUploaded() const { return flags().testFlag(Uploaded); }
inline bool isUploaded() const { return isFlagged(Uploaded); }

/// Returns @c true if the variant is "prepared".
inline bool isPrepared() const { return isUploaded() && glName() != 0; }

/**
* Returns @c true if the variant is flagged @a flagsToTest.
*/
inline bool isFlagged(Flags flagsToTest) const { return !!(flags() & flagsToTest); }

/**
* Returns the flags for the variant.
*/
Expand Down Expand Up @@ -281,6 +286,11 @@ class Texture
*/
void setOrigin(Vector2i const &newOrigin);

/**
* Returns @c true if the texture is flagged @a flagsToTest.
*/
inline bool isFlagged(Flags flagsToTest) const { return !!(flags() & flagsToTest); }

/**
* Returns the flags for the texture.
*/
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/def_main.cpp
Expand Up @@ -965,7 +965,7 @@ static void generateMaterialDefForTexture(TextureManifest &manifest)
Texture &tex = manifest.texture();
mat->width = tex.width();
mat->height = tex.height();
mat->flags = (tex.flags().testFlag(Texture::NoDraw)? Material::NoDraw : 0);
mat->flags = (tex.isFlagged(Texture::NoDraw)? Material::NoDraw : 0);
}
#if _DEBUG
else
Expand Down Expand Up @@ -1163,7 +1163,7 @@ static void interpretMaterialDef(ded_material_t const &def)
try
{
Texture &texture = App_Textures().find(*reinterpret_cast<de::Uri *>(firstLayer.stages[0].texture)).texture();
if(texture.flags().testFlag(Texture::Custom))
if(texture.isFlagged(Texture::Custom))
manifest->setFlags(MaterialManifest::Custom);
}
catch(Textures::NotFoundError const &er)
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/gl/dgl_common.cpp
Expand Up @@ -751,8 +751,8 @@ void DGL_SetPatch(patchid_t id, DGLint wrapS, DGLint wrapT)

Texture &tex = manifest.texture();
texturevariantspecification_t &texSpec =
*Rend_PatchTextureSpec(0 | (tex.flags().testFlag(Texture::Monochrome) ? TSF_MONOCHROME : 0)
| (tex.flags().testFlag(Texture::UpscaleAndSharpen) ? TSF_UPSCALE_AND_SHARPEN : 0),
*Rend_PatchTextureSpec(0 | (tex.isFlagged(Texture::Monochrome) ? TSF_MONOCHROME : 0)
| (tex.isFlagged(Texture::UpscaleAndSharpen) ? TSF_UPSCALE_AND_SHARPEN : 0),
DGL_ToGLWrapCap(wrapS), DGL_ToGLWrapCap(wrapT));
GL_BindTexture(GL_PrepareTexture(tex, texSpec));
}
Expand Down
6 changes: 3 additions & 3 deletions doomsday/client/src/gl/gl_texmanager.cpp
Expand Up @@ -622,7 +622,7 @@ static TexSource loadSourceImage(de::Texture &tex, texturevariantspecification_t
if(!tex.manifest().schemeName().compareWithoutCase("Textures"))
{
// Attempt to load an external replacement for this composite texture?
if(!noHighResTex && (loadExtAlways || highResWithPWAD || !tex.flags().testFlag(de::Texture::Custom)))
if(!noHighResTex && (loadExtAlways || highResWithPWAD || !tex.isFlagged(de::Texture::Custom)))
{
// First try the textures scheme.
de::Uri uri = tex.manifest().composeUri();
Expand All @@ -646,7 +646,7 @@ static TexSource loadSourceImage(de::Texture &tex, texturevariantspecification_t
else if(!tex.manifest().schemeName().compareWithoutCase("Flats"))
{
// Attempt to load an external replacement for this flat?
if(!noHighResTex && (loadExtAlways || highResWithPWAD || !tex.flags().testFlag(de::Texture::Custom)))
if(!noHighResTex && (loadExtAlways || highResWithPWAD || !tex.isFlagged(de::Texture::Custom)))
{
// First try the flats scheme.
de::Uri uri = tex.manifest().composeUri();
Expand Down Expand Up @@ -694,7 +694,7 @@ static TexSource loadSourceImage(de::Texture &tex, texturevariantspecification_t
}

// Attempt to load an external replacement for this patch?
if(!noHighResTex && (loadExtAlways || highResWithPWAD || !tex.flags().testFlag(de::Texture::Custom)))
if(!noHighResTex && (loadExtAlways || highResWithPWAD || !tex.isFlagged(de::Texture::Custom)))
{
de::Uri uri = tex.manifest().composeUri();
source = loadExternalTexture(image, uri.compose(), "-ck");
Expand Down
8 changes: 4 additions & 4 deletions doomsday/client/src/render/r_draw.cpp
Expand Up @@ -146,8 +146,8 @@ void R_DrawPatch(Texture &tex, int x, int y, int w, int h, bool useOffsets)
}

texturevariantspecification_t *texSpec =
Rend_PatchTextureSpec(0 | (tex.flags().testFlag(Texture::Monochrome) ? TSF_MONOCHROME : 0)
| (tex.flags().testFlag(Texture::UpscaleAndSharpen) ? TSF_UPSCALE_AND_SHARPEN : 0));
Rend_PatchTextureSpec(0 | (tex.isFlagged(Texture::Monochrome) ? TSF_MONOCHROME : 0)
| (tex.isFlagged(Texture::UpscaleAndSharpen) ? TSF_UPSCALE_AND_SHARPEN : 0));
GL_BindTexture(GL_PrepareTexture(tex, *texSpec));

if(useOffsets)
Expand All @@ -167,8 +167,8 @@ void R_DrawPatch(Texture &tex, int x, int y)
void R_DrawPatchTiled(Texture &tex, int x, int y, int w, int h, int wrapS, int wrapT)
{
texturevariantspecification_t *texSpec =
Rend_PatchTextureSpec(0 | (tex.flags().testFlag(Texture::Monochrome) ? TSF_MONOCHROME : 0)
| (tex.flags().testFlag(Texture::UpscaleAndSharpen) ? TSF_UPSCALE_AND_SHARPEN : 0),
Rend_PatchTextureSpec(0 | (tex.isFlagged(Texture::Monochrome) ? TSF_MONOCHROME : 0)
| (tex.isFlagged(Texture::UpscaleAndSharpen) ? TSF_UPSCALE_AND_SHARPEN : 0),
wrapS, wrapT);

GL_BindTexture(GL_PrepareTexture(tex, *texSpec));
Expand Down
11 changes: 11 additions & 0 deletions doomsday/client/src/resource/compositetexture.cpp
Expand Up @@ -118,6 +118,17 @@ CompositeTexture::Flags CompositeTexture::flags() const
return d->flags;
}

void CompositeTexture::setFlags(CompositeTexture::Flags flagsToChange, bool set)
{
if(set)
{
d->flags |= flagsToChange;
}
else
{
d->flags &= ~flagsToChange;
}
}

int CompositeTexture::origIndex() const
{
Expand Down
19 changes: 9 additions & 10 deletions doomsday/client/src/resource/r_data.cpp
Expand Up @@ -243,11 +243,10 @@ DENG_EXTERN_C patchid_t R_DeclarePatch(char const *name)
#undef R_GetPatchInfo
DENG_EXTERN_C boolean R_GetPatchInfo(patchid_t id, patchinfo_t *info)
{
DENG2_ASSERT(info);
LOG_AS("R_GetPatchInfo");
if(!info) LegacyCore_FatalError("R_GetPatchInfo: Argument 'info' cannot be NULL.");

std::memset(info, 0, sizeof(patchinfo_t));

if(!id) return false;

try
Expand All @@ -257,13 +256,13 @@ DENG_EXTERN_C boolean R_GetPatchInfo(patchid_t id, patchinfo_t *info)
#ifdef __CLIENT__
// Ensure we have up to date information about this patch.
texturevariantspecification_t &texSpec =
*Rend_PatchTextureSpec(0 | (tex.flags().testFlag(Texture::Monochrome) ? TSF_MONOCHROME : 0)
| (tex.flags().testFlag(Texture::UpscaleAndSharpen) ? TSF_UPSCALE_AND_SHARPEN : 0));
*Rend_PatchTextureSpec(0 | (tex.isFlagged(Texture::Monochrome) ? TSF_MONOCHROME : 0)
| (tex.isFlagged(Texture::UpscaleAndSharpen) ? TSF_UPSCALE_AND_SHARPEN : 0));
GL_PrepareTexture(tex, texSpec);
#endif

info->id = id;
info->flags.isCustom = tex.flags().testFlag(Texture::Custom);
info->flags.isCustom = tex.isFlagged(Texture::Custom);

averagealpha_analysis_t *aa = reinterpret_cast<averagealpha_analysis_t *>(tex.analysisDataPointer(Texture::AverageAlphaAnalysis));
info->flags.isEmpty = aa && FEQUAL(aa->alpha, 0);
Expand All @@ -275,7 +274,7 @@ DENG_EXTERN_C boolean R_GetPatchInfo(patchid_t id, patchinfo_t *info)
info->geometry.origin.y = tex.origin().y;

/// @todo fixme: kludge:
info->extraOffset[0] = info->extraOffset[1] = (tex.flags().testFlag(Texture::UpscaleAndSharpen)? -1 : 0);
info->extraOffset[0] = info->extraOffset[1] = (tex.isFlagged(Texture::UpscaleAndSharpen)? -1 : 0);
// Kludge end.
return true;
}
Expand All @@ -284,7 +283,7 @@ DENG_EXTERN_C boolean R_GetPatchInfo(patchid_t id, patchinfo_t *info)
// Log but otherwise ignore this error.
LOG_WARNING(er.asText() + ", ignoring.");
}
catch(Textures::Scheme::NotFoundError const &er)
catch(TextureScheme::NotFoundError const &er)
{
// Log but otherwise ignore this error.
LOG_WARNING(er.asText() + ", ignoring.");
Expand Down Expand Up @@ -557,7 +556,7 @@ static CompositeTextures loadCompositeTextureDefs()
if(!orig->percentEncodedName().compareWithoutCase(custom->percentEncodedName()))
{
// Definition 'custom' is destined to replace 'orig'.
if(custom->flags().testFlag(CompositeTexture::Custom))
if(custom->isFlagged(CompositeTexture::Custom))
{
hasReplacement = true; // Uses a custom patch.
}
Expand All @@ -573,7 +572,7 @@ static CompositeTextures loadCompositeTextureDefs()
{
// Check the patches.
short k = 0;
while(k < orig->componentCount() && !custom->flags().testFlag(CompositeTexture::Custom))
while(k < orig->componentCount() && !custom->isFlagged(CompositeTexture::Custom))
{
CompositeTexture::Component const &origP = orig->components()[k];
CompositeTexture::Component const &customP = custom->components()[k];
Expand Down Expand Up @@ -630,7 +629,7 @@ static void processCompositeTextureDefs(CompositeTextures &defs)
de::Uri uri("Textures", Path(def.percentEncodedName()));

Texture::Flags flags;
if(def.flags().testFlag(CompositeTexture::Custom)) flags |= Texture::Custom;
if(def.isFlagged(CompositeTexture::Custom)) flags |= Texture::Custom;

/*
* The id Tech 1 implementation of the texture collection has a flaw
Expand Down
6 changes: 3 additions & 3 deletions doomsday/client/src/resource/textures.cpp
Expand Up @@ -413,11 +413,11 @@ static void printTextureInfo(Texture &tex)
#ifdef __CLIENT__
Con_Printf("Texture \"%s\" [%p] x%u origin:%s\n",
path.constData(), (void *)&tex, tex.variantCount(),
tex.flags().testFlag(Texture::Custom)? "addon" : "game");
tex.isFlagged(Texture::Custom)? "addon" : "game");
#else
Con_Printf("Texture \"%s\" [%p] origin:%s\n",
path.constData(), (void *)&tex,
tex.flags().testFlag(Texture::Custom)? "addon" : "game");
tex.isFlagged(Texture::Custom)? "addon" : "game");
#endif

if(tex.width() == 0 && tex.height() == 0)
Expand All @@ -441,7 +441,7 @@ static void printManifestInfo(TextureManifest &manifest,
de::Uri::ComposeAsTextFlags uriCompositionFlags = de::Uri::DefaultComposeAsTextFlags)
{
String sourceDescription = !manifest.hasTexture()? "unknown"
: manifest.texture().flags().testFlag(Texture::Custom)? "addon" : "game";
: manifest.texture().isFlagged(Texture::Custom)? "addon" : "game";

String info = String("%1 %2")
.arg(manifest.composeUri().compose(uriCompositionFlags | de::Uri::DecodePath),
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/ui/ui2_main.cpp
Expand Up @@ -1063,8 +1063,8 @@ static void drawPicFrame(fidata_pic_t *p, uint frame, float const _origin[3],
{
Texture &tex = manifest.texture();
texturevariantspecification_t &texSpec =
*Rend_PatchTextureSpec(0 | (tex.flags().testFlag(Texture::Monochrome) ? TSF_MONOCHROME : 0)
| (tex.flags().testFlag(Texture::UpscaleAndSharpen) ? TSF_UPSCALE_AND_SHARPEN : 0));
*Rend_PatchTextureSpec(0 | (tex.isFlagged(Texture::Monochrome) ? TSF_MONOCHROME : 0)
| (tex.isFlagged(Texture::UpscaleAndSharpen) ? TSF_UPSCALE_AND_SHARPEN : 0));
GL_BindTexture(GL_PrepareTexture(tex, texSpec));
glEnable(GL_TEXTURE_2D);
textureEnabled = true;
Expand Down

0 comments on commit 39b6941

Please sign in to comment.