A healthy splash of google-collections

git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@822 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
Dave Hoover
2009-05-23 01:31:14 +00:00
parent a20117d922
commit d2b9e2ebb9
52 changed files with 246 additions and 191 deletions
+5 -5
View File
@@ -365,7 +365,7 @@ public class Model extends ModelNode
protected Model _toCopy;
/** The set of added properties. */
protected HashSet<String> _properties = new HashSet<String>();
protected HashSet<String> _properties = Sets.newHashSet();
}
/**
@@ -443,7 +443,7 @@ public class Model extends ModelNode
public void addAnimation (String name, Animation anim)
{
if (_anims == null) {
_anims = new HashMap<String, Animation>();
_anims = Maps.newHashMap();
}
_anims.put(name, anim);
@@ -727,7 +727,7 @@ public class Model extends ModelNode
if (animNames != null) {
Savable[] animValues = capsule.readSavableArray(
"animValues", null);
_anims = new HashMap<String, Animation>();
_anims = Maps.newHashMap();
for (int ii = 0; ii < animNames.length; ii++) {
_anims.put(animNames[ii], (Animation)animValues[ii]);
}
@@ -839,7 +839,7 @@ public class Model extends ModelNode
{
// collect the instance's animation and controller targets and lock
// recursively
HashSet<Spatial> targets = new HashSet<Spatial>();
HashSet<Spatial> targets = Sets.newHashSet();
for (String aname : getAnimationNames()) {
Collections.addAll(targets, getAnimation(aname).transformTargets);
}
@@ -872,7 +872,7 @@ public class Model extends ModelNode
}
mstore._prototype = this;
if (_anims != null) {
mstore._anims = new HashMap<String, Animation>();
mstore._anims = Maps.newHashMap();
}
mstore._pnodes = Maps.newHashMap(properties.originalToCopy);
mstore._animMode = _animMode;
@@ -53,7 +53,7 @@ public abstract class ModelController extends Controller
if (anims.length == 0) {
return;
}
_animations = new HashSet<String>();
_animations = Sets.newHashSet();
Collections.addAll(_animations, anims);
}
@@ -120,7 +120,7 @@ public abstract class ModelController extends Controller
_target = (Spatial)capsule.readSavable("target", null);
String[] anims = capsule.readStringArray("animations", null);
if (anims != null) {
_animations = new HashSet<String>();
_animations = Sets.newHashSet();
Collections.addAll(_animations, anims);
} else {
_animations = null;
@@ -161,7 +161,7 @@ public class ModelMesh extends TriMesh
public void addOverlay (RenderState[] overlay)
{
if (_overlays == null) {
_overlays = new ArrayList<RenderState[]>(1);
_overlays = Lists.newArrayListWithCapacity(1);
}
_overlays.add(overlay);
}
@@ -461,7 +461,7 @@ public class ModelMesh extends TriMesh
@Override // documentation inherited
protected void setupBatchList ()
{
batchList = new ArrayList<GeomBatch>(1);
batchList = Lists.newArrayListWithCapacity(1);
TriangleBatch batch = createModelBatch();
batch.setParentGeom(this);
batchList.add(batch);
@@ -222,7 +222,7 @@ public class SkinMesh extends ModelMesh
_weightGroups = weightGroups;
// compile a list of all referenced bones
HashSet<Bone> bones = new HashSet<Bone>();
HashSet<Bone> bones = Sets.newHashSet();
for (WeightGroup group : weightGroups) {
Collections.addAll(bones, group.bones);
}
@@ -238,7 +238,7 @@ public class SkinMesh extends ModelMesh
return;
}
if (_osconfigs == null) {
_osconfigs = new ArrayList<SkinShaderConfig>(1);
_osconfigs = Lists.newArrayListWithCapacity(1);
}
SkinShaderConfig osconfig = (SkinShaderConfig)_sconfig.clone();
osconfig.getState().uniforms = _sconfig.getState().uniforms;
@@ -299,7 +299,7 @@ public class SkinMesh extends ModelMesh
mstore._useDisplayLists = _useDisplayLists;
mstore._invRefTransform = _invRefTransform;
mstore._bones = new Bone[_bones.length];
HashMap<Bone, Bone> bmap = new HashMap<Bone, Bone>();
HashMap<Bone, Bone> bmap = Maps.newHashMap();
for (int ii = 0; ii < _bones.length; ii++) {
bmap.put(_bones[ii], mstore._bones[ii] =
_bones[ii].rebind(properties.originalToCopy));
@@ -58,7 +58,7 @@ public abstract class TextureController extends ModelController
protected void initTextures ()
{
// find and clone all textures under the target
final HashMap<Texture, Texture> clones = new HashMap<Texture, Texture>();
final HashMap<Texture, Texture> clones = Maps.newHashMap();
new SpatialVisitor<ModelMesh>(ModelMesh.class) {
protected void visit (ModelMesh mesh) {
TextureState otstate = (TextureState)mesh.getRenderState(RenderState.RS_TEXTURE);
@@ -53,8 +53,7 @@ public class AnimationDef
public static class FrameDef
{
/** Transform for affected nodes. */
public ArrayList<TransformDef> transforms =
new ArrayList<TransformDef>();
public ArrayList<TransformDef> transforms = Lists.newArrayList();
public void addTransform (TransformDef transform)
{
@@ -122,14 +121,13 @@ public class AnimationDef
{
return new Model.Transform(
new Vector3f(translation[0], translation[1], translation[2]),
new Quaternion(rotation[0], rotation[1], rotation[2],
rotation[3]),
new Quaternion(rotation[0], rotation[1], rotation[2], rotation[3]),
new Vector3f(scale[0], scale[1], scale[2]));
}
}
/** The individual frames of the animation. */
public ArrayList<FrameDef> frames = new ArrayList<FrameDef>();
public ArrayList<FrameDef> frames = Lists.newArrayList();
public void addFrame (FrameDef frame)
{
@@ -185,8 +183,8 @@ public class AnimationDef
Properties props, HashMap<String, Spatial> nodes, HashMap<String, TransformNode> tnodes)
{
// find all affected nodes
HashSet<Spatial> staticTargets = new HashSet<Spatial>(),
transformTargets = new HashSet<Spatial>();
HashSet<Spatial> staticTargets = Sets.newHashSet(),
transformTargets = Sets.newHashSet();
for (int ii = 0, nn = frames.size(); ii < nn; ii++) {
frames.get(ii).addTransformTargets(nodes, tnodes, staticTargets, transformTargets);
}
@@ -111,7 +111,7 @@ public class CompileModel
// preprocess the model and animations to determine which nodes never move, which never
// move within an animation, and which never move with respect to others
HashMap<String, TransformNode> tnodes = new HashMap<String, TransformNode>();
HashMap<String, TransformNode> tnodes = Maps.newHashMap();
Node troot = mdef.createTransformTree(props, tnodes);
for (AnimationDef adef : adefs) {
adef.filterTransforms(troot, tnodes);
@@ -119,7 +119,7 @@ public class CompileModel
mdef.mergeSpatials(tnodes);
// load the model content
HashMap<String, Spatial> nodes = new HashMap<String, Spatial>();
HashMap<String, Spatial> nodes = Maps.newHashMap();
Model model = mdef.createModel(props, nodes);
model.initPrototype();
@@ -81,5 +81,5 @@ public class CompileModelTask extends Task
protected File _dest;
/** A list of filesets that contain XML models. */
protected ArrayList<FileSet> _filesets = new ArrayList<FileSet>();
protected ArrayList<FileSet> _filesets = Lists.newArrayList();
}
@@ -130,5 +130,5 @@ public class ConvertModelTask extends Task
}
/** A list of filesets that contain tileset bundle definitions. */
protected ArrayList<FileSet> _filesets = new ArrayList<FileSet>();
protected ArrayList<FileSet> _filesets = Lists.newArrayList();
}
+15 -19
View File
@@ -156,7 +156,7 @@ public class ModelDef
public HashArrayList<Vertex> vertices = new HashArrayList<Vertex>();
/** The triangle indices. */
public ArrayList<Integer> indices = new ArrayList<Integer>();
public ArrayList<Integer> indices = Lists.newArrayList();
/** Whether or not any of the vertices have texture coordinates. */
public boolean tcoords;
@@ -265,7 +265,7 @@ public class ModelDef
Triangle triangle = new Triangle(tverts);
for (Vertex tvert : tverts) {
if (tvert.triangles == null) {
tvert.triangles = new ArrayList<Triangle>();
tvert.triangles = Lists.newArrayList();
}
tvert.triangles.add(triangle);
}
@@ -410,10 +410,8 @@ public class ModelDef
}
// create and set the final weight groups
SkinMesh.WeightGroup[] wgroups =
new SkinMesh.WeightGroup[_groups.size()];
HashMap<String, SkinMesh.Bone> bones =
new HashMap<String, SkinMesh.Bone>();
SkinMesh.WeightGroup[] wgroups = new SkinMesh.WeightGroup[_groups.size()];
HashMap<String, SkinMesh.Bone> bones = Maps.newHashMap();
int ii = 0;
int mweights = 0, tweights = 0;
for (Map.Entry<Set<String>, WeightGroupDef> entry :
@@ -444,7 +442,7 @@ public class ModelDef
protected void configureMesh (Properties props)
{
// divide the vertices up by weight groups
_groups = new HashMap<Set<String>, WeightGroupDef>();
_groups = Maps.newHashMap();
for (int ii = 0, nn = vertices.size(); ii < nn; ii++) {
SkinVertex svertex = (SkinVertex)vertices.get(ii);
Set<String> bones = svertex.boneWeights.keySet();
@@ -597,8 +595,7 @@ public class ModelDef
public static class SkinVertex extends Vertex
{
/** The bones influencing the vertex, mapped by name. */
public HashMap<String, BoneWeight> boneWeights =
new HashMap<String, BoneWeight>();
public HashMap<String, BoneWeight> boneWeights = Maps.newHashMap();
public void addBoneWeight (BoneWeight weight)
{
@@ -616,7 +613,7 @@ public class ModelDef
/** Finds the bone nodes influencing this vertex. */
public HashSet<ModelNode> getBones (HashMap<String, Spatial> nodes)
{
HashSet<ModelNode> bones = new HashSet<ModelNode>();
HashSet<ModelNode> bones = Sets.newHashSet();
for (String bone : boneWeights.keySet()) {
Spatial node = nodes.get(bone);
if (node instanceof ModelNode) {
@@ -651,10 +648,10 @@ public class ModelDef
public static class WeightGroupDef
{
/** The indices of the affected vertex. */
public ArrayList<Integer> indices = new ArrayList<Integer>();
public ArrayList<Integer> indices = Lists.newArrayList();
/** The interleaved vertex weights. */
public ArrayList<Float> weights = new ArrayList<Float>();
public ArrayList<Float> weights = Lists.newArrayList();
}
/** Contains the transform of a node for preprocessing. */
@@ -754,7 +751,7 @@ public class ModelDef
}
/** The meshes and bones comprising the model. */
public ArrayList<SpatialDef> spatials = new ArrayList<SpatialDef>();
public ArrayList<SpatialDef> spatials = Lists.newArrayList();
public void addSpatial (SpatialDef spatial)
{
@@ -775,7 +772,7 @@ public class ModelDef
// resolve the parents and collect the names of the bones
Node root = new Node("root");
HashSet<String> bones = new HashSet<String>();
HashSet<String> bones = Sets.newHashSet();
for (TransformNode node : nodes.values()) {
if (node.spatial.parent == null) {
root.attachChild(node);
@@ -811,7 +808,7 @@ public class ModelDef
root.updateGeometricState(0f, true);
for (TransformNode node : nodes.values()) {
node.baseLocalTransform = new Matrix4f(node.localTransform);
node.relativeTransforms = new ArrayList<Tuple<TransformNode, Matrix4f>>();
node.relativeTransforms = Lists.newArrayList();
for (TransformNode onode : nodes.values()) {
if (node == onode || !node.canMerge(props, onode)) {
continue;
@@ -858,9 +855,8 @@ public class ModelDef
nodes.put(spatial.getName(), spatial);
}
// then go through again, resolving any name references and attaching
// root children
HashSet<Spatial> referenced = new HashSet<Spatial>();
// then go through again, resolving any name references and attaching root children
HashSet<Spatial> referenced = Sets.newHashSet();
for (int ii = 0, nn = spatials.size(); ii < nn; ii++) {
SpatialDef sdef = spatials.get(ii);
sdef.resolveReferences(nodes, referenced);
@@ -1036,6 +1032,6 @@ public class ModelDef
}
/** Maps elements to their indices in the list. */
protected HashMap<Object, Integer> _indices = new HashMap<Object, Integer>();
protected HashMap<Object, Integer> _indices = Maps.newHashMap();
}
}
@@ -738,8 +738,7 @@ public class ModelViewer extends JmeCanvasApp
}
return tstate;
}
protected HashMap<String, TextureState> _tstates =
new HashMap<String, TextureState>();
protected HashMap<String, TextureState> _tstates = Maps.newHashMap();
});
_model.updateRenderState();
}
@@ -380,16 +380,13 @@ public class ImageCache
protected ResourceManager _rsrcmgr;
/** A cache of {@link Image} instances. */
protected HashMap<String,WeakReference<Image>> _imgcache =
new HashMap<String,WeakReference<Image>>();
protected HashMap<String,WeakReference<Image>> _imgcache = Maps.newHashMap();
/** A cache of {@link BImage} instances. */
protected HashMap<String,WeakReference<BImage>> _buicache =
new HashMap<String,WeakReference<BImage>>();
protected HashMap<String,WeakReference<BImage>> _buicache = Maps.newHashMap();
/** A cache of {@link BufferedImage} instances. */
protected HashMap<String,WeakReference<BufferedImage>> _bufcache =
new HashMap<String,WeakReference<BufferedImage>>();
protected HashMap<String,WeakReference<BufferedImage>> _bufcache = Maps.newHashMap();
/** Used to create buffered images in a format compatible with OpenGL. */
protected static ComponentColorModel GL_ALPHA_MODEL = new ComponentColorModel(
@@ -218,7 +218,7 @@ public class ShaderCache
public String frag;
/** The set of preprocessor definitions. */
public HashSet<String> defs = new HashSet<String>();
public HashSet<String> defs = Sets.newHashSet();
public ShaderKey (String vert, String frag, String[] defs)
{
@@ -253,8 +253,8 @@ public class ShaderCache
protected ResourceManager _rsrcmgr;
/** Maps shader names to source strings. */
protected HashMap<String, String> _sources = new HashMap<String, String>();
protected HashMap<String, String> _sources = Maps.newHashMap();
/** Maps shader keys to linked program ids. */
protected HashMap<ShaderKey, Integer> _programIds = new HashMap<ShaderKey, Integer>();
protected HashMap<ShaderKey, Integer> _programIds = Maps.newHashMap();
}
@@ -74,11 +74,11 @@ public abstract class ShaderConfig
// reconfigure the shader state, generating the derived definitions only if the
// required configuration isn't in the cache
String vert = getVertexShader(), frag = getFragmentShader();
ArrayList<String> defs = new ArrayList<String>();
ArrayList<String> defs = Lists.newArrayList();
getDefinitions(defs);
String[] darray = defs.toArray(new String[defs.size()]), ddarray = null;
if (!_scache.isLoaded(vert, frag, darray)) {
ArrayList<String> ddefs = new ArrayList<String>();
ArrayList<String> ddefs = Lists.newArrayList();
getDerivedDefinitions(ddefs);
ddarray = ddefs.toArray(new String[ddefs.size()]);
}