From e628a8e429beb037fd04e612397c6941caebb011 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Mon, 21 Apr 2003 17:08:57 +0000 Subject: [PATCH] Added support for specifying a default tileset for scenes. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2439 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../miso/client/MisoScenePanel.java | 5 ++-- .../threerings/miso/client/SceneBlock.java | 30 +++++++++++++++++-- .../threerings/miso/data/MisoSceneModel.java | 11 ++++++- .../miso/data/SparseMisoSceneModel.java | 11 ++++++- .../tools/xml/SparseMisoSceneRuleSet.java | 4 ++- .../miso/tools/xml/SparseMisoSceneWriter.java | 3 +- 6 files changed, 56 insertions(+), 8 deletions(-) diff --git a/src/java/com/threerings/miso/client/MisoScenePanel.java b/src/java/com/threerings/miso/client/MisoScenePanel.java index 689816465..66b80bd45 100644 --- a/src/java/com/threerings/miso/client/MisoScenePanel.java +++ b/src/java/com/threerings/miso/client/MisoScenePanel.java @@ -1,5 +1,5 @@ // -// $Id: MisoScenePanel.java,v 1.9 2003/04/19 22:40:34 mdb Exp $ +// $Id: MisoScenePanel.java,v 1.10 2003/04/21 17:08:56 mdb Exp $ package com.threerings.miso.client; @@ -678,7 +678,8 @@ public class MisoScenePanel extends VirtualMediaPanel // recompute our object tips computeTips(); -// Log.info("Computed " + _vizobjs.size() + " visible objects."); +// Log.info("Computed " + _vizobjs.size() + " visible objects from " + +// _blocks.size() + " blocks."); } /** diff --git a/src/java/com/threerings/miso/client/SceneBlock.java b/src/java/com/threerings/miso/client/SceneBlock.java index b833fe083..f862c57ac 100644 --- a/src/java/com/threerings/miso/client/SceneBlock.java +++ b/src/java/com/threerings/miso/client/SceneBlock.java @@ -1,5 +1,5 @@ // -// $Id: SceneBlock.java,v 1.4 2003/04/19 02:01:08 mdb Exp $ +// $Id: SceneBlock.java,v 1.5 2003/04/21 17:08:56 mdb Exp $ package com.threerings.miso.client; @@ -77,6 +77,17 @@ public class SceneBlock for (int ii = 0; ii < _objects.length; ii++) { _objects[ii] = new SceneObject(panel, set.get(ii)); } + + // resolve our default tileset + int bsetid = model.getDefaultBaseTileSet(); + try { + if (bsetid > 0) { + _defset = _panel.getTileManager().getTileSet(bsetid); + } + } catch (Exception e) { + Log.warning("Unable to fetch default base tileset [tsid=" + bsetid + + ", error=" + e + "]."); + } } /** @@ -110,7 +121,14 @@ public class SceneBlock */ public BaseTile getBaseTile (int tx, int ty) { - return _base[index(tx, ty)]; + BaseTile tile = _base[index(tx, ty)]; + if (tile == null && _defset != null) { + long seed = ((tx^ty) ^ multiplier) & mask; + long hash = (seed * multiplier + addend) & mask; + int tidx = (int)((hash >> 10) % _defset.getTileCount()); + tile = (BaseTile)_defset.getTile(tidx); + } + return tile; } /** @@ -326,6 +344,9 @@ public class SceneBlock /** A polygon bounding the footprint of this block. */ protected Polygon _footprint; + /** Used to return a tile where we have none. */ + protected TileSet _defset; + /** Our base tiles. */ protected BaseTile[] _base; @@ -344,4 +365,9 @@ public class SceneBlock // used to link up to our neighbors protected static final int[] DX = { -1, -1, 0, 1, 1, 1, 0, -1 }; protected static final int[] DY = { 0, -1, -1, -1, 0, 1, 1, 1 }; + + // for mapping tile coordinates to a pseudo-random tile + protected final static long multiplier = 0x5DEECE66DL; + protected final static long addend = 0xBL; + protected final static long mask = (1L << 48) - 1; } diff --git a/src/java/com/threerings/miso/data/MisoSceneModel.java b/src/java/com/threerings/miso/data/MisoSceneModel.java index 5779258d5..9354a889d 100644 --- a/src/java/com/threerings/miso/data/MisoSceneModel.java +++ b/src/java/com/threerings/miso/data/MisoSceneModel.java @@ -1,5 +1,5 @@ // -// $Id: MisoSceneModel.java,v 1.16 2003/04/19 22:40:34 mdb Exp $ +// $Id: MisoSceneModel.java,v 1.17 2003/04/21 17:08:57 mdb Exp $ package com.threerings.miso.data; @@ -52,6 +52,15 @@ public abstract class MisoSceneModel extends SimpleStreamableObject */ public abstract boolean setBaseTile (int fqTileId, int x, int y); + /** + * Scene models can return a default tileset to be used when no base + * tile data exists for a particular tile. + */ + public int getDefaultBaseTileSet () + { + return 0; + } + /** * Populates the supplied object set with info on all objects whose * origin falls in the requested region. diff --git a/src/java/com/threerings/miso/data/SparseMisoSceneModel.java b/src/java/com/threerings/miso/data/SparseMisoSceneModel.java index a6efcb6a0..31c165dc0 100644 --- a/src/java/com/threerings/miso/data/SparseMisoSceneModel.java +++ b/src/java/com/threerings/miso/data/SparseMisoSceneModel.java @@ -1,5 +1,5 @@ // -// $Id: SparseMisoSceneModel.java,v 1.3 2003/04/20 00:05:14 mdb Exp $ +// $Id: SparseMisoSceneModel.java,v 1.4 2003/04/21 17:08:57 mdb Exp $ package com.threerings.miso.data; @@ -173,6 +173,9 @@ public class SparseMisoSceneModel extends MisoSceneModel /** The dimensions of a section of our scene. */ public short swidth, sheight; + /** The tileset to use when we have no tile data. */ + public int defTileSet = 8; + /** * Creates a scene model with the specified bounds. * @@ -238,6 +241,12 @@ public class SparseMisoSceneModel extends MisoSceneModel return true; } + // documentation inherited + public int getDefaultBaseTileSet () + { + return defTileSet; + } + // documentation inherited public void getObjects (Rectangle region, ObjectSet set) { diff --git a/src/java/com/threerings/miso/tools/xml/SparseMisoSceneRuleSet.java b/src/java/com/threerings/miso/tools/xml/SparseMisoSceneRuleSet.java index 27b512ba6..fbaeb5f14 100644 --- a/src/java/com/threerings/miso/tools/xml/SparseMisoSceneRuleSet.java +++ b/src/java/com/threerings/miso/tools/xml/SparseMisoSceneRuleSet.java @@ -1,5 +1,5 @@ // -// $Id: SparseMisoSceneRuleSet.java,v 1.1 2003/04/19 22:40:34 mdb Exp $ +// $Id: SparseMisoSceneRuleSet.java,v 1.2 2003/04/21 17:08:57 mdb Exp $ package com.threerings.miso.tools.xml; @@ -47,6 +47,8 @@ public class SparseMisoSceneRuleSet implements NestableRuleSet // set up rules to parse and set our fields dig.addRule(prefix + "/swidth", new SetFieldRule(dig, "swidth")); dig.addRule(prefix + "/sheight", new SetFieldRule(dig, "sheight")); + dig.addRule(prefix + "/defTileSet", + new SetFieldRule(dig, "defTileSet")); String sprefix = prefix + "/sections/section"; dig.addObjectCreate(sprefix, Section.class.getName()); diff --git a/src/java/com/threerings/miso/tools/xml/SparseMisoSceneWriter.java b/src/java/com/threerings/miso/tools/xml/SparseMisoSceneWriter.java index c7aa0b1cf..b71facd5b 100644 --- a/src/java/com/threerings/miso/tools/xml/SparseMisoSceneWriter.java +++ b/src/java/com/threerings/miso/tools/xml/SparseMisoSceneWriter.java @@ -1,5 +1,5 @@ // -// $Id: SparseMisoSceneWriter.java,v 1.1 2003/04/19 22:40:34 mdb Exp $ +// $Id: SparseMisoSceneWriter.java,v 1.2 2003/04/21 17:08:57 mdb Exp $ package com.threerings.miso.tools.xml; @@ -45,6 +45,7 @@ public class SparseMisoSceneWriter implements NestableWriter { writer.dataElement("swidth", Integer.toString(model.swidth)); writer.dataElement("sheight", Integer.toString(model.sheight)); + writer.dataElement("defTileSet", Integer.toString(model.defTileSet)); writer.startElement("sections"); for (Iterator iter = model.getSections(); iter.hasNext(); ) {