Allow the minimum distance to be specified in computeEnteringLocation

git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@584 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
Charlie Groves
2008-04-22 17:35:21 +00:00
parent 4ca129e527
commit 99ee2f5a5f
@@ -406,13 +406,19 @@ public class StageSceneManager extends SpotSceneManager
", who=" + body.who() + "]."); ", who=" + body.who() + "].");
entry = _sscene.getDefaultEntrance(); entry = _sscene.getDefaultEntrance();
} }
return computeEnteringLocation(body, entry, 1);
}
/**
* Returns an entering location for body somewhere at least minDistance tiles away from entry.
*/
protected SceneLocation computeEnteringLocation (BodyObject body, Portal entry,
int minDistance)
{
MisoSceneMetrics metrics = StageSceneUtil.getMetrics(); MisoSceneMetrics metrics = StageSceneUtil.getMetrics();
SceneLocation loc = new SceneLocation( StageLocation sloc = (StageLocation)entry.getOppLocation();
entry.getOppLocation(), body.getOid()); int tx = MisoUtil.fullToTile(sloc.x), ty = MisoUtil.fullToTile(sloc.y);
StageLocation sloc = (StageLocation) loc.loc;
int tx = MisoUtil.fullToTile(sloc.x),
ty = MisoUtil.fullToTile(sloc.y);
int oidx = sloc.orient/2; int oidx = sloc.orient/2;
int lidx = (oidx+3)%4; // rotate to the left int lidx = (oidx+3)%4; // rotate to the left
int ridx = (oidx+1)%4; // rotate to the right int ridx = (oidx+1)%4; // rotate to the right
@@ -425,6 +431,10 @@ public class StageSceneManager extends SpotSceneManager
for (int fan = 1; fan < MAX_FAN; fan++) { for (int fan = 1; fan < MAX_FAN; fan++) {
tx += PORTAL_DX[oidx]; tx += PORTAL_DX[oidx];
ty += PORTAL_DY[oidx]; ty += PORTAL_DY[oidx];
if (fan < minDistance) {
// increment until we get to our min distance
continue;
}
// look in the center column // look in the center column
if (checkEntry(metrics, body, tx, ty, sloc)) { if (checkEntry(metrics, body, tx, ty, sloc)) {
@@ -460,8 +470,7 @@ public class StageSceneManager extends SpotSceneManager
ty = MisoUtil.fullToTile(sloc.y); ty = MisoUtil.fullToTile(sloc.y);
_loners.put(body.getOid(), new Rectangle(tx, ty, 1, 1)); _loners.put(body.getOid(), new Rectangle(tx, ty, 1, 1));
loc.loc = sloc; return new SceneLocation(sloc, body.getOid());
return loc;
} }
/** Helper function for {@link #computeEnteringLocation}. */ /** Helper function for {@link #computeEnteringLocation}. */
@@ -535,9 +544,7 @@ public class StageSceneManager extends SpotSceneManager
// now look to see if we just expanded our cluster over top of any // now look to see if we just expanded our cluster over top of any
// unsuspecting standers by and if so, attempt to subsume them // unsuspecting standers by and if so, attempt to subsume them
for (Iterator iter = _loners.keySet().iterator(); for (int bodyOid : _loners.keySet()) {
iter.hasNext(); ) {
int bodyOid = ((Integer)iter.next()).intValue();
// skip ourselves // skip ourselves
if (bodyOid == body.getOid()) { if (bodyOid == body.getOid()) {
continue; continue;
@@ -545,7 +552,7 @@ public class StageSceneManager extends SpotSceneManager
// do the right thing with a person standing right on the // do the right thing with a person standing right on the
// cluster (they're the person we're clustering with) // cluster (they're the person we're clustering with)
Rectangle trect = (Rectangle)_loners.get(bodyOid); Rectangle trect = _loners.get(bodyOid);
if (trect.equals(cl)) { if (trect.equals(cl)) {
continue; continue;
} }
@@ -560,8 +567,7 @@ public class StageSceneManager extends SpotSceneManager
} }
// make sure the subsumee exists // make sure the subsumee exists
final BodyObject bobj = (BodyObject) final BodyObject bobj = (BodyObject)StageServer.omgr.getObject(bodyOid);
StageServer.omgr.getObject(bodyOid);
if (bobj == null) { if (bobj == null) {
Log.warning("Can't subsume disappeared body " + Log.warning("Can't subsume disappeared body " +
"[where=" + where() + ", cluster=" + cl + "[where=" + where() + ", cluster=" + cl +
@@ -827,7 +833,7 @@ public class StageSceneManager extends SpotSceneManager
/** Rectangles containing a "footprint" for the users that aren't in /** Rectangles containing a "footprint" for the users that aren't in
* any clusters. */ * any clusters. */
protected HashIntMap _loners = new HashIntMap(); protected HashIntMap<Rectangle> _loners = new HashIntMap<Rectangle>();
/** Contains the (tile) coordinates of all of our portals. */ /** Contains the (tile) coordinates of all of our portals. */
protected HashSet _plocs = new HashSet(); protected HashSet _plocs = new HashSet();