Serious scene surgery.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@344 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2001-09-21 02:30:35 +00:00
parent fda93f4445
commit 2fb833fd5b
14 changed files with 386 additions and 338 deletions
@@ -0,0 +1,52 @@
//
// $Id: EditableMisoScene.java,v 1.1 2001/09/21 02:30:35 mdb Exp $
package com.threerings.miso.scene;
import com.threerings.whirled.data.EditableScene;
/**
* The editable Miso scene interface provides the means for modifying a
* Miso scene which is needed by things like the scene editor. This is
* separated from the read-only interface to avoid implying to users of
* the Miso scene interface that editing scenes is a safe thing to do. In
* fact it should only be done under special circumstances.
*/
public interface EditableMisoScene
extends EditableScene, MisoScene
{
/**
* Set the default entrance portal for this scene.
*
* @param entrance the entrance portal.
*/
public void setEntrance (Portal entrance);
/**
* Update the specified location in the scene. If the cluster
* index number is -1, the location will be removed from any
* cluster it may reside in.
*
* @param loc the location.
* @param clusteridx the cluster index number.
*/
public void updateLocation (Location loc, int clusteridx);
/**
* Add the specified portal to the scene. Adds the portal to the
* location list as well if it's not already present and removes
* it from any cluster it may reside in.
*
* @param portal the portal.
*/
public void addPortal (Portal portal);
/**
* Remove the given location object from the location list, and
* from any containing cluster. If the location is a portal, it
* is removed from the portal list as well.
*
* @param loc the location object.
*/
public void removeLocation (Location loc);
}
@@ -1,5 +1,5 @@
//
// $Id: XMLSceneGroupParser.java,v 1.3 2001/08/21 01:15:16 shaper Exp $
// $Id: XMLSceneGroupParser.java,v 1.4 2001/09/21 02:30:35 mdb Exp $
package com.threerings.miso.scene.xml;
@@ -14,6 +14,7 @@ import com.samskivert.util.*;
import com.samskivert.xml.XMLUtil;
import com.threerings.miso.Log;
import com.threerings.miso.scene.*;
import com.threerings.miso.scene.util.MisoSceneUtil;
import com.threerings.whirled.data.Scene;
/**
@@ -228,7 +229,7 @@ public class XMLSceneGroupParser extends DefaultHandler
protected void resolvePortal (SceneInfo sinfo, PortalInfo pinfo)
{
// get the source portal object
Portal src = sinfo.scene.getPortal(pinfo.src);
Portal src = MisoSceneUtil.getPortal(sinfo.scene, pinfo.src);
if (src == null) {
Log.warning("Missing source portal [scene=" + sinfo.name +
", pinfo=" + pinfo + "].");
@@ -244,7 +245,7 @@ public class XMLSceneGroupParser extends DefaultHandler
}
// get the destination portal object
Portal dest = destScene.getPortal(pinfo.dest);
Portal dest = MisoSceneUtil.getPortal(destScene, pinfo.dest);
if (dest == null) {
Log.warning("Missing destination portal [scene=" + sinfo.name +
", pinfo=" + pinfo + "].");
@@ -262,7 +263,8 @@ public class XMLSceneGroupParser extends DefaultHandler
*/
protected void resolveEntrance (SceneInfo sinfo)
{
Portal entrance = sinfo.scene.getPortal(sinfo.entrance);
Portal entrance = MisoSceneUtil.getPortal(
sinfo.scene, sinfo.entrance);
if (entrance == null) {
Log.warning( "Missing entrance portal [scene=" + sinfo.name +
", entrance=" + sinfo.entrance + "].");
@@ -289,12 +291,12 @@ public class XMLSceneGroupParser extends DefaultHandler
SceneInfo sinfo = (SceneInfo)sceneinfo.get(ii);
// get the portals in the scene
List portals = sinfo.scene.getPortals();
Portal[] portals = sinfo.scene.getPortals();
// check each portal to make sure it has a valid destination
int psize = portals.size();
int psize = portals.length;
for (int jj = 0; jj < size; jj++) {
Portal portal = (Portal)portals.get(jj);
Portal portal = portals[jj];
if (!portal.hasDestination()) {
Log.warning("Unbound portal [scene=" + sinfo.name +
", portal=" + portal + "].");
@@ -322,7 +324,7 @@ public class XMLSceneGroupParser extends DefaultHandler
public ArrayList portals;
/** The scene object obtained from the scene repository. */
public MisoScene scene;
public MisoSceneImpl scene;
public SceneInfo (String src)
{
@@ -1,5 +1,5 @@
//
// $Id: XMLSceneParser.java,v 1.15 2001/08/29 19:50:46 shaper Exp $
// $Id: XMLSceneParser.java,v 1.16 2001/09/21 02:30:35 mdb Exp $
package com.threerings.miso.scene.xml;
@@ -60,12 +60,12 @@ public class XMLSceneParser extends DefaultHandler
} else if (qName.equals("version")) {
int version = getInt(_chars.toString());
if (version < 0 || version > MisoScene.VERSION) {
if (version < 0 || version > XMLSceneVersion.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=" + MisoScene.VERSION + "].");
", known_version=" + XMLSceneVersion.VERSION + "].");
}
} else if (qName.equals("locations")) {
@@ -280,7 +280,7 @@ public class XMLSceneParser extends DefaultHandler
*
* @return the scene object, or null if an error occurred.
*/
public MisoScene loadScene (String fname) throws IOException
public EditableMisoScene loadScene (String fname) throws IOException
{
_fname = fname;
@@ -354,7 +354,7 @@ public class XMLSceneParser extends DefaultHandler
public int colstart;
/** The scene object constructed once all scene info is parsed. */
public MisoScene scene;
public EditableMisoScene scene;
public SceneInfo ()
{
@@ -365,7 +365,7 @@ public class XMLSceneParser extends DefaultHandler
public void constructScene (TileManager tilemgr)
{
scene = new MisoScene(
scene = new MisoSceneImpl(
_model, tilemgr, name, locations, clusters, portals, tiles);
}
}
@@ -1,5 +1,5 @@
//
// $Id: XMLSceneRepository.java,v 1.11 2001/08/29 19:50:46 shaper Exp $
// $Id: XMLSceneRepository.java,v 1.12 2001/09/21 02:30:35 mdb Exp $
package com.threerings.miso.scene.xml;
@@ -12,6 +12,7 @@ import com.threerings.media.tile.TileManager;
import com.threerings.miso.Log;
import com.threerings.miso.scene.IsoSceneViewModel;
import com.threerings.miso.scene.MisoScene;
import com.threerings.miso.scene.EditableMisoScene;
import com.threerings.miso.util.MisoUtil;
/**
@@ -63,7 +64,7 @@ public class XMLFileSceneRepository
* @param fname the full pathname to the file.
* @return the scene object.
*/
public MisoScene loadScene (String fname) throws IOException
public EditableMisoScene loadScene (String fname) throws IOException
{
String path = getScenePath() + fname;
Log.info("Loading scene [path=" + path + "].");
@@ -0,0 +1,15 @@
//
// $Id: XMLSceneVersion.java,v 1.1 2001/09/21 02:30:35 mdb Exp $
package com.threerings.miso.scene.xml;
/**
* This class tracks the version number of the XML scene file format. When
* modifications are made to the file format, the version number in this
* class should be increased.
*/
public class XMLSceneVersion
{
/** The latest scene file format version. */
public static int VERSION = 1;
}
@@ -1,5 +1,5 @@
//
// $Id: XMLSceneWriter.java,v 1.12 2001/08/29 19:50:46 shaper Exp $
// $Id: XMLSceneWriter.java,v 1.13 2001/09/21 02:30:35 mdb Exp $
package com.threerings.miso.scene.xml;
@@ -7,9 +7,10 @@ import java.awt.Point;
import java.io.*;
import java.util.ArrayList;
import com.samskivert.util.ListUtil;
import org.xml.sax.*;
import org.xml.sax.helpers.AttributesImpl;
import com.megginson.sax.DataWriter;
import com.threerings.media.tile.Tile;
@@ -52,7 +53,7 @@ public class XMLSceneWriter extends DataWriter
startElement("scene");
dataElement("name", scene.getName());
dataElement("version", "" + MisoScene.VERSION);
dataElement("version", "" + XMLSceneVersion.VERSION);
dataElement("locations", getLocationData(scene));
startElement("clusters");
@@ -86,21 +87,22 @@ public class XMLSceneWriter extends DataWriter
*/
protected void writeClusters (MisoScene scene) throws SAXException
{
ArrayList clusters = scene.getClusters();
ArrayList locs = scene.getLocations();
Cluster[] clusters = scene.getClusters();
Location[] locs = scene.getLocations();
int size = clusters.size();
int size = clusters.length;
for (int ii = 0; ii < size; ii++) {
StringBuffer buf = new StringBuffer();
Cluster cluster = (Cluster)clusters.get(ii);
Cluster cluster = clusters[ii];
ArrayList clusterlocs = cluster.getLocations();
StringBuffer buf = new StringBuffer();
int clustersize = clusterlocs.size();
for (int jj = 0; jj < clustersize; jj++) {
buf.append(locs.indexOf(clusterlocs.get(jj)));
if (jj < clustersize - 1) buf.append(",");
Location cloc = (Location)clusterlocs.get(jj);
buf.append(ListUtil.indexOfEqual(locs, cloc));
if (jj < clustersize - 1) {
buf.append(",");
}
}
dataElement("cluster", buf.toString());
@@ -144,16 +146,18 @@ public class XMLSceneWriter extends DataWriter
*/
protected String getPortalData (MisoScene scene)
{
ArrayList locs = scene.getLocations();
ArrayList portals = scene.getPortals();
Location[] locs = scene.getLocations();
Portal[] portals = scene.getPortals();
StringBuffer buf = new StringBuffer();
int size = portals.size();
int size = portals.length;
for (int ii = 0; ii < size; ii++) {
Portal portal = (Portal)portals.get(ii);
buf.append(locs.indexOf(portal)).append(",");
Portal portal = portals[ii];
buf.append(ListUtil.indexOfEqual(locs, portal)).append(",");
buf.append(portal.name);
if (ii < size - 1) buf.append(",");
if (ii < size - 1) {
buf.append(",");
}
}
return buf.toString();
@@ -168,16 +172,18 @@ public class XMLSceneWriter extends DataWriter
*/
protected String getLocationData (MisoScene scene)
{
ArrayList locs = scene.getLocations();
Location[] locs = scene.getLocations();
StringBuffer buf = new StringBuffer();
int size = locs.size();
int size = locs.length;
for (int ii = 0; ii < size; ii++) {
Location loc = (Location)locs.get(ii);
Location loc = locs[ii];
buf.append(loc.x).append(",");
buf.append(loc.y).append(",");
buf.append(loc.orient);
if (ii < size - 1) buf.append(",");
if (ii < size - 1) {
buf.append(",");
}
}
return buf.toString();
@@ -201,10 +207,11 @@ public class XMLSceneWriter extends DataWriter
int colstart, int len)
{
StringBuffer buf = new StringBuffer();
Tile[][][] tiles = scene.getTiles();
int numtiles = colstart + len;
for (int ii = colstart; ii < numtiles; ii++) {
Tile tile = scene.tiles[ii][rownum][lnum];
Tile tile = tiles[ii][rownum][lnum];
if (tile == null) {
Log.warning("Null tile [x=" + ii + ", rownum=" + rownum +
", lnum=" + lnum + "].");
@@ -213,7 +220,9 @@ public class XMLSceneWriter extends DataWriter
buf.append(tile.tsid).append(",");
buf.append(tile.tid);
if (ii != numtiles - 1) buf.append(",");
if (ii != numtiles - 1) {
buf.append(",");
}
}
return buf.toString();
@@ -265,15 +274,21 @@ public class XMLSceneWriter extends DataWriter
protected boolean getSparseColumn (
MisoScene scene, int rownum, int lnum, int info[])
{
Tile[][][] tiles = scene.getTiles();
int start = -1, len = 0;
for (int xx = info[0]; xx < _model.scenewid; xx++) {
Tile tile = scene.tiles[xx][rownum][lnum];
Tile tile = tiles[xx][rownum][lnum];
if (tile == null) {
if (start == -1) continue;
else break;
if (start == -1) {
continue;
} else {
break;
}
}
if (start == -1) start = xx;
if (start == -1) {
start = xx;
}
len++;
}