Skip to content

Commit

Permalink
Debug|libdeng2: Describing rules as text
Browse files Browse the repository at this point in the history
Added descriptions for rules so it is easier to see if there are any
mistakes in them (e.g., missing edges of a rectangle).
  • Loading branch information
skyjake committed Jun 14, 2013
1 parent 1c40395 commit 14c813e
Show file tree
Hide file tree
Showing 11 changed files with 124 additions and 3 deletions.
2 changes: 2 additions & 0 deletions doomsday/libdeng2/include/de/widgets/constantrule.h
Expand Up @@ -65,6 +65,8 @@ class DENG2_PUBLIC ConstantRule : public Rule
*/
void set(float newValue);

String description() const;

protected:
void update();

Expand Down
4 changes: 4 additions & 0 deletions doomsday/libdeng2/include/de/widgets/delegaterule.h
Expand Up @@ -49,6 +49,8 @@ class DENG2_PUBLIC DelegateRule : public ConstantRule
virtual void delegateUpdate(int id) = 0;

virtual void delegateInvalidation(int id) = 0;

virtual String delegateDescription(int id) const = 0;
};

public:
Expand All @@ -71,6 +73,8 @@ class DENG2_PUBLIC DelegateRule : public ConstantRule

void invalidate();

String description() const;

protected:
~DelegateRule(); // Counted

Expand Down
2 changes: 2 additions & 0 deletions doomsday/libdeng2/include/de/widgets/operatorrule.h
Expand Up @@ -66,6 +66,8 @@ class DENG2_PUBLIC OperatorRule : public Rule

void update();

String description() const;

private:
Operator _operator;
Rule const *_leftOperand;
Expand Down
3 changes: 3 additions & 0 deletions doomsday/libdeng2/include/de/widgets/rule.h
Expand Up @@ -23,6 +23,7 @@
#include "../libdeng2.h"
#include "../Counted"
#include "../Observers"
#include "../String"

namespace de {

Expand Down Expand Up @@ -113,6 +114,8 @@ class DENG2_PUBLIC Rule : public Counted, public DENG2_AUDIENCE_INTERFACE(RuleIn

void independentOf(Rule const *dependencyOrNull);

virtual String description() const = 0;

public:
/**
* Clears the flag that determines whether there are any invalid rules.
Expand Down
2 changes: 2 additions & 0 deletions doomsday/libdeng2/include/de/widgets/rulerectangle.h
Expand Up @@ -100,6 +100,8 @@ class DENG2_PUBLIC RuleRectangle
*/
Rectanglei recti() const;

String description() const;

private:
DENG2_PRIVATE(d)
};
Expand Down
2 changes: 2 additions & 0 deletions doomsday/libdeng2/include/de/widgets/scalarrule.h
Expand Up @@ -62,6 +62,8 @@ class DENG2_PUBLIC ScalarRule : public Rule, DENG2_OBSERVES(Clock, TimeChange)
*/
void shift(float delta);

String description() const;

protected:
~ScalarRule();
void update();
Expand Down
5 changes: 5 additions & 0 deletions doomsday/libdeng2/src/widgets/constantrule.cpp
Expand Up @@ -39,6 +39,11 @@ void ConstantRule::set(float newValue)
invalidate();
}

String ConstantRule::description() const
{
return String("Constant(%1)").arg(cachedValue());
}

void ConstantRule::update()
{
setValue(_pendingValue);
Expand Down
9 changes: 9 additions & 0 deletions doomsday/libdeng2/src/widgets/delegaterule.cpp
Expand Up @@ -61,4 +61,13 @@ void DelegateRule::invalidate()
}
}

String DelegateRule::description() const
{
if(_source)
{
return QString("Delegate(%1)").arg(_source->delegateDescription(_delegateId));
}
return "Delegate(NULL)";
}

} // namespace de
28 changes: 28 additions & 0 deletions doomsday/libdeng2/src/widgets/operatorrule.cpp
Expand Up @@ -101,4 +101,32 @@ void OperatorRule::update()
setValue(v);
}

