Formatting changes:

- removed tabs
- explicitly specify imports
- I made each comment a complete and punctuated sentance.
- other minor convention changes


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1155 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2002-03-26 23:35:02 +00:00
parent 0251b8f19f
commit 1a53da6727
6 changed files with 263 additions and 251 deletions
@@ -1,22 +1,24 @@
//
// $Id: ColorUtil.java,v 1.1 2002/03/26 20:09:43 ray Exp $
// $Id: ColorUtil.java,v 1.2 2002/03/26 23:35:01 ray Exp $
package com.threerings.media.util;
import java.awt.Color;
/**
* Utilities to manipulate colors
* Utilities to manipulate colors.
*/
public class ColorUtil
{
/**
* @return a color halfway between the two colors
* Blends the two supplied colors.
*
* @return a color halfway between the two colors.
*/
public static final Color blend (Color c1, Color c2)
{
return new Color((c1.getRed() + c2.getRed()) >> 1,
(c1.getGreen() + c2.getGreen()) >> 1,
(c1.getBlue() + c2.getBlue()) >> 1);
return new Color((c1.getRed() + c2.getRed()) >> 1,
(c1.getGreen() + c2.getGreen()) >> 1,
(c1.getBlue() + c2.getBlue()) >> 1);
}
}
@@ -1,5 +1,5 @@
//
// $Id: ObjectTileLayer.java,v 1.2 2002/03/26 20:17:51 ray Exp $
// $Id: ObjectTileLayer.java,v 1.3 2002/03/26 23:35:01 ray Exp $
package com.threerings.media.tile;
@@ -57,7 +57,7 @@ public final class ObjectTileLayer
*/
public ObjectTile getTile (int column, int row)
{
return (ObjectTile) _tiles.get(IsoUtil.coordsToKey(column, row));
return (ObjectTile) _tiles.get(IsoUtil.coordsToKey(column, row));
}
/**
@@ -67,15 +67,15 @@ public final class ObjectTileLayer
*/
public void setTile (int column, int row, ObjectTile tile)
{
_tiles.put(IsoUtil.coordsToKey(column, row), tile);
_tiles.put(IsoUtil.coordsToKey(column, row), tile);
}
/**
* Removes the tile at the specified row and column
* Removes the tile at the specified row and column.
*/
public void clearTile (int column, int row)
{
_tiles.remove(IsoUtil.coordsToKey(column, row));
_tiles.remove(IsoUtil.coordsToKey(column, row));
}
/** Our tiles. */
@@ -1,5 +1,5 @@
//
// $Id: DisplayMisoSceneImpl.java,v 1.52 2002/03/26 20:17:51 ray Exp $
// $Id: DisplayMisoSceneImpl.java,v 1.53 2002/03/26 23:35:01 ray Exp $
package com.threerings.miso.scene;
@@ -227,10 +227,14 @@ public class DisplayMisoSceneImpl
int endy = Math.max(0, (y - otile.getBaseHeight() + 1));
for (int xx = x; xx >= endx; xx--) {
if ((xx < 0) || (xx >= _model.width)) continue;
if ((xx < 0) || (xx >= _model.width)) {
continue;
}
for (int yy = y; yy >= endy; yy--) {
if ((yy < 0) || (yy >= _model.height)) continue;
if ((yy < 0) || (yy >= _model.height)) {
continue;
}
BaseTile tile = _base.getTile(xx, yy);
if (tile != null) {
@@ -1,5 +1,5 @@
//
// $Id: IsoSceneView.java,v 1.103 2002/03/26 20:17:51 ray Exp $
// $Id: IsoSceneView.java,v 1.104 2002/03/26 23:35:01 ray Exp $
package com.threerings.miso.scene;
@@ -112,7 +112,7 @@ public class IsoSceneView implements SceneView
_scene = scene;
// clear all dirty lists and tile array
clearDirtyRegions();
clearDirtyRegions();
// obtain a list of the objects in the scene and generate records
// for each of them that contain precomputed metrics
@@ -157,7 +157,7 @@ public class IsoSceneView implements SceneView
// documentation inherited from interface
public void paint (Graphics2D gfx, List invalidRects)
{
if (_scene == null) {
if (_scene == null) {
Log.warning("Scene view painted with null scene.");
return;
}
@@ -194,16 +194,16 @@ public class IsoSceneView implements SceneView
// clear out the dirty tiles and rectangles
clearDirtyRegions();
// draw sprite paths
if (_model.showPaths) {
_spritemgr.renderSpritePaths(gfx);
}
// draw sprite paths
if (_model.showPaths) {
_spritemgr.renderSpritePaths(gfx);
}
// paint our highlighted tile (if any)
paintHighlights(gfx);
// paint any extra goodies
paintExtras(gfx);
paintExtras(gfx);
}
/**
@@ -243,15 +243,15 @@ public class IsoSceneView implements SceneView
// if we've determined that there's something to highlight
if (hpoly != null) {
// set the desired stroke and color
Stroke ostroke = gfx.getStroke();
gfx.setStroke(_hstroke);
gfx.setColor(Color.green);
Stroke ostroke = gfx.getStroke();
gfx.setStroke(_hstroke);
gfx.setColor(Color.green);
// draw the outline
// draw the outline
gfx.draw(hpoly);
// restore the original stroke
gfx.setStroke(ostroke);
// restore the original stroke
gfx.setStroke(ostroke);
}
}
@@ -278,12 +278,12 @@ public class IsoSceneView implements SceneView
*/
protected void clearDirtyRegions ()
{
_dirtyRects.clear();
_dirtyRects.clear();
_dirtyItems.clear();
_numDirty = 0;
for (int xx = 0; xx < _model.scenewid; xx++) {
for (int xx = 0; xx < _model.scenewid; xx++) {
Arrays.fill(_dirty[xx], false);
}
}
}
/**
@@ -291,25 +291,25 @@ public class IsoSceneView implements SceneView
*/
protected void drawDirtyRegions (Graphics2D gfx)
{
// draw the dirty tiles
gfx.setColor(Color.cyan);
for (int xx = 0; xx < _model.scenewid; xx++) {
for (int yy = 0; yy < _model.scenehei; yy++) {
if (_dirty[xx][yy]) {
gfx.draw(getTilePoly(xx, yy));
}
}
}
// draw the dirty tiles
gfx.setColor(Color.cyan);
for (int xx = 0; xx < _model.scenewid; xx++) {
for (int yy = 0; yy < _model.scenehei; yy++) {
if (_dirty[xx][yy]) {
gfx.draw(getTilePoly(xx, yy));
}
}
}
// draw the dirty rectangles
// draw the dirty rectangles
Stroke ostroke = gfx.getStroke();
gfx.setStroke(DIRTY_RECT_STROKE);
gfx.setColor(Color.red);
int size = _dirtyRects.size();
for (int ii = 0; ii < size; ii++) {
Rectangle rect = (Rectangle)_dirtyRects.get(ii);
gfx.draw(rect);
}
gfx.setColor(Color.red);
int size = _dirtyRects.size();
for (int ii = 0; ii < size; ii++) {
Rectangle rect = (Rectangle)_dirtyRects.get(ii);
gfx.draw(rect);
}
gfx.setStroke(ostroke);
// draw the dirty item rectangles
@@ -351,9 +351,9 @@ public class IsoSceneView implements SceneView
protected void renderTiles (Graphics2D gfx)
{
// render the base and fringe layers
for (int yy = 0; yy < _model.scenehei; yy++) {
for (int xx = 0; xx < _model.scenewid; xx++) {
if (!_dirty[xx][yy]) {
for (int yy = 0; yy < _model.scenehei; yy++) {
for (int xx = 0; xx < _model.scenewid; xx++) {
if (!_dirty[xx][yy]) {
continue;
}
@@ -373,8 +373,8 @@ public class IsoSceneView implements SceneView
if (_model.showCoords) {
gfx.draw(getTilePoly(xx, yy));
}
}
}
}
}
}
/**
@@ -415,8 +415,8 @@ public class IsoSceneView implements SceneView
{
FontMetrics fm = gfx.getFontMetrics(_font);
gfx.setFont(_font);
gfx.setColor(Color.white);
gfx.setFont(_font);
gfx.setColor(Color.white);
int cx = _model.tilehwid, cy = _model.tilehhei;
int fhei = fm.getAscent();
@@ -503,12 +503,12 @@ public class IsoSceneView implements SceneView
*/
protected Polygon getTilePoly (int x, int y)
{
int key = IsoUtil.coordsToKey(x, y);
Polygon poly = (Polygon) _polys.get(key);
int key = IsoUtil.coordsToKey(x, y);
Polygon poly = (Polygon) _polys.get(key);
if (poly == null) {
poly = IsoUtil.getTilePolygon(_model, x, y);
_polys.put(key, poly);
poly = IsoUtil.getTilePolygon(_model, x, y);
_polys.put(key, poly);
}
return poly;
}
@@ -548,91 +548,91 @@ public class IsoSceneView implements SceneView
// invalidated rectangle
Rectangle tileBounds = new Rectangle(-1, -1, 0, 0);
// note that corner tiles may be included unnecessarily, but
// checking to determine whether they're actually needed
// complicates the code with likely-insufficient benefit
// note that corner tiles may be included unnecessarily, but
// checking to determine whether they're actually needed
// complicates the code with likely-insufficient benefit
// determine the top-left tile impacted by this rect
// determine the top-left tile impacted by this rect
Point tpos = new Point();
IsoUtil.screenToTile(_model, rx, ry, tpos);
// determine screen coordinates for top-left tile
Point topleft = new Point();
IsoUtil.tileToScreen(_model, tpos.x, tpos.y, topleft);
// determine screen coordinates for top-left tile
Point topleft = new Point();
IsoUtil.tileToScreen(_model, tpos.x, tpos.y, topleft);
// determine number of horizontal tiles for rect
int numh = (int)Math.ceil((float)r.width / (float)_model.tilewid);
// determine number of horizontal tiles for rect
int numh = (int)Math.ceil((float)r.width / (float)_model.tilewid);
// set up iterating variables
int tx = tpos.x, ty = tpos.y, mx = tpos.x, my = tpos.y;
// set up iterating variables
int tx = tpos.x, ty = tpos.y, mx = tpos.x, my = tpos.y;
// set the starting screen y-position
int screenY = topleft.y;
// set the starting screen y-position
int screenY = topleft.y;
// add top row if rect may overlap
if (ry < (screenY + _model.tilehhei)) {
ty--;
for (int ii = 0; ii < numh; ii++) {
addDirtyTile(tileBounds, tx++, ty--);
}
}
// add top row if rect may overlap
if (ry < (screenY + _model.tilehhei)) {
ty--;
for (int ii = 0; ii < numh; ii++) {
addDirtyTile(tileBounds, tx++, ty--);
}
}
// determine the bottom-left tile impacted by this rect
// determine the bottom-left tile impacted by this rect
Point bpos = new Point();
IsoUtil.screenToTile(_model, rx, ry + r.height, bpos);
// determine screen coordinates for bottom-left tile
Point botleft = new Point();
IsoUtil.tileToScreen(_model, bpos.x, bpos.y, botleft);
// determine screen coordinates for bottom-left tile
Point botleft = new Point();
IsoUtil.tileToScreen(_model, bpos.x, bpos.y, botleft);
// determine the number of vertical rows for our rect (we do this
// by subtracting the "height" of the top tile from that of the
// bottom tile, the height being the sum of the x and y
// coordinate)
int numv = (bpos.x + bpos.y) - (tpos.x + tpos.y);
int numv = (bpos.x + bpos.y) - (tpos.x + tpos.y);
// now we need to extend the rect to contain the row containing
// the bottom tile, and potentially the row below that
numv += ((ry + r.height) > (botleft.y + _model.tilehhei)) ? 2 : 1;
// add dirty tiles from each affected row
for (int ii = 0; ii < numv; ii++) {
// add dirty tiles from each affected row
for (int ii = 0; ii < numv; ii++) {
// set up iterating variables for this row
tx = mx;
ty = my;
int length = numh;
// set up iterating variables for this row
tx = mx;
ty = my;
int length = numh;
// set the starting screen x-position
int screenX = topleft.x;
if (ii%2 == 1) {
screenX -= _model.tilehwid;
}
// set the starting screen x-position
int screenX = topleft.x;
if (ii%2 == 1) {
screenX -= _model.tilehwid;
}
// skip leftmost tile if rect doesn't overlap
if (rx > screenX + _model.tilewid) {
tx++;
ty--;
screenX += _model.tilewid;
}
// skip leftmost tile if rect doesn't overlap
if (rx > screenX + _model.tilewid) {
tx++;
ty--;
screenX += _model.tilewid;
}
// add to the right edge if rect may overlap
if (rx + r.width > (screenX + (length * _model.tilewid))) {
length++;
}
// add to the right edge if rect may overlap
if (rx + r.width > (screenX + (length * _model.tilewid))) {
length++;
}
// add all tiles in the row to the dirty set
for (int jj = 0; jj < length; jj++) {
addDirtyTile(tileBounds, tx++, ty--);
}
// add all tiles in the row to the dirty set
for (int jj = 0; jj < length; jj++) {
addDirtyTile(tileBounds, tx++, ty--);
}
// step along the x- or y-axis appropriately
if (ii%2 == 1) {
mx++;
} else {
my++;
}
}
// step along the x- or y-axis appropriately
if (ii%2 == 1) {
mx++;
} else {
my++;
}
}
return tileBounds;
}
@@ -655,14 +655,14 @@ public class IsoSceneView implements SceneView
tileBounds.add(bounds);
}
// do nothing if the tile's already dirty
if (_dirty[x][y]) {
return false;
}
// do nothing if the tile's already dirty
if (_dirty[x][y]) {
return false;
}
// mark the tile dirty
_numDirty++;
_dirty[x][y] = true;
// mark the tile dirty
_numDirty++;
_dirty[x][y] = true;
return true;
}
@@ -738,11 +738,11 @@ public class IsoSceneView implements SceneView
IsoUtil.screenToTile(_model, x + _xoff, y + _yoff, dest);
// get a reasonable tile path through the scene
List points = AStarPathUtil.getPath(
List points = AStarPathUtil.getPath(
_scene, _model.scenewid, _model.scenehei,
sprite, sprite.getTileX(), sprite.getTileY(), dest.x, dest.y);
// construct a path object to guide the sprite on its merry way
// construct a path object to guide the sprite on its merry way
return (points == null) ? null :
new TilePath(_model, sprite, points, x, y);
}
@@ -750,8 +750,8 @@ public class IsoSceneView implements SceneView
// documentation inherited
public Point getScreenCoords (int x, int y)
{
Point coords = new Point();
IsoUtil.fullToScreen(_model, x, y, coords);
Point coords = new Point();
IsoUtil.fullToScreen(_model, x, y, coords);
// adjust for our scrolling offset
coords.x -= _xoff;
coords.y -= _yoff;
@@ -895,7 +895,7 @@ public class IsoSceneView implements SceneView
*/
protected boolean updateTileCoords (int sx, int sy, Point tpos)
{
Point npos = new Point();
Point npos = new Point();
IsoUtil.screenToTile(_model, sx + _xoff, sy + _yoff, npos);
// make sure the new coordinate is both valid and different
@@ -1,5 +1,5 @@
//
// $Id: IsoUtil.java,v 1.23 2002/03/26 20:17:51 ray Exp $
// $Id: IsoUtil.java,v 1.24 2002/03/26 23:35:02 ray Exp $
package com.threerings.miso.scene.util;
@@ -62,7 +62,7 @@ public class IsoUtil
IsoSceneViewModel model, Polygon root, ObjectTile tile)
{
Polygon boundsPoly = new SmartPolygon();
Rectangle bounds = root.getBounds();
Rectangle bounds = root.getBounds();
int bwid = tile.getBaseWidth(), bhei = tile.getBaseHeight();
int oox = bounds.x + model.tilehwid, ooy = bounds.y + model.tilehei;
@@ -107,7 +107,7 @@ public class IsoUtil
public static Polygon getObjectBounds (
IsoSceneViewModel model, Polygon root, ObjectTile tile)
{
Rectangle bounds = root.getBounds();
Rectangle bounds = root.getBounds();
// if the tile has an origin, use that, otherwise compute the
// origin based on the tile footprint
@@ -178,41 +178,41 @@ public class IsoUtil
* class's direction constants.
*/
public static int getDirection (
IsoSceneViewModel model, int ax, int ay, int bx, int by)
IsoSceneViewModel model, int ax, int ay, int bx, int by)
{
Point afpos = new Point(), bfpos = new Point();
Point afpos = new Point(), bfpos = new Point();
// convert screen coordinates to full coordinates to get both
// tile coordinates and fine coordinates
screenToFull(model, ax, ay, afpos);
screenToFull(model, bx, by, bfpos);
// convert screen coordinates to full coordinates to get both
// tile coordinates and fine coordinates
screenToFull(model, ax, ay, afpos);
screenToFull(model, bx, by, bfpos);
// pull out the tile coordinates for each point
int tax = afpos.x / FULL_TILE_FACTOR;
int tay = afpos.y / FULL_TILE_FACTOR;
// pull out the tile coordinates for each point
int tax = afpos.x / FULL_TILE_FACTOR;
int tay = afpos.y / FULL_TILE_FACTOR;
int tbx = bfpos.x / FULL_TILE_FACTOR;
int tby = bfpos.y / FULL_TILE_FACTOR;
int tbx = bfpos.x / FULL_TILE_FACTOR;
int tby = bfpos.y / FULL_TILE_FACTOR;
// compare tile coordinates to determine direction
int dir = getIsoDirection(tax, tay, tbx, tby);
if (dir != DirectionCodes.NONE) return dir;
// compare tile coordinates to determine direction
int dir = getIsoDirection(tax, tay, tbx, tby);
if (dir != DirectionCodes.NONE) return dir;
// destination point is in the same tile as the
// origination point, so consider fine coordinates
// destination point is in the same tile as the
// origination point, so consider fine coordinates
// pull out the fine coordinates for each point
int fax = afpos.x - (tax * FULL_TILE_FACTOR);
int fay = afpos.y - (tay * FULL_TILE_FACTOR);
// pull out the fine coordinates for each point
int fax = afpos.x - (tax * FULL_TILE_FACTOR);
int fay = afpos.y - (tay * FULL_TILE_FACTOR);
int fbx = bfpos.x - (tbx * FULL_TILE_FACTOR);
int fby = bfpos.y - (tby * FULL_TILE_FACTOR);
int fbx = bfpos.x - (tbx * FULL_TILE_FACTOR);
int fby = bfpos.y - (tby * FULL_TILE_FACTOR);
// compare fine coordinates to determine direction
dir = getIsoDirection(fax, fay, fbx, fby);
// compare fine coordinates to determine direction
dir = getIsoDirection(fax, fay, fbx, fby);
// arbitrarily return southwest if fine coords were also equivalent
return (dir == -1) ? SOUTHWEST : dir;
// arbitrarily return southwest if fine coords were also equivalent
return (dir == -1) ? SOUTHWEST : dir;
}
/**
@@ -233,24 +233,24 @@ public class IsoUtil
*/
public static int getIsoDirection (int ax, int ay, int bx, int by)
{
if (bx > ax) {
if (by == ay) {
if (bx > ax) {
if (by == ay) {
return SOUTH;
}
return (by < ay) ? SOUTHEAST : SOUTHWEST;
return (by < ay) ? SOUTHEAST : SOUTHWEST;
} else if (bx == ax) {
if (by == ay) {
} else if (bx == ax) {
if (by == ay) {
return DirectionCodes.NONE;
}
return (by < ay) ? EAST : WEST;
return (by < ay) ? EAST : WEST;
} else { // bx < ax
if (by == ay) {
} else { // bx < ax
if (by == ay) {
return NORTH;
}
return (by < ay) ? NORTHEAST : NORTHWEST;
}
return (by < ay) ? NORTHEAST : NORTHWEST;
}
}
/**
@@ -258,7 +258,7 @@ public class IsoUtil
*/
public static int fullToTile (int val)
{
return (val / FULL_TILE_FACTOR);
return (val / FULL_TILE_FACTOR);
}
/**
@@ -266,7 +266,7 @@ public class IsoUtil
*/
public static int fullToFine (int val)
{
return (val - ((val / FULL_TILE_FACTOR) * FULL_TILE_FACTOR));
return (val - ((val / FULL_TILE_FACTOR) * FULL_TILE_FACTOR));
}
/**
@@ -279,24 +279,24 @@ public class IsoUtil
* @param tpos the point object to place coordinates in.
*/
public static void screenToTile (
IsoSceneViewModel model, int sx, int sy, Point tpos)
IsoSceneViewModel model, int sx, int sy, Point tpos)
{
// calculate line parallel to the y-axis (from mouse pos to x-axis)
int bY = (int)(sy - (model.slopeY * sx));
// calculate line parallel to the y-axis (from mouse pos to x-axis)
int bY = (int)(sy - (model.slopeY * sx));
// determine intersection of x- and y-axis lines
int crossx = (int)((bY - (model.bX + model.origin.y)) /
(model.slopeX - model.slopeY));
int crossy = (int)((model.slopeY * crossx) + bY);
// determine intersection of x- and y-axis lines
int crossx = (int)((bY - (model.bX + model.origin.y)) /
(model.slopeX - model.slopeY));
int crossy = (int)((model.slopeY * crossx) + bY);
// determine distance of mouse pos along the x axis
int xdist = (int)MathUtil.distance(
model.origin.x, model.origin.y, crossx, crossy);
tpos.x = (int)(xdist / model.tilelen);
// determine distance of mouse pos along the x axis
int xdist = (int)MathUtil.distance(
model.origin.x, model.origin.y, crossx, crossy);
tpos.x = (int)(xdist / model.tilelen);
// determine distance of mouse pos along the y-axis
int ydist = (int)MathUtil.distance(sx, sy, crossx, crossy);
tpos.y = (int)(ydist / model.tilelen);
// determine distance of mouse pos along the y-axis
int ydist = (int)MathUtil.distance(sx, sy, crossx, crossy);
tpos.y = (int)(ydist / model.tilelen);
}
/**
@@ -309,7 +309,7 @@ public class IsoUtil
* @param spos the point object to place coordinates in.
*/
public static void tileToScreen (
IsoSceneViewModel model, int x, int y, Point spos)
IsoSceneViewModel model, int x, int y, Point spos)
{
spos.x = model.origin.x + ((x - y - 1) * model.tilehwid);
spos.y = model.origin.y + ((x + y) * model.tilehhei);
@@ -325,10 +325,10 @@ public class IsoUtil
* @param ppos the point object to place coordinates in.
*/
public static void fineToPixel (
IsoSceneViewModel model, int x, int y, Point ppos)
IsoSceneViewModel model, int x, int y, Point ppos)
{
ppos.x = model.tilehwid + ((x - y) * model.finehwid);
ppos.y = (x + y) * model.finehhei;
ppos.x = model.tilehwid + ((x - y) * model.finehwid);
ppos.y = (x + y) * model.finehhei;
}
/**
@@ -342,28 +342,28 @@ public class IsoUtil
* @param fpos the point object to place coordinates in.
*/
public static void pixelToFine (
IsoSceneViewModel model, int x, int y, Point fpos)
IsoSceneViewModel model, int x, int y, Point fpos)
{
// calculate line parallel to the y-axis (from the given
// x/y-pos to the x-axis)
float bY = y - (model.fineSlopeY * x);
// calculate line parallel to the y-axis (from the given
// x/y-pos to the x-axis)
float bY = y - (model.fineSlopeY * x);
// determine intersection of x- and y-axis lines
int crossx = (int)((bY - model.fineBX) /
(model.fineSlopeX - model.fineSlopeY));
int crossy = (int)((model.fineSlopeY * crossx) + bY);
// determine intersection of x- and y-axis lines
int crossx = (int)((bY - model.fineBX) /
(model.fineSlopeX - model.fineSlopeY));
int crossy = (int)((model.fineSlopeY * crossx) + bY);
// TODO: final position should check distance between our
// position and the surrounding fine coords and return the
// actual closest fine coord, rather than just dividing.
// TODO: final position should check distance between our
// position and the surrounding fine coords and return the
// actual closest fine coord, rather than just dividing.
// determine distance along the x-axis
float xdist = MathUtil.distance(model.tilehwid, 0, crossx, crossy);
fpos.x = (int)(xdist / model.finelen);
// determine distance along the x-axis
float xdist = MathUtil.distance(model.tilehwid, 0, crossx, crossy);
fpos.x = (int)(xdist / model.finelen);
// determine distance along the y-axis
float ydist = MathUtil.distance(x, y, crossx, crossy);
fpos.y = (int)(ydist / model.finelen);
// determine distance along the y-axis
float ydist = MathUtil.distance(x, y, crossx, crossy);
fpos.y = (int)(ydist / model.finelen);
}
/**
@@ -377,22 +377,22 @@ public class IsoUtil
* @param fpos the point object to place coordinates in.
*/
public static void screenToFull (
IsoSceneViewModel model, int sx, int sy, Point fpos)
IsoSceneViewModel model, int sx, int sy, Point fpos)
{
// get the tile coordinates
Point tpos = new Point();
screenToTile(model, sx, sy, tpos);
// get the tile coordinates
Point tpos = new Point();
screenToTile(model, sx, sy, tpos);
// get the screen coordinates for the containing tile
Point spos = new Point();
tileToScreen(model, tpos.x, tpos.y, spos);
// get the screen coordinates for the containing tile
Point spos = new Point();
tileToScreen(model, tpos.x, tpos.y, spos);
// get the fine coordinates within the containing tile
pixelToFine(model, sx - spos.x, sy - spos.y, fpos);
// get the fine coordinates within the containing tile
pixelToFine(model, sx - spos.x, sy - spos.y, fpos);
// toss in the tile coordinates for good measure
fpos.x += (tpos.x * FULL_TILE_FACTOR);
fpos.y += (tpos.y * FULL_TILE_FACTOR);
// toss in the tile coordinates for good measure
fpos.x += (tpos.x * FULL_TILE_FACTOR);
fpos.y += (tpos.y * FULL_TILE_FACTOR);
}
/**
@@ -405,21 +405,21 @@ public class IsoUtil
* @param spos the point object to place coordinates in.
*/
public static void fullToScreen (
IsoSceneViewModel model, int x, int y, Point spos)
IsoSceneViewModel model, int x, int y, Point spos)
{
// get the tile screen position
Point tspos = new Point();
int tx = x / FULL_TILE_FACTOR, ty = y / FULL_TILE_FACTOR;
tileToScreen(model, tx, ty, tspos);
// get the tile screen position
Point tspos = new Point();
int tx = x / FULL_TILE_FACTOR, ty = y / FULL_TILE_FACTOR;
tileToScreen(model, tx, ty, tspos);
// get the pixel position of the fine coords within the tile
Point ppos = new Point();
int fx = x - (tx * FULL_TILE_FACTOR), fy = y - (ty * FULL_TILE_FACTOR);
fineToPixel(model, fx, fy, ppos);
// get the pixel position of the fine coords within the tile
Point ppos = new Point();
int fx = x - (tx * FULL_TILE_FACTOR), fy = y - (ty * FULL_TILE_FACTOR);
fineToPixel(model, fx, fy, ppos);
// final position is tile position offset by fine position
spos.x = tspos.x + ppos.x;
spos.y = tspos.y + ppos.y;
// final position is tile position offset by fine position
spos.x = tspos.x + ppos.x;
spos.y = tspos.y + ppos.y;
}
/**
@@ -429,7 +429,7 @@ public class IsoUtil
* @param y the tile y-position coordinate.
*/
public static Polygon getTilePolygon (
IsoSceneViewModel model, int x, int y)
IsoSceneViewModel model, int x, int y)
{
// get the top-left screen coordinate for the tile
Point spos = new Point();
@@ -447,27 +447,33 @@ public class IsoUtil
}
/**
* @return the hash key, give x and y
* Turns x and y scene coordinates into an integer key.
*
* @return the hash key, given x and y.
*/
public static final int coordsToKey (int x, int y)
{
return ((y << 16) & (0xFFFF0000)) | (x & 0xFFFF);
return ((y << 16) & (0xFFFF0000)) | (x & 0xFFFF);
}
/**
* @return the x coordinate from the hash key
* Gets the x coordinate from an integer hash key.
*
* @return the x coordinate.
*/
public static final int xCoordFromKey (int key)
{
return (key & 0xFFFF);
return (key & 0xFFFF);
}
/**
* @return the y coordinate from the hash key
* Gets the y coordinate from an integer hash key.
*
* @return the y coordinate from the hash key.
*/
public static final int yCoordFromKey (int key)
{
return ((key >> 16) & 0xFFFF);
return ((key >> 16) & 0xFFFF);
}
/** Multiplication factor to embed tile coords in full coords. */
@@ -1,8 +1,10 @@
//
// $Id: EditableMisoSceneImpl.java,v 1.10 2002/03/26 20:17:51 ray Exp $
// $Id: EditableMisoSceneImpl.java,v 1.11 2002/03/26 23:35:02 ray Exp $
package com.threerings.miso.scene.tools;
import java.util.Iterator;
import com.samskivert.util.HashIntMap;
import com.threerings.media.tile.NoSuchTileException;
@@ -17,8 +19,6 @@ import com.threerings.miso.scene.DisplayMisoSceneImpl;
import com.threerings.miso.scene.MisoSceneModel;
import com.threerings.miso.scene.util.IsoUtil;
import java.util.Iterator;
/**
* The default implementation of the {@link EditableMisoScene} interface.
*/
@@ -108,7 +108,7 @@ public class EditableMisoSceneImpl
// object tile
setObjectTileFootprint(tile, x, y, true);
// stick this value into our non-sparse object layer
_objectTileIds.put(IsoUtil.coordsToKey(x, y), new Integer(fqTileId));
_objectTileIds.put(IsoUtil.coordsToKey(x, y), new Integer(fqTileId));
}
// documentation inherited from interface
@@ -145,7 +145,7 @@ public class EditableMisoSceneImpl
_object.clearTile(x, y);
}
// clear it out in our non-sparse array
_objectTileIds.remove(IsoUtil.coordsToKey(x, y));
_objectTileIds.remove(IsoUtil.coordsToKey(x, y));
// clear out any action for this tile as well
_actions.remove(objectKey(x, y));
}
@@ -170,15 +170,15 @@ public class EditableMisoSceneImpl
String[] actions = new String[otileCount];
int otidx = 0, actidx = 0;
Iterator keys = _objectTileIds.keys();
while (keys.hasNext()) {
int key = ((Integer) keys.next()).intValue();
int c = IsoUtil.xCoordFromKey(key);
int r = IsoUtil.yCoordFromKey(key);
otids[otidx++] = c;
otids[otidx++] = r;
otids[otidx++] = ((Integer) _objectTileIds.get(key)).intValue();
actions[actidx++] = (String)_actions.get(objectKey(c, r));
Iterator keys = _objectTileIds.keys();
while (keys.hasNext()) {
int key = ((Integer) keys.next()).intValue();
int c = IsoUtil.xCoordFromKey(key);
int r = IsoUtil.yCoordFromKey(key);
otids[otidx++] = c;
otids[otidx++] = r;
otids[otidx++] = ((Integer) _objectTileIds.get(key)).intValue();
actions[actidx++] = (String)_actions.get(objectKey(c, r));
}
// stuff the new arrays into the model
@@ -196,7 +196,7 @@ public class EditableMisoSceneImpl
protected void unpackObjectLayer ()
{
// we need this to track object layer mods
_objectTileIds = new HashIntMap();
_objectTileIds = new HashIntMap();
// populate our non-spare array
int[] otids = _model.objectTileIds;
@@ -204,8 +204,8 @@ public class EditableMisoSceneImpl
int x = otids[i];
int y = otids[i+1];
int fqTileId = otids[i+2];
_objectTileIds.put(IsoUtil.coordsToKey(x, y),
new Integer(fqTileId));
_objectTileIds.put(IsoUtil.coordsToKey(x, y),
new Integer(fqTileId));
}
}