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
This commit is contained in:
Dave Hoover
2008-11-10 23:02:00 +00:00
parent 6294232dce
commit c4af53338c
4 changed files with 59 additions and 36 deletions
@@ -60,6 +60,16 @@ public class CharacterComponent implements Serializable
_frameProvider = fprov; _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 * Returns the image frames for the specified action animation or null if
* no animation for the specified action is available for this component. * no animation for the specified action is available for this component.
@@ -43,8 +43,7 @@ import com.samskivert.util.StringUtil;
*/ */
public class ComponentClass implements Serializable public class ComponentClass implements Serializable
{ {
/** Used to effect custom render orders for particular actions, /** Used to effect custom render orders for particular actions, orientations, etc. */
* orientations, etc. */
public static class PriorityOverride public static class PriorityOverride
implements Comparable<PriorityOverride>, Serializable implements Comparable<PriorityOverride>, Serializable
{ {
@@ -54,25 +53,27 @@ public class ComponentClass implements Serializable
/** The action, if any, for which this override is appropriate. */ /** The action, if any, for which this override is appropriate. */
public String action; public String action;
/** The orientations, if any, for which this override is /** The component, if any, for which this override is appropriate. */
* appropriate. */ public String component;
/** The orientations, if any, for which this override is appropriate. */
public ArrayIntSet orients; public ArrayIntSet orients;
/** /**
* Determines whether this priority override matches the specified * 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)) && return (((orients == null) || orients.contains(orient)) &&
((this.component == null) || this.component.equals(component)) &&
((this.action == null) || this.action.equals(action))); ((this.action == null) || this.action.equals(action)));
} }
// documentation inherited from interface // documentation inherited from interface
public int compareTo (PriorityOverride po) public int compareTo (PriorityOverride po)
{ {
// overrides with both an action and an orientation should // overrides with both an action and an orientation should come first in the list
// come first in the list
int pri = priority(), opri = po.priority(); int pri = priority(), opri = po.priority();
if (pri == opri) { if (pri == opri) {
return hashCode() - po.hashCode(); return hashCode() - po.hashCode();
@@ -84,6 +85,9 @@ public class ComponentClass implements Serializable
protected int priority () protected int priority ()
{ {
int priority = 0; int priority = 0;
if (component != null) {
priority += 3; // Extra priority to things that are for specific components
}
if (action != null) { if (action != null) {
priority++; priority++;
} }
@@ -96,7 +100,7 @@ public class ComponentClass implements Serializable
@Override @Override
public String toString () public String toString ()
{ {
return "[pri=" + renderPriority + ", action=" + action + return "[pri=" + renderPriority + ", action=" + action + ", component=" + component +
", orients=" + orients + "]"; ", orients=" + orients + "]";
} }
@@ -139,20 +143,31 @@ public class ComponentClass implements Serializable
} }
/** /**
* Returns the render priority appropriate for the specified action * Returns the render priority appropriate for the specified action and orientation.
* 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) public int getRenderPriority (String action, int orientation)
{ {
// because we expect there to be relatively few priority return getRenderPriority(action, null, orientation);
// overrides, we simply search linearly through the list for the }
// closest match
/**
* 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; int ocount = (_overrides != null) ? _overrides.size() : 0;
for (int ii = 0; ii < ocount; ii++) { for (int ii = 0; ii < ocount; ii++) {
PriorityOverride over = _overrides.get(ii); PriorityOverride over = _overrides.get(ii);
// based on the way the overrides are sorted, the first match // based on the way the overrides are sorted, the first match
// is the most specific and the one we want // is the most specific and the one we want
if (over.matches(action, orientation)) { if (over.matches(action, component, orientation)) {
return over.renderPriority; return over.renderPriority;
} }
} }
@@ -161,8 +176,7 @@ public class ComponentClass implements Serializable
} }
/** /**
* Adds the supplied render priority override record to this component * Adds the supplied render priority override record to this component class.
* class.
*/ */
public void addPriorityOverride (PriorityOverride override) 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 * Returns true if this component class is a shadow layer rather than a normal component class.
* normal component class.
*/ */
public boolean isShadow () public boolean isShadow ()
{ {
@@ -107,8 +107,8 @@ public class CompositedMultiFrameImage
public long getEstimatedMemoryUsage () public long getEstimatedMemoryUsage ()
{ {
long size = 0; long size = 0;
for (int ii = 0; ii < _images.length; ii++) { for (CompositedMirage element : _images) {
size += _images[ii].getEstimatedMemoryUsage(); size += element.getEstimatedMemoryUsage();
} }
return size; return size;
} }
@@ -261,8 +261,8 @@ public class CompositedMultiFrameImage
// documentation inherited from interface // documentation inherited from interface
public int compare (ComponentFrames cf1, ComponentFrames cf2) public int compare (ComponentFrames cf1, ComponentFrames cf2)
{ {
return (cf1.ccomp.componentClass.getRenderPriority(_action, _orient) - return (cf1.ccomp.getRenderPriority(_action, _orient) -
cf2.ccomp.componentClass.getRenderPriority(_action, _orient)); cf2.ccomp.getRenderPriority(_action, _orient));
} }
/** /**
@@ -242,8 +242,8 @@ public class BundledComponentRepository
// look up the component class information // look up the component class information
ComponentClass clazz = _classes.get(cclass); ComponentClass clazz = _classes.get(cclass);
if (clazz == null) { if (clazz == null) {
log.warning("Non-existent component class [class=" + cclass + ", name=" + cname + log.warning("Non-existent component class",
", id=" + componentId + "]."); "class", cclass, "name", cname, "id", componentId);
return; return;
} }
@@ -262,7 +262,7 @@ public class BundledComponentRepository
if (!comps.contains(component)) { if (!comps.contains(component)) {
comps.add(component); comps.add(component);
} else { } else {
log.info("Requested to register the same component twice? [comp=" + component + "]."); log.info("Requested to register the same component twice?", "comp", component);
} }
} }