We're doing pathing now, so follow along with nenya's changes.

git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@954 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
Mike Thomas
2010-08-13 20:29:10 +00:00
parent 976b044aaa
commit a1ebef955c
2 changed files with 115 additions and 31 deletions
@@ -22,7 +22,11 @@ package com.threerings.stage.client {
import flash.display.DisplayObject; import flash.display.DisplayObject;
import flash.display.Sprite; import flash.display.Sprite;
import com.threerings.cast.CharacterSprite;
import com.threerings.util.DirectionCodes;
import com.threerings.media.Tickable; import com.threerings.media.Tickable;
import com.threerings.media.util.Path;
import com.threerings.media.util.Pathable;
import com.threerings.miso.util.MisoSceneMetrics; import com.threerings.miso.util.MisoSceneMetrics;
import com.threerings.miso.util.MisoUtil; import com.threerings.miso.util.MisoUtil;
import com.threerings.stage.data.StageLocation; import com.threerings.stage.data.StageLocation;
@@ -31,35 +35,43 @@ import as3isolib.display.IsoSprite;
import as3isolib.graphics.SolidColorFill; import as3isolib.graphics.SolidColorFill;
public class CharacterIsoSprite extends IsoSprite public class CharacterIsoSprite extends IsoSprite
implements Pathable
{ {
public function CharacterIsoSprite (bodyOid :int, metrics :MisoSceneMetrics, public function CharacterIsoSprite (bodyOid :int, metrics :MisoSceneMetrics,
disp :DisplayObject) charSprite :CharacterSprite)
{ {
_metrics = metrics; _metrics = metrics;
_bodyOid = bodyOid; _bodyOid = bodyOid;
setSize(1, 1, 2); setSize(1, 1, 2);
usePreciseValues = true;
// We wrap the sprite so we can shift it where we need it. Components like to line up // We wrap the sprite so we can shift it where we need it. Components like to line up
// to the middle of a tile and as3isolib likes to line up to the back of a tile. // to the middle of a tile and as3isolib likes to line up to the back of a tile.
var wrapper :Sprite = new Sprite(); var wrapper :Sprite = new Sprite();
wrapper.y = _metrics.tilehhei; wrapper.y = _metrics.tilehhei;
wrapper.addChild(disp); wrapper.addChild(charSprite);
_character = disp; _character = charSprite;
sprites = [wrapper]; sprites = [wrapper];
} }
public function tick (tickStamp :int) :void public function tick (tickStamp :int) :void
{ {
if (_character is Tickable) { if (_path != null) {
Tickable(_character).tick(tickStamp); if (_pathStamp == 0) {
_pathStamp = tickStamp
_path.init(this, _pathStamp);
}
_path.tick(this, tickStamp);
} }
_character.tick(tickStamp);
} }
public function isMoving () :Boolean public function isMoving () :Boolean
{ {
return false; //TODO Path return _path != null;
} }
public function getBodyOid () :int public function getBodyOid () :int
@@ -69,25 +81,97 @@ public class CharacterIsoSprite extends IsoSprite
public function placeAtLoc (loc :StageLocation) :void public function placeAtLoc (loc :StageLocation) :void
{ {
moveTo(MisoUtil.fullToTile(loc.x), MisoUtil.fullToTile(loc.y), 0); setLocation(MisoUtil.fullToTile(loc.x), MisoUtil.fullToTile(loc.y));
// TODO Components - handle orientation setOrientation(loc.orient);
}
public function getX () :Number
{
return x;
}
public function getY () :Number
{
return y;
}
public function setLocation (x :Number, y :Number) :void
{
moveTo(x, y, 0);
render(); render();
} }
public function move (path :Object /*TODO Path */) :void public function setOrientation (orient :int) :void
{ {
// TODO Path _character.setOrientation(toIsoOrient(orient));
render();
}
public function toIsoOrient (orient :int) :int
{
if (orient == DirectionCodes.NONE) {
return orient;
} else {
return (orient + 2) % 8;
}
}
public function fromIsoOrient (orient :int) :int
{
if (orient == DirectionCodes.NONE) {
return orient;
} else {
return (orient + 6) % 8;
}
}
public function getOrientation () :int
{
return fromIsoOrient(_character.getOrientation());
}
public function pathBeginning () :void
{
_character.pathBeginning();
}
public function pathCompleted (timestamp :int) :void
{
_character.pathCompleted(timestamp);
_path = null;
}
public function move (path :Path) :void
{
// if there's a previous path, let it know that it's going away
cancelMove();
// save off this path
_path = path;
// we'll initialize it on our next tick thanks to a zero path stamp
_pathStamp = 0;
} }
public function cancelMove () :void public function cancelMove () :void
{ {
// TODO Path if (_path != null) {
var oldpath :Path = _path;
_path = null;
oldpath.wasRemoved(this);
}
} }
protected var _bodyOid :int; protected var _bodyOid :int;
protected var _metrics :MisoSceneMetrics; protected var _metrics :MisoSceneMetrics;
protected var _character :DisplayObject; protected var _character :CharacterSprite;
/** Path we're currently following, if any. */
protected var _path :Path;
/** The time we started moving on our path. */
protected var _pathStamp :int;
} }
} }
@@ -27,11 +27,14 @@ import flash.geom.Rectangle;
import flash.events.Event; import flash.events.Event;
import flash.events.MouseEvent; import flash.events.MouseEvent;
import com.threerings.cast.CharacterSprite;
import com.threerings.crowd.client.OccupantObserver; import com.threerings.crowd.client.OccupantObserver;
import com.threerings.crowd.data.OccupantInfo; import com.threerings.crowd.data.OccupantInfo;
import com.threerings.crowd.data.PlaceObject; import com.threerings.crowd.data.PlaceObject;
import com.threerings.media.Tickable; import com.threerings.media.Tickable;
import com.threerings.media.util.LineSegmentPath;
import com.threerings.media.util.Path;
import com.threerings.util.Controller; import com.threerings.util.Controller;
import com.threerings.util.Integer; import com.threerings.util.Integer;
import com.threerings.util.Iterator; import com.threerings.util.Iterator;
@@ -77,8 +80,6 @@ public class CrowdStageScenePanel extends StageScenePanel
_isoView.size.y*_isoView.size.y))); _isoView.size.y*_isoView.size.y)));
recomputeProximate(); recomputeProximate();
_vbounds = new Rectangle(0, 0, _isoView.size.x, _isoView.size.y);
addEventListener(Event.ADDED_TO_STAGE, addedToStage); addEventListener(Event.ADDED_TO_STAGE, addedToStage);
addEventListener(Event.REMOVED_FROM_STAGE, removedFromStage); addEventListener(Event.REMOVED_FROM_STAGE, removedFromStage);
} }
@@ -318,7 +319,7 @@ public class CrowdStageScenePanel extends StageScenePanel
if (!isProximateToLoc(nloc)) { if (!isProximateToLoc(nloc)) {
if (sprite != null) { if (sprite != null) {
// if they are visible, walk them to their new location // if they are visible, walk them to their new location
if (_vbounds.intersects(sprite.screenBounds)) { if (_vbounds.intersects(sprite.getBounds(_isoView))) {
moveSpriteToLoc(sprite, nloc.loc); moveSpriteToLoc(sprite, nloc.loc);
} }
// now queue them up for removal on arrival as appropriate // now queue them up for removal on arrival as appropriate
@@ -402,8 +403,9 @@ public class CrowdStageScenePanel extends StageScenePanel
// if the source and destination are both offscreen, warp the // if the source and destination are both offscreen, warp the
// sprite to where they are going // sprite to where they are going
var endsOff :Boolean = !_vbounds.contains(nx, ny); var sc :Point = _isoView.isoToLocal(new Pt(nx, ny, 0));
if (!_vbounds.intersects(sprite.screenBounds) && endsOff) { var endsOff :Boolean = !_vbounds.contains(sc.x, sc.y);
if (!_vbounds.intersects(sprite.getBounds(_isoView)) && endsOff) {
sprite.cancelMove(); sprite.cancelMove();
sprite.placeAtLoc(loc); sprite.placeAtLoc(loc);
return true; return true;
@@ -417,6 +419,7 @@ public class CrowdStageScenePanel extends StageScenePanel
(sprite == _selfSprite)) { (sprite == _selfSprite)) {
log.info("Warp-a-saurus! " + StringUtil.toString(_vbounds) + log.info("Warp-a-saurus! " + StringUtil.toString(_vbounds) +
" -> " + StringUtil.toCoordsString(loc.x, loc.y)); " -> " + StringUtil.toCoordsString(loc.x, loc.y));
sprite.cancelMove(); sprite.cancelMove();
sprite.placeAtLoc(loc); sprite.placeAtLoc(loc);
@@ -427,11 +430,12 @@ public class CrowdStageScenePanel extends StageScenePanel
// if we made it this far, we can actually try to compute a path // if we made it this far, we can actually try to compute a path
// for this sprite; if the end of the path is off-screen, allow "partial" paths // for this sprite; if the end of the path is off-screen, allow "partial" paths
var path :Object = null;//TODO Path TilePath = TilePath(getPath(yocs, nx, ny, endsOff)); var path :LineSegmentPath = LineSegmentPath(getPath(sprite, nx, ny, endsOff));
if (path == null) { if (path == null) {
/*TODO Path log.info("Unable to compute path from " + log.info("Unable to compute path from " +
StringUtil.toCoordsString(cx, cy) + " to " + StringUtil.toCoordsString(cx, cy) + " to " +
StringUtil.toCoordsString(loc.x, loc.y) + "; warping.");*/ StringUtil.toCoordsString(nx, ny) + "; warping.");
sprite.cancelMove(); sprite.cancelMove();
sprite.placeAtLoc(loc); sprite.placeAtLoc(loc);
return true; return true;
@@ -534,9 +538,6 @@ public class CrowdStageScenePanel extends StageScenePanel
displayFeedback("m.cant_get_there"); displayFeedback("m.cant_get_there");
} }
// TODO Path - remove this
changeLocation(loc);
return; return;
} }
@@ -586,12 +587,13 @@ public class CrowdStageScenePanel extends StageScenePanel
protected function checkWalkToLoc (loc :StageLocation) :int protected function checkWalkToLoc (loc :StageLocation) :int
{ {
// obtain the screen coordinates of the location // obtain the screen coordinates of the location
var sc :Point = _isoView.isoToLocal(new Pt(loc.x, loc.y, 0)); var lx :int = MisoUtil.fullToTile(loc.x);
var ly :int = MisoUtil.fullToTile(loc.y);
var us :CharacterIsoSprite = getSprite(myOid()); var us :CharacterIsoSprite = getSprite(myOid());
if (us != null) { if (us != null) {
//TODO Path var path :TilePath = TilePath(getPath(us, loc.x, loc.y, false)); var path :LineSegmentPath = LineSegmentPath(getPath(us, lx, ly, false));
//TODO Path return (path == null) ? -1 : path.getFinalOrientation(); return (path == null) ? -1 : path.getFinalOrientation();
return -1;
} else { } else {
return -1; return -1;
} }
@@ -602,7 +604,7 @@ public class CrowdStageScenePanel extends StageScenePanel
return new CharacterIsoSprite(info.getBodyOid(), _metrics, createCharacter(info)); return new CharacterIsoSprite(info.getBodyOid(), _metrics, createCharacter(info));
} }
protected function createCharacter (info :OccupantInfo) :DisplayObject protected function createCharacter (info :OccupantInfo) :CharacterSprite
{ {
throw new Error("abstract"); throw new Error("abstract");
} }
@@ -735,12 +737,10 @@ public class CrowdStageScenePanel extends StageScenePanel
protected var _scObj :StageSceneObject; protected var _scObj :StageSceneObject;
protected var _vbounds :Rectangle;
/** Our sprite path velocity. */ /** Our sprite path velocity. */
// if we had more frames, maybe we could only update their // if we had more frames, maybe we could only update their
// location when their frame changed. Alas, we do not. // location when their frame changed. Alas, we do not.
protected static const SPRITE_PATH_VELOCITY :Number = 0.1; protected static const SPRITE_PATH_VELOCITY :Number = 0.0025;
} }
} }