Skip to content

Commit

Permalink
Cleanup: Impl Material's Decoration and Layer inner classes in materi…
Browse files Browse the repository at this point in the history
…al.cpp
  • Loading branch information
danij-deng committed Jan 16, 2013
1 parent 1556bfa commit 458b789
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 58 deletions.
74 changes: 16 additions & 58 deletions doomsday/engine/include/resource/material.h
Expand Up @@ -64,6 +64,7 @@ class MaterialVariant;
struct MaterialVariantSpec;

/**
* A logical material.
* @ingroup resource
*/
class Material
Expand All @@ -73,7 +74,9 @@ class Material
typedef QList<MaterialVariant *> Variants;

/**
* Layer.
* Each material consitutes at least one layer. Layers are arranged in a
* stack according to the order in which they should be drawn, from the
* bottom-most to the top-most layer.
*/
class Layer
{
Expand All @@ -85,36 +88,22 @@ class Material
/**
* Construct a new default layer.
*/
Layer() {}
Layer();

/**
* Construct a new layer from the specified definition.
*/
static Layer *fromDef(ded_material_layer_t &def)
{
Layer *layer = new Layer();
for(int i = 0; i < def.stageCount.num; ++i)
{
layer->stages_.push_back(&def.stages[i]);
}
return layer;
}
static Layer *fromDef(ded_material_layer_t &def);

/**
* Returns the total number of animation stages for the layer.
*/
int stageCount() const
{
return stages_.count();
}
int stageCount() const;

/**
* Provides access to the animation stages for efficient traversal.
*/
Stages const &stages() const
{
return stages_;
}
Stages const &stages() const;

private:
/// Animation stages.
Expand All @@ -137,74 +126,43 @@ class Material
/**
* Construct a new default decoration.
*/
Decoration() : patternSkip_(0, 0), patternOffset_(0, 0)
{}
Decoration();

Decoration(Vector2i const &_patternSkip, Vector2i const &_patternOffset)
: patternSkip_(_patternSkip), patternOffset_(_patternOffset)
{}
Decoration(Vector2i const &_patternSkip, Vector2i const &_patternOffset);

/**
* Construct a new decoration from the specified definition.
*/
static Decoration *fromDef(ded_material_decoration_t &def)
{
Decoration *dec = new Decoration(Vector2i(def.patternSkip),
Vector2i(def.patternOffset));
for(int i = 0; i < def.stageCount.num; ++i)
{
dec->stages_.push_back(&def.stages[i]);
}
return dec;
}
static Decoration *fromDef(ded_material_decoration_t &def);

/**
* Construct a new decoration from the specified definition.
*/
static Decoration *fromDef(ded_decoration_t &def)
{
Decoration *dec = new Decoration(Vector2i(def.patternSkip),
Vector2i(def.patternOffset));
// Only the one stage.
dec->stages_.push_back(&def.stage);
return dec;
}
static Decoration *fromDef(ded_decoration_t &def);

/**
* Retrieve the pattern skip for the decoration. Normally a decoration
* is repeated on a surface as many times as the material does. A skip
* pattern allows sparser repeats on the horizontal and vertical axes
* respectively.
*/
Vector2i const &patternSkip() const
{
return patternSkip_;
}
Vector2i const &patternSkip() const;

/**
* Retrieve the pattern offset for the decoration. Used with pattern
* skip to offset the origin of the pattern.
*/
Vector2i const &patternOffset() const
{
return patternOffset_;
}
Vector2i const &patternOffset() const;

/**
* Returns the total number of animation stages for the decoration.
*/
int stageCount() const
{
return stages_.count();
}
int stageCount() const;

/**
* Provides access to the animation stages for efficient traversal.
*/
Stages const &stages() const
{
return stages_;
}
Stages const &stages() const;

private:
/// Pattern skip intervals.
Expand Down
71 changes: 71 additions & 0 deletions doomsday/engine/src/resource/material.cpp
Expand Up @@ -34,6 +34,77 @@

using namespace de;

Material::Layer::Layer()
{}

Material::Layer *Material::Layer::fromDef(ded_material_layer_t &def)
{
Layer *layer = new Layer();
for(int i = 0; i < def.stageCount.num; ++i)
{
layer->stages_.push_back(&def.stages[i]);
}
return layer;
}

int Material::Layer::stageCount() const
{
return stages_.count();
}

Material::Layer::Stages const &Material::Layer::stages() const
{
return stages_;
}

Material::Decoration::Decoration()
: patternSkip_(0, 0), patternOffset_(0, 0)
{}

Material::Decoration::Decoration(Vector2i const &_patternSkip, Vector2i const &_patternOffset)
: patternSkip_(_patternSkip), patternOffset_(_patternOffset)
{}

Material::Decoration *Material::Decoration::fromDef(ded_material_decoration_t &def)
{
Decoration *dec = new Decoration(Vector2i(def.patternSkip),
Vector2i(def.patternOffset));
for(int i = 0; i < def.stageCount.num; ++i)
{
dec->stages_.push_back(&def.stages[i]);
}
return dec;
}

Material::Decoration *Material::Decoration::fromDef(ded_decoration_t &def)
{
Decoration *dec = new Decoration(Vector2i(def.patternSkip),
Vector2i(def.patternOffset));
// Only the one stage.
dec->stages_.push_back(&def.stage);
return dec;
}

Vector2i const &Material::Decoration::patternSkip() const
{
return patternSkip_;
}

Vector2i const &Material::Decoration::patternOffset() const
{
return patternOffset_;
}

int Material::Decoration::stageCount() const
{
return stages_.count();
}

Material::Decoration::Stages const &Material::Decoration::stages() const
{
return stages_;
}

struct material_s
{
/// DMU object header.
Expand Down

0 comments on commit 458b789

Please sign in to comment.