Skip to content

Commit

Permalink
Some repeat related fiddling; have Viz track its View in a member.
Browse files Browse the repository at this point in the history
  • Loading branch information
samskivert committed May 13, 2011
1 parent 3baae72 commit 7220ab3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 22 deletions.
14 changes: 7 additions & 7 deletions core/src/main/java/com/threerings/jiggl/tween/Tween.java
Expand Up @@ -5,6 +5,7 @@
package com.threerings.jiggl.tween;

import com.threerings.jiggl.util.Scalar;
import com.threerings.jiggl.view.Viz;

/**
* Manages the animation of a particular property of a visible.
Expand Down Expand Up @@ -146,9 +147,8 @@ protected boolean apply (float time) {
/** A tween that repeats its underlying tween over and over again (until removed). */
public static class Repeat extends Tween
{
/** Cancels this repeating tween. */
public void cancel () {
_cancelled = true;
public Repeat (Viz viz) {
_viz = viz;
}

@Override
Expand All @@ -167,20 +167,20 @@ protected boolean apply (float time) {
@Override
protected boolean apply (Tweener tweener, float time)
{
// if we're canceled, stop now
if (_cancelled) return true;

// if our current chain of tweens is still running, keep going
if (!super.apply(tweener, time)) return false;

// if our target viz is no longer active, we're done
if (!_viz.isAdded()) return true;

// otherwise, reset to the head of the chain and keep going
float overrun = _current.getOverrun(time);
_current = _next;
_current.init(time-overrun);
return false;
}

protected boolean _cancelled = false;
protected Viz _viz;
}

/**
Expand Down
10 changes: 6 additions & 4 deletions core/src/main/java/com/threerings/jiggl/tween/Tweener.java
Expand Up @@ -9,6 +9,7 @@

import com.threerings.jiggl.util.Driver;
import com.threerings.jiggl.util.Scalar;
import com.threerings.jiggl.view.Viz;

/**
* Handles the animation of viz properties (position, rotation, etc.).
Expand Down Expand Up @@ -104,12 +105,13 @@ public Tween.Delay delay (float seconds)
}

/**
* Returns a tweener which can be used to construct a tween that will be repeated until
* canceled.
* Returns a tweener which can be used to construct a tween that will be repeated until the
* supplied viz has been removed from its view. The viz must be added to the view in question
* before the next frame tick, or the cancellation will trigger immediately.
*/
public Tweener repeat ()
public Tweener repeat (Viz viz)
{
return register(new Tween.Repeat()).then();
return register(new Tween.Repeat(viz)).then();
}

/**
Expand Down
11 changes: 6 additions & 5 deletions core/src/main/java/com/threerings/jiggl/view/View.java
Expand Up @@ -8,6 +8,7 @@
import java.util.List;

import com.threerings.jiggl.rsrc.Tile;
import com.threerings.jiggl.util.Color;

/**
* Coordinates the display and animation of a collection of {@link Viz} instances.
Expand All @@ -30,7 +31,7 @@ public <T extends Viz> T add (T viz)
public void remove (Viz viz)
{
_vizs.remove(viz);
viz.onRemove(this);
viz.onRemove();
}

/**
Expand All @@ -39,7 +40,7 @@ public void remove (Viz viz)
public void clear ()
{
for (Viz v : _vizs) {
v.onRemove(this);
v.onRemove();
}
_vizs.clear();
}
Expand All @@ -50,9 +51,9 @@ public void clear ()
public abstract void render ();

/**
* Creates a visible that renders the supplied geometry.
* Creates a visible that renders the supplied geometry using the supplied color.
*/
public abstract Viz newGeomViz (Geometry geom);
public abstract Viz newGeomViz (Geometry geom, Color color);

/**
* Creates a visible to render the supplied tile.
Expand All @@ -65,7 +66,7 @@ public void clear ()
protected void renderVisibles ()
{
for (int ii = 0, ll = _vizs.size(); ii < ll; ii++) {
_vizs.get(ii).render(this);
_vizs.get(ii).render();
}
}

Expand Down
13 changes: 7 additions & 6 deletions core/src/main/java/com/threerings/jiggl/view/Viz.java
Expand Up @@ -4,7 +4,6 @@

package com.threerings.jiggl.view;

import com.threerings.jiggl.util.Color;
import com.threerings.jiggl.util.Scalar;

/**
Expand All @@ -30,9 +29,6 @@ public abstract class Viz
/** The rotation of this visible, in radians. */
public final Scalar rotation = new Scalar(0);

/** The color of this visible, or null. */
public Color color;

/**
* Returns the width of this visible, including local scaling transformations (but not
* rotation). Transformations applied by a parent of this visible are also not included.
Expand All @@ -45,6 +41,11 @@ public abstract class Viz
*/
public abstract float getHeight ();

/**
* Returns true if this viz is added to a view, false otherwise.
*/
public abstract boolean isAdded ();

/**
* Called when this viz is added to a view. The viz should prepare any buffers or shader
* programs it will need to render itself. Any exception thrown by this method will result in
Expand All @@ -57,10 +58,10 @@ public abstract class Viz
* Called when this viz is removed from a view. The viz should destroy any buffers or shader
* programs it created in {@link #onAdd}.
*/
protected abstract void onRemove (View view);
protected abstract void onRemove ();

/**
* Instructs this viz to issue the rendering calls needed to visualize itself.
*/
protected abstract void render (View view);
protected abstract void render ();
}

0 comments on commit 7220ab3

Please sign in to comment.