Moved sprite stuff into media package, removed coupling between miso stuff

and sprite stuff by added some interfaces in the sprite stuff and
implementing them with the miso stuff.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@245 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2001-08-14 23:35:22 +00:00
parent 0d0cb7f8ec
commit 3eea4dcaad
13 changed files with 221 additions and 134 deletions
@@ -1,15 +1,18 @@
//
// $Id: IsoSceneView.java,v 1.42 2001/08/14 21:29:40 shaper Exp $
// $Id: IsoSceneView.java,v 1.43 2001/08/14 23:35:22 mdb Exp $
package com.threerings.miso.scene;
import java.awt.*;
import java.awt.geom.*;
import java.awt.image.*;
import java.util.List;
import java.util.ArrayList;
import com.threerings.media.sprite.*;
import com.threerings.miso.Log;
import com.threerings.miso.sprite.*;
import com.threerings.miso.tile.Tile;
import com.threerings.miso.tile.TileManager;
import com.threerings.miso.scene.util.IsoUtil;
@@ -397,7 +400,7 @@ public class IsoSceneView implements EditableSceneView
*
* @param rects the list of Rectangle objects.
*/
public void invalidateRects (ArrayList rects)
public void invalidateRects (List rects)
{
int size = rects.size();
for (int ii = 0; ii < size; ii++) {
@@ -1,9 +1,9 @@
//
// $Id: Location.java,v 1.4 2001/08/11 00:00:13 shaper Exp $
// $Id: Location.java,v 1.5 2001/08/14 23:35:22 mdb Exp $
package com.threerings.miso.scene;
import com.threerings.miso.sprite.Path;
import com.threerings.media.sprite.Path;
/**
* The <code>Location</code> class represents a unique well-defined
@@ -1,14 +1,12 @@
//
// $Id: SceneView.java,v 1.9 2001/08/02 20:43:03 shaper Exp $
// $Id: SceneView.java,v 1.10 2001/08/14 23:35:22 mdb Exp $
package com.threerings.miso.scene;
import java.awt.Component;
import java.awt.Graphics;
import java.util.ArrayList;
import com.threerings.miso.sprite.Path;
import com.threerings.miso.sprite.Sprite;
import com.threerings.media.sprite.*;
import com.threerings.miso.tile.Tile;
/**
@@ -16,7 +14,7 @@ import com.threerings.miso.tile.Tile;
* classes that provide a view of a given scene by drawing the scene
* contents onto a particular GUI component.
*/
public interface SceneView
public interface SceneView extends AnimatedView
{
/**
* Render the scene to the given graphics context.
@@ -32,14 +30,6 @@ public interface SceneView
*/
public void setScene (Scene scene);
/**
* Invalidate a list of rectangles in screen pixel coordinates in
* the scene view for later repainting.
*
* @param rects the list of <code>java.awt.Rectangle</code> objects.
*/
public void invalidateRects (ArrayList rects);
/**
* Return a Path object detailing a valid path for the given
* sprite to take in the scene to get from its current position to
@@ -1,12 +1,12 @@
//
// $Id: SceneViewPanel.java,v 1.4 2001/08/08 03:19:38 shaper Exp $
// $Id: SceneViewPanel.java,v 1.5 2001/08/14 23:35:22 mdb Exp $
package com.threerings.miso.scene;
import java.awt.*;
import javax.swing.JPanel;
import com.threerings.miso.sprite.SpriteManager;
import com.threerings.media.sprite.SpriteManager;
import com.threerings.miso.tile.TileManager;
/**
@@ -1,14 +1,15 @@
//
// $Id: IsoUtil.java,v 1.1 2001/08/14 21:29:40 shaper Exp $
// $Id: IsoUtil.java,v 1.2 2001/08/14 23:35:22 mdb Exp $
package com.threerings.miso.scene.util;
import java.awt.Point;
import java.awt.Polygon;
import com.threerings.media.sprite.Path;
import com.threerings.media.util.MathUtil;
import com.threerings.miso.scene.*;
import com.threerings.miso.sprite.Path;
import com.threerings.miso.util.MathUtil;
/**
* The <code>IsoUtil</code> class is a holding place for miscellaneous
@@ -0,0 +1,72 @@
//
// $Id: TileUtil.java,v 1.1 2001/08/14 23:35:22 mdb Exp $
package com.threerings.miso.tile;
import java.awt.Image;
import com.threerings.media.sprite.AmbulatorySprite;
import com.threerings.media.sprite.MultiFrameImage;
import com.threerings.media.sprite.Path;
/**
* Tile-related utility functions.
*/
public class TileUtil
{
/**
* Returns an array of multi-frame images corresponding to the frames
* of animation used to render the mobile sprite in each of the
* directions it may face. The tileset id referenced must contain
* <code>Path.NUM_DIRECTIONS</code> rows of tiles, with each row
* containing <code>NUM_DIR_FRAMES</code> tiles.
*
* @param tilemgr the tile manager to retrieve tiles from.
* @param tsid the tileset id containing the sprite tiles.
*
* @return the array of multi-frame sprite images.
*/
public static MultiFrameImage[] getSpriteFrames (
TileManager tilemgr, int tsid)
{
MultiFrameImage[] anims = new MultiFrameImage[Path.NUM_DIRECTIONS];
for (int ii = 0; ii < Path.NUM_DIRECTIONS; ii++) {
Tile[] tiles = new Tile[NUM_DIR_FRAMES];
for (int jj = 0; jj < NUM_DIR_FRAMES; jj++) {
int idx = (ii * NUM_DIR_FRAMES) + jj;
tiles[jj] = tilemgr.getTile(tsid, idx);
}
anims[ii] = new MultiTileImage(tiles);
}
return anims;
}
/**
* A class that treats an array of tiles as source images for a
* multi-frame animation to be used by the sprite engine.
*/
protected static class MultiTileImage implements MultiFrameImage
{
public MultiTileImage (Tile[] tiles)
{
_tiles = tiles;
}
public int getFrameCount ()
{
return _tiles.length;
}
public Image getFrame (int index)
{
return _tiles[index].img;
}
protected Tile[] _tiles;
}
/** The number of frames of animation for each direction. */
protected static final int NUM_DIR_FRAMES = 8;
}