Changed Scene to MisoScene. Made MisoScene implement Whirled's Scene

interface.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@249 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2001-08-15 01:08:49 +00:00
parent 1ffbae2cc4
commit a07f5d4d13
9 changed files with 98 additions and 76 deletions
@@ -1,5 +1,5 @@
//
// $Id: XMLSceneParser.java,v 1.10 2001/08/13 15:00:24 shaper Exp $
// $Id: XMLSceneParser.java,v 1.11 2001/08/15 01:08:49 mdb Exp $
package com.threerings.miso.scene.xml;
@@ -58,12 +58,12 @@ public class XMLSceneParser extends DefaultHandler
} else if (qName.equals("version")) {
int version = getInt(_chars.toString());
if (version < 0 || version > Scene.VERSION) {
if (version < 0 || version > MisoScene.VERSION) {
Log.warning(
"Unrecognized scene file format version, will attempt " +
"to continue parsing file but your mileage may vary " +
"[fname=" + _fname + ", version=" + version +
", known_version=" + Scene.VERSION + "].");
", known_version=" + MisoScene.VERSION + "].");
}
} else if (qName.equals("locations")) {
@@ -79,7 +79,7 @@ public class XMLSceneParser extends DefaultHandler
_scExits = toExitList(_scLocations, vals);
} else if (qName.equals("row")) {
if (_scLnum == Scene.LAYER_BASE) {
if (_scLnum == MisoScene.LAYER_BASE) {
readRowData(_chars.toString());
} else {
readSparseRowData(_chars.toString());
@@ -87,7 +87,7 @@ public class XMLSceneParser extends DefaultHandler
} else if (qName.equals("scene")) {
// construct the scene object on tag close
_scene = new Scene(
_scene = new MisoScene(
_tilemgr, _scName, _scLocations, _scClusters,
_scExits, _scTiles);
@@ -122,7 +122,7 @@ public class XMLSceneParser extends DefaultHandler
int[] vals = StringUtil.parseIntArray(data);
// make sure we have a suitable number of tiles
int validLen = Scene.TILE_WIDTH * 2;
int validLen = MisoScene.TILE_WIDTH * 2;
if (vals.length != validLen) {
Log.warning(
"Invalid number of tiles in full row data set, skipping set " +
@@ -270,22 +270,22 @@ public class XMLSceneParser extends DefaultHandler
{
_chars = new StringBuffer();
_scene = null;
int width = Scene.TILE_WIDTH, height = Scene.TILE_HEIGHT;
_scTiles = new Tile[width][height][Scene.NUM_LAYERS];
int width = MisoScene.TILE_WIDTH, height = MisoScene.TILE_HEIGHT;
_scTiles = new Tile[width][height][MisoScene.NUM_LAYERS];
_scLocations = null;
_scExits = null;
_scClusters = new ArrayList();
}
/**
* Parse the specified XML file and return a Scene object with the
* data contained therein.
* Parse the specified XML file and return a miso scene object with
* the data contained therein.
*
* @param fname the file name.
*
* @return the scene object, or null if an error occurred.
*/
public Scene loadScene (String fname) throws IOException
public MisoScene loadScene (String fname) throws IOException
{
_fname = fname;
@@ -318,7 +318,7 @@ public class XMLSceneParser extends DefaultHandler
protected String _tag;
/** The scene object constructed as each scene file is read. */
protected Scene _scene;
protected MisoScene _scene;
/** The tile manager object for use in constructing scenes. */
protected TileManager _tilemgr;
@@ -1,5 +1,5 @@
//
// $Id: XMLSceneRepository.java,v 1.6 2001/08/15 00:10:58 mdb Exp $
// $Id: XMLSceneRepository.java,v 1.7 2001/08/15 01:08:49 mdb Exp $
package com.threerings.miso.scene.xml;
@@ -8,7 +8,7 @@ import java.util.ArrayList;
import com.samskivert.util.Config;
import com.threerings.miso.Log;
import com.threerings.miso.scene.Scene;
import com.threerings.miso.scene.MisoScene;
import com.threerings.miso.tile.TileManager;
/**
@@ -51,14 +51,14 @@ public class XMLFileSceneRepository
}
/**
* Loads and returns a Scene object for the scene described in the
* specified XML file. The filename should be relative to the
* Loads and returns a miso scene object for the scene described in
* the specified XML file. The filename should be relative to the
* scene root directory.
*
* @param fname the full pathname to the file.
* @return the Scene object.
* @return the scene object.
*/
public Scene loadScene (String fname) throws IOException
public MisoScene loadScene (String fname) throws IOException
{
String path = getScenePath() + fname;
Log.info("Loading scene [path=" + path + "].");
@@ -74,7 +74,7 @@ public class XMLFileSceneRepository
* @param scene the scene to save.
* @param fname the file to write the scene to.
*/
public void saveScene (Scene scene, String fname) throws IOException
public void saveScene (MisoScene scene, String fname) throws IOException
{
String path = getScenePath() + fname;
Log.info("Saving scene [path=" + path + "].");
@@ -1,5 +1,5 @@
//
// $Id: XMLSceneWriter.java,v 1.8 2001/08/11 00:01:40 shaper Exp $
// $Id: XMLSceneWriter.java,v 1.9 2001/08/15 01:08:49 mdb Exp $
package com.threerings.miso.scene.xml;
@@ -17,8 +17,8 @@ import com.threerings.miso.scene.*;
import com.threerings.miso.tile.Tile;
/**
* The <code>XMLSceneWriter</code> writes a <code>Scene</code> object
* to an XML file.
* The <code>XMLSceneWriter</code> writes a {@link
* com.threerings.miso.scene.MisoScene} 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
@@ -39,7 +39,7 @@ public class XMLSceneWriter extends DataWriter
*
* @param fname the file to write to.
*/
public void saveScene (Scene scene, String fname) throws IOException
public void saveScene (MisoScene scene, String fname) throws IOException
{
FileOutputStream fos = new FileOutputStream(fname);
setOutput(new OutputStreamWriter(fos));
@@ -50,7 +50,7 @@ public class XMLSceneWriter extends DataWriter
startElement("scene");
dataElement("name", scene.getName());
dataElement("version", "" + Scene.VERSION);
dataElement("version", "" + MisoScene.VERSION);
dataElement("locations", getLocationData(scene));
startElement("clusters");
@@ -60,7 +60,7 @@ public class XMLSceneWriter extends DataWriter
dataElement("exits", getExitData(scene));
startElement("tiles");
for (int lnum = 0; lnum < Scene.NUM_LAYERS; lnum++) {
for (int lnum = 0; lnum < MisoScene.NUM_LAYERS; lnum++) {
writeLayer(scene, lnum);
}
endElement("tiles");
@@ -82,7 +82,7 @@ public class XMLSceneWriter extends DataWriter
*
* @param scene the scene object.
*/
protected void writeClusters (Scene scene) throws SAXException
protected void writeClusters (MisoScene scene) throws SAXException
{
ArrayList clusters = scene.getClusters();
ArrayList locs = scene.getLocations();
@@ -115,14 +115,14 @@ public class XMLSceneWriter extends DataWriter
* @param scene the scene object.
* @param lnum the layer number.
*/
protected void writeLayer (Scene scene, int lnum) throws SAXException
protected void writeLayer (MisoScene 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) {
for (int yy = 0; yy < MisoScene.TILE_HEIGHT; yy++) {
if (lnum == MisoScene.LAYER_BASE) {
writeTileRowData(scene, yy, lnum);
} else {
writeSparseTileRowData(scene, yy, lnum);
@@ -140,7 +140,7 @@ public class XMLSceneWriter extends DataWriter
*
* @return the exits in String format.
*/
protected String getExitData (Scene scene)
protected String getExitData (MisoScene scene)
{
ArrayList locs = scene.getLocations();
ArrayList exits = scene.getExits();
@@ -164,7 +164,7 @@ public class XMLSceneWriter extends DataWriter
*
* @return the locations in String format.
*/
protected String getLocationData (Scene scene)
protected String getLocationData (MisoScene scene)
{
ArrayList locs = scene.getLocations();
@@ -195,7 +195,7 @@ public class XMLSceneWriter extends DataWriter
*
* @return the tile data in String format.
*/
protected String getTileData (Scene scene, int rownum, int lnum,
protected String getTileData (MisoScene scene, int rownum, int lnum,
int colstart, int len)
{
StringBuffer buf = new StringBuffer();
@@ -230,7 +230,7 @@ public class XMLSceneWriter extends DataWriter
* @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)
protected void writeTileRowData (MisoScene scene, int rownum, int lnum)
throws SAXException
{
// set up the attributes for this row
@@ -238,7 +238,8 @@ public class XMLSceneWriter extends DataWriter
attrs.addAttribute("", "rownum", "", "CDATA", "" + rownum);
// output the full row data element
String data = getTileData(scene, rownum, lnum, 0, Scene.TILE_WIDTH);
String data = getTileData(scene, rownum, lnum, 0,
MisoScene.TILE_WIDTH);
dataElement("", "row", "", attrs, data);
}
@@ -260,11 +261,11 @@ public class XMLSceneWriter extends DataWriter
*
* @return true if any tiles were found, false if not.
*/
protected boolean
getSparseColumn (Scene scene, int rownum, int lnum, int info[])
protected boolean getSparseColumn (
MisoScene scene, int rownum, int lnum, int info[])
{
int start = -1, len = 0;
for (int xx = info[0]; xx < Scene.TILE_WIDTH; xx++) {
for (int xx = info[0]; xx < MisoScene.TILE_WIDTH; xx++) {
Tile tile = scene.tiles[xx][rownum][lnum];
if (tile == null) {
if (start == -1) continue;
@@ -297,7 +298,7 @@ public class XMLSceneWriter extends DataWriter
* @param lnum the layer number in the scene tile array.
*/
protected void
writeSparseTileRowData (Scene scene, int rownum, int lnum)
writeSparseTileRowData (MisoScene scene, int rownum, int lnum)
throws SAXException
{
// set up the attributes for this row