String OperatorRule::description() const
{
static char const *texts[] = {
"Equals",
"Negate",
"Half",
"Double",
"Sum",
"Subtract",
"Multiply",
"Divide",
"Maximum",
"Minimum",
"Floor"
};

String desc = String("Operator %1 { ").arg(texts[_operator]);
if(_leftOperand)
{
desc += _leftOperand->description();
}
if(_rightOperand)
{
desc += ", " + _rightOperand->description();
}
return desc + " }";
}

} // namespace de
60 changes: 57 additions & 3 deletions doomsday/libdeng2/src/widgets/rulerectangle.cpp
Expand Up @@ -24,7 +24,7 @@

namespace de {

DENG2_PIMPL_NOREF(RuleRectangle),
DENG2_PIMPL(RuleRectangle),
DENG2_OBSERVES(Clock, TimeChange),
public DelegateRule::ISource
{
Expand Down Expand Up @@ -54,7 +54,7 @@ public DelegateRule::ISource
// The output rules.
DelegateRule *outputRules[MAX_OUTPUT_RULES];

Instance()
Instance(Public *i) : Base(i)
{
zap(inputRules);

Expand Down Expand Up @@ -187,6 +187,13 @@ public DelegateRule::ISource
leftDefined = true;
}

#ifdef _DEBUG
if(!leftDefined || !rightDefined)
{
qDebug() << self.description().toLatin1();
}
#endif

DENG2_ASSERT(leftDefined);
DENG2_ASSERT(rightDefined);

Expand Down Expand Up @@ -246,6 +253,12 @@ public DelegateRule::ISource
topDefined = true;
}

#ifdef _DEBUG
if(!topDefined || !bottomDefined)
{
qDebug() << self.description().toLatin1();
}
#endif
DENG2_ASSERT(topDefined);
DENG2_ASSERT(bottomDefined);

Expand Down Expand Up @@ -319,6 +332,20 @@ public DelegateRule::ISource
}
}

String delegateDescription(int id) const
{
static char const *names[MAX_OUTPUT_RULES] = {
"Left output",
"Right output",
"Width output",
"Top output",
"Bottom output",
"Height output"
};
return String(names[id]) + " of RuleRectangle " +
QString("0x%1").arg(dintptr(thisPublic), 0, 16);
}

void timeChanged(Clock const &clock)
{
invalidateOutputs();
Expand All @@ -330,7 +357,7 @@ public DelegateRule::ISource
}
};

RuleRectangle::RuleRectangle() : d(new Instance)
RuleRectangle::RuleRectangle() : d(new Instance(this))
{}

Rule const &RuleRectangle::left() const
Expand Down Expand Up @@ -434,4 +461,31 @@ Rectanglei RuleRectangle::recti() const
Vector2i(de::floor(r.bottomRight.x), de::floor(r.bottomRight.y)));
}

String RuleRectangle::description() const
{
String desc = String("RuleRectangle 0x%1:").arg(dintptr(this), 0, 16);

for(int i = 0; i < int(Rule::MAX_SEMANTICS); ++i)
{
desc += String("\n - ") +
(i == Rule::Left? "Left" :
i == Rule::Top? "Top" :
i == Rule::Right? "Right" :
i == Rule::Bottom? "Bottom" :
i == Rule::Width? "Width" :
i == Rule::Height? "Height" :
i == Rule::AnchorX? "AnchorX" : "AnchorY") + ": ";

if(d->inputRules[i])
{
desc += d->inputRules[i]->description();
}
else
{
desc += "(null)";
}
}
return desc;
}

} // namespace de
10 changes: 10 additions & 0 deletions doomsday/libdeng2/src/widgets/scalarrule.cpp
Expand Up @@ -63,6 +63,16 @@ void ScalarRule::shift(float delta)
invalidate();
}

String ScalarRule::description() const
{
String desc = "Scalar(" + _animation.asText();
if(_targetRule)
{
desc += "; target: " + _targetRule->description();
}
return desc + ")";
}

void ScalarRule::update()
{
// When using a rule for the target, keep it updated.
Expand Down

0 comments on commit 14c813e

Please sign in to comment.