Initial work on reading and writing scenes to XML files.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@113 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: DisplayMisoSceneImpl.java,v 1.9 2001/07/23 18:52:51 shaper Exp $
|
||||
// $Id: DisplayMisoSceneImpl.java,v 1.10 2001/07/23 22:31:47 shaper Exp $
|
||||
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
@@ -16,24 +16,25 @@ import java.io.*;
|
||||
*/
|
||||
public class Scene
|
||||
{
|
||||
/** String translations of each tile layer name. */
|
||||
public static final String[] XLATE_LAYERS = { "Base", "Object" };
|
||||
|
||||
public Tile tiles[][][]; // the tiles comprising the scene
|
||||
/** The tiles comprising the scene. */
|
||||
public Tile tiles[][][];
|
||||
|
||||
/**
|
||||
* Construct a new Scene object initialized to a default state.
|
||||
* Construct a new Scene object initialized to a default state,
|
||||
* specifying the tile manager from which the scene obtains tiles.
|
||||
*
|
||||
* @param tilemgr the tile manager.
|
||||
*/
|
||||
public Scene (TileManager tmgr)
|
||||
public Scene (TileManager tilemgr, int sid)
|
||||
{
|
||||
_tmgr = tmgr;
|
||||
|
||||
_tilemgr = tilemgr;
|
||||
_name = DEF_SCENE_NAME;
|
||||
_sid = 0;
|
||||
_version = VERSION;
|
||||
|
||||
tiles = new Tile[TILE_WIDTH][TILE_HEIGHT][NUM_LAYERS];
|
||||
|
||||
Tile tile = _tmgr.getTile(DEF_TSID, DEF_TID);
|
||||
Tile tile = _tilemgr.getTile(DEF_TSID, DEF_TID);
|
||||
for (int xx = 0; xx < TILE_WIDTH; xx++) {
|
||||
for (int yy = 0; yy < TILE_HEIGHT; yy++) {
|
||||
for (int ii = 0; ii < NUM_LAYERS; ii++) {
|
||||
@@ -44,7 +45,39 @@ public class Scene
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the scene name.
|
||||
*/
|
||||
public String getName ()
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the scene identifier.
|
||||
*/
|
||||
public short getId ()
|
||||
{
|
||||
return _sid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the scene hot spots array.
|
||||
*/
|
||||
public Point[] getHotSpots ()
|
||||
{
|
||||
return _hotspots;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the scene exit points array.
|
||||
*/
|
||||
public ExitPoint[] getExits ()
|
||||
{
|
||||
return _exits;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of actual (non-null) tiles present in the
|
||||
* specified tile layer for this scene.
|
||||
@@ -75,12 +108,12 @@ public class Scene
|
||||
// read scene header information
|
||||
_name = dis.readUTF();
|
||||
_sid = dis.readShort();
|
||||
_version = dis.readShort();
|
||||
short version = dis.readShort();
|
||||
|
||||
// make sure we can understand the file format
|
||||
if (_version < 0 || _version > VERSION) {
|
||||
if (version < 0 || version > VERSION) {
|
||||
throw new IOException("Can't understand scene file format " +
|
||||
" [version=" + _version + "]");
|
||||
" [version=" + version + "]");
|
||||
}
|
||||
|
||||
// allocate full tile array. null tiles denote tiles in absentia.
|
||||
@@ -94,7 +127,7 @@ public class Scene
|
||||
short tid = dis.readShort();
|
||||
|
||||
// retrieve tile from tile manager
|
||||
tiles[xx][yy][LAYER_BASE] = _tmgr.getTile(tsid, tid);
|
||||
tiles[xx][yy][LAYER_BASE] = _tilemgr.getTile(tsid, tid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,7 +144,7 @@ public class Scene
|
||||
byte ty = dis.readByte();
|
||||
|
||||
// retrieve tile from tile manager
|
||||
tiles[tx][ty][lnum] = _tmgr.getTile(tsid, tid);
|
||||
tiles[tx][ty][lnum] = _tilemgr.getTile(tsid, tid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,7 +178,7 @@ public class Scene
|
||||
// write scene header information
|
||||
dos.writeUTF(_name);
|
||||
dos.writeShort(_sid);
|
||||
dos.writeShort(_version);
|
||||
dos.writeShort(VERSION);
|
||||
|
||||
// write tiles for the base layer
|
||||
for (int xx = 0; xx < TILE_WIDTH; xx++) {
|
||||
@@ -190,28 +223,45 @@ public class Scene
|
||||
}
|
||||
}
|
||||
|
||||
// the latest scene file format version number
|
||||
/** The latest scene file format version. */
|
||||
protected static final short VERSION = 1;
|
||||
|
||||
// scene width/height in tiles
|
||||
/** The scene width in tiles. */
|
||||
protected static final int TILE_WIDTH = 55;
|
||||
|
||||
/** The scene height in tiles. */
|
||||
protected static final int TILE_HEIGHT = 55;
|
||||
|
||||
// layer identifiers and total number of layers
|
||||
/** 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. */
|
||||
protected static final String DEF_SCENE_NAME = "Untitled Scene";
|
||||
|
||||
/** The default tileset id. */
|
||||
protected static final short DEF_TSID = 1000;
|
||||
|
||||
/** The default tile id. */
|
||||
protected static final short DEF_TID = 1;
|
||||
|
||||
protected String _name; // the scene name
|
||||
protected short _sid; // the unique scene id
|
||||
protected short _version; // file format version
|
||||
protected Point _hotspots[]; // hot spot zone points
|
||||
protected ExitPoint _exits[]; // exit points to different scenes
|
||||
/** The scene name. */
|
||||
protected String _name;
|
||||
|
||||
protected TileManager _tmgr;
|
||||
/** The unique scene id. */
|
||||
protected short _sid;
|
||||
|
||||
/** Hot-spot zone points */
|
||||
protected Point _hotspots[];
|
||||
|
||||
/** Exit points to different scenes. */
|
||||
protected ExitPoint _exits[];
|
||||
|
||||
/** The tile manager. */
|
||||
protected TileManager _tilemgr;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,68 @@
|
||||
//
|
||||
// $Id: EditableSceneManager.java,v 1.5 2001/07/23 18:52:51 shaper Exp $
|
||||
// $Id: EditableSceneManager.java,v 1.6 2001/07/23 22:31:47 shaper Exp $
|
||||
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.threerings.miso.Log;
|
||||
|
||||
/**
|
||||
* The EditableSceneManager extends general scene manager
|
||||
* functionality to allow reading scenes from and writing scenes to
|
||||
* XML files.
|
||||
*/
|
||||
public class EditableSceneManager extends SceneManagerImpl
|
||||
{
|
||||
/**
|
||||
* Load all scenes described in the specified XML file into the
|
||||
* hashtable of scenes currently available.
|
||||
*
|
||||
* @param fname the file to load scenes from.
|
||||
*/
|
||||
public void loadScenes (String fname) throws IOException
|
||||
{
|
||||
ArrayList scenes = null;
|
||||
_sid = 0;
|
||||
try {
|
||||
scenes = new XMLSceneParser().loadScenes(fname);
|
||||
} catch (IOException ioe) {
|
||||
Log.warning("Exception loading scenes [fname=" + fname +
|
||||
", ioe=" + ioe + "].");
|
||||
return;
|
||||
}
|
||||
|
||||
// bail if we didn't find any scenes
|
||||
int size = scenes.size();
|
||||
if (size == 0) {
|
||||
Log.warning("No scenes found [fname=" + fname + "].");
|
||||
return;
|
||||
}
|
||||
|
||||
// copy new scenes into the main scene hashtable
|
||||
for (int ii = 0; ii < size; ii++) {
|
||||
Scene scene = (Scene)scenes.get(ii);
|
||||
_scenes.put(scene.getId(), scene);
|
||||
Log.info("Adding scene to cache [scene=" + scene + "].");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write all scenes currently available to the specified file in
|
||||
* XML format.
|
||||
*
|
||||
* @param fname the file to write the scenes to.
|
||||
*/
|
||||
public void writeAllScenes (String fname)
|
||||
{
|
||||
try {
|
||||
ArrayList scenes = getAllScenes();
|
||||
new XMLSceneWriter(scenes).writeToFile(fname);
|
||||
|
||||
} catch (IOException ioe) {
|
||||
Log.warning("Exception writing scenes to file [fname=" +
|
||||
fname + ", ioe=" + ioe + "].");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
//
|
||||
// $Id: SceneManager.java,v 1.5 2001/07/23 18:52:51 shaper Exp $
|
||||
// $Id: SceneManager.java,v 1.6 2001/07/23 22:31:47 shaper Exp $
|
||||
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Manages the various scenes that are displayed during the game and
|
||||
@@ -12,6 +13,20 @@ import java.io.InputStream;
|
||||
*/
|
||||
public interface SceneManager
|
||||
{
|
||||
/**
|
||||
* Return an ArrayList containing all Scene objects available.
|
||||
*
|
||||
* @return the list of scenes.
|
||||
*/
|
||||
public ArrayList getAllScenes ();
|
||||
|
||||
/**
|
||||
* Return a new Scene object with the next unique scene id. The
|
||||
* scene id is only guaranteed to be unique in the context of the
|
||||
* scenes currently available via this SceneManager.
|
||||
*/
|
||||
public Scene getNewScene ();
|
||||
|
||||
/**
|
||||
* Return the Scene object for the specified scene id.
|
||||
*/
|
||||
|
||||
@@ -1,17 +1,23 @@
|
||||
//
|
||||
// $Id: SceneManagerImpl.java,v 1.5 2001/07/23 18:52:51 shaper Exp $
|
||||
// $Id: SceneManagerImpl.java,v 1.6 2001/07/23 22:31:47 shaper Exp $
|
||||
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
import com.threerings.miso.Log;
|
||||
|
||||
import com.samskivert.util.ConfigUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.samskivert.util.*;
|
||||
import com.threerings.miso.Log;
|
||||
import com.threerings.miso.tile.TileManager;
|
||||
|
||||
public abstract class SceneManagerImpl implements SceneManager
|
||||
{
|
||||
public void init (TileManager tilemgr)
|
||||
{
|
||||
_tilemgr = tilemgr;
|
||||
}
|
||||
|
||||
public Scene getScene (int sid)
|
||||
{
|
||||
// TBD
|
||||
@@ -22,4 +28,27 @@ public abstract class SceneManagerImpl implements SceneManager
|
||||
{
|
||||
return Scene.XLATE_LAYERS;
|
||||
}
|
||||
|
||||
public ArrayList getAllScenes ()
|
||||
{
|
||||
ArrayList list = new ArrayList();
|
||||
CollectionUtil.addAll(list, _scenes.elements());
|
||||
return list;
|
||||
}
|
||||
|
||||
public Scene getNewScene ()
|
||||
{
|
||||
Scene scene = new Scene(_tilemgr, _sid);
|
||||
_scenes.put(_sid++, scene);
|
||||
return scene;
|
||||
}
|
||||
|
||||
/** The next monotonically-increasing scene id. */
|
||||
protected int _sid = 0;
|
||||
|
||||
/** The tile manager for use by all scenes. */
|
||||
protected TileManager _tilemgr;
|
||||
|
||||
/** The scenes currently available. */
|
||||
protected IntMap _scenes = new IntMap();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user