Skip to content

Commit

Permalink
libdeng2|Clock: Priority audience for time change
Browse files Browse the repository at this point in the history
In some cases it is necessary for certain time change audience members
to be notified before other members (e.g., ScalarRule must be already
invalidated when the regular time change notifications go out).

Added a "priority" audience to Clock that will always be notified
before the regular audience. Animation-related clock observers are now
put in the priority audience.
  • Loading branch information
skyjake committed Jun 13, 2013
1 parent c73f377 commit 34a4280
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
11 changes: 11 additions & 0 deletions doomsday/libdeng2/include/de/core/clock.h
Expand Up @@ -32,8 +32,19 @@ namespace de {
class DENG2_PUBLIC Clock
{
public:
/**
* Notified whenever the time of the clock changes. The audience members
* will be notified in unspecified order.
*/
DENG2_DEFINE_AUDIENCE(TimeChange, void timeChanged(Clock const &))

/**
* Notified whenever the time of the clock changes. The entire priority
* audience is notified before the regular TimeChange audience.
*/
typedef Observers<DENG2_AUDIENCE_INTERFACE(TimeChange)> PriorityTimeChangeAudience;
PriorityTimeChangeAudience audienceForPriorityTimeChange;

public:
Clock();

Expand Down
7 changes: 7 additions & 0 deletions doomsday/libdeng2/include/de/widgets/scalarrule.h
Expand Up @@ -40,6 +40,13 @@ class DENG2_PUBLIC ScalarRule : public Rule, DENG2_OBSERVES(Clock, TimeChange)

void set(Rule const &target, TimeDelta transition = 0);

/**
* Sets the animation style of the rule.
*
* @param style Animation style.
*/
void setStyle(Animation::Style style);

/**
* Read-only access to the scalar animation.
*/
Expand Down
4 changes: 4 additions & 0 deletions doomsday/libdeng2/src/core/clock.cpp
Expand Up @@ -36,6 +36,10 @@ void Clock::setTime(Time const &currentTime)

if(changed)
{
DENG2_FOR_EACH_OBSERVER(PriorityTimeChangeAudience, i, audienceForPriorityTimeChange)
{
i->timeChanged(*this);
}
DENG2_FOR_AUDIENCE(TimeChange, i) i->timeChanged(*this);
}
}
Expand Down
4 changes: 2 additions & 2 deletions doomsday/libdeng2/src/widgets/rulerectangle.cpp
Expand Up @@ -325,7 +325,7 @@ public DelegateRule::ISource

if(normalizedAnchorPoint.done())
{
clock.audienceForTimeChange -= this;
clock.audienceForPriorityTimeChange -= this;
}
}
};
Expand Down Expand Up @@ -417,7 +417,7 @@ void RuleRectangle::setAnchorPoint(Vector2f const &normalizedPoint, TimeDelta co
if(transition > 0.0)
{
// Animation started, keep an eye on the clock until it ends.
Clock::appClock().audienceForTimeChange += d;
Clock::appClock().audienceForPriorityTimeChange += d;
}
}

Expand Down
9 changes: 7 additions & 2 deletions doomsday/libdeng2/src/widgets/scalarrule.cpp
Expand Up @@ -37,7 +37,7 @@ void ScalarRule::set(float target, de::TimeDelta transition)
independentOf(_targetRule);
_targetRule = 0;

_animation.clock().audienceForTimeChange += this;
_animation.clock().audienceForPriorityTimeChange += this;

_animation.setValue(target, transition);
invalidate();
Expand All @@ -52,6 +52,11 @@ void ScalarRule::set(Rule const &target, TimeDelta transition)
dependsOn(_targetRule);
}

void ScalarRule::setStyle(Animation::Style style)
{
_animation.setStyle(style);
}

void ScalarRule::shift(float delta)
{
_animation.shift(delta);
Expand All @@ -75,7 +80,7 @@ void ScalarRule::timeChanged(Clock const &clock)

if(_animation.done())
{
clock.audienceForTimeChange -= this;
clock.audienceForPriorityTimeChange -= this;
}
}

Expand Down

0 comments on commit 34a4280

Please sign in to comment.