From 833aa75ff4e1ff45238cd6df5f68983010305edf Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Thu, 4 Apr 2002 04:06:57 +0000 Subject: [PATCH] Added code to read configuration of which fringing tiles we have images for. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1183 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../miso/tile/FringeConfiguration.java | 47 ++++++++++++++++++- .../tools/xml/FringeConfigurationParser.java | 25 ++++++++-- 2 files changed, 68 insertions(+), 4 deletions(-) diff --git a/src/java/com/threerings/miso/tile/FringeConfiguration.java b/src/java/com/threerings/miso/tile/FringeConfiguration.java index 6e4f8d4d7..dd89b6c82 100644 --- a/src/java/com/threerings/miso/tile/FringeConfiguration.java +++ b/src/java/com/threerings/miso/tile/FringeConfiguration.java @@ -1,5 +1,5 @@ // -// $Id: FringeConfiguration.java,v 1.1 2002/04/03 22:52:44 ray Exp $ +// $Id: FringeConfiguration.java,v 1.2 2002/04/04 04:06:57 ray Exp $ package com.threerings.miso.scene; @@ -59,6 +59,25 @@ public class FringeConfiguration implements Serializable _frecs.put(frec.base_tsid, frec); } + /** + * During parsing we get an int[] representing the fringes we have + * defined. + */ + public void setTiles (int[] tiles) + { + // create an array of all possible tiles and set them all to invalid + _bits = new int[256]; + for (int ii=0; ii < 256; ii++) { + _bits[ii] = -1; + } + + // fill in the fringebit configurations we have tiles for with the + // index of the tiles + for (int ii=0; ii < tiles.length; ii++) { + _bits[tiles[ii]] = ii; + } + } + /** * Does the first tileset fringe upon the second? */ @@ -85,6 +104,32 @@ public class FringeConfiguration implements Serializable return false; } + /** + * Return the tile index of any fringing tileset that should be used + * if the following fringebits are turned on. + * @return -1 if not defined + */ + public int getTileIndexFromFringeBits (int bits) + { + return _bits[bits]; + } + + /** + * Get the tileset id of the fringe for the specified basesetid. + * We don't error check anything because you should be doing the right + * thing here. + */ + public int getFringeTileSetID (int basesetid) + { + FringeRecord f = (FringeRecord) _frecs.get(basesetid); + + // for now we just return the 1st tilesetid... no randomization + return ((FringeTileSetRecord) f.tilesets.get(0)).fringe_tsid; + } + /** The mapping from base tileset id to fringerecord. */ protected HashIntMap _frecs = new HashIntMap(); + + /** An array that matches fringebits to fringe tile indexes. */ + protected int[] _bits; } diff --git a/src/java/com/threerings/miso/tile/tools/xml/FringeConfigurationParser.java b/src/java/com/threerings/miso/tile/tools/xml/FringeConfigurationParser.java index 038ae6b5c..5e1e56a66 100644 --- a/src/java/com/threerings/miso/tile/tools/xml/FringeConfigurationParser.java +++ b/src/java/com/threerings/miso/tile/tools/xml/FringeConfigurationParser.java @@ -1,5 +1,5 @@ // -// $Id: FringeConfigurationParser.java,v 1.1 2002/04/03 22:52:44 ray Exp $ +// $Id: FringeConfigurationParser.java,v 1.2 2002/04/04 04:06:57 ray Exp $ package com.threerings.miso.scene.tools.xml; @@ -42,8 +42,27 @@ public class FringeConfigurationParser extends CompiledConfigParser protected void addRules (Digester digest) { // configure top-level constraints - String prefix = "fringes"; - digest.addRule(prefix, new SetPropertyFieldsRule(digest)); + String prefix = "fringe"; + digest.addRule(prefix, new Rule(digest) { + // parse the bits + public void begin (Attributes attrs) + throws Exception + { + FringeConfiguration fc = (FringeConfiguration) digester.peek(); + + for (int ii=0; ii < attrs.getLength(); ii++) { + String name = attrs.getLocalName(ii); + if (StringUtil.blank(name)) { + name = attrs.getQName(ii); + } + String value = attrs.getValue(ii); + + if ("tiles".equals(name)) { + fc.setTiles(StringUtil.parseIntArray(value)); + } + } + } + }); // create and configure fringe config instances prefix += "/base";