From c4af53338c0890c3c411ea24b3df3d109e33b094 Mon Sep 17 00:00:00 2001 From: Dave Hoover Date: Mon, 10 Nov 2008 23:02:00 +0000 Subject: [PATCH] Rejigger component rendering order a bit so that individual components can have their own priority overrides, since unfortunately, not all male/familiars are created equal. git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@693 ed5b42cb-e716-0410-a449-f6a68f950b19 --- .../threerings/cast/CharacterComponent.java | 12 ++++- .../com/threerings/cast/ComponentClass.java | 53 ++++++++++++------- .../cast/CompositedMultiFrameImage.java | 24 ++++----- .../bundle/BundledComponentRepository.java | 6 +-- 4 files changed, 59 insertions(+), 36 deletions(-) diff --git a/src/java/com/threerings/cast/CharacterComponent.java b/src/java/com/threerings/cast/CharacterComponent.java index 8d1c0337..25e82f43 100644 --- a/src/java/com/threerings/cast/CharacterComponent.java +++ b/src/java/com/threerings/cast/CharacterComponent.java @@ -60,6 +60,16 @@ public class CharacterComponent implements Serializable _frameProvider = fprov; } + + /** + * Returns the render priority appropriate for this component at the specified action and + * orientation. + */ + public int getRenderPriority (String action, int orientation) + { + return componentClass.getRenderPriority(action, name, orientation); + } + /** * Returns the image frames for the specified action animation or null if * no animation for the specified action is available for this component. @@ -78,7 +88,7 @@ public class CharacterComponent implements Serializable * * @param type null for the normal action frames or one of the custom * action sub-types: {@link StandardActions#SHADOW_TYPE}, etc. - * + * * @param existentPaths the set of all paths for which there are valid frames. */ public String getFramePath (String action, String type, Set existentPaths) diff --git a/src/java/com/threerings/cast/ComponentClass.java b/src/java/com/threerings/cast/ComponentClass.java index 33e7be84..1dfdecd2 100644 --- a/src/java/com/threerings/cast/ComponentClass.java +++ b/src/java/com/threerings/cast/ComponentClass.java @@ -43,8 +43,7 @@ import com.samskivert.util.StringUtil; */ public class ComponentClass implements Serializable { - /** Used to effect custom render orders for particular actions, - * orientations, etc. */ + /** Used to effect custom render orders for particular actions, orientations, etc. */ public static class PriorityOverride implements Comparable, Serializable { @@ -54,25 +53,27 @@ public class ComponentClass implements Serializable /** The action, if any, for which this override is appropriate. */ public String action; - /** The orientations, if any, for which this override is - * appropriate. */ + /** The component, if any, for which this override is appropriate. */ + public String component; + + /** The orientations, if any, for which this override is appropriate. */ public ArrayIntSet orients; /** * Determines whether this priority override matches the specified - * action and orientation combination. + * action, orientation ant component combination. */ - public boolean matches (String action, int orient) + public boolean matches (String action, String component, int orient) { return (((orients == null) || orients.contains(orient)) && + ((this.component == null) || this.component.equals(component)) && ((this.action == null) || this.action.equals(action))); } // documentation inherited from interface public int compareTo (PriorityOverride po) { - // overrides with both an action and an orientation should - // come first in the list + // overrides with both an action and an orientation should come first in the list int pri = priority(), opri = po.priority(); if (pri == opri) { return hashCode() - po.hashCode(); @@ -84,6 +85,9 @@ public class ComponentClass implements Serializable protected int priority () { int priority = 0; + if (component != null) { + priority += 3; // Extra priority to things that are for specific components + } if (action != null) { priority++; } @@ -96,8 +100,8 @@ public class ComponentClass implements Serializable @Override public String toString () { - return "[pri=" + renderPriority + ", action=" + action + - ", orients=" + orients + "]"; + return "[pri=" + renderPriority + ", action=" + action + ", component=" + component + + ", orients=" + orients + "]"; } /** Increase this value when object's serialized state is impacted @@ -139,20 +143,31 @@ public class ComponentClass implements Serializable } /** - * Returns the render priority appropriate for the specified action - * and orientation. + * Returns the render priority appropriate for the specified action and orientation. + * + * This is deprecated; you should really use {@link #getRenderPriority(String, String, int)} + * to handle potential per-component priority overrides. */ + @Deprecated public int getRenderPriority (String action, int orientation) { - // because we expect there to be relatively few priority - // overrides, we simply search linearly through the list for the - // closest match + return getRenderPriority(action, null, orientation); + } + + /** + * Returns the render priority appropriate for the specified action, orientation and + * component. + */ + public int getRenderPriority (String action, String component, int orientation) + { + // because we expect there to be relatively few priority overrides, we simply search + // linearly through the list for the closest match int ocount = (_overrides != null) ? _overrides.size() : 0; for (int ii = 0; ii < ocount; ii++) { PriorityOverride over = _overrides.get(ii); // based on the way the overrides are sorted, the first match // is the most specific and the one we want - if (over.matches(action, orientation)) { + if (over.matches(action, component, orientation)) { return over.renderPriority; } } @@ -161,8 +176,7 @@ public class ComponentClass implements Serializable } /** - * Adds the supplied render priority override record to this component - * class. + * Adds the supplied render priority override record to this component class. */ public void addPriorityOverride (PriorityOverride override) { @@ -183,8 +197,7 @@ public class ComponentClass implements Serializable } /** - * Returns true if this component class is a shadow layer rather than a - * normal component class. + * Returns true if this component class is a shadow layer rather than a normal component class. */ public boolean isShadow () { diff --git a/src/java/com/threerings/cast/CompositedMultiFrameImage.java b/src/java/com/threerings/cast/CompositedMultiFrameImage.java index 2a1a4752..148ebc01 100644 --- a/src/java/com/threerings/cast/CompositedMultiFrameImage.java +++ b/src/java/com/threerings/cast/CompositedMultiFrameImage.java @@ -60,7 +60,7 @@ public class CompositedMultiFrameImage _images[ii] = createCompositedMirage(ii); } } - + // documentation inherited public int getFrameCount () { return _images.length; @@ -107,8 +107,8 @@ public class CompositedMultiFrameImage public long getEstimatedMemoryUsage () { long size = 0; - for (int ii = 0; ii < _images.length; ii++) { - size += _images[ii].getEstimatedMemoryUsage(); + for (CompositedMirage element : _images) { + size += element.getEstimatedMemoryUsage(); } return size; } @@ -128,7 +128,7 @@ public class CompositedMultiFrameImage } return new CompositedVolatileMirage(index); } - + /** * A CompositedMirage that forwards all of its Mirage calls to a delegate Mirage. */ @@ -149,7 +149,7 @@ public class CompositedMultiFrameImage { return y; } - + public long getEstimatedMemoryUsage () { return delegate.getEstimatedMemoryUsage(); @@ -179,12 +179,12 @@ public class CompositedMultiFrameImage { delegate.paint(gfx, x, y); } - + protected int x, y; - + protected Mirage delegate; } - + // documentation inherited protected Mirage getFrame (int orient, int index) { @@ -247,7 +247,7 @@ public class CompositedMultiFrameImage // render our volatile image for the first time createVolatileImage(); } - + public int getXOrigin () { return _origin.x; @@ -261,8 +261,8 @@ public class CompositedMultiFrameImage // documentation inherited from interface public int compare (ComponentFrames cf1, ComponentFrames cf2) { - return (cf1.ccomp.componentClass.getRenderPriority(_action, _orient) - - cf2.ccomp.componentClass.getRenderPriority(_action, _orient)); + return (cf1.ccomp.getRenderPriority(_action, _orient) - + cf2.ccomp.getRenderPriority(_action, _orient)); } /** @@ -278,7 +278,7 @@ public class CompositedMultiFrameImage } return bounds; } - + @Override protected int getTransparency () { diff --git a/src/java/com/threerings/cast/bundle/BundledComponentRepository.java b/src/java/com/threerings/cast/bundle/BundledComponentRepository.java index ee956387..e1f6bc98 100644 --- a/src/java/com/threerings/cast/bundle/BundledComponentRepository.java +++ b/src/java/com/threerings/cast/bundle/BundledComponentRepository.java @@ -242,8 +242,8 @@ public class BundledComponentRepository // look up the component class information ComponentClass clazz = _classes.get(cclass); if (clazz == null) { - log.warning("Non-existent component class [class=" + cclass + ", name=" + cname + - ", id=" + componentId + "]."); + log.warning("Non-existent component class", + "class", cclass, "name", cname, "id", componentId); return; } @@ -262,7 +262,7 @@ public class BundledComponentRepository if (!comps.contains(component)) { comps.add(component); } else { - log.info("Requested to register the same component twice? [comp=" + component + "]."); + log.info("Requested to register the same component twice?", "comp", component); } }