Added sparse layer tile format in XML output for layers other than BASE.
Refresh the scene view when coordinates are toggled. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@118 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: DisplayMisoSceneImpl.java,v 1.11 2001/07/24 16:10:19 shaper Exp $
|
// $Id: DisplayMisoSceneImpl.java,v 1.12 2001/07/24 19:15:51 shaper Exp $
|
||||||
|
|
||||||
package com.threerings.miso.scene;
|
package com.threerings.miso.scene;
|
||||||
|
|
||||||
@@ -16,6 +16,24 @@ import java.io.*;
|
|||||||
*/
|
*/
|
||||||
public class Scene
|
public class Scene
|
||||||
{
|
{
|
||||||
|
/** The base layer id. */
|
||||||
|
public static final int LAYER_BASE = 0;
|
||||||
|
|
||||||
|
/** The object layer id. */
|
||||||
|
public static final int LAYER_OBJECT = 1;
|
||||||
|
|
||||||
|
/** The total number of layers. */
|
||||||
|
public static final int NUM_LAYERS = 2;
|
||||||
|
|
||||||
|
/** The latest scene file format version. */
|
||||||
|
public static final short VERSION = 1;
|
||||||
|
|
||||||
|
/** The scene width in tiles. */
|
||||||
|
public static final int TILE_WIDTH = 55;
|
||||||
|
|
||||||
|
/** The scene height in tiles. */
|
||||||
|
public static final int TILE_HEIGHT = 55;
|
||||||
|
|
||||||
/** String translations of each tile layer name. */
|
/** String translations of each tile layer name. */
|
||||||
public static final String[] XLATE_LAYERS = { "Base", "Object" };
|
public static final String[] XLATE_LAYERS = { "Base", "Object" };
|
||||||
|
|
||||||
@@ -32,8 +50,10 @@ public class Scene
|
|||||||
{
|
{
|
||||||
_tilemgr = tilemgr;
|
_tilemgr = tilemgr;
|
||||||
_name = DEF_SCENE_NAME;
|
_name = DEF_SCENE_NAME;
|
||||||
tiles = new Tile[TILE_WIDTH][TILE_HEIGHT][NUM_LAYERS];
|
_hotspots = new Point[0];
|
||||||
|
_exits = new ExitPoint[0];
|
||||||
|
|
||||||
|
tiles = new Tile[TILE_WIDTH][TILE_HEIGHT][NUM_LAYERS];
|
||||||
Tile tile = _tilemgr.getTile(DEF_TSID, DEF_TID);
|
Tile tile = _tilemgr.getTile(DEF_TSID, DEF_TID);
|
||||||
for (int xx = 0; xx < TILE_WIDTH; xx++) {
|
for (int xx = 0; xx < TILE_WIDTH; xx++) {
|
||||||
for (int yy = 0; yy < TILE_HEIGHT; yy++) {
|
for (int yy = 0; yy < TILE_HEIGHT; yy++) {
|
||||||
@@ -71,9 +91,9 @@ public class Scene
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the scene exit points array.
|
* Return the scene exits array.
|
||||||
*/
|
*/
|
||||||
public ExitPoint[] getExits ()
|
public ExitPoint[] getExitPoints ()
|
||||||
{
|
{
|
||||||
return _exits;
|
return _exits;
|
||||||
}
|
}
|
||||||
@@ -97,44 +117,6 @@ public class Scene
|
|||||||
return numTiles;
|
return numTiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getNumLayers ()
|
|
||||||
{
|
|
||||||
return NUM_LAYERS;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getVersion ()
|
|
||||||
{
|
|
||||||
return VERSION;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getTileWidth ()
|
|
||||||
{
|
|
||||||
return TILE_WIDTH;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getTileHeight ()
|
|
||||||
{
|
|
||||||
return TILE_HEIGHT;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The latest scene file format version. */
|
|
||||||
protected static final short VERSION = 1;
|
|
||||||
|
|
||||||
/** The scene width in tiles. */
|
|
||||||
protected static final int TILE_WIDTH = 55;
|
|
||||||
|
|
||||||
/** The scene height in tiles. */
|
|
||||||
protected static final int TILE_HEIGHT = 55;
|
|
||||||
|
|
||||||
/** The base layer id. */
|
|
||||||
protected static final int LAYER_BASE = 0;
|
|
||||||
|
|
||||||
/** The object layer id. */
|
|
||||||
protected static final int LAYER_OBJECT = 1;
|
|
||||||
|
|
||||||
/** The total number of layers. */
|
|
||||||
protected static final int NUM_LAYERS = 2;
|
|
||||||
|
|
||||||
/** The default scene name. */
|
/** The default scene name. */
|
||||||
protected static final String DEF_SCENE_NAME = "Untitled Scene";
|
protected static final String DEF_SCENE_NAME = "Untitled Scene";
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: ExitPoint.java,v 1.3 2001/07/23 18:52:51 shaper Exp $
|
// $Id: ExitPoint.java,v 1.4 2001/07/24 19:15:51 shaper Exp $
|
||||||
|
|
||||||
package com.threerings.miso.scene;
|
package com.threerings.miso.scene;
|
||||||
|
|
||||||
@@ -14,4 +14,7 @@ public class ExitPoint
|
|||||||
|
|
||||||
/** The scene id this exit transitions to. */
|
/** The scene id this exit transitions to. */
|
||||||
public short sid;
|
public short sid;
|
||||||
|
|
||||||
|
/** The scene name this exit transitions to. */
|
||||||
|
public String name;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: XMLSceneRepository.java,v 1.1 2001/07/24 16:10:19 shaper Exp $
|
// $Id: XMLSceneRepository.java,v 1.2 2001/07/24 19:15:51 shaper Exp $
|
||||||
|
|
||||||
package com.threerings.miso.scene.xml;
|
package com.threerings.miso.scene.xml;
|
||||||
|
|
||||||
@@ -31,6 +31,8 @@ public class XMLFileSceneRepository extends SceneRepositoryImpl
|
|||||||
{
|
{
|
||||||
super.init(config, tilemgr);
|
super.init(config, tilemgr);
|
||||||
_root = _config.getValue(CONFIG_ROOT, DEF_ROOT);
|
_root = _config.getValue(CONFIG_ROOT, DEF_ROOT);
|
||||||
|
_parser = new XMLSceneParser();
|
||||||
|
_writer = new XMLSceneWriter();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,21 +1,28 @@
|
|||||||
//
|
//
|
||||||
// $Id: XMLSceneWriter.java,v 1.1 2001/07/24 16:10:19 shaper Exp $
|
// $Id: XMLSceneWriter.java,v 1.2 2001/07/24 19:15:51 shaper Exp $
|
||||||
|
|
||||||
package com.threerings.miso.scene.xml;
|
package com.threerings.miso.scene.xml;
|
||||||
|
|
||||||
|
import java.awt.Point;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import com.megginson.sax.DataWriter;
|
|
||||||
import org.xml.sax.*;
|
import org.xml.sax.*;
|
||||||
import org.xml.sax.helpers.AttributesImpl;
|
import org.xml.sax.helpers.AttributesImpl;
|
||||||
|
|
||||||
import com.samskivert.util.StringUtil;
|
import com.megginson.sax.DataWriter;
|
||||||
|
|
||||||
import com.threerings.miso.Log;
|
import com.threerings.miso.Log;
|
||||||
|
import com.threerings.miso.scene.ExitPoint;
|
||||||
import com.threerings.miso.scene.Scene;
|
import com.threerings.miso.scene.Scene;
|
||||||
|
import com.threerings.miso.tile.Tile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The XMLSceneWriter writes a Scene object to an XML file.
|
* The XMLSceneWriter writes a Scene object to an XML file.
|
||||||
|
*
|
||||||
|
* <p> The scene id is omitted as the scene id is assigned when the
|
||||||
|
* scene template is actually loaded into a server. Similarly, exit
|
||||||
|
* points are specified by scene name rather than scene id.
|
||||||
*/
|
*/
|
||||||
public class XMLSceneWriter extends DataWriter
|
public class XMLSceneWriter extends DataWriter
|
||||||
{
|
{
|
||||||
@@ -43,27 +50,13 @@ public class XMLSceneWriter extends DataWriter
|
|||||||
startElement("scene");
|
startElement("scene");
|
||||||
|
|
||||||
dataElement("name", scene.getName());
|
dataElement("name", scene.getName());
|
||||||
dataElement("sid", "" + scene.getId());
|
dataElement("version", "" + Scene.VERSION);
|
||||||
dataElement("version", "" + Scene.getVersion());
|
dataElement("hotspots", getHotSpotData(scene));
|
||||||
dataElement("hotspots",
|
dataElement("exits", getExitData(scene));
|
||||||
StringUtil.toString(scene.getHotSpots()));
|
|
||||||
dataElement("exits", StringUtil.toString(scene.getExits()));
|
|
||||||
|
|
||||||
startElement("tiles");
|
startElement("tiles");
|
||||||
for (int jj = 0; jj < Scene.getNumLayers(); jj++) {
|
for (int lnum = 0; lnum < Scene.NUM_LAYERS; lnum++) {
|
||||||
AttributesImpl attrs = new AttributesImpl();
|
writeLayer(scene, lnum);
|
||||||
attrs.addAttribute("", "lnum", "", "CDATA", "" + jj);
|
|
||||||
|
|
||||||
startElement("", "layer", "", attrs);
|
|
||||||
for (int yy = 0; yy < Scene.getTileHeight(); yy++) {
|
|
||||||
attrs.clear();
|
|
||||||
attrs.addAttribute("", "rownum", "", "CDATA", "" + yy);
|
|
||||||
|
|
||||||
startElement("", "row", "", attrs);
|
|
||||||
// TODO: write row data.
|
|
||||||
endElement("row");
|
|
||||||
}
|
|
||||||
endElement("layer");
|
|
||||||
}
|
}
|
||||||
endElement("tiles");
|
endElement("tiles");
|
||||||
|
|
||||||
@@ -76,4 +69,215 @@ public class XMLSceneWriter extends DataWriter
|
|||||||
", saxe=" + saxe + "].");
|
", saxe=" + saxe + "].");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Output XML detailing the tiles at the specified layer in the
|
||||||
|
* given scene. The first layer is outputted in its entirety,
|
||||||
|
* whereas subsequent layers are outputted in a sparse notation
|
||||||
|
* that details each contiguous horizontal chunk of tiles in each
|
||||||
|
* row separately.
|
||||||
|
*
|
||||||
|
* @param scene the scene object.
|
||||||
|
* @param lnum the layer number.
|
||||||
|
*/
|
||||||
|
protected void writeLayer (Scene scene, int lnum) throws SAXException
|
||||||
|
{
|
||||||
|
AttributesImpl attrs = new AttributesImpl();
|
||||||
|
attrs.addAttribute("", "lnum", "", "CDATA", "" + lnum);
|
||||||
|
|
||||||
|
startElement("", "layer", "", attrs);
|
||||||
|
for (int yy = 0; yy < Scene.TILE_HEIGHT; yy++) {
|
||||||
|
if (lnum == Scene.LAYER_BASE) {
|
||||||
|
writeTileRowData(scene, yy, lnum);
|
||||||
|
} else {
|
||||||
|
writeSparseTileRowData(scene, yy, lnum);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
endElement("layer");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a string representation of the exit points in the
|
||||||
|
* scene. Each exit point is specified by a comma-delimited
|
||||||
|
* triplet of (x, y, scene name) values.
|
||||||
|
*
|
||||||
|
* @param scene the scene object.
|
||||||
|
*
|
||||||
|
* @return the exit points in String format.
|
||||||
|
*/
|
||||||
|
protected String getExitData (Scene scene)
|
||||||
|
{
|
||||||
|
ExitPoint[] exits = scene.getExitPoints();
|
||||||
|
|
||||||
|
Object exitinfo[] = new Object[exits.length * 3];
|
||||||
|
StringBuffer buf = new StringBuffer();
|
||||||
|
for (int ii = 0; ii < exits.length; ii++) {
|
||||||
|
int idx = ii * 3;
|
||||||
|
buf.append(exits[ii].x).append(",");
|
||||||
|
buf.append(exits[ii].y).append(",");
|
||||||
|
buf.append(exits[ii].name);
|
||||||
|
if (ii < exits.length - 1) buf.append(",");
|
||||||
|
}
|
||||||
|
|
||||||
|
return buf.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a string representation of the hotspot points in the
|
||||||
|
* scene. Each hotspot point is specified by a comma-delimited
|
||||||
|
* tuple of (x, y) values.
|
||||||
|
*
|
||||||
|
* @return the hotspot points in String format.
|
||||||
|
*/
|
||||||
|
protected String getHotSpotData (Scene scene)
|
||||||
|
{
|
||||||
|
StringBuffer buf = new StringBuffer();
|
||||||
|
|
||||||
|
Point[] hotspots = scene.getHotSpots();
|
||||||
|
for (int ii = 0; ii < hotspots.length; ii++) {
|
||||||
|
buf.append(hotspots[ii].x).append(",");
|
||||||
|
buf.append(hotspots[ii].y);
|
||||||
|
if (ii < hotspots.length - 1) buf.append(",");
|
||||||
|
}
|
||||||
|
|
||||||
|
return buf.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a string representation of the tiles at the specified
|
||||||
|
* row and layer in the given scene. Only <code>len</code> tiles
|
||||||
|
* starting at column <code>colstart</code> are included in the
|
||||||
|
* string.
|
||||||
|
*
|
||||||
|
* @param scene the scene object.
|
||||||
|
* @param rownum the row number.
|
||||||
|
* @param lnum the layer number.
|
||||||
|
* @param colstart the first column of data.
|
||||||
|
* @param len the number of columns of data.
|
||||||
|
*
|
||||||
|
* @return the tile data in String format.
|
||||||
|
*/
|
||||||
|
protected String getTileData (Scene scene, int rownum, int lnum,
|
||||||
|
int colstart, int len)
|
||||||
|
{
|
||||||
|
StringBuffer buf = new StringBuffer();
|
||||||
|
|
||||||
|
int numtiles = colstart + len;
|
||||||
|
for (int ii = colstart; ii < numtiles; ii++) {
|
||||||
|
Tile tile = scene.tiles[ii][rownum][lnum];
|
||||||
|
if (tile == null) {
|
||||||
|
Log.warning("Null tile [x=" + ii + ", rownum=" + rownum +
|
||||||
|
", lnum=" + lnum + "].");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
buf.append(tile.tsid).append(",");
|
||||||
|
buf.append(tile.tid);
|
||||||
|
if (ii != numtiles - 1) buf.append(",");
|
||||||
|
}
|
||||||
|
|
||||||
|
return buf.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write the row data for a specified row in the scene tile array.
|
||||||
|
*
|
||||||
|
* <p> The row is written as a <code>row</code> element. Each
|
||||||
|
* tile is specified by a comma-delimited tuple of (tile set id,
|
||||||
|
* tile id) numbers, with the associated row number detailed in
|
||||||
|
* the <code>rownum</code> attribute of the <code>row</code>
|
||||||
|
* element.
|
||||||
|
*
|
||||||
|
* @param scene the scene object.
|
||||||
|
* @param rownum the row in the scene tile array.
|
||||||
|
* @param lnum the layer number in the scene tile array.
|
||||||
|
*/
|
||||||
|
protected void writeTileRowData (Scene scene, int rownum, int lnum)
|
||||||
|
throws SAXException
|
||||||
|
{
|
||||||
|
// set up the attributes for this row
|
||||||
|
AttributesImpl attrs = new AttributesImpl();
|
||||||
|
attrs.addAttribute("", "rownum", "", "CDATA", "" + rownum);
|
||||||
|
|
||||||
|
// output the full row data element
|
||||||
|
String data = getTileData(scene, rownum, lnum, 0, Scene.TILE_WIDTH);
|
||||||
|
dataElement("", "row", "", attrs, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility routine used by <code>writeSparseTileRowData</code> to
|
||||||
|
* obtain the sets of contiguous tile sets in each row.
|
||||||
|
*
|
||||||
|
* <p> The search for contiguous tiles starts at the column
|
||||||
|
* specified in <code>info[0]</code.
|
||||||
|
*
|
||||||
|
* <p> Results are returned in the <code>info</code> array as
|
||||||
|
* <code>{ colstart, len }</code>. colstart is -1 if no
|
||||||
|
* tiles were found in the rest of the row.
|
||||||
|
*
|
||||||
|
* @param scene the scene object.
|
||||||
|
* @param rownum the row number.
|
||||||
|
* @param lnum the layer number.
|
||||||
|
* @param info the info array.
|
||||||
|
*
|
||||||
|
* @return true if any tiles were found, false if not.
|
||||||
|
*/
|
||||||
|
protected boolean
|
||||||
|
getSparseColumn (Scene scene, int rownum, int lnum, int info[])
|
||||||
|
{
|
||||||
|
int start = -1, len = 0;
|
||||||
|
for (int xx = info[0]; xx < Scene.TILE_WIDTH; xx++) {
|
||||||
|
Tile tile = scene.tiles[xx][rownum][lnum];
|
||||||
|
if (tile == null) {
|
||||||
|
if (start == -1) continue;
|
||||||
|
else break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (start == -1) start = xx;
|
||||||
|
len++;
|
||||||
|
}
|
||||||
|
|
||||||
|
info[0] = start;
|
||||||
|
info[1] = len;
|
||||||
|
|
||||||
|
return (start != -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write the row data for a specified row in the scene tile array
|
||||||
|
* in sparse row format.
|
||||||
|
*
|
||||||
|
* <p> Sparse row format is identical to the format detailed in
|
||||||
|
* <code>writeTileRowData()</code> except that a separate
|
||||||
|
* <code>row</code> element is outputted for each contiguous set
|
||||||
|
* of tiles, with the starting column detailed in the
|
||||||
|
* <code>colstart</code> attribute of the <code>row</code>
|
||||||
|
* element.
|
||||||
|
*
|
||||||
|
* @param scene the scene object.
|
||||||
|
* @param rownum the row in the scene tile array.
|
||||||
|
* @param lnum the layer number in the scene tile array.
|
||||||
|
*/
|
||||||
|
protected void
|
||||||
|
writeSparseTileRowData (Scene scene, int rownum, int lnum)
|
||||||
|
throws SAXException
|
||||||
|
{
|
||||||
|
// set up the attributes for this row
|
||||||
|
AttributesImpl attrs = new AttributesImpl();
|
||||||
|
attrs.addAttribute("", "rownum", "", "CDATA", "" + rownum);
|
||||||
|
attrs.addAttribute("", "colstart", "", "CDATA", "0");
|
||||||
|
|
||||||
|
int info[] = new int[] { 0, 0 };
|
||||||
|
while (getSparseColumn(scene, rownum, lnum, info)) {
|
||||||
|
// update the colstart attribute
|
||||||
|
attrs.setAttribute(1, "", "colstart", "", "CDATA", "" + info[0]);
|
||||||
|
|
||||||
|
// output the partial row data element
|
||||||
|
String data = getTileData(scene, rownum, lnum, info[0], info[1]);
|
||||||
|
dataElement("", "row", "", attrs, data);
|
||||||
|
|
||||||
|
// update the colstart value
|
||||||
|
info[0] = info[0] + info[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user