Type safety, redundant case removal, other cleanup.

git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@490 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
Michael Bayne
2008-05-09 11:39:45 +00:00
parent 95400b6050
commit 51c01493f2
9 changed files with 63 additions and 78 deletions
@@ -238,8 +238,7 @@ public class ModelMesh extends TriMesh
((ModelController)controller).putClone(null, properties));
}
}
TriangleBatch batch = (TriangleBatch)getBatch(0),
mbatch = (TriangleBatch)mstore.getBatch(0);
TriangleBatch batch = getBatch(0), mbatch = mstore.getBatch(0);
mbatch.setVertexBuffer(properties.isSet("vertices") ?
batch.getVertexBuffer() :
BufferUtils.clone(batch.getVertexBuffer()));
@@ -317,7 +316,7 @@ public class ModelMesh extends TriMesh
"localRotation", null));
setLocalScale((Vector3f)capsule.readSavable(
"localScale", null));
TriangleBatch batch = (TriangleBatch)getBatch(0);
TriangleBatch batch = getBatch(0);
batch.setModelBound((BoundingVolume)capsule.readSavable(
"modelBound", null));
_textureKey = capsule.readString("textureKey", null);
@@ -344,8 +344,7 @@ public class SkinMesh extends ModelMesh
@Override // documentation inherited
public void expandModelBounds ()
{
BoundingVolume obound =
(BoundingVolume)getBatch(0).getModelBound().clone(null);
BoundingVolume obound = getBatch(0).getModelBound().clone(null);
updateModelBound();
getBatch(0).getModelBound().mergeLocal(obound);
}
@@ -538,8 +537,7 @@ public class SkinMesh extends ModelMesh
protected void storeFrame ()
{
if (_storeBlend) {
_frames.put(_storeFrameId, new BlendFrame(
(float[])_vbuf.clone(), (float[])_nbuf.clone()));
_frames.put(_storeFrameId, new BlendFrame(_vbuf.clone(), _nbuf.clone()));
} else {
TriangleBatch batch = getBatch(0), tbatch = new TriangleBatch();
tbatch.setParentGeom(DUMMY_MESH);
@@ -789,7 +789,7 @@ public class ModelViewer extends JmeCanvasApp
TextureKey.setLocationOverride(new TextureKey.LocationOverride() {
public URL getLocation (String name)
throws MalformedURLException {
return new URL(parent.toURL(), name);
return new URL(parent.toURI().toURL(), name);
}
});
try {
@@ -1107,7 +1107,7 @@ public class ModelViewer extends JmeCanvasApp
{
Vector3f target = new Vector3f();
if (_model != null) {
BoundingVolume bound = (BoundingVolume)_model.getWorldBound();
BoundingVolume bound = _model.getWorldBound();
if (bound != null) {
bound.getCenter(target);
}
@@ -99,13 +99,13 @@ public abstract class ShaderConfig
other._state.uniforms.put(uniform.name, (ShaderUniform)uniform.clone());
}
if (_lights != null) {
other._lights = (LightConfig[])_lights.clone();
other._lights = _lights.clone();
for (int ii = 0; ii < _lights.length; ii++) {
other._lights[ii] = (LightConfig)_lights[ii].clone();
}
}
if (_textures != null) {
other._textures = (TextureConfig[])_textures.clone();
other._textures = _textures.clone();
for (int ii = 0; ii < _textures.length; ii++) {
other._textures[ii] = (TextureConfig)_textures[ii].clone();
}
@@ -40,17 +40,19 @@ import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import javax.swing.Icon;
import javax.swing.JFrame;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.samskivert.swing.Controller;
import com.samskivert.swing.RadialMenu;
import com.samskivert.swing.RuntimeAdjust;
@@ -60,6 +62,7 @@ import com.samskivert.util.StringUtil;
import com.threerings.media.VirtualMediaPanel;
import com.threerings.media.sprite.Sprite;
import com.threerings.media.tile.ObjectTile;
import com.threerings.media.tile.Tile;
import com.threerings.media.tile.TileManager;
import com.threerings.media.tile.TileSet;
@@ -352,9 +355,9 @@ public class MisoScenePanel extends VirtualMediaPanel
*/
public void reportMemoryUsage ()
{
HashMap base = new HashMap();
HashSet fringe = new HashSet();
HashMap object = new HashMap();
Map<Tile.Key,BaseTile> base = Maps.newHashMap();
Set<BaseTile> fringe = Sets.newHashSet();
Map<Tile.Key,ObjectTile> object = Maps.newHashMap();
long[] usage = new long[3];
for (SceneBlock block : _blocks.values()) {
block.computeMemoryUsage(base, fringe, object, usage);
@@ -594,7 +597,7 @@ public class MisoScenePanel extends VirtualMediaPanel
_spritemgr.getHitSprites(_hitSprites, x, y);
int hslen = _hitSprites.size();
for (int i = 0; i < hslen; i++) {
Sprite sprite = (Sprite)_hitSprites.get(i);
Sprite sprite = _hitSprites.get(i);
appendDirtySprite(_hitList, sprite);
}
@@ -824,10 +827,8 @@ public class MisoScenePanel extends VirtualMediaPanel
int bkey = compose(bx, by);
if (!_blocks.containsKey(bkey)) {
SceneBlock block = new SceneBlock(
this, origin.x, origin.y,
_metrics.blockwid, _metrics.blockhei);
boolean visible =
block.getFootprint().getBounds().intersects(_vibounds);
this, origin.x, origin.y, _metrics.blockwid, _metrics.blockhei);
boolean visible = block.getFootprint().getBounds().intersects(_vibounds);
block.setVisiBlock(visible);
_blocks.put(bkey, block);
@@ -847,8 +848,7 @@ public class MisoScenePanel extends VirtualMediaPanel
// recompute our visible object set
recomputeVisible();
Log.debug("Rethunk [pending=" + _pendingBlocks +
", visible=" + _visiBlocks.size() + "].");
Log.debug("Rethunk [pending=" + _pendingBlocks + ", visible=" + _visiBlocks.size() + "].");
return _visiBlocks.size();
}
@@ -1026,8 +1026,7 @@ public class MisoScenePanel extends VirtualMediaPanel
*/
public void computeIndicators ()
{
Map<SceneObject, SceneObjectIndicator> _unupdated = new HashMap<SceneObject, SceneObjectIndicator>(
_indicators);
Map<SceneObject, SceneObjectIndicator> _unupdated = Maps.newHashMap(_indicators);
for (int ii = 0, nn = _vizobjs.size(); ii < nn; ii++) {
SceneObject scobj = _vizobjs.get(ii);
String action = scobj.info.action;
@@ -1276,7 +1275,7 @@ public class MisoScenePanel extends VirtualMediaPanel
_spritemgr.getIntersectingSprites(_dirtySprites, clip);
int size = _dirtySprites.size();
for (int ii = 0; ii < size; ii++) {
Sprite sprite = (Sprite)_dirtySprites.get(ii);
Sprite sprite = _dirtySprites.get(ii);
Rectangle bounds = sprite.getBounds();
if (!bounds.intersects(clip)) {
continue;
@@ -1319,8 +1318,8 @@ public class MisoScenePanel extends VirtualMediaPanel
{
// make sure the indicators are ready
if (!_indicatorsLaidOut) {
List<Rectangle> boundaries = new ArrayList<Rectangle>();
for (Entry<SceneObject, SceneObjectIndicator> entry : _indicators.entrySet()) {
List<Rectangle> boundaries = Lists.newArrayList();
for (Map.Entry<SceneObject, SceneObjectIndicator> entry : _indicators.entrySet()) {
entry.getValue().layout(gfx, entry.getKey(), _vbounds, boundaries);
dirtyIndicator(entry.getValue());
boundaries.add(entry.getValue().getBounds());
@@ -1596,7 +1595,7 @@ public class MisoScenePanel extends VirtualMediaPanel
/** Used by {@link #rethink}. */
protected class RethinkOp implements TileOp
{
public HashSet blocks = new HashSet();
public Set blocks = Sets.newHashSet();
public void apply (int tx, int ty, Rectangle tbounds) {
_key.x = MathUtil.floorDiv(tx, _metrics.blockwid) *
@@ -1643,23 +1642,23 @@ public class MisoScenePanel extends VirtualMediaPanel
protected int _pendingBlocks;
/** Used to track visible blocks that are waiting to be resolved. */
protected HashSet _visiBlocks = new HashSet();
protected Set<SceneBlock> _visiBlocks = Sets.newHashSet();
/** Used to avoid repaints while we don't yet have resolved all the
* blocks needed to render the visible view. */
protected boolean _delayRepaint = false;
/** A list of the potentially visible objects in the scene. */
protected ArrayList<SceneObject> _vizobjs = new ArrayList<SceneObject>();
protected List<SceneObject> _vizobjs = Lists.newArrayList();
/** For computing fringe tiles. */
protected HashMap _masks = new HashMap();
protected Map _masks = Maps.newHashMap();
/** The dirty sprites and objects that need to be re-painted. */
protected DirtyItemList _dirtyItems = new DirtyItemList();
/** The working sprites list used when calculating dirty regions. */
protected ArrayList _dirtySprites = new ArrayList();
protected List<Sprite> _dirtySprites = Lists.newArrayList();
/** Used when rendering tiles. */
protected Rectangle _tbounds;
@@ -1672,7 +1671,7 @@ public class MisoScenePanel extends VirtualMediaPanel
/** Used to collect the list of sprites "hit" by a particular mouse
* location. */
protected List _hitSprites = new ArrayList();
protected List<Sprite> _hitSprites = Lists.newArrayList();
/** The list that we use to track and sort the items over which the
* mouse is hovering. */
@@ -1691,8 +1690,7 @@ public class MisoScenePanel extends VirtualMediaPanel
protected Point _hcoords = new Point();
/** Our object indicators, indexed by the object that they indicate. */
protected HashMap<SceneObject, SceneObjectIndicator> _indicators =
new HashMap<SceneObject, SceneObjectIndicator>();
protected Map<SceneObject, SceneObjectIndicator> _indicators = Maps.newHashMap();
/** Have the indicators been laid out? */
protected boolean _indicatorsLaidOut = false;
@@ -25,16 +25,17 @@ import java.awt.Polygon;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import com.samskivert.util.ArrayUtil;
import com.samskivert.util.HashIntMap;
import com.samskivert.util.IntMap;
import com.samskivert.util.StringUtil;
import com.threerings.geom.GeomUtil;
import com.threerings.media.tile.NoSuchTileSetException;
import com.threerings.media.tile.ObjectTile;
import com.threerings.media.tile.Tile;
import com.threerings.media.tile.TileSet;
import com.threerings.media.tile.TileUtil;
import com.threerings.media.util.MathUtil;
@@ -401,8 +402,8 @@ public class SceneBlock
* is placed into the zeroth array element, fringe tile usage into the
* first and object tile usage into the second.
*/
public void computeMemoryUsage (
HashMap bases, HashSet fringes, HashMap objects, long[] usage)
public void computeMemoryUsage (Map<Tile.Key,BaseTile> bases, Set<BaseTile> fringes,
Map<Tile.Key,ObjectTile> objects, long[] usage)
{
// account for our base tiles
MisoSceneModel model = _panel.getSceneModel();
@@ -415,7 +416,7 @@ public class SceneBlock
continue;
}
BaseTile sbase = (BaseTile)bases.get(base.key);
BaseTile sbase = bases.get(base.key);
if (sbase == null) {
bases.put(base.key, base);
usage[0] += base.getEstimatedMemoryUsage();
@@ -440,7 +441,7 @@ public class SceneBlock
int ocount = (_objects == null) ? 0 : _objects.length;
for (int ii = 0; ii < ocount; ii++) {
SceneObject scobj = _objects[ii];
ObjectTile tile = (ObjectTile)objects.get(scobj.tile.key);
ObjectTile tile = objects.get(scobj.tile.key);
if (tile == null) {
objects.put(scobj.tile.key, scobj.tile);
usage[2] += scobj.tile.getEstimatedMemoryUsage();
@@ -482,7 +483,7 @@ public class SceneBlock
* Links this block to its neighbors; informs neighboring blocks of
* object coverage.
*/
protected void update (HashIntMap blocks)
protected void update (IntMap blocks)
{
boolean recover = false;
@@ -527,7 +528,7 @@ public class SceneBlock
/**
* Sets the footprint of this object tile
*/
protected void setCovered (HashIntMap blocks, SceneObject scobj)
protected void setCovered (IntMap blocks, SceneObject scobj)
{
int endx = scobj.info.x - scobj.tile.getBaseWidth() + 1;
int endy = scobj.info.y - scobj.tile.getBaseHeight() + 1;
@@ -25,7 +25,7 @@ import java.awt.Graphics2D;
import java.awt.Transparency;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import com.samskivert.util.CheapIntMap;
import com.samskivert.util.QuickSort;
@@ -44,8 +44,7 @@ import com.threerings.miso.Log;
import com.threerings.miso.data.MisoSceneModel;
/**
* Automatically fringes a scene according to the rules in the supplied
* fringe configuration.
* Automatically fringes a scene according to the rules in the supplied fringe configuration.
*/
public class AutoFringer
{
@@ -72,8 +71,7 @@ public class AutoFringer
* Compute and return the fringe tile to be inserted at the specified
* location.
*/
public BaseTile getFringeTile (MisoSceneModel scene, int col, int row,
HashMap masks)
public BaseTile getFringeTile (MisoSceneModel scene, int col, int row, Map masks)
{
// get the tileset id of the base tile we are considering
int underset = adjustTileSetId(scene.getBaseTileId(col, row) >> 16);
@@ -150,8 +148,7 @@ public class AutoFringer
/**
* Compose a FringeTile out of the various fringe images needed.
*/
protected void composeFringeTile (
Tile frTile, FringerRec[] fringers, HashMap masks, int hashValue)
protected void composeFringeTile (Tile frTile, FringerRec[] fringers, Map masks, int hashValue)
{
// sort the array so that higher priority fringers get drawn first
QuickSort.sort(fringers);
@@ -161,11 +158,9 @@ public class AutoFringer
int[] indexes = getFringeIndexes(fringers[ii].bits);
for (int jj = 0; jj < indexes.length; jj++) {
try {
ftimg = getTileImage(ftimg, fringers[ii].baseset,
indexes[jj], masks, hashValue);
ftimg = getTileImage(ftimg, fringers[ii].baseset, indexes[jj], masks, hashValue);
} catch (NoSuchTileSetException nstse) {
Log.warning("Autofringer couldn't find a needed tileset " +
"[error=" + nstse + "].");
Log.warning("Autofringer couldn't find a needed tileset [error=" + nstse + "].");
}
}
}
@@ -176,26 +171,22 @@ public class AutoFringer
/**
* Retrieve or compose an image for the specified fringe.
*/
protected BufferedImage getTileImage (
BufferedImage ftimg, int baseset, int index,
HashMap masks, int hashValue)
protected BufferedImage getTileImage (BufferedImage ftimg, int baseset, int index,
Map masks, int hashValue)
throws NoSuchTileSetException
{
FringeConfiguration.FringeTileSetRecord tsr =
_fringeconf.getFringe(baseset, hashValue);
FringeConfiguration.FringeTileSetRecord tsr = _fringeconf.getFringe(baseset, hashValue);
int fringeset = tsr.fringe_tsid;
TileSet fset = _tmgr.getTileSet(fringeset);
if (!tsr.mask) {
// oh good, this is easy
Tile stamp = fset.getTile(index);
return stampTileImage(stamp, ftimg, stamp.getWidth(),
stamp.getHeight());
return stampTileImage(stamp, ftimg, stamp.getWidth(), stamp.getHeight());
}
// otherwise, it's a mask.. look for it in the cache..
Long maskkey = Long.valueOf((((long) baseset) << 32) +
(fringeset << 16) + index);
Long maskkey = Long.valueOf((((long) baseset) << 32) + (fringeset << 16) + index);
BufferedImage img = (BufferedImage)masks.get(maskkey);
if (img == null) {
BufferedImage fsrc = fset.getRawTileImage(index);
@@ -203,15 +194,13 @@ public class AutoFringer
img = ImageUtil.composeMaskedImage(_imgr, fsrc, bsrc);
masks.put(maskkey, img);
}
ftimg = stampTileImage(img, ftimg, img.getWidth(null),
img.getHeight(null));
ftimg = stampTileImage(img, ftimg, img.getWidth(null), img.getHeight(null));
return ftimg;
}
/** Helper function for {@link #getTileImage}. */
protected BufferedImage stampTileImage (Object stamp, BufferedImage ftimg,
int width, int height)
protected BufferedImage stampTileImage (Object stamp, BufferedImage ftimg, int width, int height)
{
// create the target image if necessary
if (ftimg == null) {
@@ -231,9 +220,8 @@ public class AutoFringer
}
/**
* Get the fringe index specified by the fringebits. If no index
* is available, try breaking down the bits into contiguous regions of
* bits and look for indexes for those.
* Get the fringe index specified by the fringebits. If no index is available, try breaking
* down the bits into contiguous regions of bits and look for indexes for those.
*/
protected int[] getFringeIndexes (int bits)
{