From cdec138fcb020730d7fb44cdff12984eb529ce7b Mon Sep 17 00:00:00 2001 From: Mike Thomas Date: Fri, 6 Aug 2010 05:23:48 +0000 Subject: [PATCH] Checkpoint commit wiring up a CrowdStageScenePanel that handles Occupant locations and making a sprite for them on the screen. Lots of TODOs still in this stuff, esp. related to Pathing. git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@965 ed5b42cb-e716-0410-a449-f6a68f950b19 --- .../threerings/miso/client/MisoScenePanel.as | 51 +++++++++++++++++-- .../com/threerings/miso/client/SceneBlock.as | 6 +++ src/as/com/threerings/miso/util/MisoUtil.as | 24 +++++++++ 3 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 src/as/com/threerings/miso/util/MisoUtil.as diff --git a/src/as/com/threerings/miso/client/MisoScenePanel.as b/src/as/com/threerings/miso/client/MisoScenePanel.as index a363de11..9d5289e0 100644 --- a/src/as/com/threerings/miso/client/MisoScenePanel.as +++ b/src/as/com/threerings/miso/client/MisoScenePanel.as @@ -87,6 +87,9 @@ public class MisoScenePanel extends Sprite _isoView.addEventListener(MouseEvent.CLICK, onClick); + _objScene = new IsoScene(); + _objScene.layoutRenderer = new ClassFactory(PrioritizedSceneLayoutRenderer); + addChild(_loading = createLoadingPanel()); } @@ -118,13 +121,27 @@ public class MisoScenePanel extends Sprite } public function onClick (event :MouseEvent) :void + { + // TODO - handle _hobject + handleMousePressed(null, event); + } + + public function handleMousePressed (hobject :Object, event :MouseEvent) :Boolean { var viewPt :Point = _isoView.globalToLocal(new Point(event.stageX, event.stageY)); moveBy(new Point(viewPt.x - _isoView.width / 2, viewPt.y - _isoView.height / 2)); + return true; } public function moveBy (pt :Point) :void { + // No scene model yet, just do it... + if (_model == null) { + _isoView.centerOnPt(new Pt(pt.x + _isoView.currentX, + pt.y + _isoView.currentY), false); + return; + } + if (_pendingMoveBy != null) { log.info("Already performing a move..."); return; @@ -330,9 +347,6 @@ public class MisoScenePanel extends Sprite // Clear it out... _isoView.removeAllScenes(); - _objScene = new IsoScene(); - _objScene.layoutRenderer = new ClassFactory(PrioritizedSceneLayoutRenderer); - refreshBaseBlockScenes(); } @@ -345,6 +359,37 @@ public class MisoScenePanel extends Sprite return null; } + // documentation inherited + public function canTraverse (traverser :Object, tx :int, ty :int) :Boolean + { + var block :SceneBlock = _blocks.get(SceneBlock.getBlockKey(tx, ty)); + return (block == null) ? canTraverseUnresolved(traverser, tx, ty) : + block.canTraverse(traverser, tx, ty); + } + + /** + * Derived classes can control whether or not we consider unresolved tiles to be traversable + * or not. + */ + protected function canTraverseUnresolved (traverser :Object, tx :int, ty :int) :Boolean + { + return false; + } + + /** + * Computes a path for the specified sprite to the specified tile coordinates. + * + * @param loose if true, an approximate path will be returned if a complete path cannot be + * located. This path will navigate the sprite "legally" as far as possible and then walk the + * sprite in a straight line to its final destination. This is generally only useful if the + * the path goes "off screen". + */ + public function getPath (sprite :Sprite, x :int, y :int, loose :Boolean) :Object // TODO Path + { + // TODO Path + return null; + } + protected var _model :MisoSceneModel; protected var _isoView :IsoView; diff --git a/src/as/com/threerings/miso/client/SceneBlock.as b/src/as/com/threerings/miso/client/SceneBlock.as index 1aceab2f..7c2529fe 100644 --- a/src/as/com/threerings/miso/client/SceneBlock.as +++ b/src/as/com/threerings/miso/client/SceneBlock.as @@ -209,6 +209,12 @@ public class SceneBlock } } + public function canTraverse (traverser :Object, tx :int, ty :int) :Boolean + { + // TODO Path + return true; + } + protected function noteTileToLoad () :void { _pendingCt++; diff --git a/src/as/com/threerings/miso/util/MisoUtil.as b/src/as/com/threerings/miso/util/MisoUtil.as new file mode 100644 index 00000000..f5feb053 --- /dev/null +++ b/src/as/com/threerings/miso/util/MisoUtil.as @@ -0,0 +1,24 @@ +package com.threerings.miso.util { + +import com.threerings.util.MathUtil; + +public class MisoUtil +{ + public static function fullToTile (fullCoord :int) :int + { + return MathUtil.floorDiv(fullCoord, FULL_TILE_FACTOR); + } + + public static function tileToFull (tileCoord :int, fine :int = 0) :int + { + return tileCoord * FULL_TILE_FACTOR + fine; + } + + public static function fullToFine (fullCoord :int) :int + { + return (fullCoord - (fullToTile(fullCoord) * FULL_TILE_FACTOR)); + } + + protected static const FULL_TILE_FACTOR :int = 100; +} +} \ No newline at end of file