General updating per initial code review. Created EditableSceneView

to separate scene display from editing functionality.  Load and
initialize managers in a fashion that more appropriately hides the
implementation details.  Tidied comments up a bit.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@103 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Walter Korman
2001-07-23 18:52:51 +00:00
parent 00388caaa5
commit 2572535f95
19 changed files with 210 additions and 252 deletions
@@ -1,15 +1,8 @@
//
// $Id: CompiledSceneManager.java,v 1.4 2001/07/20 08:08:59 shaper Exp $
// $Id: CompiledSceneManager.java,v 1.5 2001/07/23 18:52:51 shaper Exp $
package com.threerings.miso.scene;
import java.io.InputStream;
import java.io.IOException;
public class CompiledSceneManager extends SceneManagerImpl
{
public void loadScenes (InputStream in) throws IOException
{
}
}
@@ -1,5 +1,5 @@
//
// $Id: DisplayMisoSceneImpl.java,v 1.8 2001/07/20 07:09:56 shaper Exp $
// $Id: DisplayMisoSceneImpl.java,v 1.9 2001/07/23 18:52:51 shaper Exp $
package com.threerings.miso.scene;
@@ -43,18 +43,6 @@ public class Scene
}
}
}
_file = null;
}
public File getFile ()
{
return _file;
}
public void setFile (File file)
{
_file = file;
}
/**
@@ -225,7 +213,5 @@ public class Scene
protected Point _hotspots[]; // hot spot zone points
protected ExitPoint _exits[]; // exit points to different scenes
protected File _file; // the file last associated with this scene
protected TileManager _tmgr;
}
@@ -1,15 +1,8 @@
//
// $Id: EditableSceneManager.java,v 1.4 2001/07/20 08:08:59 shaper Exp $
// $Id: EditableSceneManager.java,v 1.5 2001/07/23 18:52:51 shaper Exp $
package com.threerings.miso.scene;
import java.io.InputStream;
import java.io.IOException;
public class EditableSceneManager extends SceneManagerImpl
{
public void loadScenes (InputStream in) throws IOException
{
}
}
@@ -1,13 +1,17 @@
//
// $Id: ExitPoint.java,v 1.2 2001/07/18 21:45:42 shaper Exp $
// $Id: ExitPoint.java,v 1.3 2001/07/23 18:52:51 shaper Exp $
package com.threerings.miso.scene;
/**
* Represents a point in a scene that leads to a different scene.
* The ExitPoint class represents a point in a scene that leads to a
* different scene.
*/
public class ExitPoint
{
byte x, y; // coordinates for this exit point
short sid; // scene id this exit transitions to
/** Coordinates for this exit point. */
public byte x, y;
/** The scene id this exit transitions to. */
public short sid;
}
@@ -1,5 +1,5 @@
//
// $Id: IsoSceneView.java,v 1.13 2001/07/20 08:17:10 shaper Exp $
// $Id: IsoSceneView.java,v 1.14 2001/07/23 18:52:51 shaper Exp $
package com.threerings.miso.scene;
@@ -15,7 +15,7 @@ import java.awt.image.*;
* The IsoSceneView provides an isometric graphics view of a
* particular scene.
*/
public class IsoSceneView implements SceneView
public class IsoSceneView implements EditableSceneView
{
public IsoSceneView (TileManager tmgr)
{
@@ -246,19 +246,23 @@ public class IsoSceneView implements SceneView
_scene.tiles[tpos.x][tpos.y][lnum] = tile;
}
// default dimensions of the scene view
/** The default width of a scene in pixels. */
protected static final int DEF_BOUNDS_WIDTH = 18 * Tile.WIDTH;
/** The default height of a scene in pixels. */
protected static final int DEF_BOUNDS_HEIGHT = 37 * Tile.HEIGHT;
// total number of tile rows to render the full view
/** The total number of tile rows to render the full scene view. */
protected static final int TILE_RENDER_ROWS =
(Scene.TILE_WIDTH * Scene.TILE_HEIGHT) - 1;
// starting x/y-positions to render the view
/** The starting x-position to render the view. */
protected static final int DEF_CENTER_X = DEF_BOUNDS_WIDTH / 2;
/** The starting y-position to render the view. */
protected static final int DEF_CENTER_Y = -(9 * Tile.HEIGHT);
// length of a tile edge as rendered from an isometric perspective
/** The length of a tile edge as rendered from an isometric perspective. */
public static final float TILE_EDGE_LENGTH = (float)
Math.sqrt((Tile.HALF_WIDTH * Tile.HALF_WIDTH) +
(Tile.HALF_HEIGHT * Tile.HALF_HEIGHT));
@@ -1,5 +1,5 @@
//
// $Id: SceneManager.java,v 1.4 2001/07/20 08:08:59 shaper Exp $
// $Id: SceneManager.java,v 1.5 2001/07/23 18:52:51 shaper Exp $
package com.threerings.miso.scene;
@@ -22,16 +22,4 @@ public interface SceneManager
* layer id.
*/
public String[] getLayerNames ();
/**
* Load all scene objects described in the specified file into the
* set of available scenes.
*/
public void loadScenes (String fname);
/**
* Load all scene objects described in the specified input stream
* into the set of available scenes.
*/
public void loadScenes (InputStream in) throws IOException;
}
@@ -1,5 +1,5 @@
//
// $Id: SceneManagerImpl.java,v 1.4 2001/07/20 08:08:59 shaper Exp $
// $Id: SceneManagerImpl.java,v 1.5 2001/07/23 18:52:51 shaper Exp $
package com.threerings.miso.scene;
@@ -22,21 +22,4 @@ public abstract class SceneManagerImpl implements SceneManager
{
return Scene.XLATE_LAYERS;
}
public void loadScenes (String fname)
{
try {
InputStream tis = ConfigUtil.getStream(fname);
if (tis == null) {
Log.warning("Couldn't find file [fname=" + fname + "].");
return;
}
loadScenes(tis);
} catch (IOException ioe) {
Log.warning("Exception loading tileset [fname=" + fname +
", ioe=" + ioe + "].");
}
}
}
@@ -1,5 +1,5 @@
//
// $Id: SceneView.java,v 1.6 2001/07/20 00:35:09 shaper Exp $
// $Id: SceneView.java,v 1.7 2001/07/23 18:52:51 shaper Exp $
package com.threerings.miso.scene;
@@ -9,9 +9,9 @@ import java.awt.Component;
import java.awt.Graphics;
/**
* An interface to be implemented by classes that provide a view of a
* given scene by drawing the scene contents onto a particular GUI
* component.
* The SceneView interface provides an interface to be implemented by
* classes that provide a view of a given scene by drawing the scene
* contents onto a particular GUI component.
*/
public interface SceneView
{
@@ -20,23 +20,8 @@ public interface SceneView
*/
public void paint (Graphics g);
/**
* Set a tile to be highlighted when the scene is rendered.
*/
public void setHighlightedTile (int x, int y);
/**
* Set the scene that we're rendering.
*/
public void setScene (Scene scene);
/**
* Set whether coordinates should be drawn for each tile.
*/
public void setShowCoordinates (boolean show);
/**
* Set the tile at the specified location and layer in the scene.
*/
public void setTile (int x, int y, int lnum, Tile tile);
}
@@ -1,17 +1,8 @@
//
// $Id: CompiledTileSetManager.java,v 1.6 2001/07/21 01:51:10 shaper Exp $
// $Id: CompiledTileSetManager.java,v 1.7 2001/07/23 18:52:51 shaper Exp $
package com.threerings.miso.tile;
import com.threerings.media.ImageManager;
import java.io.InputStream;
import java.io.IOException;
public class CompiledTileSetManager extends TileSetManagerImpl
{
public void loadTileSets (InputStream tis) throws IOException
{
// TBD
}
}
@@ -1,15 +1,17 @@
//
// $Id: EditableTileSetManager.java,v 1.6 2001/07/21 01:51:10 shaper Exp $
// $Id: EditableTileSetManager.java,v 1.7 2001/07/23 18:52:51 shaper Exp $
package com.threerings.miso.tile;
import com.threerings.miso.Log;
import com.threerings.media.ImageManager;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import com.samskivert.util.Config;
import com.samskivert.util.ConfigUtil;
import com.threerings.miso.Log;
import com.threerings.media.ImageManager;
/**
* Extends general tileset manager functionality to allow reading
* tileset information from XML files. The XML file format allows for
@@ -18,25 +20,47 @@ import java.util.ArrayList;
*/
public class EditableTileSetManager extends TileSetManagerImpl
{
public void loadTileSets (InputStream tis) throws IOException
public void init (Config config, ImageManager imgmgr)
{
// read all tileset descriptions from the XML input stream
XMLTileSetParser parser = new XMLTileSetParser();
parser.loadTileSets(tis);
super.init(config, imgmgr);
// grab any resulting tileset objects
ArrayList tsets = parser.getTileSets();
if (tsets == null) {
Log.warning("No tileset descriptions found [tis=" + tis + "].");
return;
}
// load the tileset descriptions
String fname = config.getValue("miso.tilesets", (String)null);
loadTileSets(fname);
}
// and copy them into the main tileset hashtable
int size = tsets.size();
for (int ii = 0; ii < size; ii++) {
TileSet tset = (TileSet)tsets.get(ii);
_tilesets.put(tset.getId(), tset);
Log.info("Adding tileset to cache [tset=" + tset + "].");
/**
* Load the tilesets described in the specified file into the set
* of available tilesets.
*/
protected void loadTileSets (String fname)
{
try {
InputStream tis = ConfigUtil.getStream(fname);
if (tis == null) {
Log.warning("Couldn't find file [fname=" + fname + "].");
return;
}
// read all tileset descriptions from the XML input stream
XMLTileSetParser parser = new XMLTileSetParser();
ArrayList tsets = parser.loadTileSets(tis);
if (tsets == null) {
Log.warning("No tilesets found [tis=" + tis + "].");
return;
}
// copy new tilesets into the main tileset hashtable
int size = tsets.size();
for (int ii = 0; ii < size; ii++) {
TileSet tset = (TileSet)tsets.get(ii);
_tilesets.put(tset.getId(), tset);
Log.info("Adding tileset to cache [tset=" + tset + "].");
}
} catch (IOException ioe) {
Log.warning("Exception loading tileset [fname=" + fname +
", ioe=" + ioe + "].");
}
}
}
+50 -13
View File
@@ -1,27 +1,44 @@
//
// $Id: MisoUtil.java,v 1.1 2001/07/21 01:51:10 shaper Exp $
// $Id: MisoUtil.java,v 1.2 2001/07/23 18:52:51 shaper Exp $
package com.threerings.miso.util;
import java.awt.Frame;
import java.io.IOException;
import java.io.*;
import java.net.URL;
import java.net.MalformedURLException;
import com.samskivert.util.Config;
import com.samskivert.util.*;
import com.threerings.media.ImageManager;
import com.threerings.miso.Log;
import com.threerings.miso.scene.*;
import com.threerings.miso.tile.*;
import com.threerings.resource.ResourceManager;
/**
* MisoUtil provides miscellaneous routines for applications or other
* layers that intend to make use of Miso services.
*/
public class MisoUtil
{
/**
* Populate the config object with miso configuration values.
*
* @param config the Config object to populate.
*/
public static void bindProperties (Config config) throws IOException
{
config.bindProperties("miso", "rsrc/config/miso/miso");
}
/**
* Create a SceneManager object, reading the class name to
* instantiate from the "miso.scenemgr" config value.
*
* @param config the Config object.
*
* @return the new SceneManager object or null if an error occurred.
*/
public static SceneManager createSceneManager (Config config)
{
try {
@@ -34,6 +51,14 @@ public class MisoUtil
}
}
/**
* Create a TileManager object.
*
* @param config the Config object.
* @param frame the root frame to which images will be rendered.
*
* @return the new TileManager object or null if an error occurred.
*/
public static TileManager createTileManager (Config config, Frame frame)
{
ResourceManager rmgr = createResourceManager();
@@ -41,13 +66,14 @@ public class MisoUtil
TileSetManager tilesetmgr = createTileSetManager(config, imgmgr);
TileManager tilemgr = new TileManager(tilesetmgr);
// load the tileset descriptions
String tfile = config.getValue("miso.tilesets", (String)null);
tilemgr.loadTileSets(tfile);
return tilemgr;
}
/**
* Create a ResourceManager object.
*
* @return the new ResourceManager object or null if an error occurred.
*/
protected static ResourceManager createResourceManager ()
{
String root = System.getProperty("root", "");
@@ -59,19 +85,27 @@ public class MisoUtil
} catch (MalformedURLException mue) {
Log.warning("Malformed resource manager URL [url=" + localroot +
", mue=" + mue + "].");
return null;
}
return null;
}
/**
* Create a TileSetManager object, reading the class name to
* instantiate from the "miso.tilesetmgr" config value.
*
* @param config the Config object.
* @param imgmgr the ImageManager object from which images are obtained.
*
* @return the new TileSetManager object or null if an error occurred.
*/
protected static TileSetManager
createTileSetManager (Config config, ImageManager imgmgr)
{
TileSetManager tilesetmgr = null;
TileSetManagerImpl tilesetmgr = null;
try {
tilesetmgr = (TileSetManager)
tilesetmgr = (TileSetManagerImpl)
config.instantiateValue("miso.tilesetmgr", DEF_TILESETMGR);
tilesetmgr.init(imgmgr);
tilesetmgr.init(config, imgmgr);
} catch (Exception e) {
Log.warning("Failed to instantiate tileset manager " +
@@ -81,8 +115,11 @@ public class MisoUtil
return tilesetmgr;
}
protected static final String DEF_SCENEMGR =
/** The default SceneManager class name. */
protected static final String DEF_SCENEMGR =
CompiledSceneManager.class.getName();
/** The default TileSetManager class name. */
protected static final String DEF_TILESETMGR =
EditableTileSetManager.class.getName();
}