Further whipping of dynamic clusters into shape.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2323 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: SpotSceneDirector.java,v 1.21 2003/02/12 07:23:31 mdb Exp $
|
||||
// $Id: SpotSceneDirector.java,v 1.22 2003/03/25 19:28:58 mdb Exp $
|
||||
|
||||
package com.threerings.whirled.spot.client;
|
||||
|
||||
@@ -177,7 +177,7 @@ public class SpotSceneDirector extends BasicDirector
|
||||
{
|
||||
// refuse if there's a pending location change or if we're already
|
||||
// at the specified location
|
||||
if (loc.equals(_location) || (_pendingLoc != null)) {
|
||||
if (loc.equivalent(_location) || (_pendingLoc != null)) {
|
||||
Log.info("Not going to " + loc + "; we're at " + _location +
|
||||
" and we're headed to " + _pendingLoc + ".");
|
||||
return;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: Location.java,v 1.6 2003/02/12 07:23:31 mdb Exp $
|
||||
// $Id: Location.java,v 1.7 2003/03/25 19:28:58 mdb Exp $
|
||||
|
||||
package com.threerings.whirled.spot.data;
|
||||
|
||||
@@ -75,6 +75,15 @@ public class Location extends SimpleStreamableObject
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Location equivalence means that the coordinates and orientation are
|
||||
* the same.
|
||||
*/
|
||||
public boolean equivalent (Location oloc)
|
||||
{
|
||||
return equals(oloc) && (orient == oloc.orient);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes a reasonable hashcode for location instances.
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: SpotSceneManager.java,v 1.28 2003/03/17 19:34:26 mdb Exp $
|
||||
// $Id: SpotSceneManager.java,v 1.29 2003/03/25 19:28:59 mdb Exp $
|
||||
|
||||
package com.threerings.whirled.spot.server;
|
||||
|
||||
@@ -337,14 +337,21 @@ public class SpotSceneManager extends SceneManager
|
||||
public boolean addBody (BodyObject body)
|
||||
{
|
||||
if (body instanceof ClusteredBodyObject) {
|
||||
// if they're already in the cluster, do nothing
|
||||
if (containsKey(body.getOid())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
put(body.getOid(), body);
|
||||
_cluster.occupants++;
|
||||
recomputeCenter();
|
||||
if (_clobj != null) {
|
||||
_ssobj.updateClusters(_cluster);
|
||||
_clobj.addToOccupants(body.getOid());
|
||||
((ClusteredBodyObject)body).setClusterOid(_clobj.getOid());
|
||||
_clobj.addToOccupants(body.getOid());
|
||||
_ssobj.updateClusters(_cluster);
|
||||
}
|
||||
|
||||
Log.info("Added " + body.who() + " to "+ this + ".");
|
||||
return true;
|
||||
|
||||
} else {
|
||||
@@ -362,16 +369,18 @@ public class SpotSceneManager extends SceneManager
|
||||
Log.warning("Requested to remove unknown body from cluster " +
|
||||
"[cloid=" + _clobj.getOid() +
|
||||
", size=" + size() + ", who=" + bodyOid + "].");
|
||||
} else {
|
||||
body.setClusterOid(-1);
|
||||
_cluster.occupants--;
|
||||
recomputeCenter();
|
||||
if (_clobj != null) {
|
||||
_clobj.removeFromOccupants(bodyOid);
|
||||
_ssobj.updateClusters(_cluster);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
body.setClusterOid(-1);
|
||||
_cluster.occupants--;
|
||||
recomputeCenter();
|
||||
if (_clobj != null) {
|
||||
_clobj.removeFromOccupants(bodyOid);
|
||||
_ssobj.updateClusters(_cluster);
|
||||
}
|
||||
Log.info("Removed " + bodyOid + " from "+ this + ".");
|
||||
|
||||
// if we've removed our last body; stick a fork in ourselves
|
||||
if (size() == 0) {
|
||||
destroy();
|
||||
@@ -388,10 +397,6 @@ public class SpotSceneManager extends SceneManager
|
||||
// keep this feller around
|
||||
_clobj = (ClusterObject)object;
|
||||
|
||||
// configure our cluster record and publish it
|
||||
_cluster.clusterOid = _clobj.getOid();
|
||||
_ssobj.addToClusters(_cluster);
|
||||
|
||||
// let any mapped users know about our cluster
|
||||
Iterator iter = values().iterator();
|
||||
while (iter.hasNext()) {
|
||||
@@ -400,6 +405,10 @@ public class SpotSceneManager extends SceneManager
|
||||
_clobj.addToOccupants(((BodyObject)body).getOid());
|
||||
}
|
||||
|
||||
// configure our cluster record and publish it
|
||||
_cluster.clusterOid = _clobj.getOid();
|
||||
_ssobj.addToClusters(_cluster);
|
||||
|
||||
// if we didn't manage to add our creating user when we first
|
||||
// started up, there's no point in our sticking around
|
||||
if (size() == 0) {
|
||||
@@ -420,6 +429,11 @@ public class SpotSceneManager extends SceneManager
|
||||
}
|
||||
}
|
||||
|
||||
public String toString ()
|
||||
{
|
||||
return "[cluster=" + _cluster + ", size=" + size() + "]";
|
||||
}
|
||||
|
||||
protected void recomputeCenter ()
|
||||
{
|
||||
int tx = 0, ty = 0, count = 0;
|
||||
@@ -437,16 +451,19 @@ public class SpotSceneManager extends SceneManager
|
||||
}
|
||||
}
|
||||
|
||||
// convert the center back to "location" coordinates
|
||||
coordsToLocation(tx/count, ty/count, _scratch);
|
||||
_cluster.x = _scratch.x;
|
||||
_cluster.y = _scratch.y;
|
||||
if (count > 1) {
|
||||
// convert the center back to "location" coordinates
|
||||
coordsToLocation(tx/count, ty/count, _scratch);
|
||||
_cluster.x = _scratch.x;
|
||||
_cluster.y = _scratch.y;
|
||||
}
|
||||
}
|
||||
|
||||
protected void destroy ()
|
||||
{
|
||||
Log.info("Cluster empty, going away " +
|
||||
"[cloid=" + _clobj.getOid() + "].");
|
||||
_ssobj.removeFromClusters(_cluster.getKey());
|
||||
CrowdServer.omgr.destroyObject(_clobj.getOid());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user