Various and sundry modifications to clean up orientation handling and add
support for 16 orientations in situations where it is merited. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1548 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: ActionFrames.java,v 1.4 2002/06/19 23:31:57 mdb Exp $
|
||||
// $Id: ActionFrames.java,v 1.5 2002/06/26 23:53:06 mdb Exp $
|
||||
|
||||
package com.threerings.cast;
|
||||
|
||||
@@ -17,6 +17,12 @@ import com.threerings.util.DirectionCodes;
|
||||
*/
|
||||
public interface ActionFrames
|
||||
{
|
||||
/**
|
||||
* Returns the number of orientations available in this set of action
|
||||
* frames.
|
||||
*/
|
||||
public int getOrientationCount ();
|
||||
|
||||
/**
|
||||
* Returns the multi-frame image that comprises the frames for the
|
||||
* specified orientation.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: ActionSequence.java,v 1.3 2002/03/27 21:51:33 mdb Exp $
|
||||
// $Id: ActionSequence.java,v 1.4 2002/06/26 23:53:06 mdb Exp $
|
||||
|
||||
package com.threerings.cast;
|
||||
|
||||
@@ -24,12 +24,17 @@ public class ActionSequence implements Serializable
|
||||
/** The position of the character's base for this sequence. */
|
||||
public Point origin = new Point();
|
||||
|
||||
/** Orientation codes for the orientations available for this
|
||||
* action. */
|
||||
public int[] orients;
|
||||
|
||||
/**
|
||||
* Returns a string representation of this action sequence.
|
||||
*/
|
||||
public String toString ()
|
||||
{
|
||||
return "[name=" + name + ", framesPerSecond=" + framesPerSecond +
|
||||
", origin=" + origin + "]";
|
||||
", origin=" + origin +
|
||||
", orients=" + (orients == null ? 0 : orients.length) + "]";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: CompositedActionFrames.java,v 1.6 2002/06/20 18:31:03 mdb Exp $
|
||||
// $Id: CompositedActionFrames.java,v 1.7 2002/06/26 23:53:06 mdb Exp $
|
||||
|
||||
package com.threerings.cast;
|
||||
|
||||
@@ -37,12 +37,19 @@ public class CompositedActionFrames
|
||||
}
|
||||
_sources = sources;
|
||||
|
||||
// the sources must all have the same frame count, and each
|
||||
// the sources must all have the same orientation count, and each
|
||||
// orientation must also have the same frame count, so we just use
|
||||
// the count from the first source and first orientation
|
||||
// the counts from the first source and orientation
|
||||
_orientCount = _sources[0].getOrientationCount();
|
||||
_frameCount = _sources[0].getFrames(NORTH).getFrameCount();
|
||||
_images = new Image[DIRECTION_COUNT][_frameCount];
|
||||
_bounds = new Rectangle[DIRECTION_COUNT][_frameCount];
|
||||
_images = new Image[_orientCount][_frameCount];
|
||||
_bounds = new Rectangle[_orientCount][_frameCount];
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
public int getOrientationCount ()
|
||||
{
|
||||
return _orientCount;
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
@@ -198,6 +205,9 @@ public class CompositedActionFrames
|
||||
return dest;
|
||||
}
|
||||
|
||||
/** The number of orientations. */
|
||||
protected int _orientCount;
|
||||
|
||||
/** The number of frames in each orientation. */
|
||||
protected int _frameCount;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: BundledComponentRepository.java,v 1.14 2002/06/19 23:31:57 mdb Exp $
|
||||
// $Id: BundledComponentRepository.java,v 1.15 2002/06/26 23:53:06 mdb Exp $
|
||||
|
||||
package com.threerings.cast.bundle;
|
||||
|
||||
@@ -19,6 +19,7 @@ import java.util.Iterator;
|
||||
|
||||
import com.samskivert.io.NestableIOException;
|
||||
import com.samskivert.util.HashIntMap;
|
||||
import com.samskivert.util.IntIntMap;
|
||||
import com.samskivert.util.Tuple;
|
||||
|
||||
import org.apache.commons.collections.FilterIterator;
|
||||
@@ -307,6 +308,22 @@ public class BundledComponentRepository
|
||||
{
|
||||
_set = set;
|
||||
_actseq = actseq;
|
||||
|
||||
// compute these now to avoid pointless recomputation later
|
||||
_ocount = actseq.orients.length;
|
||||
_fcount = set.getTileCount() / _ocount;
|
||||
|
||||
// create our mapping from orientation to animation sequence
|
||||
// index
|
||||
for (int ii = 0; ii < _ocount; ii++) {
|
||||
_orients.put(actseq.orients[ii], ii);
|
||||
}
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
public int getOrientationCount ()
|
||||
{
|
||||
return _ocount;
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
@@ -316,7 +333,7 @@ public class BundledComponentRepository
|
||||
// documentation inherited
|
||||
public int getFrameCount ()
|
||||
{
|
||||
return _set.getTileCount() / DIRECTION_COUNT;
|
||||
return _fcount;
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
@@ -388,8 +405,7 @@ public class BundledComponentRepository
|
||||
*/
|
||||
protected Tile getTile (int orient, int index)
|
||||
{
|
||||
int fcount = _set.getTileCount() / DIRECTION_COUNT;
|
||||
int tileIndex = orient * fcount + index;
|
||||
int tileIndex = _orients.get(orient) * _fcount + index;
|
||||
try {
|
||||
return _set.getTile(tileIndex);
|
||||
} catch (NoSuchTileException nste) {
|
||||
@@ -404,6 +420,13 @@ public class BundledComponentRepository
|
||||
|
||||
/** The action sequence for which we're providing frame images. */
|
||||
protected ActionSequence _actseq;
|
||||
|
||||
/** Frame and orientation counts. */
|
||||
protected int _fcount, _ocount;
|
||||
|
||||
/** A mapping from orientation code to animation sequence
|
||||
* index. */
|
||||
protected IntIntMap _orients = new IntIntMap();
|
||||
}
|
||||
|
||||
/** We use the image manager to decode and cache images. */
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: MetadataBundlerTask.java,v 1.2 2002/02/05 20:29:09 mdb Exp $
|
||||
// $Id: MetadataBundlerTask.java,v 1.3 2002/06/26 23:53:07 mdb Exp $
|
||||
|
||||
package com.threerings.cast.bundle.tools;
|
||||
|
||||
@@ -169,6 +169,14 @@ public class MetadataBundlerTask extends Task
|
||||
for (int i = 0; i < setlist.size(); i++) {
|
||||
TileSet set = (TileSet)setlist.get(i);
|
||||
ActionSequence act = (ActionSequence)actlist.get(i);
|
||||
// make sure nothing was missing in the action sequence
|
||||
// definition parsed from XML
|
||||
String errmsg = ActionRuleSet.validate(act);
|
||||
if (errmsg != null) {
|
||||
errmsg = "Action sequence invalid [seq=" + act +
|
||||
", error=" + errmsg + "].";
|
||||
throw new BuildException(errmsg);
|
||||
}
|
||||
actmap.put(act.name, act);
|
||||
setmap.put(act.name, set);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: ActionRuleSet.java,v 1.1 2001/11/27 08:09:35 mdb Exp $
|
||||
// $Id: ActionRuleSet.java,v 1.2 2002/06/26 23:53:07 mdb Exp $
|
||||
|
||||
package com.threerings.cast.tools.xml;
|
||||
|
||||
@@ -12,6 +12,9 @@ import com.samskivert.xml.CallMethodSpecialRule;
|
||||
import com.samskivert.xml.SetFieldRule;
|
||||
import com.samskivert.xml.SetPropertyFieldsRule;
|
||||
|
||||
import com.threerings.util.DirectionCodes;
|
||||
import com.threerings.util.DirectionUtil;
|
||||
|
||||
import com.threerings.cast.ActionSequence;
|
||||
|
||||
/**
|
||||
@@ -78,6 +81,47 @@ public class ActionRuleSet extends RuleSetBase
|
||||
}
|
||||
};
|
||||
digester.addRule(_prefix + ACTION_PATH + "/origin", origin);
|
||||
|
||||
CallMethodSpecialRule orient = new CallMethodSpecialRule(digester) {
|
||||
public void parseAndSet (String bodyText, Object target)
|
||||
throws Exception {
|
||||
ActionSequence seq = ((ActionSequence)target);
|
||||
String[] ostrs = StringUtil.parseStringArray(bodyText);
|
||||
seq.orients = new int[ostrs.length];
|
||||
for (int ii = 0; ii < ostrs.length; ii++) {
|
||||
int orient = DirectionUtil.fromShortString(ostrs[ii]);
|
||||
if (orient != DirectionCodes.NONE) {
|
||||
seq.orients[ii] = orient;
|
||||
} else {
|
||||
String errmsg = "Invalid orientation specification " +
|
||||
"[index=" + ii + ", orient=" + ostrs[ii] + "].";
|
||||
throw new Exception(errmsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
digester.addRule(_prefix + ACTION_PATH + "/orients", orient);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates that all necessary fields have been parsed and set in
|
||||
* this action sequence object and are valid.
|
||||
*
|
||||
* @return null if the sequence is valid, a string explaining the
|
||||
* invalidity if it is not.
|
||||
*/
|
||||
public static String validate (ActionSequence seq)
|
||||
{
|
||||
if (StringUtil.blank(seq.name)) {
|
||||
return "Missing 'name' definition.";
|
||||
}
|
||||
if (seq.framesPerSecond == 0) {
|
||||
return "Missing 'framesPerSecond' definition.";
|
||||
}
|
||||
if (seq.orients == null) {
|
||||
return "Missing 'orients' definition.";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** The prefix at which me match our actions. */
|
||||
|
||||
Reference in New Issue
Block a user