First pass at getting miso working with actual tiles and tileset data.

Still to do:
- Handle tile priorities in ISO sorting.
- Handle recoloring tiles (this may result in annoyingly significant changes to Tile/TileSet API)
- Dynamically loading sections rather than loading all the tiles of a scene.
- Better handling of the state where the scene's not yet loaded.
- Portals.
- Dynamic sizing of the MisoScenePanel



git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@932 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
Mike Thomas
2010-07-01 22:27:37 +00:00
parent 941a6a83b2
commit e3c79a6be8
25 changed files with 2724 additions and 30 deletions
@@ -1,9 +1,30 @@
//
// Nenya library - tools for developing networked games
// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
// http://www.threerings.net/code/nenya/
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.threerings.miso.client {
import flash.utils.getTimer;
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Point;
import flash.geom.Rectangle;
@@ -11,6 +32,9 @@ import flash.events.MouseEvent;
import com.threerings.crowd.client.PlaceView;
import com.threerings.crowd.data.PlaceObject;
import com.threerings.media.tile.NoSuchTileSetError;
import com.threerings.media.tile.TileSet;
import com.threerings.media.tile.TileUtil;
import com.threerings.miso.client.MisoMetricsTransformation;
import com.threerings.miso.data.MisoSceneModel;
import com.threerings.miso.data.ObjectInfo;
@@ -30,10 +54,13 @@ public class MisoScenePanel extends Sprite
{
public function MisoScenePanel (ctx :MisoContext, metrics :MisoSceneMetrics)
{
_ctx = ctx;
// Excitingly, we get to override this globally for as3isolib...
IsoMath.transformationObject = new MisoMetricsTransformation(metrics,
metrics.tilehei * 3 / 4);
_metrics = metrics;
_isoView = new IsoView();
_isoView.setSize(DEF_WIDTH, DEF_HEIGHT);
@@ -42,11 +69,6 @@ public class MisoScenePanel extends Sprite
addChild(_isoView);
}
public function setSize (width :int, height :int) :void
{
_isoView.setSize(width, height);
}
public function onClick (event :MouseEvent) :void
{
var viewPt :Point = _isoView.globalToLocal(new Point(event.stageX, event.stageY));
@@ -78,13 +100,43 @@ public class MisoScenePanel extends Sprite
var time :int = getTimer();
var baseArr :Array = [];
for (var si :int = -10; si < 3; si++) {
for (var sj :int = -8; sj < 4; sj++) {
for (var si :int = -2; si < 4; si++) {
for (var sj :int = -1; sj < 3; sj++) {
var baseScene :IsoScene = new IsoScene();
for (var ii :int = 10*si; ii < 10*si + 10; ii++) {
for (var jj :int = 10*sj; jj < 10*sj + 10; jj++) {
var tileId :int = _model.getBaseTileId(ii, jj);
if (tileId <= 0) {
var defSet :TileSet;
try {
var setId :int = _model.getDefaultBaseTileSet();
defSet = _ctx.getTileManager().getTileSet(setId);
tileId = TileUtil.getFQTileId(setId,
TileUtil.getTileHash(ii, jj) % defSet.getTileCount());
} catch (err :NoSuchTileSetError) {
// Someone else already complained...
continue;
}
}
var tileSet :TileSet;
try {
tileSet =
_ctx.getTileManager().getTileSet(TileUtil.getTileSetId(tileId));
} catch (err :NoSuchTileSetError) {
// Someone else already complained...
continue;
}
if (tileSet == null) {
trace("TileManager returned null tilset: " +
TileUtil.getTileSetId(tileId));
continue;
}
baseScene.addChild(
new BaseTileIsoSprite(ii, jj, _model.getBaseTileId(ii, jj)));
new BaseTileIsoSprite(ii, jj, tileId,
tileSet.getTile(TileUtil.getTileIndex(tileId)), _metrics));
}
}
baseScene.render();
@@ -97,9 +149,24 @@ public class MisoScenePanel extends Sprite
time = getTimer();
for (ii = 0; ii < set.size(); ii++) {
var objInfo :ObjectInfo = set.get(ii);
if (objInfo.priority == 0) {
scene.addChild(new ObjectTileIsoSprite(objInfo.x, objInfo.y, objInfo.tileId));
var objTileId :int = objInfo.tileId;
var objTileSet :TileSet;
try {
objTileSet =
_ctx.getTileManager().getTileSet(TileUtil.getTileSetId(objTileId));
} catch (err :NoSuchTileSetError) {
// Someone else already complained...
continue;
}
if (objTileSet == null) {
trace("TileManager returned null TileSet: " + TileUtil.getTileSetId(objTileId));
continue;
}
scene.addChild(
new ObjectTileIsoSprite(objInfo.x, objInfo.y, objTileId,
objTileSet.getTile(TileUtil.getTileIndex(objTileId)), _metrics));
}
time = getTimer();
@@ -112,6 +179,10 @@ public class MisoScenePanel extends Sprite
protected var _isoView :IsoView;
protected var _ctx :MisoContext;
protected var _metrics :MisoSceneMetrics;
protected const DEF_WIDTH :int = 985;
protected const DEF_HEIGHT :int = 560;
}