We now automatically handle lazy action sequence compositing.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2180 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2003-01-18 03:13:08 +00:00
parent 35f0954744
commit 1d4d5be6ed
2 changed files with 42 additions and 52 deletions
@@ -1,5 +1,5 @@
// //
// $Id: CharacterSprite.java,v 1.40 2003/01/13 23:54:19 mdb Exp $ // $Id: CharacterSprite.java,v 1.41 2003/01/18 03:13:08 mdb Exp $
package com.threerings.cast; package com.threerings.cast;
@@ -47,18 +47,14 @@ public class CharacterSprite extends ImageSprite
/** /**
* Reconfigures this sprite to use the specified character descriptor. * Reconfigures this sprite to use the specified character descriptor.
*
* @param lazy if true, wait to recomposite our action sequence until
* our next tick, otherwise we recomposite immediately.
*/ */
public void setCharacterDescriptor (CharacterDescriptor descrip, public void setCharacterDescriptor (CharacterDescriptor descrip)
boolean lazy)
{ {
// keep the new descriptor // keep the new descriptor
_descrip = descrip; _descrip = descrip;
// reset our action which will reload our frames // reset our action which will reload our frames
setActionSequence(_action, lazy); setActionSequence(_action);
} }
/** /**
@@ -102,14 +98,16 @@ public class CharacterSprite extends ImageSprite
/** /**
* Sets the action sequence used when rendering the character, from * Sets the action sequence used when rendering the character, from
* the set of available sequences. * the set of available sequences.
*
* @param lazy if true, wait to recomposite our action sequence until
* our next tick, otherwise we recomposite immediately.
*/ */
public void setActionSequence (String action, boolean lazy) public void setActionSequence (String action)
{ {
// no need to noop
if (action.equals(_action)) {
return;
}
// keep track of our current action in case someone swaps out our // keep track of our current action in case someone swaps out our
// character description // character descriptor
_action = action; _action = action;
// get a reference to the action sequence so that we can obtain // get a reference to the action sequence so that we can obtain
@@ -124,11 +122,8 @@ public class CharacterSprite extends ImageSprite
// obtain our animation frames for this action sequence // obtain our animation frames for this action sequence
_aframes = _charmgr.getActionFrames(_descrip, action); _aframes = _charmgr.getActionFrames(_descrip, action);
// grab our frames, or not // clear out our frames so that we recomposite on next tick
_frames = null; _frames = null;
if (!lazy) {
compositeActionFrames();
}
// update the sprite render attributes // update the sprite render attributes
setFrameRate(actseq.framesPerSecond); setFrameRate(actseq.framesPerSecond);
@@ -142,21 +137,10 @@ public class CharacterSprite extends ImageSprite
// documentation inherited // documentation inherited
public void setOrientation (int orient) public void setOrientation (int orient)
{ {
setOrientation(orient, false); int oorient = _orient;
}
/**
* Sets our orientation without recompositing our action sequence.
*
* @param lazy if true, wait to recomposite our action sequence until
* our next tick, otherwise we recomposite immediately.
*/
public void setOrientation (int orient, boolean lazy)
{
super.setOrientation(orient); super.setOrientation(orient);
_frames = null; if (_orient != oorient) {
if (!lazy) { _frames = null;
compositeActionFrames();
} }
} }
@@ -171,18 +155,36 @@ public class CharacterSprite extends ImageSprite
// documentation inherited // documentation inherited
public void tick (long tickStamp) public void tick (long tickStamp)
{ {
super.tick(tickStamp); // composite our action frames if something since the last call to
// tick caused them to become invalid
// attempt to composite our action frames if necessary
compositeActionFrames(); compositeActionFrames();
super.tick(tickStamp);
// composite our action frames if something during tick() caused
// them to become invalid
compositeActionFrames();
}
// documentation inherited
protected boolean tickPath (long tickStamp)
{
boolean moved = super.tickPath(tickStamp);
// composite our action frames if our path caused them to become
// invalid
compositeActionFrames();
return moved;
}
/** Called to recomposite our action frames if needed. */
protected final void compositeActionFrames ()
{
if (_frames == null) {
setFrames(_aframes.getFrames(_orient));
}
} }
// documentation inherited // documentation inherited
public void paint (Graphics2D gfx) public void paint (Graphics2D gfx)
{ {
// attempt to composite our action frames if necessary
compositeActionFrames();
if (_frames != null) { if (_frames != null) {
decorateBehind(gfx); decorateBehind(gfx);
// paint the image using _ibounds rather than _bounds which // paint the image using _ibounds rather than _bounds which
@@ -195,18 +197,6 @@ public class CharacterSprite extends ImageSprite
} }
} }
/**
* Obtains our composited action frames and configures the sprite with
* their frames. This is called lazily after we have been instructed
* to use a new action.
*/
protected final void compositeActionFrames ()
{
if (_frames == null) {
setFrames(_aframes.getFrames(_orient));
}
}
/** /**
* Called to paint any decorations that should appear behind the * Called to paint any decorations that should appear behind the
* character sprite image. * character sprite image.
@@ -289,7 +279,7 @@ public class CharacterSprite extends ImageSprite
super.pathBeginning(); super.pathBeginning();
// enable walking animation // enable walking animation
setActionSequence(getFollowingPathAction(), false); setActionSequence(getFollowingPathAction());
setAnimationMode(TIME_BASED); setAnimationMode(TIME_BASED);
} }
@@ -313,7 +303,7 @@ public class CharacterSprite extends ImageSprite
// come to a halt looking settled and at peace // come to a halt looking settled and at peace
String rest = getRestingAction(); String rest = getRestingAction();
if (rest != null) { if (rest != null) {
setActionSequence(rest, false); setActionSequence(rest);
} }
} }
} }
@@ -1,5 +1,5 @@
// //
// $Id: SpritePanel.java,v 1.15 2003/01/13 22:53:04 mdb Exp $ // $Id: SpritePanel.java,v 1.16 2003/01/18 03:13:08 mdb Exp $
package com.threerings.cast.builder; package com.threerings.cast.builder;
@@ -87,7 +87,7 @@ public class SpritePanel extends JPanel
*/ */
protected void setSprite (CharacterSprite sprite) protected void setSprite (CharacterSprite sprite)
{ {
sprite.setActionSequence(StandardActions.STANDING, false); sprite.setActionSequence(StandardActions.STANDING);
sprite.setOrientation(WEST); sprite.setOrientation(WEST);
_sprite = sprite; _sprite = sprite;
centerSprite(); centerSprite();