Get AS fringing actually working. We end up with a double-layer of sprites on the base tiles for the background as one and all the fringing as another. This is definitely pretty slow in the debug player, so still need to track down what's spending all that time.
git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@954 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
@@ -37,6 +37,9 @@ import com.threerings.util.Integer;
|
||||
import com.threerings.util.Log;
|
||||
import com.threerings.util.Maps;
|
||||
import com.threerings.util.Map;
|
||||
import com.threerings.util.Sets;
|
||||
import com.threerings.util.Set;
|
||||
import com.threerings.util.StringUtil;
|
||||
import com.threerings.util.WeakReference;
|
||||
import com.threerings.miso.data.MisoSceneModel;
|
||||
|
||||
@@ -72,6 +75,25 @@ public class AutoFringer
|
||||
return _fringeConf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all the tilesets that fringe on the specified tilesets.
|
||||
*/
|
||||
public function getFringeSets (tilesets :Set) :Set
|
||||
{
|
||||
var fringeSets :Set = Sets.newSetOf(int);
|
||||
|
||||
tilesets.forEach(function(o :int) :void {
|
||||
var fringes :Array = _fringeConf.getFringeSets(o);
|
||||
if (fringes != null) {
|
||||
for each (var fringe :int in fringes) {
|
||||
fringeSets.add(fringe);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return fringeSets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute and return the fringe tile to be inserted at the specified location.
|
||||
*/
|
||||
@@ -79,7 +101,9 @@ public class AutoFringer
|
||||
masks :Map) :BaseTile
|
||||
{
|
||||
// get the tileset id of the base tile we are considering
|
||||
var underset :int = adjustTileSetId(scene.getBaseTileId(col, row) >> 16);
|
||||
var utid :int = scene.getBaseTileId(col, row);
|
||||
var underset :int = adjustTileSetId((utid <= 0) ?
|
||||
scene.getDefaultBaseTileSet() : (utid >> 16));
|
||||
|
||||
// start with a clean temporary fringer map
|
||||
_fringers.clear();
|
||||
@@ -135,13 +159,7 @@ public class AutoFringer
|
||||
}
|
||||
|
||||
// otherwise compose a FringeTile from the specified fringes
|
||||
var frecs :Array = new Array(numfringers);
|
||||
for (var ii :int = 0, pp :int = 0; ii < 16; ii++) {
|
||||
var rec :FringerRec = FringerRec(_fringers.get(ii));
|
||||
if (rec != null) {
|
||||
frecs[pp++] = rec;
|
||||
}
|
||||
}
|
||||
var frecs :Array = _fringers.values();
|
||||
|
||||
return composeFringeTile(frecs, fringes, TileUtil.getTileHash(col, row), passable, masks);
|
||||
}
|
||||
@@ -197,10 +215,11 @@ public class AutoFringer
|
||||
var tsr :FringeTileSetRecord = _fringeConf.getFringe(fringer.baseset, hashValue);
|
||||
getTileImageHelper0(img, tsr, fringer.baseset, hashValue, masks, indexes, 0,
|
||||
function (result :Bitmap) :void {
|
||||
if (fringerIdx == fringers.size() - 1) {
|
||||
if (fringerIdx == fringers.length - 1) {
|
||||
callback(result);
|
||||
} else {
|
||||
getTileImageHelper1(img, hashValue, masks, fringers, fringerIdx + 1, callback);
|
||||
getTileImageHelper1(result, hashValue, masks, fringers, fringerIdx + 1,
|
||||
callback);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -212,10 +231,10 @@ public class AutoFringer
|
||||
try {
|
||||
getTileImage(img, tsr, baseset, indexes[indexIdx], hashValue, masks,
|
||||
function (result :Bitmap) :void {
|
||||
if (indexIdx == indexes.size() - 1) {
|
||||
if (indexIdx == indexes.length - 1) {
|
||||
callback(result);
|
||||
} else {
|
||||
getTileImageHelper0(img, tsr, baseset, hashValue, masks, indexes,
|
||||
getTileImageHelper0(result, tsr, baseset, hashValue, masks, indexes,
|
||||
indexIdx + 1, callback);
|
||||
}
|
||||
});
|
||||
@@ -231,12 +250,19 @@ public class AutoFringer
|
||||
protected function getTileImage (img :Bitmap, tsr :FringeTileSetRecord ,
|
||||
baseset :int, index :int, hashValue :int, masks :Map, callback :Function) :void
|
||||
{
|
||||
|
||||
var fringeset :int = tsr.fringe_tsid;
|
||||
var fset :TileSet = _tMgr.getTileSet(fringeset);
|
||||
if (!tsr.mask) {
|
||||
// oh good, this is easy
|
||||
var stamp :Tile = fset.getTile(index);
|
||||
callback(stampTileImage(stamp, img, stamp.getWidth(), stamp.getHeight()));
|
||||
if (stamp.getImage() != null) {
|
||||
callback(stampTileImage(stamp, img, stamp.getWidth(), stamp.getHeight()));
|
||||
} else {
|
||||
stamp.notifyOnLoad(function(tile :Tile) :void {
|
||||
callback(stampTileImage(stamp, img, stamp.getWidth(), stamp.getHeight()));
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -325,7 +351,7 @@ public class AutoFringer
|
||||
} else if (weebits != 0) {
|
||||
index = BITS_TO_INDEX[weebits];
|
||||
if (index != -1) {
|
||||
indexes.add(index);
|
||||
indexes.push(index);
|
||||
}
|
||||
weebits = 0;
|
||||
}
|
||||
@@ -333,7 +359,7 @@ public class AutoFringer
|
||||
if (weebits != 0) {
|
||||
index = BITS_TO_INDEX[weebits];
|
||||
if (index != -1) {
|
||||
indexes.add(index);
|
||||
indexes.push(index);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -53,13 +53,18 @@ public class FringeConfiguration
|
||||
*/
|
||||
public function fringesOn (first :int, second :int) :int
|
||||
{
|
||||
// Short-circuit if we're fringing on ourselves.
|
||||
if (first == second) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
var f1 :FringeRecord = _frecs.get(first);
|
||||
|
||||
// we better have a fringe record for the first
|
||||
if (null != f1) {
|
||||
|
||||
// it had better have some tilesets defined
|
||||
if (f1.tilesets.size() > 0) {
|
||||
if (f1.tilesets.length > 0) {
|
||||
|
||||
var f2 :FringeRecord = _frecs.get(second);
|
||||
|
||||
@@ -81,7 +86,23 @@ public class FringeConfiguration
|
||||
public function getFringe (baseset :int, hashValue :int) :FringeTileSetRecord
|
||||
{
|
||||
var f :FringeRecord = _frecs.get(baseset);
|
||||
return f.tilesets.get(hashValue % f.tilesets.size());
|
||||
return f.tilesets[hashValue % f.tilesets.length];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all the tilesets used to fringe with this baseset.
|
||||
*/
|
||||
public function getFringeSets (baseset :int) :Array
|
||||
{
|
||||
var f :FringeRecord = _frecs.get(baseset);
|
||||
if (f == null) {
|
||||
return [];
|
||||
} else {
|
||||
return f.tilesets.map(
|
||||
function (element :FringeTileSetRecord, index:int, arr:Array) :int {
|
||||
return element.fringe_tsid;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/** The mapping from base tileset id to fringerecord. */
|
||||
|
||||
@@ -31,7 +31,7 @@ public class FringeRecord
|
||||
public var priority :int;
|
||||
|
||||
/** A list of the possible tilesets that can be used for fringing. */
|
||||
public var tilesets :Array;
|
||||
public var tilesets :Array = [];
|
||||
|
||||
public static function fromXml (xml :XML, idMap :TileSetIdMap) :FringeRecord
|
||||
{
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
package com.threerings.miso.tile {
|
||||
|
||||
import com.threerings.media.tile.TileSetIdMap;
|
||||
import com.threerings.util.XmlUtil;
|
||||
|
||||
public class FringeTileSetRecord
|
||||
{
|
||||
@@ -33,7 +34,7 @@ public class FringeTileSetRecord
|
||||
{
|
||||
var rec :FringeTileSetRecord = new FringeTileSetRecord();
|
||||
rec.fringe_tsid = idMap.getTileSetId(xml.@name);
|
||||
rec.mask = xml.@mask;
|
||||
rec.mask = XmlUtil.getBooleanAttr(xml, "mask", false);
|
||||
return rec;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
package com.threerings.miso.tile {
|
||||
|
||||
import com.threerings.media.tile.TileManager;
|
||||
import com.threerings.util.Set;
|
||||
|
||||
/**
|
||||
* Extends the basic tile manager and provides support for automatically generating fringes in
|
||||
@@ -27,6 +28,28 @@ import com.threerings.media.tile.TileManager;
|
||||
*/
|
||||
public class MisoTileManager extends TileManager
|
||||
{
|
||||
// TODO: Fringing.
|
||||
public function setFringer (fringer :AutoFringer) :void
|
||||
{
|
||||
_fringer = fringer;
|
||||
}
|
||||
|
||||
public function getFringer () :AutoFringer
|
||||
{
|
||||
return _fringer;
|
||||
}
|
||||
|
||||
override public function ensureLoaded (tileSets :Set, completeCallback :Function,
|
||||
progressCallback :Function) :void
|
||||
{
|
||||
// Get those we'll use to fringe with us, too.
|
||||
var fringeSets :Set = _fringer.getFringeSets(tileSets);
|
||||
fringeSets.forEach(function (tsetId :int) :void {
|
||||
tileSets.add(tsetId);
|
||||
});
|
||||
|
||||
super.ensureLoaded(tileSets, completeCallback, progressCallback);
|
||||
}
|
||||
|
||||
protected var _fringer :AutoFringer;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user